Search in sources :

Example 1 with FacesConfig

use of com.liferay.faces.util.config.FacesConfig in project liferay-faces-bridge-impl by liferay.

the class BridgePhaseResourceImpl method getConfiguredFacesServletMappings.

protected List<ConfiguredServletMapping> getConfiguredFacesServletMappings() {
    String appConfigAttrName = ApplicationConfig.class.getName();
    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, Object> applicationMap = externalContext.getApplicationMap();
    ApplicationConfig applicationConfig = (ApplicationConfig) applicationMap.get(appConfigAttrName);
    FacesConfig facesConfig = applicationConfig.getFacesConfig();
    return facesConfig.getConfiguredFacesServletMappings();
}
Also used : FacesConfig(com.liferay.faces.util.config.FacesConfig) ApplicationConfig(com.liferay.faces.util.config.ApplicationConfig) ExternalContext(javax.faces.context.ExternalContext)

Example 2 with FacesConfig

use of com.liferay.faces.util.config.FacesConfig 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)

Aggregations

ApplicationConfig (com.liferay.faces.util.config.ApplicationConfig)2 FacesConfig (com.liferay.faces.util.config.FacesConfig)2 ConfiguredServletMapping (com.liferay.faces.util.config.ConfiguredServletMapping)1 ExternalContext (javax.faces.context.ExternalContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1