Search in sources :

Example 21 with Product

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

the class HeadRendererBridgeImpl method encodeChildren.

@Override
public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // Build up a list of components that are intended for the <head> section of the portal page.
    UIViewRoot uiViewRoot = facesContext.getViewRoot();
    List<UIComponent> headResources = new ArrayList<UIComponent>();
    // Add the list of components that are to appear first.
    List<UIComponent> firstResources = getFirstResources(facesContext, uiComponent);
    if (firstResources != null) {
        headResources.addAll(firstResources);
    }
    // Sort the components that are in the view root into stylesheets, scripts, and other.
    List<UIComponent> headComponentResources = uiViewRoot.getComponentResources(facesContext, "head");
    ExternalContext externalContext = facesContext.getExternalContext();
    final Product BOOTSFACES = ProductFactory.getProductInstance(externalContext, Product.Name.BOOTSFACES);
    final boolean BOOTSFACES_DETECTED = BOOTSFACES.isDetected();
    List<UIComponent> styleSheetResources = new ArrayList<UIComponent>();
    List<UIComponent> scriptResources = new ArrayList<UIComponent>();
    List<UIComponent> otherHeadResources = new ArrayList<UIComponent>();
    for (UIComponent headComponentResource : headComponentResources) {
        if (RenderKitUtil.isStyleSheetResource(headComponentResource, BOOTSFACES_DETECTED) || isInlineStyleSheet(headComponentResource)) {
            styleSheetResources.add(headComponentResource);
        } else if (RenderKitUtil.isScriptResource(headComponentResource, BOOTSFACES_DETECTED) || isInlineScript(headComponentResource)) {
            scriptResources.add(headComponentResource);
        } else {
            // Other head resources include <base>, <meta>, and <noscript> elments as well as passthrough <link>,
            // <style>, and <script> elements.
            otherHeadResources.add(headComponentResource);
        }
    }
    // Sort children into stylesheets, scripts, and other.
    List<UIComponent> children = uiComponent.getChildren();
    for (UIComponent child : children) {
        if (RenderKitUtil.isStyleSheetResource(child, BOOTSFACES_DETECTED) || isInlineStyleSheet(child)) {
            styleSheetResources.add(child);
        } else if (RenderKitUtil.isScriptResource(child, BOOTSFACES_DETECTED) || isInlineScript(child)) {
            scriptResources.add(child);
        } else {
            // Other head resources include <base>, <meta>, and <noscript> elments as well as passthrough <link>,
            // <style>, and <script> elements.
            otherHeadResources.add(child);
        }
    }
    if (!otherHeadResources.isEmpty()) {
        headResources.addAll(otherHeadResources);
    }
    // Add the list of stylesheet components that are in the view root.
    if (!styleSheetResources.isEmpty()) {
        headResources.addAll(styleSheetResources);
    }
    // Add the list of components that are to appear in the middle.
    List<UIComponent> middleResources = getMiddleResources(facesContext, uiComponent);
    if (middleResources != null) {
        headResources.addAll(middleResources);
    }
    // Add the list of script components that are in the view root.
    if (!scriptResources.isEmpty()) {
        headResources.addAll(scriptResources);
    }
    // Add the list of components that are to appear last.
    List<UIComponent> lastResources = getLastResources(facesContext, uiComponent);
    if (lastResources != null) {
        headResources.addAll(lastResources);
    }
    List<UIComponent> headResourcesToRenderInBody = new ArrayList<UIComponent>();
    PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
    PortalContext portalContext = portletRequest.getPortalContext();
    Iterator<UIComponent> iterator = headResources.iterator();
    while (iterator.hasNext()) {
        UIComponent headResource = iterator.next();
        // portal page, then
        if (!ableToAddResourceToHead(portalContext, headResource, BOOTSFACES_DETECTED)) {
            // Add it to the list of resources that are to be rendered in the body section by the body renderer.
            headResourcesToRenderInBody.add(headResource);
            // Remove it from the list of resources that are to be rendered in the head section by this renderer.
            iterator.remove();
            if (logger.isDebugEnabled()) {
                Map<String, Object> componentResourceAttributes = headResource.getAttributes();
                logger.debug("Relocating resource to body: name=[{0}] library=[{1}] rendererType=[{2}] value=[{3}] className=[{4}]", componentResourceAttributes.get("name"), componentResourceAttributes.get("library"), headResource.getRendererType(), ComponentUtil.getComponentValue(headResource), headResource.getClass().getName());
            }
        }
    }
    // Save the list of resources that are to be rendered in the body section so that the body renderer can find it.
    Map<Object, Object> facesContextAttributes = facesContext.getAttributes();
    facesContextAttributes.put(RenderKitUtil.HEAD_RESOURCES_TO_RENDER_IN_BODY, headResourcesToRenderInBody);
    if (!headResources.isEmpty()) {
        // Save a temporary reference to the ResponseWriter provided by the FacesContext.
        ResponseWriter responseWriterBackup = facesContext.getResponseWriter();
        // Replace the ResponseWriter in the FacesContext with a HeadResponseWriter that knows how to write to
        // the <head>...</head> section of the rendered portal page.
        ResponseWriter headResponseWriter = (ResponseWriter) portletRequest.getAttribute("com.liferay.faces.bridge.HeadResponseWriter");
        if (headResponseWriter == null) {
            PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
            PortletContext portletContext = (PortletContext) externalContext.getContext();
            headResponseWriter = HeadResponseWriterFactory.getHeadResponseWriterInstance(responseWriterBackup, portletContext, portletResponse);
        }
        portletRequest.setAttribute("com.liferay.faces.bridge.HeadResponseWriter", headResponseWriter);
        facesContext.setResponseWriter(headResponseWriter);
        Set<String> headResourceIds = RenderKitUtil.getHeadResourceIds(facesContext);
        for (UIComponent headResource : headResources) {
            headResource.encodeAll(facesContext);
            if (RenderKitUtil.isScriptResource(headResource, BOOTSFACES_DETECTED) || RenderKitUtil.isStyleSheetResource(headResource, BOOTSFACES_DETECTED)) {
                headResourceIds.add(ResourceUtil.getResourceId(headResource));
            }
        }
        // Restore the temporary ResponseWriter reference.
        facesContext.setResponseWriter(responseWriterBackup);
    }
}
Also used : PortletResponse(javax.portlet.PortletResponse) UIComponent(javax.faces.component.UIComponent) ArrayList(java.util.ArrayList) Product(com.liferay.faces.util.product.Product) PortletRequest(javax.portlet.PortletRequest) ResponseWriter(javax.faces.context.ResponseWriter) ExternalContext(javax.faces.context.ExternalContext) PortalContext(javax.portlet.PortalContext) BridgePortalContext(com.liferay.faces.bridge.context.BridgePortalContext) PortletContext(javax.portlet.PortletContext) UIViewRoot(javax.faces.component.UIViewRoot)

Example 22 with Product

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

the class FacesRuntimeUtil method isNamespacedViewStateSupported.

private static boolean isNamespacedViewStateSupported(ProductFactory productFactory) {
    boolean namespacedViewStateSupported = false;
    final Product MOJARRA = productFactory.getProductInfo(Product.Name.MOJARRA);
    final Product JSF = productFactory.getProductInfo(Product.Name.JSF);
    int jsfMajorVersion = JSF.getMajorVersion();
    if (MOJARRA.isDetected()) {
        int mojarraMajorVersion = MOJARRA.getMajorVersion();
        if (mojarraMajorVersion == 2) {
            int mojarraMinorVersion = MOJARRA.getMinorVersion();
            if (mojarraMinorVersion == 1) {
                namespacedViewStateSupported = (MOJARRA.getPatchVersion() >= 27);
            } else if (mojarraMinorVersion == 2) {
                namespacedViewStateSupported = (MOJARRA.getPatchVersion() >= 4);
            } else if (mojarraMinorVersion > 2) {
                namespacedViewStateSupported = true;
            }
        } else if (mojarraMajorVersion > 2) {
            namespacedViewStateSupported = true;
        }
    } else if ((jsfMajorVersion > 2) || ((jsfMajorVersion == 2) && (JSF.getMinorVersion() >= 3))) {
        namespacedViewStateSupported = true;
    }
    logger.debug("JSF runtime [{0}] version [{1}].[{2}].[{3}] supports namespacing [{4}]: [{5}]", JSF.getTitle(), jsfMajorVersion, JSF.getMinorVersion(), JSF.getPatchVersion(), ResponseStateManager.VIEW_STATE_PARAM, namespacedViewStateSupported);
    return namespacedViewStateSupported;
}
Also used : Product(com.liferay.faces.util.product.Product)

Example 23 with Product

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

the class RenderKitBridgeImpl method getRenderer.

@Override
public Renderer getRenderer(String family, String rendererType) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    ProductFactory productFactory = (ProductFactory) FactoryExtensionFinder.getFactory(externalContext, ProductFactory.class);
    final Product PRIMEFACES = productFactory.getProductInfo(Product.Name.PRIMEFACES);
    final boolean PRIMEFACES_DETECTED = PRIMEFACES.isDetected();
    Renderer renderer = super.getRenderer(family, rendererType);
    if (UIOutput.COMPONENT_FAMILY.equals(family)) {
        if (JAVAX_FACES_HEAD.equals(rendererType)) {
            final Product ICEFACES = productFactory.getProductInfo(Product.Name.ICEFACES);
            final boolean ICEFACES_DETECTED = ICEFACES.isDetected();
            if (ICEFACES_DETECTED) {
                renderer = new HeadRendererICEfacesImpl();
            } else if (PRIMEFACES_DETECTED) {
                renderer = new HeadRendererPrimeFacesImpl();
            } else {
                renderer = new HeadRendererBridgeImpl();
            }
        } else if (JAVAX_FACES_BODY.equals(rendererType)) {
            renderer = new BodyRendererBridgeImpl(renderer);
        } else if (RenderKitUtil.SCRIPT_RENDERER_TYPE.equals(rendererType) || RenderKitUtil.STYLESHEET_RENDERER_TYPE.equals(rendererType)) {
            renderer = new ResourceRendererBridgeImpl(renderer);
        }
    } else if (UIForm.COMPONENT_FAMILY.equals(family) && JAVAX_FACES_FORM.equals(rendererType) && PRIMEFACES_DETECTED) {
        renderer = new FormRendererPrimeFacesImpl(PRIMEFACES.getMajorVersion(), PRIMEFACES.getMinorVersion(), renderer);
    } else if (PRIMEFACES_FAMILY.equals(family) && PRIMEFACES_FILE_UPLOAD_RENDERER_TYPE.equals(rendererType)) {
        renderer = new FileUploadRendererPortletImpl(renderer);
    } else if (RICHFACES_FILE_UPLOAD_FAMILY.equals(family) && RICHFACES_FILE_UPLOAD_RENDERER_TYPE.equals(rendererType)) {
        renderer = new FileUploadRendererPortletImpl(new FileUploadRendererRichFacesImpl(renderer));
    }
    return renderer;
}
Also used : FacesContext(javax.faces.context.FacesContext) ProductFactory(com.liferay.faces.util.product.ProductFactory) FileUploadRendererPortletImpl(com.liferay.faces.bridge.renderkit.bridge.internal.FileUploadRendererPortletImpl) Product(com.liferay.faces.util.product.Product) FileUploadRendererRichFacesImpl(com.liferay.faces.bridge.renderkit.richfaces.internal.FileUploadRendererRichFacesImpl) HeadRendererICEfacesImpl(com.liferay.faces.bridge.renderkit.icefaces.internal.HeadRendererICEfacesImpl) FormRendererPrimeFacesImpl(com.liferay.faces.bridge.renderkit.primefaces.internal.FormRendererPrimeFacesImpl) ExternalContext(javax.faces.context.ExternalContext) Renderer(javax.faces.render.Renderer) HeadRendererPrimeFacesImpl(com.liferay.faces.bridge.renderkit.primefaces.internal.HeadRendererPrimeFacesImpl)

Example 24 with Product

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

the class HeadRenderer method processEvent.

@Override
public void processEvent(ComponentSystemEvent componentSystemEvent) throws AbortProcessingException {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    final Product LIFERAY_PORTAL = ProductFactory.getProductInstance(externalContext, Product.Name.LIFERAY_PORTAL);
    // to behave responsively.
    if (!LIFERAY_PORTAL.isDetected()) {
        UIViewRoot uiViewRoot = facesContext.getViewRoot();
        ResponsiveMetadata responsiveMetadata = new ResponsiveMetadata();
        Map<String, Object> attributes = responsiveMetadata.getAttributes();
        attributes.put("name", ResponsiveMetadata.COMPONENT_FAMILY);
        uiViewRoot.addComponentResource(facesContext, responsiveMetadata);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product) UIViewRoot(javax.faces.component.UIViewRoot)

Example 25 with Product

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

the class JSFUtil method isFaces_2_2_OrNewer.

public static boolean isFaces_2_2_OrNewer(FacesContext facesContext) {
    ExternalContext externalContext = facesContext.getExternalContext();
    final Product JSF = ProductFactory.getProductInstance(externalContext, Product.Name.JSF);
    return JSF.isDetected() && ((JSF.getMajorVersion() > 2) || ((JSF.getMajorVersion() == 2) && (JSF.getMinorVersion() >= 2)));
}
Also used : ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product)

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