Author: markt Date: Sun Nov 27 12:41:41 2005 New Revision: 349305 URL: http://svn.apache.org/viewcvs?rev=349305&view=rev Log: Fix SSI so it works when getContext() requires an exact context path
Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ssi/SSIServletExternalResolver.java Modified: tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ssi/SSIServletExternalResolver.java URL: http://svn.apache.org/viewcvs/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ssi/SSIServletExternalResolver.java?rev=349305&r1=349304&r2=349305&view=diff ============================================================================== --- tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ssi/SSIServletExternalResolver.java (original) +++ tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/ssi/SSIServletExternalResolver.java Sun Nov 27 12:41:41 2005 @@ -347,12 +347,12 @@ } - protected String getPathWithoutContext(String servletPath) { + protected String getPathWithoutContext(String contextPath, String servletPath) { String retVal = null; - int secondSlash = servletPath.indexOf('/', 1); - if (secondSlash >= 0) { + + if (contextPath.length() >= 0) { //cut off context - retVal = servletPath.substring(secondSlash); + retVal = servletPath.substring(contextPath.length()); } return retVal; } @@ -403,17 +403,19 @@ if (isVirtualWebappRelative) { return new ServletContextAndPath(context, normalized); } else { - ServletContext normContext = context.getContext(normalized); - if (normContext == null) { + String contextPath = getContextPath(normalized); + if (contextPath == null) { throw new IOException("Couldn't get context for path: " + normalized); } + ServletContext normContext = context.getContext(contextPath); + //If it's the root context, then there is no context element // to remove, // ie: // '/file1.shtml' vs '/appName1/file1.shtml' if (!isRootContext(normContext)) { - String noContext = getPathWithoutContext(normalized); + String noContext = getPathWithoutContext(contextPath, normalized); if (noContext == null) { throw new IOException( "Couldn't remove context from path: " @@ -427,17 +429,38 @@ } } + // Looks for the longest matching context path + protected String getContextPath(String uri) { + String candidatePath = uri; + ServletContext contextFound = null; + String result = null; + + while (true) { + contextFound = context.getContext(candidatePath); + if (contextFound != null) { + result = candidatePath; + break; + } + + int slash = candidatePath.lastIndexOf('/'); + if (slash < 0) + break; + + candidatePath = candidatePath.substring(0, slash); + } + return result; + } //Assumes servletContext is not-null //Assumes that identity comparison will be true for the same context - //Assuming the above, getContext("/") will be non-null as long as the root + //Assuming the above, getContext("") will be non-null as long as the root // context is // accessible. //If it isn't, then servletContext can't be the root context anyway, hence // they will // not match. protected boolean isRootContext(ServletContext servletContext) { - return servletContext == servletContext.getContext("/"); + return servletContext == servletContext.getContext(""); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]