Hi,

Here is my proposal of a patch for the bug report #16603.

I changed the RequestProcessor and the RequestUtils so that I can endly set
a multi-modules app with pages under WEB-INF.

But nobody seems to care about... I think I'll be glad if somebody write me
a word even to say : "Stop boring us with your stupid bug which is not, and
RTFM".

Malik.
Index: jakarta-struts/src/share/org/apache/struts/action/RequestProcessor.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/action/RequestProcessor.java,v
retrieving revision 1.24
diff -u -r1.24 RequestProcessor.java
--- jakarta-struts/src/share/org/apache/struts/action/RequestProcessor.java     30 Jan 
2003 17:58:13 -0000      1.24
+++ jakarta-struts/src/share/org/apache/struts/action/RequestProcessor.java     4 Feb 
+2003 14:47:22 -0000
@@ -560,7 +560,7 @@
             return (true);
         }
 
-        internalModuleRelativeForward(forward, request, response);
+           internalModuleRelativeForward(forward, request, response);        
         return (false);
 
     }
@@ -968,9 +968,10 @@
     protected void internalModuleRelativeForward(String uri, HttpServletRequest 
request,
                              HttpServletResponse response)
         throws IOException, ServletException
-    {
-    // Construct a request dispatcher for the specified path
-    uri = moduleConfig.getPrefix() + uri;
+    {    
+    // Construct a request dispatcher for the specified path  
+    String pattern =  moduleConfig.getControllerConfig().getForwardPattern();
+    uri = RequestUtils.contextRelativeURL(uri, moduleConfig.getPrefix(), pattern);
 
     // Delegate the processing of this request
     // FIXME - exception handling?
@@ -994,9 +995,10 @@
     protected void internalModuleRelativeInclude(String uri, HttpServletRequest 
request,
                              HttpServletResponse response)
         throws IOException, ServletException
-    {
-    // Construct a request dispatcher for the specified path
-    uri = moduleConfig.getPrefix() + uri;
+    {    
+    // Construct a request dispatcher for the specified path  
+    String pattern =  moduleConfig.getControllerConfig().getForwardPattern();
+    uri = RequestUtils.contextRelativeURL(uri, moduleConfig.getPrefix(), pattern);
 
     // Delegate the processing of this request
     // FIXME - exception handling?
Index: jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
retrieving revision 1.79
diff -u -r1.79 RequestUtils.java
--- jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java   12 Jan 2003 
20:31:21 -0000      1.79
+++ jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java   4 Feb 2003 
+14:51:39 -0000
@@ -1350,58 +1350,37 @@
 
     }
 
-    /**
-     * Return the context-relative URL that corresponds to the specified
-     * {@link ForwardConfig}, relative to the module associated
-     * with the current {@link ModuleConfig}. The forward path is
-     * gracefully prefixed with a '/' according to the boolean
-     *
-     *
-     * @param request The servlet request we are processing
-     * @param forward ForwardConfig to be evaluated
-     * @return context-relative URL
-     * @since Struts 1.1b2
-     */
-    public static String forwardURL(HttpServletRequest request, ForwardConfig 
forward) {
-
-        String path = forward.getPath();
-
-        // Handle a ForwardConfig marked as context relative
-        StringBuffer sb = new StringBuffer();
-        if (forward.getContextRelative()) {
-            if (!path.startsWith("/")) {
-                sb.append("/");
-            }
-            sb.append(path);
-            return (sb.toString());
-        }
-
-        // Calculate a context relative path for this ForwardConfig
-        ModuleConfig appConfig = (ModuleConfig) 
request.getAttribute(Globals.MODULE_KEY);
-        String forwardPattern = appConfig.getControllerConfig().getForwardPattern();
-        if (forwardPattern == null) {
-            // Performance optimization for previous default behavior
-            sb.append(appConfig.getPrefix());
-            // smoothly insert a '/' if needed
-            if (!path.startsWith("/")) {
-                sb.append("/");
-            }
-            sb.append(path);
+       /**
+        * Return the context-relative URL that corresponds to the specified
+     * <code>uri</code> parametter value, calculated based on the
+     * <code>pattern</code> parametter or of the <code>prefix</code> parametter.
+     * If <code>pattern</code> is null then the <code>uri</code> is only 
+     * prefixed with the module <code>prefix</code>.
+     * @param uri The module-relative URI to be substituted.
+     * @param prefix The prefix of the module.
+     * @param pattern The replacement pattern to use for substitution.
+     * @return context-relative URL     
+        */
+       public static String contextRelativeURL(String uri, String prefix, String 
+pattern){
+               
+               StringBuffer sb = new StringBuffer();
+                
+        if (pattern == null) {
+                       // If pattern is null only add the prefix.
+            sb.append(prefix);
+            sb.append(uri);
         } else {
+               // Else replace $M and $P by prefix and uri.
             boolean dollar = false;
-            for (int i = 0; i < forwardPattern.length(); i++) {
-                char ch = forwardPattern.charAt(i);
+            for (int i = 0; i < pattern.length(); i++) {
+                char ch = pattern.charAt(i);
                 if (dollar) {
                     switch (ch) {
                         case 'M' :
-                            sb.append(appConfig.getPrefix());
+                            sb.append(prefix);
                             break;
                         case 'P' :
-                            // add '/' if needed
-                            if (!path.startsWith("/")) {
-                                sb.append("/");
-                            }
-                            sb.append(path);
+                            sb.append(uri);
                             break;
                         case '$' :
                             sb.append('$');
@@ -1419,7 +1398,29 @@
             }
         }
         return (sb.toString());
+       }       
+
+    /**
+     * Return the context-relative URL that corresponds to the specified
+     * {@link ForwardConfig}, relative to the module associated
+     * with the current {@link ModuleConfig}.
+     *
+     *
+     * @param request The servlet request we are processing
+     * @param forward ForwardConfig to be evaluated
+     * @return context-relative URL
+     * @since Struts 1.1b2
+     */
+    public static String forwardURL(HttpServletRequest request, ForwardConfig 
+forward) {
 
+        String path = forward.getPath();                                      
+               
+        ModuleConfig appConfig = (ModuleConfig) 
+request.getAttribute(Globals.MODULE_KEY);                              
+        
+        String pattern = appConfig.getControllerConfig().getForwardPattern();
+        
+               // return a context relative path for this ForwardConfig
+               return contextRelativeURL(path, appConfig.getPrefix(), pattern);       
+                 
     }
 
     /**
@@ -1439,38 +1440,8 @@
         StringBuffer sb = new StringBuffer();
         ModuleConfig appConfig = (ModuleConfig) 
request.getAttribute(Globals.MODULE_KEY);
         String pagePattern = appConfig.getControllerConfig().getPagePattern();
-        if (pagePattern == null) {
-            sb.append(appConfig.getPrefix());
-            sb.append(page);
-        } else {
-            boolean dollar = false;
-            for (int i = 0; i < pagePattern.length(); i++) {
-                char ch = pagePattern.charAt(i);
-                if (dollar) {
-                    switch (ch) {
-                        case 'M' :
-                            sb.append(appConfig.getPrefix());
-                            break;
-                        case 'P' :
-                            sb.append(page);
-                            break;
-                        case '$' :
-                            sb.append('$');
-                            break;
-                        default :
-                            ; // Silently swallow
-                    }
-                    dollar = false;
-                    continue;
-                } else if (ch == '$') {
-                    dollar = true;
-                } else {
-                    sb.append(ch);
-                }
-            }
-        }
-        return (sb.toString());
-
+        
+        return contextRelativeURL(page, appConfig.getPrefix(), pagePattern);        
     }
 
     /**

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to