Search in sources :

Example 6 with Product

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

the class PreDestroyInvokerFactoryImpl method getPreDestroyInvoker.

@Override
public PreDestroyInvoker getPreDestroyInvoker(ServletContext servletContext) {
    PortletContextAdapter portletContextAdapter = new PortletContextAdapter(servletContext);
    ProductFactory productFactory = (ProductFactory) BridgeFactoryFinder.getFactory(portletContextAdapter, ProductFactory.class);
    final Product MOJARRA = productFactory.getProductInfo(Product.Name.MOJARRA);
    if (MOJARRA.isDetected()) {
        return new PreDestroyInvokerMojarraImpl(servletContext);
    } else {
        return new PreDestroyInvokerImpl();
    }
}
Also used : ProductFactory(com.liferay.faces.util.product.ProductFactory) Product(com.liferay.faces.util.product.Product) PortletContextAdapter(com.liferay.faces.bridge.context.internal.PortletContextAdapter)

Example 7 with Product

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

the class ResourceHandlerRichfacesImpl method createResource.

private Resource createResource(String resourceName, Resource resource) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    final Product RICHFACES = ProductFactory.getProductInstance(externalContext, Product.Name.RICHFACES);
    final boolean RICHFACES_DETECTED = RICHFACES.isDetected();
    if ((resource != null) && RICHFACES_DETECTED) {
        // If this is a RichFaces static css resource, then return a filtered Richfaces static CSS resource.
        if (resourceName.startsWith(RICHFACES_STATIC_RESOURCE) && resourceName.endsWith(".css")) {
            resource = new ResourceRichFacesCSSImpl(resource);
        } else // resource.
        if (resourceName.startsWith(RICHFACES_STATIC_RESOURCE) && resourceName.endsWith("packed.js")) {
            resource = new ResourceRichFacesPackedJSImpl(resource);
        } else if (resource.getClass().getName().startsWith(ORG_RICHFACES_RESOURCE)) {
            resource = new ResourceRichFacesImpl(resource);
        }
    }
    return resource;
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product)

Example 8 with Product

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

the class ExceptionHandlerFactoryBridgeImpl method getExceptionHandler.

@Override
public ExceptionHandler getExceptionHandler() {
    ExceptionHandler wrappedExceptionHandler = wrappedExceptionHandlerFactory.getExceptionHandler();
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    Product ICEFACES = ProductFactory.getProductInstance(externalContext, Product.Name.ICEFACES);
    final int MAJOR_VERSION = ICEFACES.getMajorVersion();
    if (ICEFACES.isDetected() && (((MAJOR_VERSION == 4) && (ICEFACES.getMinorVersion() < 2)) || (MAJOR_VERSION < 4))) {
        // Workaround for https://issues.liferay.com/browse/FACES-3012
        facesContext.getPartialViewContext();
    }
    return new ExceptionHandlerBridgeImpl(wrappedExceptionHandler);
}
Also used : ExceptionHandler(javax.faces.context.ExceptionHandler) FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product)

Example 9 with Product

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

the class BridgeDependencyVerifier method verify.

public static void verify(ExternalContext externalContext) {
    Package bridgePackage = BridgeDependencyVerifier.class.getPackage();
    String implementationTitle = bridgePackage.getImplementationTitle();
    String implementationVersion = bridgePackage.getImplementationVersion();
    ProductFactory productFactory = (ProductFactory) FactoryExtensionFinder.getFactory(externalContext, ProductFactory.class);
    final Product LIFERAY_PORTAL = productFactory.getProductInfo(Product.Name.LIFERAY_PORTAL);
    if (LIFERAY_PORTAL.isDetected()) {
        final Product LIFERAY_FACES_BRIDGE_EXT = productFactory.getProductInfo(Product.Name.LIFERAY_FACES_BRIDGE_EXT);
        if (!LIFERAY_FACES_BRIDGE_EXT.isDetected()) {
            logger.error("{0} {1} is running in Liferay Portal {2}.{3} but the com.liferay.faces.bridge.ext.jar dependency is not in the classpath", implementationTitle, implementationVersion, LIFERAY_PORTAL.getMajorVersion(), LIFERAY_PORTAL.getMinorVersion());
        }
    }
    final Product PORTLET_API = productFactory.getProductInfo(Product.Name.PORTLET_API);
    final int PORTLET_API_MAJOR_VERSION = PORTLET_API.getMajorVersion();
    final int PORTLET_API_MINOR_VERSION = PORTLET_API.getMinorVersion();
    if (!((PORTLET_API_MAJOR_VERSION > 3) || ((PORTLET_API_MAJOR_VERSION == 3) && (PORTLET_API_MINOR_VERSION >= 0)))) {
        logger.error("{0} {1} is designed to be used with Portlet 3.0+ but detected {2}.{3}", implementationTitle, implementationVersion, PORTLET_API_MAJOR_VERSION, PORTLET_API_MINOR_VERSION);
    }
    final Product JSF = productFactory.getProductInfo(Product.Name.JSF);
    final int JSF_MAJOR_VERSION = JSF.getMajorVersion();
    final int JSF_MINOR_VERSION = JSF.getMinorVersion();
    if (!((JSF_MAJOR_VERSION == 2) && (JSF_MINOR_VERSION == 3))) {
        logger.error("{0} {1} is designed to be used with JSF 2.3 but detected {2}.{3}", implementationTitle, implementationVersion, JSF_MAJOR_VERSION, JSF_MINOR_VERSION);
    }
    String lsv485PatchVersion = externalContext.getInitParameter("com.liferay.faces.lsv.485.patch.version");
    if ((lsv485PatchVersion != null) && !lsv485PatchVersion.equals("")) {
        logger.error("{0} {1} contains fixes for LSV-485 so it is incompatible with com.liferay.faces.lsv.485.patch.jar. Please remove com.liferay.faces.lsv.485.patch.jar from the classpath.", implementationTitle, implementationVersion);
    }
}
Also used : ProductFactory(com.liferay.faces.util.product.ProductFactory) Product(com.liferay.faces.util.product.Product)

Example 10 with Product

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

the class BodyRendererBridgeImpl method encodeBegin.

/**
 * It is forbidden for a portlet to render the &amp;&lt;body&amp;&gt; element, so instead, render a
 * &amp;&lt;div&amp;&gt;element.
 *
 * @see  Renderer#encodeBegin(FacesContext, UIComponent)
 */
@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    ResponseWriter originalResponseWriter = facesContext.getResponseWriter();
    ResponseWriter responseWriter = new ResponseWriterBridgeBodyImpl(originalResponseWriter);
    facesContext.setResponseWriter(responseWriter);
    super.encodeBegin(facesContext, uiComponent);
    PortletNamingContainerUIViewRoot viewRoot = (PortletNamingContainerUIViewRoot) facesContext.getViewRoot();
    String clientId = viewRoot.getContainerClientId(facesContext);
    responseWriter.writeAttribute("id", clientId, null);
    String styleClass = (String) uiComponent.getAttributes().get("styleClass");
    // ResponseWriterBridgeBodyImpl will append STYLE_CLASS_PORTLET_BODY to the specified styleClass.
    if (styleClass == null) {
        responseWriter.writeAttribute("class", RenderKitUtil.STYLE_CLASS_PORTLET_BODY, "styleClass");
    }
    // Render each of the head resources that were not renderable in the head section into the top of the portlet
    // body (the outer <div> of the portlet markup). This happens when the portlet container may not support adding
    // resources to the <head> section. For example, Pluto does not support the feature of adding resources to the
    // <head> section. Liferay supports it with the exception of "runtime" and WSRP portlets. See
    // PortalContextBridgeImpl and PortalContextBridgeLiferayImpl (in bridge-ext) for more information. Script
    // resources are rendered at the top of the portlet body instead of the bottom because elements and scripts in
    // the portlet body may depend on these resources (for example jquery.js), so head resource scripts must be
    // loaded before the portlet body is rendered.
    Map<Object, Object> facesContextAttributes = facesContext.getAttributes();
    List<UIComponent> headResourcesToRenderInBody = (List<UIComponent>) facesContextAttributes.get(RenderKitUtil.HEAD_RESOURCES_TO_RENDER_IN_BODY);
    Set<String> headResourceIds = RenderKitUtil.getHeadResourceIds(facesContext);
    // https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
    if (headResourcesToRenderInBody != null) {
        ExternalContext externalContext = facesContext.getExternalContext();
        final Product BOOTSFACES = ProductFactory.getProductInstance(externalContext, Product.Name.BOOTSFACES);
        final boolean BOOTSFACES_DETECTED = BOOTSFACES.isDetected();
        for (UIComponent headResource : headResourcesToRenderInBody) {
            headResource.encodeAll(facesContext);
            // tracked as if they were rendered in the <head> section so that they are not loaded multiple times.
            if (RenderKitUtil.isScriptResource(headResource, BOOTSFACES_DETECTED)) {
                headResourceIds.add(ResourceUtil.getResourceId(headResource));
            }
        }
    }
    facesContext.setResponseWriter(originalResponseWriter);
}
Also used : UIComponent(javax.faces.component.UIComponent) Product(com.liferay.faces.util.product.Product) ResponseWriter(javax.faces.context.ResponseWriter) ExternalContext(javax.faces.context.ExternalContext) List(java.util.List) PortletNamingContainerUIViewRoot(javax.portlet.faces.component.PortletNamingContainerUIViewRoot)

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