struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1129979 - in /struts/struts2/trunk/xwork-core/src: main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java test/java/com/opensymphony/xwork2/interceptor/ParametersInterceptorTest.java
Date Wed, 01 Jun 2011 00:30:25 GMT
Author: jafl
Date: Wed Jun  1 00:30:25 2011
New Revision: 1129979

URL: http://svn.apache.org/viewvc?rev=1129979&view=rev
Log:
XW-386 allow x['y'] as well as x.y

Modified:
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/interceptor/ParametersInterceptorTest.java

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java?rev=1129979&r1=1129978&r2=1129979&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java
Wed Jun  1 00:30:25 2011
@@ -1,12 +1,12 @@
 /*
  * Copyright 2002-2007,2009 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -160,18 +160,22 @@ public class ParametersInterceptor exten
         }
     }
 
+    static private int countOGNLCharacters(String s) {
+        int count = 0;
+        for (int i = s.length() - 1; i >= 0; i--) {
+            char c = s.charAt(i);
+            if (c == '.' || c == '[') count++;
+        }
+        return count;
+    }
+
     /**
-     * Compares based on number of '.' characters (fewer is higher)
+     * Compares based on number of '.' and '[' characters (fewer is higher)
      */
     static final Comparator<String> rbCollator = new Comparator<String>() {
         public int compare(String s1, String s2) {
-            int l1 = 0, l2 = 0;
-            for (int i = s1.length() - 1; i >= 0; i--) {
-                if (s1.charAt(i) == '.') l1++;
-            }
-            for (int i = s2.length() - 1; i >= 0; i--) {
-                if (s2.charAt(i) == '.') l2++;
-            }
+            int l1 = countOGNLCharacters(s1),
+                l2 = countOGNLCharacters(s2);
             return l1 < l2 ? -1 : (l2 < l1 ? 1 : s1.compareTo(s2));
         }
 
@@ -328,7 +332,7 @@ public class ParametersInterceptor exten
             if (entry.getValue() instanceof Object[]) {
                 Object[] valueArray = (Object[]) entry.getValue();
                 logEntry.append("[ ");
-		        if (valueArray.length > 0 ) {
+                if (valueArray.length > 0 ) {
                     for (int indexA = 0; indexA < (valueArray.length - 1); indexA++) {
                         Object valueAtIndex = valueArray[indexA];
                         logEntry.append(String.valueOf(valueAtIndex));

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/interceptor/ParametersInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/interceptor/ParametersInterceptorTest.java?rev=1129979&r1=1129978&r2=1129979&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/interceptor/ParametersInterceptorTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/interceptor/ParametersInterceptorTest.java
Wed Jun  1 00:30:25 2011
@@ -394,20 +394,23 @@ public class ParametersInterceptorTest e
 
         Map<String, Object> parameters = new HashMap<String, Object>();
         parameters.put("user.address.city", "London");
+        parameters.put("user.address['postal']", "QJR387");
         parameters.put("user.name", "Superman");
 
         Action action = new SimpleAction();
         pi.setParameters(action, stack, parameters);
 
         assertEquals(true, pi.isOrdered());
-        assertEquals(2, actual.size());
+        assertEquals(3, actual.size());
         assertEquals("London", actual.get("user.address.city"));
+        assertEquals("QJR387", actual.get("user.address['postal']"));
         assertEquals("Superman", actual.get("user.name"));
 
         // should be ordered so user.name should be first
         List<Object> values = new ArrayList<Object>(actual.values());
         assertEquals("Superman", values.get(0));
         assertEquals("London", values.get(1));
+        assertEquals("QJR387", values.get(2));
     }
 
     public void testSetOrdered() throws Exception {



Mime
View raw message