Search in sources :

Example 1 with MutablePreferenceMap

use of com.liferay.faces.bridge.preference.internal.MutablePreferenceMap in project liferay-faces-bridge-impl by liferay.

the class ELResolverImpl method resolveVariable.

@Override
protected Object resolveVariable(ELContext elContext, String varName) {
    Object value = null;
    if (varName != null) {
        if (varName.equals(ACTION_REQUEST)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.ACTION_PHASE) {
                value = getPortletRequest(facesContext);
            } else {
                throw new ELException("Unable to get actionRequest during " + portletPhase);
            }
        } else if (varName.equals(ACTION_RESPONSE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.ACTION_PHASE) {
                value = getPortletResponse(facesContext);
            } else {
                throw new ELException("Unable to get actionResponse during " + portletPhase);
            }
        } else if (varName.equals(BRIDGE_CONFIG) || varName.equals(BRIDGE_CONTEXT) || varName.equals(PORTLET_CONFIG)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            ExternalContext externalContext = facesContext.getExternalContext();
            PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
            BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(portletRequest);
            if (varName.equals(BRIDGE_CONFIG)) {
                value = bridgeConfig;
            } else if (varName.equals(PORTLET_CONFIG)) {
                value = unwrapPortletConfig(RequestMapUtil.getPortletConfig(portletRequest));
            } else {
                value = new LegacyBridgeContext(bridgeConfig);
            }
        } else if (varName.equals(EVENT_REQUEST)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.EVENT_PHASE) {
                value = getPortletRequest(facesContext);
            } else {
                throw new ELException("Unable to get eventRequest during " + portletPhase);
            }
        } else if (varName.equals(EVENT_RESPONSE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.EVENT_PHASE) {
                value = getPortletResponse(facesContext);
            } else {
                throw new ELException("Unable to get eventResponse during " + portletPhase);
            }
        } else if (varName.equals(FLASH)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            value = getFlash(facesContext);
        } else if (varName.equals(HTTP_SESSION_SCOPE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            ExternalContext externalContext = facesContext.getExternalContext();
            PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
            PortletSession portletSession = (PortletSession) externalContext.getSession(true);
            PortletConfig portletConfig = RequestMapUtil.getPortletConfig(portletRequest);
            PortletContext portletContext = portletConfig.getPortletContext();
            boolean preferPreDestroy = PortletConfigParam.PreferPreDestroy.getBooleanValue(portletConfig);
            ContextMapFactory contextMapFactory = (ContextMapFactory) BridgeFactoryFinder.getFactory(portletContext, ContextMapFactory.class);
            value = contextMapFactory.getSessionScopeMap(portletContext, portletSession, PortletSession.APPLICATION_SCOPE, preferPreDestroy);
        } else if (varName.equals(MUTABLE_PORTLET_PREFERENCES_VALUES)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            PortletRequest portletRequest = getPortletRequest(facesContext);
            if (portletRequest != null) {
                value = new MutablePreferenceMap(portletRequest.getPreferences());
            }
        } else if (varName.equals(PORTLET_SESSION)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            value = facesContext.getExternalContext().getSession(true);
        } else if (varName.equals(PORTLET_SESSION_SCOPE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            value = facesContext.getExternalContext().getSessionMap();
        } else if (varName.equals(PORTLET_PREFERENCES)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            PortletRequest portletRequest = getPortletRequest(facesContext);
            if (portletRequest != null) {
                value = portletRequest.getPreferences();
            }
        } else if (varName.equals(PORTLET_PREFERENCES_VALUES)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            PortletRequest portletRequest = getPortletRequest(facesContext);
            if (portletRequest != null) {
                value = portletRequest.getPreferences().getMap();
            }
        } else if (varName.equals(RENDER_REQUEST)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if ((portletPhase == Bridge.PortletPhase.HEADER_PHASE) || (portletPhase == Bridge.PortletPhase.RENDER_PHASE)) {
                value = getPortletRequest(facesContext);
            } else {
                throw new ELException("Unable to get renderRequest during " + portletPhase);
            }
        } else if (varName.equals(RENDER_RESPONSE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if ((portletPhase == Bridge.PortletPhase.HEADER_PHASE) || (portletPhase == Bridge.PortletPhase.RENDER_PHASE)) {
                value = getPortletResponse(facesContext);
            } else {
                throw new ELException("Unable to get renderResponse during " + portletPhase);
            }
        } else if (varName.equals(RESOURCE_REQUEST)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.RESOURCE_PHASE) {
                value = getPortletRequest(facesContext);
            } else {
                throw new ELException("Unable to get resourceRequest during " + portletPhase);
            }
        } else if (varName.equals(RESOURCE_RESPONSE)) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            Bridge.PortletPhase portletPhase = BridgeUtil.getPortletRequestPhase(facesContext);
            if (portletPhase == Bridge.PortletPhase.RESOURCE_PHASE) {
                value = getPortletResponse(facesContext);
            } else {
                throw new ELException("Unable to get renderResponse during " + portletPhase);
            }
        } else {
            value = super.resolveVariable(elContext, varName);
        }
    }
    return value;
}
Also used : FacesContext(javax.faces.context.FacesContext) LegacyBridgeContext(com.liferay.faces.bridge.context.internal.LegacyBridgeContext) ContextMapFactory(com.liferay.faces.bridge.context.map.internal.ContextMapFactory) MutablePreferenceMap(com.liferay.faces.bridge.preference.internal.MutablePreferenceMap) PortletRequest(javax.portlet.PortletRequest) PortletSession(javax.portlet.PortletSession) ExternalContext(javax.faces.context.ExternalContext) PortletConfig(javax.portlet.PortletConfig) BridgeConfig(javax.portlet.faces.BridgeConfig) PortletContext(javax.portlet.PortletContext) ELException(javax.el.ELException) Bridge(javax.portlet.faces.Bridge)

Aggregations

LegacyBridgeContext (com.liferay.faces.bridge.context.internal.LegacyBridgeContext)1 ContextMapFactory (com.liferay.faces.bridge.context.map.internal.ContextMapFactory)1 MutablePreferenceMap (com.liferay.faces.bridge.preference.internal.MutablePreferenceMap)1 ELException (javax.el.ELException)1 ExternalContext (javax.faces.context.ExternalContext)1 FacesContext (javax.faces.context.FacesContext)1 PortletConfig (javax.portlet.PortletConfig)1 PortletContext (javax.portlet.PortletContext)1 PortletRequest (javax.portlet.PortletRequest)1 PortletSession (javax.portlet.PortletSession)1 Bridge (javax.portlet.faces.Bridge)1 BridgeConfig (javax.portlet.faces.BridgeConfig)1