Revision: 343
Author:   tfenne
Date:     2006-07-08 06:07:43 -0700 (Sat, 08 Jul 2006)
ViewCVS:  http://svn.sourceforge.net/stripes/?rev=343&view=rev

Log Message:
-----------
Fix for STS-213: parameter binding should be ordered by the length of the 
parameter name.

Modified Paths:
--------------
    
trunk/stripes/src/net/sourceforge/stripes/controller/OgnlActionBeanPropertyBinder.java
    trunk/stripes/src/net/sourceforge/stripes/controller/ParameterName.java
Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/OgnlActionBeanPropertyBinder.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/OgnlActionBeanPropertyBinder.java
      2006-07-08 00:12:11 UTC (rev 342)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/OgnlActionBeanPropertyBinder.java
      2006-07-08 13:07:43 UTC (rev 343)
@@ -54,6 +54,8 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
+import java.util.SortedMap;
 import java.util.regex.Pattern;
 import java.security.GeneralSecurityException;
 
@@ -234,7 +236,7 @@
 
         // Converted values for all fields are accumulated in this map to make 
post-conversion
         // validation go a little easier
-        Map<ParameterName,List<Object>> allConvertedFields = new 
HashMap<ParameterName,List<Object>>();
+        Map<ParameterName,List<Object>> allConvertedFields = new 
TreeMap<ParameterName,List<Object>>();
 
         // First we bind all the regular parameters
         for (Map.Entry<ParameterName,String[]> entry : parameters.entrySet() ) 
{
@@ -493,10 +495,12 @@
 
     /**
      * Converts the map of parameters in the request into a Map of 
ParameterName to String[].
+     * Returns a SortedMap so that when iterated over parameter names are 
accessed in order
+     * of length of parameter name.
      */
-    protected Map<ParameterName, String[]> getParameters(ActionBeanContext 
context) {
+    protected SortedMap<ParameterName, String[]> 
getParameters(ActionBeanContext context) {
         Map<String, String[]> requestParameters = 
context.getRequest().getParameterMap();
-        Map<ParameterName, String[]> parameters = new 
HashMap<ParameterName,String[]>();
+        SortedMap<ParameterName, String[]> parameters = new 
TreeMap<ParameterName,String[]>();
 
         for (Map.Entry<String,String[]> entry : requestParameters.entrySet()) {
             parameters.put(new ParameterName(entry.getKey().trim()), 
entry.getValue());

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/ParameterName.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/ParameterName.java     
2006-07-08 00:12:11 UTC (rev 342)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/ParameterName.java     
2006-07-08 13:07:43 UTC (rev 343)
@@ -23,7 +23,7 @@
  *
  * @author Tim Fennell
  */
-public class ParameterName {
+public class ParameterName implements Comparable<ParameterName> {
     /** Stores the regular expression that will remove all [] segments. */
     public static final Pattern pattern = Pattern.compile("\\[.*\\]");
 
@@ -83,13 +83,30 @@
     }
 
     /**
+     * Orders ParameterNames so that those with shorter (unstripped) names 
come first. Two
+     * names of the same length are then ordered alphabetically by 
String.compareTo().
+     *
+     * @param that another ParameterName to compare to
+     * @return -1 if this value sorts first, 0 if the values are identical and 
+1 if the
+     *         parameter passed in sorts first.
+     */
+    public int compareTo(ParameterName that) {
+        int result = new 
Integer(this.name.length()).compareTo(that.name.length());
+        if (result == 0) {
+            result = this.name.compareTo(that.name);
+        }
+
+        return result;
+    }
+
+    /**
      * Checks for equality as efficiently as possible.  First checks for JVM 
equality to
      * see if we can short circuit, and then checks for equality of the name 
attribute for
      * a real test.
      */
     public boolean equals(Object obj) {
         return (obj instanceof ParameterName) &&
-                (this == obj || this.name.equals(((ParameterName) obj).name) );
+                (this == obj || compareTo((ParameterName) obj) == 0);
     }
 
     /**


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to