Search in sources :

Example 6 with BridgeConfig

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

the class BridgeRequestAttributeListener method attributeAdded.

/**
 * This method is called after an attribute is added to the ServletRequest. Note that this should only get called
 * for remote WSRP portlets. For more info, see: http://issues.liferay.com/browse/FACES-146
 */
@Override
public void attributeAdded(ServletRequestAttributeEvent servletRequestAttributeEvent) {
    // NOTE: We only care about phases prior to the HEADER_PHASE because we're concerned here about managed beans
    // that get added to the request scope when the BridgeRequestScope begins. We're trying to provide those managed
    // beans with an opportunity to prepare for an unexpected invocation of their methods annotated with
    // @PreDestroy.
    ServletRequest servletRequest = servletRequestAttributeEvent.getServletRequest();
    PortletPhase phase = (PortletPhase) servletRequest.getAttribute(Bridge.PORTLET_LIFECYCLE_PHASE);
    // HEADER_PHASE, then
    if ((phase != null) && (phase != PortletPhase.HEADER_PHASE)) {
        // If the attribute being added is not excluded, then invoke all methods on the attribute value (class
        // instance) that are annotated with the BridgeRequestScopeAttributeAdded annotation.
        String attributeName = servletRequestAttributeEvent.getName();
        FacesContext facesContext = FacesContext.getCurrentInstance();
        BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(facesContext);
        Set<String> excludedRequestScopeAttributes = bridgeConfig.getExcludedRequestAttributes();
        if (!excludedRequestScopeAttributes.contains(attributeName)) {
            Object attributeValue = servletRequestAttributeEvent.getValue();
            logger.trace("Attribute added name=[{0}] value=[{1}]", attributeName, attributeValue);
            if (attributeValue != null) {
                Method[] methods = attributeValue.getClass().getMethods();
                if (methods != null) {
                    for (Method method : methods) {
                        if (method != null) {
                            if (method.isAnnotationPresent(BridgeRequestScopeAttributeAdded.class)) {
                                try {
                                    method.invoke(attributeValue);
                                } catch (Exception e) {
                                    logger.error(e);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ServletRequest(javax.servlet.ServletRequest) FacesContext(javax.faces.context.FacesContext) PortletPhase(javax.portlet.faces.Bridge.PortletPhase) BridgeConfig(javax.portlet.faces.BridgeConfig) Method(java.lang.reflect.Method)

Example 7 with BridgeConfig

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

the class ApplicationImpl method createComponent.

/**
 * This method provides the ability to supply an instance of the bridge API's {@link
 * PortletNamingContainerUIViewRoot} class which properly handles namespacing of "id" attributes for portlets.
 *
 * @see  Application#createComponent(String)
 */
@Override
@SuppressWarnings("unchecked")
public UIComponent createComponent(String componentType) throws FacesException {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (componentType.equals(UIViewRoot.COMPONENT_TYPE) && BridgeUtil.isPortletRequest(facesContext)) {
        // to cleanup @ViewScoped managed-beans.
        if (subscribeToEventsAtRuntime) {
            // order to ensure that it only happens once.
            synchronized (subscribeToEventsAtRuntime) {
                // Need to check again within the synchronization block, just in case.
                if (subscribeToEventsAtRuntime) {
                    BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(facesContext);
                    List<ConfiguredSystemEventListener> configuredSystemEventListeners = (List<ConfiguredSystemEventListener>) bridgeConfig.getAttributes().get(BridgeConfigAttributeMap.CONFIGURED_SYSTEM_EVENT_LISTENERS);
                    if (configuredSystemEventListeners != null) {
                        for (ConfiguredSystemEventListener configuredSystemEventListener : configuredSystemEventListeners) {
                            if (UIVIEWROOT_FQCN.equals(configuredSystemEventListener.getSourceClass())) {
                                subscribeToJSF2SystemEvent(configuredSystemEventListener);
                            }
                        }
                    }
                }
                subscribeToEventsAtRuntime = false;
            }
        }
        return new UIViewRootBridgeImpl();
    } else {
        return getWrapped().createComponent(componentType);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) UIViewRootBridgeImpl(com.liferay.faces.bridge.component.internal.UIViewRootBridgeImpl) BridgeConfig(javax.portlet.faces.BridgeConfig) List(java.util.List) ConfiguredSystemEventListener(com.liferay.faces.util.config.ConfiguredSystemEventListener)

Example 8 with BridgeConfig

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

the class ResourceInnerImpl method getRequestPath.

@Override
public String getRequestPath() {
    // Get the requestPath value from the wrapped resource.
    String wrappedRequestPath = wrappedResource.getRequestPath();
    FacesContext facesContext = FacesContext.getCurrentInstance();
    // append extension-mapped suffixes which have no meaning in a portlet environment.
    if (wrappedRequestPath != null) {
        if (wrappedRequestPath.contains(ResourceHandler.RESOURCE_IDENTIFIER)) {
            // If this resource request was initiated from a ResourceURL (not via the FacesServlet), then
            if (facesContext != null) {
                BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(facesContext);
                List<ConfiguredServletMapping> configuredFacesServletMappings = (List<ConfiguredServletMapping>) bridgeConfig.getAttributes().get(BridgeConfigAttributeMap.CONFIGURED_FACES_SERVLET_MAPPINGS);
                if (configuredFacesServletMappings != null) {
                    for (ConfiguredServletMapping configuredServletMapping : configuredFacesServletMappings) {
                        if (configuredServletMapping.isExtensionMapped()) {
                            String extension = configuredServletMapping.getExtension();
                            // Note: Both Mojarra and MyFaces construct a requestPath that looks something like
                            // "/javax.faces.resource/jsf.js.faces?ln=javax.faces" and so we look for the
                            // ".faces?" as an indicator that ".faces" needs to be removed from the requestPath.
                            String token = extension + "?";
                            int pos = wrappedRequestPath.indexOf(token);
                            // meaning in a portlet environment.
                            if (pos > 0) {
                                wrappedRequestPath = wrappedRequestPath.substring(0, pos) + wrappedRequestPath.substring(pos + extension.length());
                                logger.debug("Removed extension=[{0}] from requestPath=[{1}]", extension, wrappedRequestPath);
                                break;
                            } else // path, then
                            if (wrappedRequestPath.endsWith(extension)) {
                                if (extension.equals(EXTENSION_FACES) && wrappedRequestPath.endsWith(LIBRARY_NAME_JAVAX_FACES)) {
                                // Special case: Don't remove ".faces" if request path ends with "javax.faces"
                                // http://issues.liferay.com/browse/FACES-1202
                                } else {
                                    // Sometimes resources like the ICEfaces bridge.js file don't have a library
                                    // name (ln=) parameter and simply look like this:
                                    // /my-portlet/javax.faces.resource/bridge.js.faces
                                    wrappedRequestPath = wrappedRequestPath.substring(0, wrappedRequestPath.lastIndexOf(extension));
                                    logger.debug("Removed extension=[{0}] from requestPath=[{1}]", extension, wrappedRequestPath);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        // If the wrapped request path ends with "org.richfaces" then
        if (wrappedRequestPath.endsWith(ResourceRichFacesImpl.ORG_RICHFACES)) {
            // Check to see if the resource physically exists in the META-INF/resources/org.richfaces folder of the
            // RichFaces JAR. If it does, then this qualifies as a special case in which the
            // ResourceHandlerImpl#fixRichFacesImageURLs(FacesContext, String) method is unable to handle resources
            // such as "node_icon.gif" and the library name must be "org.richfaces.images" instead of
            // "org.richfaces".
            String resourcePath = "META-INF/resources/org.richfaces/" + getResourceName();
            URL resourceURL = getClass().getClassLoader().getResource(resourcePath);
            if (resourceURL != null) {
                wrappedRequestPath = wrappedRequestPath + ".images";
            }
        }
    }
    return wrappedRequestPath;
}
Also used : FacesContext(javax.faces.context.FacesContext) BridgeConfig(javax.portlet.faces.BridgeConfig) ArrayList(java.util.ArrayList) List(java.util.List) ConfiguredServletMapping(com.liferay.faces.util.config.ConfiguredServletMapping) URL(java.net.URL)

Example 9 with BridgeConfig

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

the class BridgeImpl method doFacesRequest.

@Override
public void doFacesRequest(RenderRequest renderRequest, RenderResponse renderResponse) throws BridgeDefaultViewNotSpecifiedException, BridgeUninitializedException, BridgeException {
    checkNull(renderRequest, renderResponse);
    if (initialized) {
        String nonFacesTargetPath = renderRequest.getParameter(Bridge.NONFACES_TARGET_PATH_PARAMETER);
        if (nonFacesTargetPath != null) {
            throw new BridgeNotAFacesRequestException(nonFacesTargetPath);
        }
        PortletConfig wrappedPortletConfig = BridgePortletConfigFactory.getPortletConfigInstance(portletConfig);
        BridgeConfig bridgeConfig = BridgeConfigFactory.getBridgeConfigInstance(wrappedPortletConfig);
        BridgePhase bridgePhase = new BridgePhaseRenderImpl(renderRequest, renderResponse, wrappedPortletConfig, bridgeConfig);
        bridgePhase.execute();
    } else {
        throw new BridgeUninitializedException();
    }
}
Also used : PortletConfig(javax.portlet.PortletConfig) BridgeNotAFacesRequestException(javax.portlet.faces.BridgeNotAFacesRequestException) BridgeConfig(javax.portlet.faces.BridgeConfig) BridgeUninitializedException(javax.portlet.faces.BridgeUninitializedException)

Example 10 with BridgeConfig

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

the class BridgeImpl method doFacesRequest.

@Override
public void doFacesRequest(EventRequest eventRequest, EventResponse eventResponse) throws BridgeUninitializedException, BridgeException {
    checkNull(eventRequest, eventResponse);
    if (initialized) {
        String nonFacesTargetPath = eventRequest.getParameter(Bridge.NONFACES_TARGET_PATH_PARAMETER);
        if (nonFacesTargetPath != null) {
            throw new BridgeNotAFacesRequestException(nonFacesTargetPath);
        }
        PortletConfig wrappedPortletConfig = BridgePortletConfigFactory.getPortletConfigInstance(portletConfig);
        BridgeConfig bridgeConfig = BridgeConfigFactory.getBridgeConfigInstance(wrappedPortletConfig);
        BridgePhase bridgePhase = new BridgePhaseEventImpl(eventRequest, eventResponse, wrappedPortletConfig, bridgeConfig);
        bridgePhase.execute();
    } else {
        throw new BridgeUninitializedException();
    }
}
Also used : PortletConfig(javax.portlet.PortletConfig) BridgeNotAFacesRequestException(javax.portlet.faces.BridgeNotAFacesRequestException) BridgeConfig(javax.portlet.faces.BridgeConfig) BridgeUninitializedException(javax.portlet.faces.BridgeUninitializedException)

Aggregations

BridgeConfig (javax.portlet.faces.BridgeConfig)14 PortletConfig (javax.portlet.PortletConfig)9 FacesContext (javax.faces.context.FacesContext)5 BridgeUninitializedException (javax.portlet.faces.BridgeUninitializedException)5 ExternalContext (javax.faces.context.ExternalContext)4 PortletRequest (javax.portlet.PortletRequest)3 BridgeNotAFacesRequestException (javax.portlet.faces.BridgeNotAFacesRequestException)3 List (java.util.List)2 PortletContext (javax.portlet.PortletContext)2 PortletSession (javax.portlet.PortletSession)2 UIViewRootBridgeImpl (com.liferay.faces.bridge.component.internal.UIViewRootBridgeImpl)1 IncongruityContext (com.liferay.faces.bridge.context.internal.IncongruityContext)1 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 BridgeRequestScope (com.liferay.faces.bridge.scope.internal.BridgeRequestScope)1 ConfiguredServletMapping (com.liferay.faces.util.config.ConfiguredServletMapping)1 ConfiguredSystemEventListener (com.liferay.faces.util.config.ConfiguredSystemEventListener)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1