protected ServletMapping calculateServletMapping(FacesContext context)
{
ExternalContext externalContext = context.getExternalContext();
Map<String, Object> requestMap = externalContext.getRequestMap();
ServletMapping mapping = null;
if (requestMap.containsKey(externalContext))
{
mapping = (ServletMapping) requestMap.get(SERVLET_MAPPING);
}
else
{
String servletPath = externalContext.getRequestServletPath();
String requestPathInfo = externalContext.getRequestPathInfo();
WebXml webxml = WebXml.getWebXml(externalContext);
List mappings = webxml.getFacesServletMappings();
if (requestPathInfo == null)
{
// might be extension mapping
for (int i = 0, size = mappings.size(); i < size && mapping == null; i++)
{
ServletMapping servletMapping = (ServletMapping) mappings.get(i);
String urlpattern = servletMapping.getUrlPattern();
String extension = urlpattern.substring(1, urlpattern.length());
if (servletPath.endsWith(extension))
{
mapping = servletMapping;
}
else if (servletPath.equals(urlpattern))
{
// path mapping with no pathInfo for the current request
mapping = servletMapping;
}
}
}
else
{
// path mapping
for (int i = 0, size = mappings.size(); i < size && mapping == null; i++)
{
ServletMapping servletMapping = (ServletMapping) mappings.get(i);
String urlpattern = servletMapping.getUrlPattern();
urlpattern = urlpattern.substring(0, urlpattern.length() - 2);
// servletPath starts with "/" except in the case where the
// request is matched with the "/*" pattern, in which case
// it is the empty string (see Servlet Sepc 2.3 SRV4.4)
if (servletPath.equals(urlpattern))