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;
}
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;
}
Aggregations