Search in sources :

Example 1 with Product

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

the class ScriptsEncoderAlloyImpl method allowLiferayToHandleScripts.

private static boolean allowLiferayToHandleScripts(FacesContext facesContext) {
    ExternalContext externalContext = facesContext.getExternalContext();
    ProductFactory productFactory = (ProductFactory) FactoryExtensionFinder.getFactory(externalContext, ProductFactory.class);
    final Product LIFERAY_PORTAL = productFactory.getProductInfo(Product.Name.LIFERAY_PORTAL);
    final Product LIFERAY_FACES_BRIDGE = productFactory.getProductInfo(Product.Name.LIFERAY_FACES_BRIDGE);
    return LIFERAY_PORTAL.isDetected() && LIFERAY_FACES_BRIDGE.isDetected();
}
Also used : ProductFactory(com.liferay.faces.util.product.ProductFactory) ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product)

Example 2 with Product

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

the class ResourceVerifierAlloyImpl method isDependencySatisfied.

@Override
public boolean isDependencySatisfied(FacesContext facesContext, UIComponent componentResource) {
    boolean dependencySatisfied;
    ExternalContext externalContext = facesContext.getExternalContext();
    final Product LIFERAY_PORTAL = ProductFactory.getProductInstance(externalContext, Product.Name.LIFERAY_PORTAL);
    if (LIFERAY_PORTAL.isDetected() && LIFERAY_PORTAL_INCLUDED_RESOURCE_IDS.contains(ResourceUtil.getResourceId(componentResource))) {
        dependencySatisfied = true;
    } else {
        dependencySatisfied = super.isDependencySatisfied(facesContext, componentResource);
    }
    return dependencySatisfied;
}
Also used : ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product)

Example 3 with Product

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

the class InputFileRenderer method getUploadedFileMap.

protected Map<String, List<UploadedFile>> getUploadedFileMap(FacesContext facesContext, String location) {
    Map<String, List<UploadedFile>> uploadedFileMap = null;
    ExternalContext externalContext = facesContext.getExternalContext();
    final Product LIFERAY_FACES_BRIDGE = ProductFactory.getProductInstance(externalContext, Product.Name.LIFERAY_FACES_BRIDGE);
    if (LIFERAY_FACES_BRIDGE.isDetected()) {
        Map<String, Object> requestAttributeMap = facesContext.getExternalContext().getRequestMap();
        MultiPartFormData multiPartFormData = (MultiPartFormData) requestAttributeMap.get(MultiPartFormData.class.getName());
        if (multiPartFormData != null) {
            uploadedFileMap = multiPartFormData.getUploadedFileMap();
        }
    } else {
        InputFileDecoder inputFileDecoder = getWebappInputFileDecoder(facesContext);
        uploadedFileMap = inputFileDecoder.decode(facesContext, location);
    }
    return uploadedFileMap;
}
Also used : ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product) List(java.util.List) MultiPartFormData(com.liferay.faces.util.context.map.MultiPartFormData)

Example 4 with Product

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

the class ResourceRichFacesPackedJSImpl method filter.

@Override
protected String filter(String javaScriptText) {
    // Replace the URL used by rich:fileUpload for forum submission.
    // http://issues.liferay.com/browse/FACES-1234
    // https://issues.jboss.org/browse/RF-12273
    String token = "this.form.attr(\"action\", originalAction + delimiter + UID + \"=\" + this.loadableItem.uid);";
    int pos = javaScriptText.indexOf(token);
    if (pos > 0) {
        logger.debug("Found first token in packed.js");
        StringBuilder buf = new StringBuilder();
        buf.append(javaScriptText.substring(0, pos));
        buf.append("this.form.attr(\"action\", this.form.children(\"input[name&='javax.faces.encodedURL']\").val() + delimiter + UID + \"=\" + this.loadableItem.uid);");
        buf.append(javaScriptText.substring(pos + token.length() + 1));
        javaScriptText = buf.toString();
    }
    javaScriptText = replaceToken(javaScriptText, "this.fileUpload.form.attr(\"action\")", "this.fileUpload.form.children(\"input[name$='javax.faces.encodedURL']\").val()");
    // Fix JavaScript error "TypeError: jQuery.atmosphere is undefined" by inserting checks for undefined variable.
    // http://issues.liferay.com/browse/FACES-1532
    javaScriptText = prependToken(javaScriptText, "if (jQuery.atmosphere.requests.length > 0) {", "if (!jQuery.atmosphere) { return; }; ");
    javaScriptText = prependToken(javaScriptText, "jQuery.atmosphere.unsubscribe();", "if (!jQuery.atmosphere) { return; }; ");
    javaScriptText = prependToken(javaScriptText, "$.atmosphere.unsubscribe();", "if (!$.atmosphere) { return; }; ");
    // JSF 2.3 incompatibility due to non-namespaced request parameters.
    // http://issues.liferay.com/browse/FACES-3014
    token = "this.fileUpload.form.find(\"input[name='javax.faces.ViewState']\").val();";
    pos = javaScriptText.indexOf(token);
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    final Product JSF = ProductFactory.getProductInstance(externalContext, Product.Name.JSF);
    final int JSF_MAJOR_VERSION = JSF.getMajorVersion();
    if (((JSF_MAJOR_VERSION > 2) || ((JSF_MAJOR_VERSION == 2) && (JSF.getMinorVersion() >= 3))) && (pos > 0)) {
        logger.debug("Found javax.faces.ViewState selector in packed.js");
        javaScriptText = replaceToken(javaScriptText, token, "'',vsElem=this.fileUpload.form.find(\"input[name$='javax.faces.ViewState']\"),paramPrefix=vsElem.attr('name').substring(0,vsElem.attr('name').indexOf('javax.faces.ViewState'));");
        javaScriptText = replaceToken(javaScriptText, "append(\"javax.faces.ViewState\",", "append(vsElem.attr('name'),vsElem.val()+");
        javaScriptText = replaceToken(javaScriptText, "javax.faces.partial.ajax=", "\" + paramPrefix + \"javax.faces.partial.ajax=");
        javaScriptText = replaceToken(javaScriptText, "javax.faces.partial.execute=", "\" + paramPrefix + \"javax.faces.partial.execute=");
        javaScriptText = replaceToken(javaScriptText, "javax.faces.ViewState=", "\" + paramPrefix + \"javax.faces.ViewState=");
        javaScriptText = replaceToken(javaScriptText, "javax.faces.source=", "\" + paramPrefix + \"javax.faces.source=");
        javaScriptText = replaceToken(javaScriptText, "org.richfaces.ajax.component=", "\" + paramPrefix + \"org.richfaces.ajax.component=");
        // Uncompressed: newAction =  originalAction + delimiter + UID + "=" + this.uid
        // Compressed: R=T+L+A+"="+this.uid
        String regEx = "\\w+\\s*=\\s*\\w+\\s*\\+\\s*\\w+\\s*\\+\\s*\\w+\\s*\\+\\s*\"=\"\\s*\\+\\s*this.uid";
        Matcher matcher = Pattern.compile(regEx).matcher(javaScriptText);
        if (matcher.find()) {
            String matchingText = javaScriptText.substring(matcher.start(), matcher.end());
            String[] parts = matchingText.split("\\+");
            String fixedMatchingText = parts[0] + "+" + parts[1] + "+ paramPrefix +" + parts[2] + "+" + parts[3] + "+" + parts[4];
            javaScriptText = javaScriptText.substring(0, matcher.start()) + fixedMatchingText + javaScriptText.substring(matcher.end());
        } else {
            logger.warn("Unable fix the javax.faces.ViewState value because newAction can't be found");
        }
        // Uncompressed: javax.faces.ViewState=" + encodeURIComponent(viewState)
        // Compressed: javax.faces.ViewState="+encodeURIComponent(C)
        regEx = "javax.faces.ViewState\\=\"\\s*\\+\\s*encodeURIComponent[(]\\w+[)]";
        matcher = Pattern.compile(regEx).matcher(javaScriptText);
        if (matcher.find()) {
            String matchingText = javaScriptText.substring(matcher.start(), matcher.end());
            int openParenPos = matchingText.indexOf("(");
            String fixedMatchingText = matchingText.substring(0, openParenPos) + "(vsElem.val())";
            javaScriptText = javaScriptText.substring(0, matcher.start()) + fixedMatchingText + javaScriptText.substring(matcher.end());
        } else {
            logger.warn("Unable to find and fix encodeURIComponent(viewState)");
        }
    }
    return javaScriptText;
}
Also used : FacesContext(javax.faces.context.FacesContext) Matcher(java.util.regex.Matcher) ExternalContext(javax.faces.context.ExternalContext) Product(com.liferay.faces.util.product.Product)

Example 5 with Product

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

the class ResourceValidatorBridgeImpl method isSelfReferencing.

@Override
public boolean isSelfReferencing(FacesContext facesContext, String resourceId) {
    ExternalContext externalContext = facesContext.getExternalContext();
    final Product PLUTO = ProductFactory.getProductInstance(externalContext, Product.Name.PLUTO);
    // If the delegation chain indicates that the specified resource is not self-referencing, then
    boolean selfReferencing = super.isSelfReferencing(facesContext, resourceId);
    if (PLUTO.isDetected() && (!selfReferencing) && (resourceId != null)) {
        // Process the configured servlet entries in order to determine which ones are portlet invokers.
        Set<String> invokerServletNames = new HashSet<String>();
        Map<String, Object> applicationMap = externalContext.getApplicationMap();
        ApplicationConfig applicationConfig = (ApplicationConfig) applicationMap.get(ApplicationConfig.class.getName());
        WebConfig webConfig = applicationConfig.getWebConfig();
        List<ConfiguredServlet> configuredServlets = webConfig.getConfiguredServlets();
        for (ConfiguredServlet configuredServlet : configuredServlets) {
            String configuredServletClass = configuredServlet.getServletClass();
            if (isInvokerServletClass(configuredServletClass)) {
                invokerServletNames.add(configuredServlet.getServletName());
            }
        }
        // For each of the servlet-mapping entries:
        List<ConfiguredServletMapping> configuredServletMappings = webConfig.getConfiguredServletMappings();
        for (ConfiguredServletMapping configuredServletMapping : configuredServletMappings) {
            // Determine whether or not the current servlet-mapping is mapped to a portlet invoker servlet-class.
            if (invokerServletNames.contains(configuredServletMapping.getServletName())) {
                if (configuredServletMapping.isMatch(resourceId)) {
                    selfReferencing = true;
                    break;
                }
            }
        }
    }
    return selfReferencing;
}
Also used : Product(com.liferay.faces.util.product.Product) WebConfig(com.liferay.faces.util.config.WebConfig) ApplicationConfig(com.liferay.faces.util.config.ApplicationConfig) ExternalContext(javax.faces.context.ExternalContext) ConfiguredServlet(com.liferay.faces.util.config.ConfiguredServlet) ConfiguredServletMapping(com.liferay.faces.util.config.ConfiguredServletMapping) HashSet(java.util.HashSet)

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