husted 2004/02/13 03:07:55 Modified: doc/userGuide struts-html.xml src/share/org/apache/struts/action RequestProcessor.java src/share/org/apache/struts/config ForwardConfig.java src/share/org/apache/struts/taglib TagUtils.java src/share/org/apache/struts/util RequestUtils.java src/test/org/apache/struts/util TestRequestUtils.java web/examples/WEB-INF struts-config.xml web/examples/WEB-INF/exercise struts-config.xml web/examples/exercise html-link.jsp web/exercise-taglib html-link.jsp web/exercise-taglib/WEB-INF web.xml Log: Apply additional patch per #24235 " html:link tag plus module support" submitted by Gary Ashley. Revision Changes Path 1.75 +85 -9 jakarta-struts/doc/userGuide/struts-html.xml Index: struts-html.xml =================================================================== RCS file: /home/cvs/jakarta-struts/doc/userGuide/struts-html.xml,v retrieving revision 1.74 retrieving revision 1.75 diff -u -r1.74 -r1.75 --- struts-html.xml 1 Feb 2004 18:53:05 -0000 1.74 +++ struts-html.xml 13 Feb 2004 11:07:54 -0000 1.75 @@ -1617,10 +1617,29 @@ <code>forward</code> attribute, the <code>href</code> attribute, or the <code>page</code> attribute.</p> - </info> - </attribute> + + <p>Additionally, you can specify a <code>module</code> prefix + for linking to other modules.</p> + + </info> + </attribute> + + <attribute> + <name>module</name> + <required>false</required> + <rtexprvalue>true</rtexprvalue> + <info> + <p>Prefix name of a <code>Module</code> that + contains the action mapping for the <code>Action</code> + that is specified by the <code>action</code> attribute. + You <strong>must</strong> specify an <code>action</code> + attribute for this to have an effect.</p> + + <p><strong>Note: </strong>Use "" to map to the default module.</p> + </info> + </attribute> - <attribute> + <attribute> <name>anchor</name> <required>false</required> <rtexprvalue>true</rtexprvalue> @@ -3036,8 +3055,27 @@ <strong>must</strong> specify the <code>action</code>, <code>page</code> attribute or the <code>src</code> attribute.</p> - </info> - </attribute> + + <p>Additionally, you can specify a <code>module</code> prefix + for linking to other modules.</p> + + </info> + </attribute> + + <attribute> + <name>module</name> + <required>false</required> + <rtexprvalue>true</rtexprvalue> + <info> + <p>Prefix name of a <code>Module</code> that + contains the action mapping for the <code>Action</code> + that is specified by the <code>action</code> attribute. + You <strong>must</strong> specify an <code>action</code> + attribute for this to have an effect.</p> + + <p><strong>Note: </strong>Use "" to map to the default module.</p> + </info> + </attribute> <attribute> <name>paramName</name> @@ -3487,8 +3525,27 @@ <code>forward</code> attribute, the <code>href</code> attribute, the <code>linkName</code> attribute, or the <code>page</code> attribute.</p> - </info> - </attribute> + + <p>Additionally, you can specify a <code>module</code> prefix + for linking to other modules.</p> + + </info> + </attribute> + + <attribute> + <name>module</name> + <required>false</required> + <rtexprvalue>true</rtexprvalue> + <info> + <p>Prefix name of a <code>Module</code> that + contains the action mapping for the <code>Action</code> + that is specified by the <code>action</code> attribute. + You <strong>must</strong> specify an <code>action</code> + attribute for this to have an effect.</p> + + <p><strong>Note: </strong>Use "" to map to the default module.</p> + </info> + </attribute> <attribute> <name>anchor</name> @@ -5631,8 +5688,27 @@ <code>forward</code> attribute, the <code>href</code> attribute, or the <code>page</code> attribute.</p> - </info> - </attribute> + + <p>Additionally, you can specify a <code>module</code> prefix + for linking to other modules.</p> + + </info> + </attribute> + + <attribute> + <name>module</name> + <required>false</required> + <rtexprvalue>true</rtexprvalue> + <info> + <p>Prefix name of a <code>Module</code> that + contains the action mapping for the <code>Action</code> + that is specified by the <code>action</code> attribute. + You <strong>must</strong> specify an <code>action</code> + attribute for this to have an effect.</p> + + <p><strong>Note: </strong>Use "" to map to the default module.</p> + </info> + </attribute> <attribute> <name>anchor</name> 1.43 +5 -5 jakarta-struts/src/share/org/apache/struts/action/RequestProcessor.java Index: RequestProcessor.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/RequestProcessor.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- RequestProcessor.java 10 Jan 2004 21:03:38 -0000 1.42 +++ RequestProcessor.java 13 Feb 2004 11:07:54 -0000 1.43 @@ -413,7 +413,7 @@ // paths not starting with / should be passed through without any processing // (ie. they're absolute) if (forwardPath.startsWith("/")) { - uri = RequestUtils.forwardURL(request, forward); // get module relative uri + uri = RequestUtils.forwardURL(request, forward, null); // get module relative uri } else { uri = forwardPath; } 1.12 +23 -4 jakarta-struts/src/share/org/apache/struts/config/ForwardConfig.java Index: ForwardConfig.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ForwardConfig.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ForwardConfig.java 13 Jan 2004 12:48:45 -0000 1.11 +++ ForwardConfig.java 13 Feb 2004 11:07:54 -0000 1.12 @@ -181,6 +181,7 @@ * <p>The URL to which this <code>ForwardConfig</code> entry points, * which must start with a slash ("/") character. It is * interpreted according to the following rules:</p> + * <ul> * <li>If <code>contextRelative</code> property is <code>true</code>, the * path is considered to be context-relative within the current web * application (even if we are in a named module). It will be @@ -208,6 +209,24 @@ } this.path = path; } + + + /** + * <p>The prefix of the module to which this <code>ForwardConfig</code> entry points, + * which must start with a slash ("/") character. </p> + */ + protected String module = null; + + public String getModule() { + return (this.module); + } + + public void setModule(String module) { + if (configured) { + throw new IllegalStateException("Configuration is frozen"); + } + this.module = module; + } /** 1.32 +18 -19 jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java Index: TagUtils.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/TagUtils.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- TagUtils.java 7 Feb 2004 15:55:02 -0000 1.31 +++ TagUtils.java 13 Feb 2004 11:07:54 -0000 1.32 @@ -478,24 +478,24 @@ } // Look up the module configuration for this request - ModuleConfig config = instance.getModuleConfig(module, pageContext); + ModuleConfig moduleConfig = instance.getModuleConfig(module, pageContext); // Calculate the appropriate URL StringBuffer url = new StringBuffer(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); if (forward != null) { - ForwardConfig fc = config.findForwardConfig(forward); - if (fc == null) { + ForwardConfig forwardConfig = moduleConfig.findForwardConfig(forward); + if (forwardConfig == null) { throw new MalformedURLException(messages.getMessage("computeURL.forward", forward)); } - if (fc.getRedirect()) { + if (forwardConfig.getRedirect()) { redirect = true; } - if (fc.getPath().startsWith("/")) { + if (forwardConfig.getPath().startsWith("/")) { url.append(request.getContextPath()); - url.append(RequestUtils.forwardURL(request, fc)); + url.append(RequestUtils.forwardURL(request, forwardConfig, moduleConfig)); } else { - url.append(fc.getPath()); + url.append(forwardConfig.getPath()); } } else if (href != null) { url.append(href); @@ -504,7 +504,7 @@ } else /* if (page != null) */ { url.append(request.getContextPath()); - url.append(this.pageURL(request, page)); + url.append(this.pageURL(request, page, moduleConfig)); } // Add anchor if requested (replacing any existing anchor) @@ -796,10 +796,10 @@ HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); StringBuffer value = new StringBuffer(request.getContextPath()); - ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(module, request, pageContext.getServletContext()); + ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(module, request, pageContext.getServletContext()); - if ((config != null) && (!contextRelative)) { - value.append(config.getPrefix()); + if ((moduleConfig != null) && (!contextRelative)) { + value.append(moduleConfig.getPrefix()); } // Use our servlet mapping, if one is specified @@ -1149,10 +1149,9 @@ * (<strong>MUST</strong> start with a slash) * @return context-relative URL */ - public String pageURL(HttpServletRequest request, String page) { + public String pageURL(HttpServletRequest request, String page, ModuleConfig moduleConfig) { StringBuffer sb = new StringBuffer(); - ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request); String pagePattern = moduleConfig.getControllerConfig().getPagePattern(); if (pagePattern == null) { @@ -1257,10 +1256,10 @@ } if (resources == null) { - ModuleConfig config = getModuleConfig(pageContext); + ModuleConfig moduleConfig = getModuleConfig(pageContext); resources = (MessageResources) pageContext.getAttribute( - bundle + config.getPrefix(), + bundle + moduleConfig.getPrefix(), PageContext.APPLICATION_SCOPE); } 1.146 +120 -110 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.145 retrieving revision 1.146 diff -u -r1.145 -r1.146 --- RequestUtils.java 7 Feb 2004 15:55:02 -0000 1.145 +++ RequestUtils.java 13 Feb 2004 11:07:54 -0000 1.146 @@ -753,112 +753,120 @@ return sb.toString(); } + + /** + * <p>Return the context-relative URL that corresponds to the specified + * <code>ForwardConfig</code>. The URL is calculated based on the properties + * of the [EMAIL PROTECTED] ForwardConfig} instance as follows:</p> + * <ul> + * <li>If the <code>contextRelative</code> property is set, it is + * assumed that the <code>path</code> property contains a path + * that is already context-relative: + * <ul> + * <li>If the <code>path</code> property value starts with a slash, + * it is returned unmodified.</li> + * <li>If the <code>path</code> property value does not start + * with a slash, a slash is prepended.</li> + * </ul></li> + * <li>Acquire the <code>forwardPattern</code> property from the + * <code>ControllerConfig</code> for the application module used + * to process this request. If no pattern was configured, default + * to a pattern of <code>$M$P</code>, which is compatible with the + * hard-coded mapping behavior in Struts 1.0.</li> + * <li>Process the acquired <code>forwardPattern</code>, performing the + * following substitutions: + * <ul> + * <li><strong>$M</strong> - Replaced by the module prefix for the + * application module processing this request.</li> + * <li><strong>$P</strong> - Replaced by the <code>path</code> + * property of the specified [EMAIL PROTECTED] ForwardConfig}, prepended + * with a slash if it does not start with one.</li> + * <li><strong>$$</strong> - Replaced by a single dollar sign + * character.</li> + * <li><strong>$x</strong> (where "x" is any charater not listed + * above) - Silently omit these two characters from the result + * value. (This has the side effect of causing all other + * $+letter combinations to be reserved.)</li> + * </ul></li> + * </ul> + * + * @param request The servlet request we are processing + * @param forward ForwardConfig to be evaluated + * + * @return context-relative URL + * @since Struts 1.1 + */ + public static String forwardURL(HttpServletRequest request, ForwardConfig forward, ModuleConfig moduleConfig) { + //load the current moduleConfig, if null + if(moduleConfig == null) { + moduleConfig = ModuleUtils.getInstance().getModuleConfig(request); + } + + String path = forward.getPath(); + //load default prefix + String prefix = moduleConfig.getPrefix(); + + //override prefix if supplied by forward + if(forward.getModule() != null) { + prefix = forward.getModule(); + } + + // 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 + String forwardPattern = moduleConfig.getControllerConfig().getForwardPattern(); + if (forwardPattern == null) { + // Performance optimization for previous default behavior + sb.append(prefix); + // smoothly insert a '/' if needed + if (!path.startsWith("/")) { + sb.append("/"); + } + sb.append(path); + + } else { + boolean dollar = false; + for (int i = 0; i < forwardPattern.length(); i++) { + char ch = forwardPattern.charAt(i); + if (dollar) { + switch (ch) { + case 'M': + sb.append(prefix); + break; + case 'P': + // add '/' if needed + if (!path.startsWith("/")) { + sb.append("/"); + } + sb.append(path); + break; + case '$': + sb.append('$'); + break; + default : + ; // Silently swallow + } + dollar = false; + continue; + } else if (ch == '$') { + dollar = true; + } else { + sb.append(ch); + } + } + } + return (sb.toString()); - /** - * <p>Return the context-relative URL that corresponds to the specified - * <code>ForwardConfig</code>. The URL is calculated based on the properties - * of the [EMAIL PROTECTED] ForwardConfig} instance as follows:</p> - * <ul> - * <li>If the <code>contextRelative</code> property is set, it is - * assumed that the <code>path</code> property contains a path - * that is already context-relative: - * <ul> - * <li>If the <code>path</code> property value starts with a slash, - * it is returned unmodified.</li> - * <li>If the <code>path</code> property value does not start - * with a slash, a slash is prepended.</li> - * </ul></li> - * <li>Acquire the <code>forwardPattern</code> property from the - * <code>ControllerConfig</code> for the application module used - * to process this request. If no pattern was configured, default - * to a pattern of <code>$M$P</code>, which is compatible with the - * hard-coded mapping behavior in Struts 1.0.</li> - * <li>Process the acquired <code>forwardPattern</code>, performing the - * following substitutions: - * <ul> - * <li><strong>$M</strong> - Replaced by the module prefix for the - * application module processing this request.</li> - * <li><strong>$P</strong> - Replaced by the <code>path</code> - * property of the specified [EMAIL PROTECTED] ForwardConfig}, prepended - * with a slash if it does not start with one.</li> - * <li><strong>$$</strong> - Replaced by a single dollar sign - * character.</li> - * <li><strong>$x</strong> (where "x" is any charater not listed - * above) - Silently omit these two characters from the result - * value. (This has the side effect of causing all other - * $+letter combinations to be reserved.)</li> - * </ul></li> - * </ul> - * - * @param request The servlet request we are processing - * @param forward ForwardConfig to be evaluated - * - * @return context-relative URL - * @since Struts 1.1 - */ - 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 moduleConfig = - ModuleUtils.getInstance().getModuleConfig(request); - String forwardPattern = moduleConfig.getControllerConfig().getForwardPattern(); - if (forwardPattern == null) { - // Performance optimization for previous default behavior - sb.append(moduleConfig.getPrefix()); - // smoothly insert a '/' if needed - if (!path.startsWith("/")) { - sb.append("/"); - } - sb.append(path); - - } else { - boolean dollar = false; - for (int i = 0; i < forwardPattern.length(); i++) { - char ch = forwardPattern.charAt(i); - if (dollar) { - switch (ch) { - case 'M': - sb.append(moduleConfig.getPrefix()); - break; - case 'P': - // add '/' if needed - if (!path.startsWith("/")) { - sb.append("/"); - } - sb.append(path); - break; - case '$': - sb.append('$'); - break; - default : - ; // Silently swallow - } - dollar = false; - continue; - } else if (ch == '$') { - dollar = true; - } else { - sb.append(ch); - } - } - } - - return (sb.toString()); - - } + } /** @@ -1572,8 +1580,10 @@ * This will be removed after Struts 1.2. */ public static String pageURL(HttpServletRequest request, String page) { - - return TagUtils.getInstance().pageURL(request, page); + //load the current moduleConfig + ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request); + + return TagUtils.getInstance().pageURL(request, page, moduleConfig); //:TODO: Remove after Struts 1.2 } 1.25 +87 -22 jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java Index: TestRequestUtils.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/test/org/apache/struts/util/TestRequestUtils.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- TestRequestUtils.java 13 Jan 2004 12:48:57 -0000 1.24 +++ TestRequestUtils.java 13 Feb 2004 11:07:54 -0000 1.25 @@ -1218,7 +1218,7 @@ // redirect=false, contextRelative=false forward = moduleConfig.findForwardConfig("moduleForward"); assertNotNull("moduleForward found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("moduleForward computed", result); assertEquals("moduleForward value", "/module/forward", @@ -1227,7 +1227,7 @@ // redirect=true, contextRelative=false forward = moduleConfig.findForwardConfig("moduleRedirect"); assertNotNull("moduleRedirect found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("moduleRedirect computed", result); assertEquals("moduleRedirect value", "/module/redirect", @@ -1236,7 +1236,7 @@ // redirect=false, contextRelative=true forward = moduleConfig.findForwardConfig("contextForward"); assertNotNull("contextForward found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("contextForward computed", result); assertEquals("contextForward value", "/context/forward", @@ -1245,7 +1245,7 @@ // redirect=true, contextRelative=true forward = moduleConfig.findForwardConfig("contextRedirect"); assertNotNull("contextRedirect found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("contextRedirect computed", result); assertEquals("contextRedirct value", "/context/redirect", @@ -1254,7 +1254,7 @@ // noslash, contextRelative=false forward = moduleConfig.findForwardConfig("moduleNoslash"); assertNotNull("moduleNoslash found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("moduleNoslash computed", result); assertEquals("moduleNoslash value", "/module/noslash", @@ -1263,7 +1263,7 @@ // noslash, contextRelative=true forward = moduleConfig.findForwardConfig("contextNoslash"); assertNotNull("contextNoslash found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("contextNoslash computed", result); assertEquals("contextNoslash value", "/context/noslash", @@ -1283,7 +1283,7 @@ // redirect=false, contextRelative=false forward = moduleConfig2.findForwardConfig("moduleForward"); assertNotNull("moduleForward found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("moduleForward computed", result); assertEquals("moduleForward value", "/2/module/forward", @@ -1292,7 +1292,7 @@ // redirect=true, contextRelative=false forward = moduleConfig2.findForwardConfig("moduleRedirect"); assertNotNull("moduleRedirect found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("moduleRedirect computed", result); assertEquals("moduleRedirect value", "/2/module/redirect", @@ -1301,7 +1301,7 @@ // redirect=false, contextRelative=true forward = moduleConfig2.findForwardConfig("contextForward"); assertNotNull("contextForward found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("contextForward computed", result); assertEquals("contextForward value", "/context/forward", @@ -1310,7 +1310,7 @@ // redirect=true, contextRelative=true forward = moduleConfig2.findForwardConfig("contextRedirect"); assertNotNull("contextRedirect found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("contextRedirect computed", result); assertEquals("contextRedirct value", "/context/redirect", @@ -1319,7 +1319,7 @@ // noslash, contextRelative=false forward = moduleConfig2.findForwardConfig("moduleNoslash"); assertNotNull("moduleNoslash found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("moduleNoslash computed", result); assertEquals("moduleNoslash value", "/2/module/noslash", @@ -1328,7 +1328,7 @@ // noslash, contextRelative=true forward = moduleConfig2.findForwardConfig("contextNoslash"); assertNotNull("contextNoslash found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("contextNoslash computed", result); assertEquals("contextNoslash value", "/context/noslash", @@ -1348,7 +1348,7 @@ // redirect=false, contextRelative=false forward = moduleConfig3.findForwardConfig("moduleForward"); assertNotNull("moduleForward found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("moduleForward computed", result); assertEquals("moduleForward value", "/forwarding/3/module/forward", @@ -1357,7 +1357,7 @@ // redirect=true, contextRelative=false forward = moduleConfig3.findForwardConfig("moduleRedirect"); assertNotNull("moduleRedirect found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("moduleRedirect computed", result); assertEquals("moduleRedirect value", "/forwarding/3/module/redirect", @@ -1366,7 +1366,7 @@ // redirect=false, contextRelative=true forward = moduleConfig3.findForwardConfig("contextForward"); assertNotNull("contextForward found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("contextForward computed", result); assertEquals("contextForward value", "/context/forward", @@ -1375,7 +1375,7 @@ // redirect=true, contextRelative=true forward = moduleConfig3.findForwardConfig("contextRedirect"); assertNotNull("contextRedirect found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("contextRedirect computed", result); assertEquals("contextRedirct value", "/context/redirect", @@ -1384,7 +1384,7 @@ // noslash, contextRelative=false forward = moduleConfig3.findForwardConfig("moduleNoslash"); assertNotNull("moduleNoslash found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("moduleNoslash computed", result); assertEquals("moduleNoslash value", "/forwarding/3/module/noslash", @@ -1393,13 +1393,78 @@ // noslash, contextRelative=true forward = moduleConfig3.findForwardConfig("contextNoslash"); assertNotNull("contextNoslash found", forward); - result = RequestUtils.forwardURL(request, forward); + result = RequestUtils.forwardURL(request, forward, null); assertNotNull("contextNoslash computed", result); assertEquals("contextNoslash value", "/context/noslash", result); } + + + // Cross module forwards + public void testForwardURLa() { + + request.setAttribute(Globals.MODULE_KEY, moduleConfig); + request.setPathElements("/myapp", "/action.do", null, null); + ForwardConfig forward = null; + String result = null; + + // redirect=false, contextRelative=false, link to module 3 + forward = moduleConfig3.findForwardConfig("moduleForward"); + assertNotNull("moduleForward found", forward); + result = RequestUtils.forwardURL(request, forward, moduleConfig3); + assertNotNull("moduleForward computed", result); + assertEquals("moduleForward value", + "/forwarding/3/module/forward", + result); + + // redirect=true, contextRelative=false, link to module 3 + forward = moduleConfig3.findForwardConfig("moduleRedirect"); + assertNotNull("moduleRedirect found", forward); + result = RequestUtils.forwardURL(request, forward, moduleConfig3); + assertNotNull("moduleRedirect computed", result); + assertEquals("moduleRedirect value", + "/forwarding/3/module/redirect", + result); + + // redirect=false, contextRelative=true, link to module 3 + forward = moduleConfig3.findForwardConfig("contextForward"); + assertNotNull("contextForward found", forward); + result = RequestUtils.forwardURL(request, forward, moduleConfig3); + assertNotNull("contextForward computed", result); + assertEquals("contextForward value", + "/context/forward", + result); + + // redirect=true, contextRelative=true, link to module 3 + forward = moduleConfig3.findForwardConfig("contextRedirect"); + assertNotNull("contextRedirect found", forward); + result = RequestUtils.forwardURL(request, forward, moduleConfig3); + assertNotNull("contextRedirect computed", result); + assertEquals("contextRedirct value", + "/context/redirect", + result); + + // noslash, contextRelative=false, link to module 3 + forward = moduleConfig3.findForwardConfig("moduleNoslash"); + assertNotNull("moduleNoslash found", forward); + result = RequestUtils.forwardURL(request, forward, moduleConfig3); + assertNotNull("moduleNoslash computed", result); + assertEquals("moduleNoslash value", + "/forwarding/3/module/noslash", + result); + + // noslash, contextRelative=true, link to module 3 + forward = moduleConfig3.findForwardConfig("contextNoslash"); + assertNotNull("contextNoslash found", forward); + result = RequestUtils.forwardURL(request, forward, moduleConfig3); + assertNotNull("contextNoslash computed", result); + assertEquals("contextNoslash value", + "/context/noslash", + result); + + } // -------------------------------------------------------------- pageURL() 1.4 +2 -2 jakarta-struts/web/examples/WEB-INF/struts-config.xml Index: struts-config.xml =================================================================== RCS file: /home/cvs/jakarta-struts/web/examples/WEB-INF/struts-config.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- struts-config.xml 7 Feb 2004 00:09:33 -0000 1.3 +++ struts-config.xml 13 Feb 2004 11:07:54 -0000 1.4 @@ -13,7 +13,7 @@ <forward name="welcome" path="/welcome.do" /> </global-forwards> <action-mappings> - <action path="/welcome" forward="/welcome.html" /> + <action path="/welcome" forward="/welcome.jsp" /> </action-mappings> <message-resources parameter="MessageResources" /> </struts-config> 1.7 +1 -0 jakarta-struts/web/examples/WEB-INF/exercise/struts-config.xml Index: struts-config.xml =================================================================== RCS file: /home/cvs/jakarta-struts/web/examples/WEB-INF/exercise/struts-config.xml,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- struts-config.xml 20 Jan 2004 03:57:02 -0000 1.6 +++ struts-config.xml 13 Feb 2004 11:07:55 -0000 1.7 @@ -16,6 +16,7 @@ <forward name="relative" path="/welcome.do" /> <forward name="redirect-default" path="/" redirect="true" /> <forward name="logic-forward" path="/logic-forward.do" /> + <forward name="cross-module" module="" path="/welcome.do" /> </global-forwards> <action-mappings> <action path="/welcome" forward="/index.html" /> 1.3 +90 -29 jakarta-struts/web/examples/exercise/html-link.jsp Index: html-link.jsp =================================================================== RCS file: /home/cvs/jakarta-struts/web/examples/exercise/html-link.jsp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- html-link.jsp 17 Jan 2004 04:15:00 -0000 1.2 +++ html-link.jsp 13 Feb 2004 11:07:55 -0000 1.3 @@ -90,35 +90,61 @@ </td> </tr> <tr> - <th colspan="4" align="center">Hyperlinks To Be Tested via action attribute</th> - </tr> - <tr> - <td colspan="4" align="center"> - <html:link action="/html-link-submit">No modifications at all</html:link> - </td> - </tr> - <tr> - <td colspan="4" align="center"> - <html:link action="/html-link-submit?doubleProperty=321.321&longProperty=321321">Double and long via hard coded changes</html:link> - </td> - </tr> - <tr> - <td colspan="4" align="center"> - <html:link action="/html-link-submit" paramId="stringProperty" paramName="newValue">String via paramId and paramName</html:link> - </td> - </tr> - <tr> - <td colspan="4" align="center"> - <html:link action="/html-link-submit" paramId="booleanProperty" paramName="testbean" paramProperty="nested.booleanProperty">Boolean via paramId, paramName, and paramValue</html:link> - </td> - </tr> - <tr> - <td colspan="4" align="center"> - <html:link action="/html-link-submit" name="newValues">Float, int, and stringArray via name (Map)</html:link> - </td> - </tr> - <tr> - <th colspan="4" align="center">Reset and Cancel Buttons</th> + + <tr> + <th colspan="4" align="center"> + Hyperlinks To Be Tested via action and module attributes + </th> + </tr> + + <tr> + <td colspan="4" align="center"> + <html:link action="/html-link"> + No modifications at all, but link to the default module. + </html:link> + </td> + </tr> + + <tr> + <td colspan="4" align="center"> + <html:link action="/html-link?doubleProperty=321.321&longProperty=321321" + module="/exercise"> + Double and long via hard coded changes (module) + </html:link> + </td> + </tr> + + <tr> + <td colspan="4" align="center"> + <html:link action="/html-link" + paramId="stringProperty" paramName="newValue"> + String via paramId and paramName + </html:link> + </td> + </tr> + + <tr> + <td colspan="4" align="center"> + <html:link action="/html-link" + paramId="booleanProperty" + paramName="testbean" paramProperty="nested.booleanProperty" + module="/exercise"> + Boolean via paramId, paramName, and paramValue (module) + </html:link> + </td> + </tr> + + <tr> + <td colspan="4" align="center"> + <html:link action="/html-link" + name="newValues"> + Float, int, and stringArray via name (Map) + </html:link> + </td> + </tr> + + <tr> + <th colspan="4" align="center">Reset and Cancel Buttons</th> </tr> <tr> <td colspan="4" align="center"> @@ -128,7 +154,9 @@ </tr> </table> </html:form> + <p>The following list tests relative, context-relative, and absolute links. Press (back) to return.</p> + <p>Forwards</p> <ul> <li> <html:link forward="relative">module welcome page</html:link> @@ -143,5 +171,38 @@ <html:link forward="redirect-default">Redirect to the default page ("/")</html:link> </li> </ul> + <p>Actions</p> + <ul> + <li> + <html:link action="/welcome" module="/">application welcome page</html:link> + <!-- Test with empty string for module: <html:link action="/welcome" module="">application welcome page</html:link> --> + </li> + <li> + <html:link action="/welcome" module="/exercise">Exercise module welcome page</html:link> + </li> + <li> + <html:link action="/upload" module="/upload">Upload welcome page</html:link> + </li> + <li> + <html:link action="/welcome" module="/validator">Validator welcome page</html:link> + </li> + </ul> + + <p>Pages</p> + <ul> + <li> + <html:link page="/welcome.do" module="">application welcome page</html:link> + <%-- FIXME: "/" slash throws NPE: <html:link page="/welcome.do" module="/">application welcome page</html:link> --%> + </li> + <li> + <html:link page="/welcome.do" module="/exercise">Exercise module welcome page</html:link> + </li> + <li> + <html:link page="/upload.do" module="/upload">Upload welcome page</html:link> + </li> + <li> + <html:link page="/welcome.do" module="/validator">Validator welcome page</html:link> + </li> + </ul> </body> </html:html> 1.6 +55 -0 jakarta-struts/web/exercise-taglib/html-link.jsp Index: html-link.jsp =================================================================== RCS file: /home/cvs/jakarta-struts/web/exercise-taglib/html-link.jsp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- html-link.jsp 21 Dec 2003 22:46:27 -0000 1.5 +++ html-link.jsp 13 Feb 2004 11:07:55 -0000 1.6 @@ -178,6 +178,61 @@ </html:link> </td> </tr> + + <tr> + <th colspan="4" align="center"> + Hyperlinks To Be Tested via action and module attributes + </th> + </tr> + + <tr> + <td colspan="4" align="center"> + <html:link action="/html-link" + module=""> + No modifications at all, but link to the default module. + </html:link> + </td> + </tr> + + <tr> + <td colspan="4" align="center"> + <html:link action="/html-module-link?doubleProperty=321.321&longProperty=321321" + module="/moduleA"> + Double and long via hard coded changes + </html:link> + </td> + </tr> + + <tr> + <td colspan="4" align="center"> + <html:link action="/html-module-link" + paramId="stringProperty" paramName="newValue" + module="/moduleA"> + String via paramId and paramName + </html:link> + </td> + </tr> + + <tr> + <td colspan="4" align="center"> + <html:link action="/html-module-link" + paramId="booleanProperty" + paramName="testbean" paramProperty="nested.booleanProperty" + module="/moduleA"> + Boolean via paramId, paramName, and paramValue + </html:link> + </td> + </tr> + + <tr> + <td colspan="4" align="center"> + <html:link action="/html-module-link" + name="newValues" + module="/moduleA"> + Float, int, and stringArray via name (Map) + </html:link> + </td> + </tr> <tr> <th colspan="4" align="center">Reset and Cancel Buttons</th> 1.5 +4 -0 jakarta-struts/web/exercise-taglib/WEB-INF/web.xml Index: web.xml =================================================================== RCS file: /home/cvs/jakarta-struts/web/exercise-taglib/WEB-INF/web.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- web.xml 22 Apr 2003 03:25:47 -0000 1.4 +++ web.xml 13 Feb 2004 11:07:55 -0000 1.5 @@ -20,6 +20,10 @@ <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> + <param-name>config/moduleA</param-name> + <param-value>/WEB-INF/struts-moduleA.xml</param-value> + </init-param> + <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]