Search in sources :

Example 1 with ContextMapFactory

use of com.liferay.faces.bridge.context.map.internal.ContextMapFactory 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)

Example 2 with ContextMapFactory

use of com.liferay.faces.bridge.context.map.internal.ContextMapFactory in project liferay-faces-bridge-impl by liferay.

the class FileUploadRendererPortletImpl method decode.

@Override
public void decode(FacesContext facesContext, UIComponent uiComponent) {
    ExternalContext externalContext = facesContext.getExternalContext();
    ClientDataRequest clientDataRequest = (ClientDataRequest) externalContext.getRequest();
    ContextMapFactory contextMapFactory = (ContextMapFactory) FactoryExtensionFinder.getFactory(externalContext, ContextMapFactory.class);
    Map<String, List<UploadedFile>> uploadedFileMap = (Map<String, List<UploadedFile>>) contextMapFactory.getUploadedFileMap(clientDataRequest);
    if (!uploadedFileMap.isEmpty()) {
        try {
            externalContext.setRequest(new HttpServletRequestFileUploadAdapter(clientDataRequest, uploadedFileMap, externalContext));
            super.decode(facesContext, uiComponent);
        } finally {
            externalContext.setRequest(clientDataRequest);
        }
    }
}
Also used : ClientDataRequest(javax.portlet.ClientDataRequest) ContextMapFactory(com.liferay.faces.bridge.context.map.internal.ContextMapFactory) UploadedFile(com.liferay.faces.bridge.model.UploadedFile) ExternalContext(javax.faces.context.ExternalContext) List(java.util.List) Map(java.util.Map)

Example 3 with ContextMapFactory

use of com.liferay.faces.bridge.context.map.internal.ContextMapFactory in project liferay-faces-bridge-impl by liferay.

the class InputFileRenderer method getUploadedFileMap.

/* package-private */
static Map<String, List<UploadedFile>> getUploadedFileMap(FacesContext facesContext) {
    ExternalContext externalContext = facesContext.getExternalContext();
    PortletContext portletContext = (PortletContext) externalContext.getContext();
    ContextMapFactory contextMapFactory = (ContextMapFactory) BridgeFactoryFinder.getFactory(portletContext, ContextMapFactory.class);
    PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
    return contextMapFactory.getUploadedFileMap(portletRequest);
}
Also used : ContextMapFactory(com.liferay.faces.bridge.context.map.internal.ContextMapFactory) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) PortletContext(javax.portlet.PortletContext)

Aggregations

ContextMapFactory (com.liferay.faces.bridge.context.map.internal.ContextMapFactory)3 ExternalContext (javax.faces.context.ExternalContext)3 PortletContext (javax.portlet.PortletContext)2 PortletRequest (javax.portlet.PortletRequest)2 LegacyBridgeContext (com.liferay.faces.bridge.context.internal.LegacyBridgeContext)1 UploadedFile (com.liferay.faces.bridge.model.UploadedFile)1 MutablePreferenceMap (com.liferay.faces.bridge.preference.internal.MutablePreferenceMap)1 List (java.util.List)1 Map (java.util.Map)1 ELException (javax.el.ELException)1 FacesContext (javax.faces.context.FacesContext)1 ClientDataRequest (javax.portlet.ClientDataRequest)1 PortletConfig (javax.portlet.PortletConfig)1 PortletSession (javax.portlet.PortletSession)1 Bridge (javax.portlet.faces.Bridge)1 BridgeConfig (javax.portlet.faces.BridgeConfig)1