Search in sources :

Example 6 with ConfiguredServletMapping

use of com.liferay.faces.util.config.ConfiguredServletMapping in project liferay-faces-alloy by liferay.

the class ResLibResourceHandler method getResourceName.

protected String getResourceName(ExternalContext externalContext) {
    // Attempt to get the resource name from the "javax.faces.resource" request parameter. If it exists, then
    // this is probably a non-Liferay portlet environment like Pluto.
    String resourceName = externalContext.getRequestParameterMap().get("javax.faces.resource");
    if (resourceName == null) {
        // If the specified request was extension-mapped (suffix-mapped), then determine the resource name based
        // on the configured mappings to the Faces Servlet.
        Object request = externalContext.getRequest();
        if (request instanceof HttpServletRequest) {
            HttpServletRequest httpServletRequest = (HttpServletRequest) request;
            String servletPath = httpServletRequest.getServletPath();
            if ((servletPath != null) && servletPath.startsWith(RESOURCE_IDENTIFIER)) {
                Map<String, Object> applicationMap = externalContext.getApplicationMap();
                String appConfigAttrName = ApplicationConfig.class.getName();
                ApplicationConfig applicationConfig = (ApplicationConfig) applicationMap.get(appConfigAttrName);
                FacesConfig facesConfig = applicationConfig.getFacesConfig();
                List<ConfiguredServletMapping> configuredFacesServletMappings = facesConfig.getConfiguredFacesServletMappings();
                resourceName = servletPath.substring(RESOURCE_IDENTIFIER.length() + 1);
                for (ConfiguredServletMapping configuredFacesServletMapping : configuredFacesServletMappings) {
                    String configuredExtension = configuredFacesServletMapping.getExtension();
                    if (servletPath.endsWith(configuredExtension)) {
                        resourceName = resourceName.substring(0, resourceName.length() - configuredExtension.length());
                        break;
                    }
                }
            } else // Otherwise, it must be path-mapped.
            {
                resourceName = httpServletRequest.getPathInfo();
            }
        }
    }
    return resourceName;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FacesConfig(com.liferay.faces.util.config.FacesConfig) ApplicationConfig(com.liferay.faces.util.config.ApplicationConfig) ConfiguredServletMapping(com.liferay.faces.util.config.ConfiguredServletMapping)

Example 7 with ConfiguredServletMapping

use of com.liferay.faces.util.config.ConfiguredServletMapping in project liferay-faces-bridge-ext by liferay.

the class ResourceValidatorLiferayImpl method isSelfReferencing.

@Override
public boolean isSelfReferencing(FacesContext facesContext, String resourceId) {
    // If the delegation chain indicates that the specified resource is not self-referencing, then
    boolean selfReferencing = super.isSelfReferencing(facesContext, resourceId);
    if ((!selfReferencing) && (resourceId != null)) {
        // Process the configured servlet entries in order to determine which ones are portlet invokers.
        Set<String> invokerServletNames = new HashSet<String>();
        ExternalContext externalContext = facesContext.getExternalContext();
        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 : 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

ConfiguredServletMapping (com.liferay.faces.util.config.ConfiguredServletMapping)7 ApplicationConfig (com.liferay.faces.util.config.ApplicationConfig)3 ExternalContext (javax.faces.context.ExternalContext)3 ConfiguredServlet (com.liferay.faces.util.config.ConfiguredServlet)2 WebConfig (com.liferay.faces.util.config.WebConfig)2 Product (com.liferay.faces.util.product.Product)2 HashSet (java.util.HashSet)2 ResourceValidator (com.liferay.faces.util.application.ResourceValidator)1 FacesConfig (com.liferay.faces.util.config.FacesConfig)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FacesContext (javax.faces.context.FacesContext)1 PortletRequestDispatcher (javax.portlet.PortletRequestDispatcher)1 BridgeConfig (javax.portlet.faces.BridgeConfig)1 BridgeException (javax.portlet.faces.BridgeException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1