craigmcc 2002/07/05 15:03:16
Modified: src/share/org/apache/struts/util RequestUtils.java
src/test/org/apache/struts/util TestRequestUtils.java
Log:
It makes much more sense for actionURL(), forwardURL(), and pageURL() to
return context-relative URLs instead of server-relative URLs.
Revision Changes Path
1.44 +16 -18
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.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- RequestUtils.java 5 Jul 2002 20:56:27 -0000 1.43
+++ RequestUtils.java 5 Jul 2002 22:03:16 -0000 1.44
@@ -412,10 +412,12 @@
if (fc.getRedirect()) {
redirect = true;
}
+ url.append(request.getContextPath());
url.append(forwardURL(request, fc));
} else if (href != null) {
url.append(href);
} else /* if (page != null) */ {
+ url.append(request.getContextPath());
url.append(pageURL(request, page));
}
@@ -1139,20 +1141,21 @@
/**
- * Return the server-relative URL that corresponds to the specified
+ * Return the context-relative URL that corresponds to the specified
* {@link ActionConfig}, relative to the sub-application associated
* with the current subapp's {@link ApplicationConfig}.
*
* @param request The servlet request we are processing
* @param action ActionConfig to be evaluated
* @param pattern URL pattern used to map the controller servlet
+ *
+ * @since Struts 1.1b2
*/
public static String actionURL(HttpServletRequest request,
ActionConfig action,
String pattern) {
StringBuffer sb = new StringBuffer();
- sb.append(request.getContextPath());
if (pattern.endsWith("/*")) {
sb.append(pattern.substring(0, pattern.length() - 2));
sb.append(action.getPath());
@@ -1171,12 +1174,14 @@
/**
- * Return the server-relative URL that corresponds to the specified
+ * Return the context-relative URL that corresponds to the specified
* {@link ForwardConfig}, relative to the sub-application associated
* with the current subapp's {@link ApplicationConfig}.
*
* @param request The servlet request we are processing
* @param forward ForwardConfig to be evaluated
+ *
+ * @since Struts 1.1b2
*/
public static String forwardURL(HttpServletRequest request,
ForwardConfig forward) {
@@ -1184,19 +1189,17 @@
// Handle a ForwardConfig marked as context relative
StringBuffer sb = new StringBuffer();
if (forward.getContextRelative()) {
- sb.append(request.getContextPath());
sb.append(forward.getPath());
return (sb.toString());
}
- // Calculate a subapp relative path for this ForwardConfig
+ // Calculate a context relative path for this ForwardConfig
ApplicationConfig appConfig = (ApplicationConfig)
request.getAttribute(Action.APPLICATION_KEY);
String forwardPattern =
appConfig.getControllerConfig().getForwardPattern();
if (forwardPattern == null) {
// Performance optimization for previous default behavior
- sb.append(request.getContextPath());
sb.append(appConfig.getPrefix());
sb.append(forward.getPath());
} else {
@@ -1205,9 +1208,6 @@
char ch = forwardPattern.charAt(i);
if (dollar) {
switch (ch) {
- case 'C':
- sb.append(request.getContextPath());
- break;
case 'A':
sb.append(appConfig.getPrefix());
break;
@@ -1235,7 +1235,7 @@
/**
- * Return the server-relative URL that corresponds to the specified
+ * Return the context-relative URL that corresponds to the specified
* <code>page</code> attribute value, calculated based on the
* <code>pagePattern</code> property of the current subapp's
* {@link ApplicationConfig}.
@@ -1243,6 +1243,8 @@
* @param request The servlet request we are processing
* @param page The application-relative URL to be substituted in
* to the <code>pagePattern</code> pattern for the current subapp
+ *
+ * @since Struts 1.1b2
*/
public static String pageURL(HttpServletRequest request,
String page) {
@@ -1253,7 +1255,6 @@
String pagePattern =
appConfig.getControllerConfig().getPagePattern();
if (pagePattern == null) {
- sb.append(request.getContextPath());
sb.append(appConfig.getPrefix());
sb.append(page);
} else {
@@ -1262,9 +1263,6 @@
char ch = pagePattern.charAt(i);
if (dollar) {
switch (ch) {
- case 'C':
- sb.append(request.getContextPath());
- break;
case 'A':
sb.append(appConfig.getPrefix());
break;
1.5 +7 -7
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestRequestUtils.java 5 Jul 2002 20:56:27 -0000 1.4
+++ TestRequestUtils.java 5 Jul 2002 22:03:16 -0000 1.5
@@ -164,7 +164,7 @@
(request, appConfig.findActionConfig("/dynamic"), "*.do");
assertNotNull("URL was returned", url);
assertEquals("URL value",
- "/myapp/dynamic.do",
+ "/dynamic.do",
url);
}
@@ -179,7 +179,7 @@
(request, appConfig2.findActionConfig("/dynamic2"), "*.do");
assertNotNull("URL was returned", url);
assertEquals("URL value",
- "/myapp/2/dynamic2.do",
+ "/2/dynamic2.do",
url);
}
@@ -194,7 +194,7 @@
(request, appConfig.findActionConfig("/dynamic"), "/do/*");
assertNotNull("URL was returned", url);
assertEquals("URL value",
- "/myapp/do/dynamic",
+ "/do/dynamic",
url);
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>