Hi all,

The attached patch allows relative paths to be specified for actions defined in the action-mappings element of struts-config.xml.

If the path attribute of the action element is specified without a leading slash, struts now suffix matches the action-mapping paths against the path in the request, instead of doing an exact match. Previously in this case the path would never match.

If the path attribute is specified with a leading slash, the behaviour is to find an exact match the same as now.

This feature is useful where you want struts to ignore directories in your URL, for example:

http://somewhere/context/struts/-country-/show/info.do might display info on a particular "country". Defining the action-mapping path as "show/info" will match all URLs ending with "show/info.do" regardless of the value of "-country-".

Previously "-country-" would have to be specified as either a cookie (not always on), in the session (which may be lost at any time), or as a parameter (requiring link mangling on pages).

Comments...?

Regards,
Graham
--
-----------------------------------------
[EMAIL PROTECTED] "There's a moon
over Bourbon Street
tonight..."
--- ApplicationConfig-orig.java Thu Jan  9 13:48:14 2003
+++ ApplicationConfig.java      Thu Jan  9 13:50:50 2003
@@ -66,6 +66,8 @@
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
+
 import javax.servlet.ServletException;
 import javax.servlet.UnavailableException;
 
@@ -363,8 +365,23 @@
      */
     public ActionConfig findActionConfig(String path) {
 
-        return ((ActionConfig) actionConfigs.get(path));
+        /* check absolute references */
+        ActionConfig config = ((ActionConfig) actionConfigs.get(path));
+        if (config != null) {
+            return config;
+        }
+
+        /* check relative references */
+        Iterator i = actionConfigs.keySet().iterator();
+        while (i.hasNext()) {
+            String configPath = (String)i.next();
+            if (configPath.charAt(0) != '/' && path.endsWith(configPath)) {
+                return (ActionConfig)actionConfigs.get(configPath);
+            }
+        }
 
+        /* neither absolute nor relative paths matched */
+        return null;
     }
 
 

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

Reply via email to