Search in sources :

Example 1 with BridgePublicRenderParameterHandler

use of javax.portlet.faces.BridgePublicRenderParameterHandler in project liferay-faces-bridge-impl by liferay.

the class InitMethodTestPortlet method init.

public void init(PortletConfig portletConfig) throws PortletException {
    super.init(portletConfig);
    boolean bTestPassed = true;
    StringBuilder msg = new StringBuilder();
    // getBridgeClassName test
    if (bGetBridgeClassNameCalled) {
        msg.append("getBridgeClassName() called.");
    } else {
        bTestPassed = false;
        msg.append("getBridgeClassName() not called.");
    }
    // to those returned from getExcludedRequestAttributes.
    if (bGetExcludedRequestAttributesCalled) {
        msg.append("  getExcludedRequestAttributes() called.");
    } else {
        bTestPassed = false;
        msg.append("  getExcludedRequestAttributes() not called.");
    }
    List<String> attrs = (List<String>) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".excludedRequestAttributes");
    for (String expectedAttr : mExcludedRequestAttrs) {
        if (!attrs.contains(expectedAttr)) {
            bTestPassed = false;
            msg.append("  Missing excluded request attribute ").append(expectedAttr).append(".");
        }
    }
    // to the same value as isPreserveActionParameters.
    if (bIsPreserveActionParametersCalled) {
        msg.append("  isPreserveActionParameters() called.");
    } else {
        bTestPassed = false;
        msg.append("  isPreserveActionParameters() not called.");
    }
    Boolean contextValue = (Boolean) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".preserveActionParams");
    if (!Boolean.valueOf(bIsPreserveActionParametersResult).equals(contextValue)) {
        msg.append("  Value of the preserveActionParams context attribute is ").append(contextValue).append(", expected value is ").append(Boolean.valueOf(bIsPreserveActionParametersResult)).append(".");
        bTestPassed = false;
    }
    // getDefaultViewIdMap.
    if (bGetDefaultViewIdMapCalled) {
        msg.append("  getDefaultViewIdMapCalled() called.");
    } else {
        msg.append("  getDefaultViewIdMapCalled() not called.");
        bTestPassed = false;
    }
    Map viewIdMapAttr = (Map) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".defaultViewIdMap");
    if (!mDefaultViewIdMap.isEmpty()) {
        if (viewIdMapAttr == null) {
            msg.append("  Portlet context attribute javax.portlet.faces.").append(getPortletName()).append(".defaultViewIdMap has not been set.");
        } else {
            for (String mode : mDefaultViewIdMap.keySet()) {
                if (viewIdMapAttr.get(mode) == null) {
                    bTestPassed = false;
                    msg.append("  Mode, ").append(mode).append(", has been set in the map returned by getDefaultViewIdMap but has not been set in javax.portlet.faces.").append(getPortletName()).append(".defaultViewIdMap");
                }
            }
        }
    } else {
        if (viewIdMapAttr != null) {
            msg.append("  Portlet context attribute javax.portlet.faces.").append(getPortletName()).append(".defaultViewIdMap has been set while the getDefaultViewIdMap returns null.");
            bTestPassed = false;
        }
    }
    // to the same value as mEventHandler.
    if (bGetBridgeEventHandlerCalled) {
        msg.append("  getBridgeEventHandler() called.");
    } else {
        bTestPassed = false;
        msg.append("  getBridgeEventHandler() not called.");
    }
    BridgeEventHandler eventHandler = (BridgeEventHandler) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".bridgeEventHandler");
    if (((eventHandler == null) && (mEventHandler != null)) || ((mEventHandler == null) && (eventHandler != null)) || (!mEventHandler.equals(eventHandler))) {
        msg.append("  Value of the bridgeEventHandler context attribute is ").append(eventHandler).append(", expected value is ").append(mEventHandler).append(".");
        bTestPassed = false;
    }
    // to the same value as mPRPHandler.
    if (bGetBridgePRPHandlerCalled) {
        msg.append("  getBridgePublicRenderParameterHandler() called.");
    } else {
        bTestPassed = false;
        msg.append("  getBridgePublicRenderParameterHandler() not called.");
    }
    BridgePublicRenderParameterHandler prpHandler = (BridgePublicRenderParameterHandler) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".bridgePublicRenderParameterHandler");
    if (((prpHandler == null) && (mPRPhandler != null)) || ((mPRPhandler == null) && (prpHandler != null)) || (!mPRPhandler.equals(prpHandler))) {
        msg.append("  Value of the bridgePublicRenderParameterHandler context attribute is ").append(prpHandler).append(", expected value is ").append(mPRPhandler).append(".");
        bTestPassed = false;
    }
    // to the same value as mDefaultRenderKitId.
    if (bGetDefaultRenderKitIdCalled) {
        msg.append("  getDefaultRenderKitId() called.");
    } else {
        bTestPassed = false;
        msg.append("  getDefaultRenderKitId() not called.");
    }
    String defaultRenderKitId = (String) getPortletContext().getAttribute("javax.portlet.faces." + getPortletName() + ".defaultRenderKitId");
    if (((defaultRenderKitId == null) && (mDefaultRenderKitId != null)) || ((mDefaultRenderKitId == null) && (defaultRenderKitId != null)) || (!mDefaultRenderKitId.equals(defaultRenderKitId))) {
        msg.append("  Value of the defaultRenderKitId context attribute is ").append(defaultRenderKitId).append(", expected value is ").append(mDefaultRenderKitId).append(".");
        bTestPassed = false;
    }
    if (bTestPassed) {
        getPortletContext().setAttribute(TEST_PASS_PREFIX + getPortletName(), msg.toString());
    } else {
        getPortletContext().setAttribute(TEST_FAIL_PREFIX + getPortletName(), msg.toString());
    }
}
Also used : BridgeEventHandler(javax.portlet.faces.BridgeEventHandler) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) BridgePublicRenderParameterHandler(javax.portlet.faces.BridgePublicRenderParameterHandler)

Example 2 with BridgePublicRenderParameterHandler

use of javax.portlet.faces.BridgePublicRenderParameterHandler in project liferay-faces-bridge-impl by liferay.

the class BridgePublicRenderParameterHandlerFactoryImpl method getBridgePublicRenderParameterHandler.

@Override
public BridgePublicRenderParameterHandler getBridgePublicRenderParameterHandler(PortletConfig portletConfig) {
    BridgePublicRenderParameterHandler bridgePublicRenderParameterHandler = null;
    // TCK: initMethodTest
    String bridgePublicRenderParameterHandlerClass = portletConfig.getInitParameter("javax.portlet.faces.bridgePublicRenderParameterHandler");
    if (bridgePublicRenderParameterHandlerClass != null) {
        try {
            Class<?> clazz = TCCLUtil.loadClassFromContext(getClass(), bridgePublicRenderParameterHandlerClass);
            bridgePublicRenderParameterHandler = (BridgePublicRenderParameterHandler) clazz.newInstance();
        } catch (Exception e) {
            logger.error(e);
        }
    }
    return bridgePublicRenderParameterHandler;
}
Also used : BridgePublicRenderParameterHandler(javax.portlet.faces.BridgePublicRenderParameterHandler)

Example 3 with BridgePublicRenderParameterHandler

use of javax.portlet.faces.BridgePublicRenderParameterHandler in project liferay-faces-bridge-impl by liferay.

the class IPCPhaseListener method processIncomingPublicRenderParameters.

/**
 * This method processes the "incoming" Public Render Parameters in accordance with Section 5.3.2 of the Spec.
 */
public void processIncomingPublicRenderParameters(FacesContext facesContext) {
    try {
        // since this phase listener is being executed within the portlet lifecycle.
        if (facesContext != null) {
            // Section 5.3.2 requires the phase listener to inject the public render parameters into the
            // Model concern of the MVC design pattern (as in JSF model managed-beans) after RESTORE_VIEW
            // phase completes. This is accomplished below by evaluating the EL expressions found in the
            // <model-el>...</model-el> section of the WEB-INF/faces-config.xml file.
            ExternalContext externalContext = facesContext.getExternalContext();
            PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
            BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(portletRequest);
            Map<String, String[]> publicParameterMappings = bridgeConfig.getPublicParameterMappings();
            if (publicParameterMappings != null) {
                boolean invokeHandler = false;
                PortletConfig portletConfig = RequestMapUtil.getPortletConfig(portletRequest);
                String portletName = portletConfig.getPortletName();
                Map<String, String[]> publicParameterMap = portletRequest.getPublicParameterMap();
                Set<String> publicRenderParameterNames = publicParameterMappings.keySet();
                // For each of the public render parameters found in the WEB-INF/faces-config.xml file:
                for (String prefixedParameterName : publicRenderParameterNames) {
                    String[] modelExpressions = publicParameterMappings.get(prefixedParameterName);
                    if (modelExpressions != null) {
                        String parameterPrefix;
                        String nonPrefixedParameterName;
                        int colonPos = prefixedParameterName.indexOf(":");
                        if (colonPos > 0) {
                            parameterPrefix = prefixedParameterName.substring(0, colonPos);
                            nonPrefixedParameterName = prefixedParameterName.substring(colonPos + 1);
                        } else {
                            parameterPrefix = null;
                            nonPrefixedParameterName = prefixedParameterName;
                        }
                        if (publicParameterMap.containsKey(nonPrefixedParameterName)) {
                            for (String originalModelEL : modelExpressions) {
                                String[] parameterValues = publicParameterMap.get(nonPrefixedParameterName);
                                String parameterValue = null;
                                if ((parameterValues != null) && (parameterValues.length > 0)) {
                                    parameterValue = parameterValues[0];
                                }
                                PublicRenderParameter publicRenderParameter = new PublicRenderParameterImpl(parameterPrefix, parameterValue, originalModelEL, portletName);
                                if (logger.isTraceEnabled()) {
                                    logger.trace("portletName=[{0}] public render parameter=[{1}] originalModelEL=[{2}] modifiedModelEL=[{3}] isForThisPortlet=[{4}]", portletName, nonPrefixedParameterName, originalModelEL, publicRenderParameter.getModifiedModelEL(), publicRenderParameter.isForThisPortlet());
                                }
                                if (publicRenderParameter.isForThisPortlet()) {
                                    logger.debug("Injecting render parameter=[{0}] value=[{1}] into expression=[{2}]", nonPrefixedParameterName, parameterValue, publicRenderParameter.getModifiedModelEL());
                                    invokeHandler = publicRenderParameter.injectIntoModel(facesContext);
                                } else {
                                    logger.debug("NOT injecting render parameter=[{0}] value=[{1}] into expression=[{2}] because it is NOT for this portletName=[{3}]", nonPrefixedParameterName, parameterValue, publicRenderParameter.getModifiedModelEL(), portletName);
                                }
                            }
                        } else {
                            logger.debug("NOT injecting render parameter=[{0}] because it is not found in the public parameter map", nonPrefixedParameterName);
                        }
                    }
                }
                // processing that might be necessary.
                if (invokeHandler) {
                    String bridgePublicRenderParameterHandlerAttributeName = Bridge.BRIDGE_PACKAGE_PREFIX + portletName + "." + Bridge.BRIDGE_PUBLIC_RENDER_PARAMETER_HANDLER;
                    logger.trace("bridgePublicRenderParameterHandlerAttributeName=[{0}]", bridgePublicRenderParameterHandlerAttributeName);
                    BridgePublicRenderParameterHandler bridgePublicRenderParameterHandler = (BridgePublicRenderParameterHandler) externalContext.getApplicationMap().get(bridgePublicRenderParameterHandlerAttributeName);
                    if (bridgePublicRenderParameterHandler == null) {
                        bridgePublicRenderParameterHandler = BridgePublicRenderParameterHandlerFactory.getBridgePublicRenderParameterHandlerInstance(portletConfig);
                    }
                    if (bridgePublicRenderParameterHandler != null) {
                        logger.debug("Invoking {0} for class=[{1}]", bridgePublicRenderParameterHandler, bridgePublicRenderParameterHandler.getClass());
                        bridgePublicRenderParameterHandler.processUpdates(facesContext);
                    }
                }
            }
        }
    } catch (Exception e) {
        // There's no point in throwing a RuntimeException of any kind like FacesException because the Faces
        // runtime will swallow it. So the best we can do is log the exception.
        logger.error(e);
    }
}
Also used : BridgePublicRenderParameterHandler(javax.portlet.faces.BridgePublicRenderParameterHandler) PortletRequest(javax.portlet.PortletRequest) ExternalContext(javax.faces.context.ExternalContext) PortletConfig(javax.portlet.PortletConfig) BridgeConfig(javax.portlet.faces.BridgeConfig)

Aggregations

BridgePublicRenderParameterHandler (javax.portlet.faces.BridgePublicRenderParameterHandler)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ExternalContext (javax.faces.context.ExternalContext)1 PortletConfig (javax.portlet.PortletConfig)1 PortletRequest (javax.portlet.PortletRequest)1 BridgeConfig (javax.portlet.faces.BridgeConfig)1 BridgeEventHandler (javax.portlet.faces.BridgeEventHandler)1