Return-Path: Delivered-To: apmail-jakarta-struts-dev-archive@apache.org Received: (qmail 97978 invoked from network); 5 Jul 2002 20:56:37 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 5 Jul 2002 20:56:37 -0000 Received: (qmail 21113 invoked by uid 97); 5 Jul 2002 20:56:47 -0000 Delivered-To: qmlist-jakarta-archive-struts-dev@jakarta.apache.org Received: (qmail 21072 invoked by uid 97); 5 Jul 2002 20:56:46 -0000 Mailing-List: contact struts-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Struts Developers List" Reply-To: "Struts Developers List" Delivered-To: mailing list struts-dev@jakarta.apache.org Received: (qmail 21061 invoked by uid 97); 5 Jul 2002 20:56:45 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Date: 5 Jul 2002 20:56:27 -0000 Message-ID: <20020705205627.69553.qmail@icarus.apache.org> From: craigmcc@apache.org To: jakarta-struts-cvs@apache.org Subject: cvs commit: jakarta-struts/src/test/org/apache/struts/util TestRequestUtils.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N craigmcc 2002/07/05 13:56:27 Modified: src/share/org/apache/struts/util RequestUtils.java src/test/org/apache/struts/util TestRequestUtils.java Log: For completeness, define actionURL() to calculate the appropriate server relative URL for an Action, along with associated unit tests. Revision Changes Path 1.43 +37 -4 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.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- RequestUtils.java 4 Jul 2002 00:05:48 -0000 1.42 +++ RequestUtils.java 5 Jul 2002 20:56:27 -0000 1.43 @@ -98,6 +98,7 @@ import org.apache.struts.action.ActionServletWrapper; import org.apache.struts.action.DynaActionFormClass; import org.apache.struts.action.RequestProcessor; +import org.apache.struts.config.ActionConfig; import org.apache.struts.config.ApplicationConfig; import org.apache.struts.config.FormBeanConfig; import org.apache.struts.config.ForwardConfig; @@ -1133,6 +1134,38 @@ sb.append(ref); return (sb.toString()); } + + } + + + /** + * Return the server-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 + */ + 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()); + } else if (pattern.startsWith("*.")) { + ApplicationConfig appConfig = (ApplicationConfig) + request.getAttribute(Action.APPLICATION_KEY); + sb.append(appConfig.getPrefix()); + sb.append(action.getPath()); + sb.append(pattern.substring(1)); + } else { + throw new IllegalArgumentException(pattern); + } + return (sb.toString()); } 1.4 +52 -4 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TestRequestUtils.java 4 Jul 2002 00:05:48 -0000 1.3 +++ TestRequestUtils.java 5 Jul 2002 20:56:27 -0000 1.4 @@ -152,6 +152,54 @@ } + // ------------------------------------------------------------ actionURL() + + + // Default application -- extension mapping + public void testActionURL1() { + + request.setAttribute(Action.APPLICATION_KEY, appConfig); + request.setPathElements("/myapp", "/foo.do", null, null); + String url = RequestUtils.actionURL + (request, appConfig.findActionConfig("/dynamic"), "*.do"); + assertNotNull("URL was returned", url); + assertEquals("URL value", + "/myapp/dynamic.do", + url); + + } + + + // Second application -- extension mapping + public void testActionURL2() { + + request.setAttribute(Action.APPLICATION_KEY, appConfig2); + request.setPathElements("/myapp", "/2/foo.do", null, null); + String url = RequestUtils.actionURL + (request, appConfig2.findActionConfig("/dynamic2"), "*.do"); + assertNotNull("URL was returned", url); + assertEquals("URL value", + "/myapp/2/dynamic2.do", + url); + + } + + + // Default application -- path mapping + public void testActionURL3() { + + request.setAttribute(Action.APPLICATION_KEY, appConfig); + request.setPathElements("/myapp", "/do/foo", null, null); + String url = RequestUtils.actionURL + (request, appConfig.findActionConfig("/dynamic"), "/do/*"); + assertNotNull("URL was returned", url); + assertEquals("URL value", + "/myapp/do/dynamic", + url); + + } + + // ---------------------------------------------------- computeParameters() -- To unsubscribe, e-mail: For additional commands, e-mail: