cedric 2002/11/05 06:07:09 Modified: src/share/org/apache/struts/util RequestUtils.java Log: Factorize the module name computation in method getModuleName(). Let selectApplication(...) use this new method. Revision Changes Path 1.67 +27 -15 jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java Index: RequestUtils.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v retrieving revision 1.66 retrieving revision 1.67 diff -u -r1.66 -r1.67 --- RequestUtils.java 30 Oct 2002 02:29:15 -0000 1.66 +++ RequestUtils.java 5 Nov 2002 14:07:09 -0000 1.67 @@ -1436,31 +1436,45 @@ */ public static void selectApplication(HttpServletRequest request, ServletContext context) { + // Compute module name + String prefix = getModuleName( request, context); + // Expose the resources for this module + selectApplication(prefix, request, context); + + } - // Acquire the path used to compute the module + /** + * Get the module name to which the specified request belong. + * @param request The servlet request we are processing + * @param context The ServletContext for this web application + */ + public static String getModuleName(HttpServletRequest request, + ServletContext context) { + + // Acquire the path used to compute the module String matchPath = (String) request.getAttribute(RequestProcessor.INCLUDE_SERVLET_PATH); - + if (matchPath == null) { matchPath = request.getServletPath(); } if (LOG.isDebugEnabled()) { - LOG.debug("Selecting module for path " + matchPath); + LOG.debug("Get module name for path " + matchPath); } String prefix = ""; // Initialize prefix before we try lookup String prefixes[] = getApplicationPrefixes(context); // Get all other possible prefixes int lastSlash = 0; // Initialize before loop - + while (prefix.equals("") && ((lastSlash = matchPath.lastIndexOf("/")) > 0)) { - + // We may be in a non-default module. Try to get it's prefix. matchPath = matchPath.substring(0, lastSlash); - + // Match against the list of module prefixes for (int i = 0; i < prefixes.length; i++) { if (matchPath.equals(prefixes[i])) { @@ -1472,14 +1486,12 @@ if (LOG.isDebugEnabled()) { - LOG.debug("Activating module " + + LOG.debug("Module name found: " + (prefix.equals("") ? "default" : prefix)); } - - // Expose the resources for this module - selectApplication(prefix, request, context); - + return prefix; } + /** * Return the ApplicationConfig object is it exists, null otherwise.
-- To unsubscribe, e-mail: <mailto:struts-dev-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:struts-dev-help@;jakarta.apache.org>