Search in sources :

Example 11 with Product

use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-impl by liferay.

the class ResourceRendererBridgeImpl method encodeEnd.

@Override
public void encodeEnd(FacesContext facesContext, UIComponent uiComponentResource) throws IOException {
    ResponseWriter responseWriter = null;
    boolean ajaxRequest = facesContext.getPartialViewContext().isAjaxRequest();
    ExternalContext externalContext = facesContext.getExternalContext();
    final Product BOOTSFACES = ProductFactory.getProductInstance(externalContext, Product.Name.BOOTSFACES);
    final boolean BOOTSFACES_DETECTED = BOOTSFACES.isDetected();
    // If this is taking place during an Ajax request, then:
    if (ajaxRequest && (RenderKitUtil.isScriptResource(uiComponentResource, BOOTSFACES_DETECTED) || RenderKitUtil.isStyleSheetResource(uiComponentResource, BOOTSFACES_DETECTED))) {
        // Set a custom response writer that doesn't escape ampersands from URLs.
        responseWriter = facesContext.getResponseWriter();
        facesContext.setResponseWriter(new ResponseWriterResourceImpl(facesContext, responseWriter));
    }
    // Ask the wrapped renderer to encode the script.
    super.encodeEnd(facesContext, uiComponentResource);
    if (responseWriter != null) {
        // Restore the original response writer.
        facesContext.setResponseWriter(responseWriter);
    }
}
Also used : ResponseWriter(javax.faces.context.ResponseWriter) ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product)

Example 12 with Product

use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-impl by liferay.

the class BridgePortletRequestFactoryTCKResinImpl method isResinDetected.

@Override
protected boolean isResinDetected(PortletConfig portletConfig) {
    PortletContext portletContext = portletConfig.getPortletContext();
    ProductFactory productFactory = (ProductFactory) BridgeFactoryFinder.getFactory(portletContext, ProductFactory.class);
    final Product RESIN = productFactory.getProductInfo(Product.Name.RESIN);
    return RESIN.isDetected();
}
Also used : ProductFactory(com.liferay.faces.util.product.ProductFactory) Product(com.liferay.faces.util.product.Product) PortletContext(javax.portlet.PortletContext)

Example 13 with Product

use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-impl by liferay.

the class ViewHandlerCompatImpl method getRedirectURL.

@Override
public String getRedirectURL(FacesContext facesContext, String viewId, Map<String, List<String>> parameters, boolean includeViewParams) {
    PortletPhase portletRequestPhase = BridgeUtil.getPortletRequestPhase(facesContext);
    ExternalContext externalContext = facesContext.getExternalContext();
    // Determine whether or not it is necessary to work-around the patch applied to Mojarra in JAVASERVERFACES-3023.
    final Product MOJARRA = ProductFactory.getProductInstance(externalContext, Product.Name.MOJARRA);
    boolean workaroundMojarra = (MOJARRA.isDetected()) && ((portletRequestPhase == Bridge.PortletPhase.ACTION_PHASE) || (portletRequestPhase == Bridge.PortletPhase.EVENT_PHASE));
    Map<String, Object> requestMap = externalContext.getRequestMap();
    if (workaroundMojarra) {
        requestMap.put(BridgeExt.RESPONSE_CHARACTER_ENCODING, "UTF-8");
    }
    String redirectURL = super.getRedirectURL(facesContext, viewId, parameters, includeViewParams);
    if (workaroundMojarra) {
        requestMap.remove(BridgeExt.RESPONSE_CHARACTER_ENCODING);
    }
    return redirectURL;
}
Also used : PortletPhase(javax.portlet.faces.Bridge.PortletPhase) ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product)

Example 14 with Product

use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-impl by liferay.

the class ViewDeclarationLanguageBridgeJspImpl method buildView.

@Override
public void buildView(FacesContext facesContext, UIViewRoot uiViewRoot) throws IOException {
    ExternalContext externalContext = facesContext.getExternalContext();
    ProductFactory productFactory = (ProductFactory) FactoryExtensionFinder.getFactory(externalContext, ProductFactory.class);
    final Product MYFACES = productFactory.getProductInfo(Product.Name.MYFACES);
    final boolean MYFACES_DETECTED = MYFACES.isDetected();
    PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
    PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
    // adapter that implements HttpServletRequest.
    if (MYFACES_DETECTED) {
        if (portletRequest instanceof HeaderRequest) {
            String requestCharacterEncoding = externalContext.getRequestCharacterEncoding();
            externalContext.setRequest(new HeaderRequestHttpServletAdapter((HeaderRequest) portletRequest, requestCharacterEncoding));
        } else if (portletRequest instanceof ResourceRequest) {
            externalContext.setRequest(new ResourceRequestHttpServletAdapter((ResourceRequest) portletRequest));
        }
    }
    final Product MOJARRA = productFactory.getProductInfo(Product.Name.MOJARRA);
    final boolean MOJARRA_DETECTED = MOJARRA.isDetected();
    // PortletResponse with an adapter that implements HttpServletResponse.
    if (MOJARRA_DETECTED || MYFACES_DETECTED) {
        if (portletResponse instanceof HeaderResponse) {
            externalContext.setResponse(new HeaderResponseHttpServletAdapter((HeaderResponse) portletResponse));
        } else if (portletResponse instanceof ResourceResponse) {
            externalContext.setResponse(new ResourceResponseHttpServletAdapter((ResourceResponse) portletResponse));
        }
    }
    // Delegate
    super.buildView(facesContext, uiViewRoot);
    // If Mojarra or MyFaces is detected, then un-decorate the PortletRequest.
    if (MOJARRA_DETECTED || MYFACES_DETECTED) {
        externalContext.setResponse(portletResponse);
    }
    // If MyFaces is detected, then un-decorate the PortletResponse.
    if (MYFACES_DETECTED) {
        externalContext.setRequest(portletRequest);
    }
}
Also used : ProductFactory(com.liferay.faces.util.product.ProductFactory) ResourceResponseHttpServletAdapter(com.liferay.faces.bridge.filter.internal.ResourceResponseHttpServletAdapter) PortletResponse(javax.portlet.PortletResponse) Product(com.liferay.faces.util.product.Product) ResourceRequestHttpServletAdapter(com.liferay.faces.bridge.filter.internal.ResourceRequestHttpServletAdapter) HeaderResponseHttpServletAdapter(com.liferay.faces.bridge.filter.internal.HeaderResponseHttpServletAdapter) HeaderResponse(javax.portlet.HeaderResponse) PortletRequest(javax.portlet.PortletRequest) HeaderRequestHttpServletAdapter(com.liferay.faces.bridge.filter.internal.HeaderRequestHttpServletAdapter) ResourceResponse(javax.portlet.ResourceResponse) ExternalContext(javax.faces.context.ExternalContext) HeaderRequest(javax.portlet.HeaderRequest) ResourceRequest(javax.portlet.ResourceRequest)

Example 15 with Product

use of com.liferay.faces.util.product.Product in project liferay-faces-bridge-impl by liferay.

the class BridgePhaseResourceImpl method execute.

@Override
public void execute() throws BridgeDefaultViewNotSpecifiedException, BridgeException {
    logger.debug(Logger.SEPARATOR);
    logger.debug("execute(ResourceRequest, ResourceResponse) portletName=[{0}]", portletName);
    try {
        init(resourceRequest, resourceResponse, Bridge.PortletPhase.RESOURCE_PHASE);
        // resource, then
        if (isJSF2ResourceRequest(facesContext)) {
            logger.debug("Detected JSF2 resource request");
            // Ask the Faces resource handler to copy the contents of the resource to the response.
            handleJSF2ResourceRequest(facesContext);
        } else if ((resourceRequest.getResourceID() != null) && !resourceRequest.getResourceID().equals("wsrp")) {
            logger.debug("Detected non-Faces resource");
            String resourceId = resourceRequest.getResourceID();
            String autoResourceDispatch = portletConfig.getInitParameter("javax.portlet.automaticResourceDispatching");
            if ((autoResourceDispatch != null) && autoResourceDispatch.equalsIgnoreCase("true")) {
                ExternalContext externalContext = facesContext.getExternalContext();
                ResourceValidator resourceValidator = ResourceValidatorFactory.getResourceValidatorInstance(externalContext);
                // resource.
                if (resourceValidator.containsBannedPath(resourceId)) {
                    // Simulate Liferay Portal's behavior for containers like Pluto
                    logger.warn("Invalid request for resource with banned path: resourceId=[{0}]", resourceId);
                    externalContext.setResponseStatus(HttpServletResponse.SC_OK);
                } else // serve the resource.
                if (resourceValidator.isBannedSequence(resourceId)) {
                    logger.warn("Invalid request for resource with banned sequence: resourceId=[{0}]", resourceId);
                    externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                } else // Otherwise, if the resourceId targets a Facelet document, then do not serve the resource.
                if (resourceValidator.isFaceletDocument(facesContext, resourceId)) {
                    logger.warn("Invalid request for Facelet document: resourceId=[{0}]", resourceId);
                    externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                } else // Otherwise,
                {
                    // Sanitize the resource path by removing special characters that indicate URL fragments, URL
                    // query-strings, etc.
                    String resourcePath = resourceId;
                    for (String urlSeparatorChar : URL_SEPARATOR_CHARS) {
                        int pos = resourcePath.indexOf(urlSeparatorChar);
                        if (pos > 0) {
                            resourcePath = resourcePath.substring(0, pos);
                        }
                    }
                    // has been enforced.
                    if (resourcePath.trim().length() == 0) {
                        final Product LIFERAY_PORTAL = ProductFactory.getProductInstance(externalContext, Product.Name.LIFERAY_PORTAL);
                        if (LIFERAY_PORTAL.isDetected()) {
                            logger.warn("Invalid request for resourceId=[] possibly due to Liferay Portal enforcing the portlet.resource.id.banned.paths.regexp property.");
                        } else {
                            logger.warn("Invalid request for resourceId=[].");
                            externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                        }
                    } else // Otherwise,
                    {
                        // portlet, then do not serve the resource.
                        if (resourceValidator.isSelfReferencing(facesContext, resourcePath)) {
                            logger.warn("Invalid request for resource that is self-referencing: resourceId=[{0}]", resourceId);
                            externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                        } else // Otherwise,
                        {
                            // If the resourceId maps to the FacesServlet, then do not serve the resource.
                            boolean mappedToFacesServlet = false;
                            ConfiguredServletMapping explicitFacesServletExtensionMapping = getExplicitFacesServletExtensionMapping(resourcePath);
                            if (explicitFacesServletExtensionMapping != null) {
                                logger.warn("Invalid request for resource that is EXPLICITLY extension-mapped to the FacesServlet: resourceId=[{0}] resourcePath=[{1}] servlet-mapping extension=[{2}]", resourceId, resourcePath, explicitFacesServletExtensionMapping.getExtension());
                                mappedToFacesServlet = true;
                                externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                            } else {
                                ConfiguredServletMapping facesServletPathMapping = getFacesServletPathMapping(resourceId);
                                if (facesServletPathMapping != null) {
                                    logger.warn("Invalid request for resource that is path-mapped to the FacesServlet: resourceId=[{0}] resourcePath=[{1}] servlet-mapping url-pattern=[{2}]", resourceId, resourcePath, facesServletPathMapping.getUrlPattern());
                                    mappedToFacesServlet = true;
                                    externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                                }
                            }
                            // Otherwise, attempt to serve the resource.
                            if (!mappedToFacesServlet) {
                                PortletRequestDispatcher portletRequestDispatcher = portletContext.getRequestDispatcher(resourceId);
                                if (portletRequestDispatcher != null) {
                                    portletRequestDispatcher.forward(resourceRequest, resourceResponse);
                                } else {
                                    logger.warn("Request for non-Faces resource=[{0}] but request dispatcher was null.", resourceId);
                                    externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
                                }
                            }
                        }
                    }
                }
            } else {
                logger.warn("Request for non-Faces resource=[{0}] but automatic dispatching is disabled.", resourceId);
            }
        } else // Otherwise, must be an Ajax (partial-submit) request. Though technically a postback type of request,
        // Ajax requests also utilize the portlet RESOURCE_PHASE. Therefore treat it like a postback, and
        // execute the entire Faces lifecycle: RESTORE_VIEW, APPLY_REQUEST_VALUES, PROCESS_VALIDATIONS,
        // UPDATE_MODEL, INVOKE_APPLICATION.
        {
            ExternalContext externalContext = facesContext.getExternalContext();
            if (logger.isDebugEnabled()) {
                String facesAjaxParameter = externalContext.getRequestParameterMap().get(Bridge.FACES_AJAX_PARAMETER);
                if (BooleanHelper.isTrueToken(facesAjaxParameter)) {
                    logger.debug("Detected Ajax ResourceRequest");
                } else {
                    logger.debug("Detected Non-Ajax ResourceRequest");
                }
            }
            String viewId = getFacesViewId(externalContext);
            logger.debug("Running Faces lifecycle for viewId=[{0}]", viewId);
            // Attach the JSF 2.2 client window to the JSF lifecycle so that Faces Flows can be utilized.
            attachClientWindowToLifecycle(facesContext, facesLifecycle);
            // Execute the JSF lifecycle.
            facesLifecycle.execute(facesContext);
            // Also execute the RENDER_RESPONSE phase of the Faces lifecycle, which will ultimately return a
            // DOM-update back to the jsf.js Javascript code that issued the XmlHttpRequest in the first place.
            facesLifecycle.render(facesContext);
            // "javax.portlet.faces.BRIDGE_REQUEST_SCOPE_AJAX_ENABLED" configuration parameter, then
            if (bridgeRequestScope != null) {
                // PROPOSED-FOR-BRIDGE3-API: https://issues.apache.org/jira/browse/PORTLETBRIDGE-202
                bridgeRequestScope.setPortletMode(resourceRequest.getPortletMode());
                // TCK: nonFacesResourceTest
                // TCK: resourceAttrRetainedAfterRedisplayPPRTest -- Preserve the non-excluded request
                // attributes in the BridgeRequestScope so that they can be restored in subsequent render requests.
                bridgeRequestScope.saveState(facesContext);
                maintainBridgeRequestScope(resourceRequest, resourceResponse, BridgeRequestScope.Transport.PORTLET_SESSION_ATTRIBUTE);
            }
            // Spec 6.6 (Namespacing)
            indicateNamespacingToConsumers(facesContext.getViewRoot(), resourceResponse);
        }
    } catch (Throwable t) {
        throw new BridgeException(t);
    } finally {
        cleanup(resourceRequest);
    }
    logger.debug(Logger.SEPARATOR);
}
Also used : PortletRequestDispatcher(javax.portlet.PortletRequestDispatcher) BridgeException(javax.portlet.faces.BridgeException) ResourceValidator(com.liferay.faces.util.application.ResourceValidator) ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product) ConfiguredServletMapping(com.liferay.faces.util.config.ConfiguredServletMapping)

Aggregations

Product (com.liferay.faces.util.product.Product)29 ExternalContext (javax.faces.context.ExternalContext)19 ProductFactory (com.liferay.faces.util.product.ProductFactory)12 FacesContext (javax.faces.context.FacesContext)7 PortletContext (javax.portlet.PortletContext)5 List (java.util.List)4 MultiPartFormData (com.liferay.faces.util.context.map.MultiPartFormData)3 ArrayList (java.util.ArrayList)3 ResponseWriter (javax.faces.context.ResponseWriter)3 PortletRequest (javax.portlet.PortletRequest)3 ConfiguredServletMapping (com.liferay.faces.util.config.ConfiguredServletMapping)2 FacesRequestParameterMap (com.liferay.faces.util.context.map.FacesRequestParameterMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UIComponent (javax.faces.component.UIComponent)2 UIViewRoot (javax.faces.component.UIViewRoot)2 PortalContext (javax.portlet.PortalContext)2 PortletResponse (javax.portlet.PortletResponse)2 PortletSession (javax.portlet.PortletSession)2 BridgePortalContext (com.liferay.faces.bridge.context.BridgePortalContext)1