dgraham 2003/08/02 13:40:18 Modified: src/share/org/apache/struts/util RequestUtils.java src/share/org/apache/struts/taglib TagUtils.java Log: Moved pageURL() to TagUtils. Revision Changes Path 1.131 +7 -43 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.130 retrieving revision 1.131 diff -u -r1.130 -r1.131 --- RequestUtils.java 2 Aug 2003 20:35:28 -0000 1.130 +++ RequestUtils.java 2 Aug 2003 20:40:18 -0000 1.131 @@ -61,11 +61,8 @@ package org.apache.struts.util; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; -import java.net.URLEncoder; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; @@ -1180,44 +1177,11 @@ * (<strong>MUST</strong> start with a slash) * @return context-relative URL * @since Struts 1.1 + * @deprecated Use TagUtils.pageURL() instead. This will be removed + * after Struts 1.2. */ public static String pageURL(HttpServletRequest request, String page) { - - StringBuffer sb = new StringBuffer(); - ModuleConfig moduleConfig = getRequestModuleConfig(request); - String pagePattern = moduleConfig.getControllerConfig().getPagePattern(); - if (pagePattern == null) { - sb.append(moduleConfig.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(moduleConfig.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 TagUtils.getInstance().pageURL(request, page); } /** 1.19 +60 -5 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.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- TagUtils.java 2 Aug 2003 20:35:28 -0000 1.18 +++ TagUtils.java 2 Aug 2003 20:40:18 -0000 1.19 @@ -438,7 +438,7 @@ } else /* if (page != null) */ { url.append(request.getContextPath()); - url.append(RequestUtils.pageURL(request, page)); + url.append(this.pageURL(request, page)); } // Add anchor if requested (replacing any existing anchor) @@ -1008,6 +1008,61 @@ return resources.getMessage(userLocale, key, args); } + } + + /** + * <p>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 module's + * [EMAIL PROTECTED] ModuleConfig}.</p> + * + * @param request The servlet request we are processing + * @param page The module-relative URL to be substituted in + * to the <code>pagePattern</code> pattern for the current module + * (<strong>MUST</strong> start with a slash) + * @return context-relative URL + */ + public String pageURL(HttpServletRequest request, String page) { + + StringBuffer sb = new StringBuffer(); + ModuleConfig moduleConfig = RequestUtils.getRequestModuleConfig(request); + String pagePattern = moduleConfig.getControllerConfig().getPagePattern(); + + if (pagePattern == null) { + sb.append(moduleConfig.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(moduleConfig.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(); } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]