Commits

Anonymous committed a68e08e

WW-1475 (ChainingInterceptor does not properly parse the incoming included or excluded methods)

git-svn-id: http://svn.opensymphony.com/svn/xwork/branches/xwork_1-2@1695e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (6)

src/java/com/opensymphony/xwork/interceptor/ChainingInterceptor.java

 import com.opensymphony.xwork.util.CompoundRoot;
 import com.opensymphony.xwork.util.OgnlUtil;
 import com.opensymphony.xwork.util.OgnlValueStack;
+import com.opensymphony.xwork.util.TextParseUtil;
 
 import java.util.*;
 
  * <!-- END SNIPPET: example -->
  * </pre>
  *
- * @author $Author$
- * @author tm_jee ( tm_jee(at)yahoo.co.uk )
- * @version $Revision$
+ * @author Rainer
+ * @author tmjee
+ * @version $Date$ $Id$
  */
 public class ChainingInterceptor extends AroundInterceptor {
 	
     Collection excludes;
     Collection includes;
 
+    /**
+     * No operation, does nothing
+     * 
+     * @param invocation
+     * @param result
+     * @throws Exception
+     */
     protected void after(ActionInvocation invocation, String result) throws Exception {
     }
 
+    /**
+     * Copy value of method invocation excluded and included by {@link #includes} {@link #excludes} separately
+     * into ValueStack's CompoundRoot.
+     * 
+     * @param invocation
+     * @throws Exception
+     */
     protected void before(ActionInvocation invocation) throws Exception {
         OgnlValueStack stack = invocation.getStack();
         CompoundRoot root = stack.getRoot();
         return excludes;
     }
 
-    public void setExcludes(Collection excludes) {
-        this.excludes = excludes;
+    public void setExcludes(String excludes) {
+        // WW-1475
+        this.excludes = TextParseUtil.commaDelimitedStringToSet(excludes);
     }
 
     public Collection getIncludes() {
         return includes;
     }
 
-    public void setIncludes(Collection includes) {
-        this.includes = includes;
+    public void setIncludes(String includes) {
+        // WW-1475
+        this.includes = TextParseUtil.commaDelimitedStringToSet(includes);
     }
 }

src/java/com/opensymphony/xwork/interceptor/MethodFilterInterceptor.java

  * 
  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
  * @author Rainer Hermanns
+ * @author tmjee
+ * @version $Date$ $Id$
  * 
  * @see com.opensymphony.webwork.interceptor.TokenInterceptor
  * @see com.opensymphony.webwork.interceptor.TokenSessionStoreInterceptor
  * @see com.opensymphony.xwork.interceptor.DefaultWorkflowInterceptor
  * @see com.opensymphony.xwork.validator.ValidationInterceptor
- * 
- * @version $Date$ $Id$
  */
 public abstract class MethodFilterInterceptor implements Interceptor {
     protected transient Log log = LogFactory.getLog(getClass());

src/java/com/opensymphony/xwork/validator/ValidationInterceptor.java

  * @author Jason Carreira
  * @author Rainer Hermanns
  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
+ * @author tmjee
+ * @version $Date$ $Id$
+ * 
  * @see ActionValidatorManager
  * @see com.opensymphony.xwork.interceptor.DefaultWorkflowInterceptor
- * 
- * @version $Date$ $Id$
  */
 public class ValidationInterceptor extends MethodFilterInterceptor {
     /**

src/test/com/opensymphony/xwork/interceptor/ChainingInterceptorTest.java

 
 import java.util.Date;
 import java.util.HashMap;
-import java.util.ArrayList;
-import java.util.Collection;
 
 
 /**
  * Unit test for {@link ChainingInterceptor}.
  *
  * @author Jason Carreira
+ * @author tmjee
+ * @version $Date$ $Id$
  */
 public class ChainingInterceptorTest extends TestCase {
 
         stack.push(bean);
         stack.push(action);
 
-        Collection excludes = new ArrayList();
-        excludes.add("count");
+        // WW-1475
+        String excludes = "count";
         interceptor.setExcludes(excludes);
         interceptor.intercept(invocation);
         assertEquals(bean.getBirth(), action.getBirth());
         assertEquals(bean.getName(), action.getName());
         assertEquals(0, action.getCount());
-        assertEquals(excludes, interceptor.getExcludes());
+        assertEquals(1, interceptor.getExcludes().size());
+        assertTrue(interceptor.getExcludes().contains("count"));
+        assertFalse(interceptor.getExcludes().contains("xxxx"));
     }
 
     public void testTwoExcludesPropertiesChained() throws Exception {
         stack.push(bean);
         stack.push(action);
 
-        Collection excludes = new ArrayList();
-        excludes.add("name");
-        excludes.add("count");
+        // WW-1475
+        String excludes = "name,count";
         interceptor.setExcludes(excludes);
         interceptor.intercept(invocation);
         assertEquals(bean.getBirth(), action.getBirth());
         assertEquals(null, action.getName());
         assertEquals(0, action.getCount());
-        assertEquals(excludes, interceptor.getExcludes());
+        assertEquals(2, interceptor.getExcludes().size());
+        assertTrue(interceptor.getExcludes().contains("name"));
+        assertTrue(interceptor.getExcludes().contains("count"));
+        assertFalse(interceptor.getExcludes().contains("xxxx"));
     }
 
     public void testNullCompoundRootElementAllowsProcessToContinue() throws Exception {

src/test/com/opensymphony/xwork/util/MyListObject.java

+package com.opensymphony.xwork.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author tmjee
+ * @version $Date$ $Id$
+ */
+public class MyListObject {
+
+    List includes = new ArrayList();
+    List excludes = new ArrayList();
+
+    public List getIncludes() {
+        return includes;
+    }
+
+    public void setIncludes(List includes) {
+        this.includes = includes;
+    }
+
+    public List getExcludes() {
+        return excludes;
+    }
+
+    public void setExcludes(List excludes) {
+        this.excludes = excludes;
+    }
+}

src/test/com/opensymphony/xwork/util/OgnlUtilTest.java

 
 /**
  * Unit test of {@link OgnlUtil}.
+ *
+ * @author Jason Carreirra
+ * @author tmjee
+ * @version $Date$ $Id$
  */
 public class OgnlUtilTest extends XWorkTestCase {
 
 
 
     public void testSetList() throws Exception {
-        ChainingInterceptor foo = new ChainingInterceptor();
-        ChainingInterceptor foo2 = new ChainingInterceptor();
+        MyListObject foo = new MyListObject();
+        MyListObject foo2 = new MyListObject();
 
         OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
         SimpleNode expression = (SimpleNode) Ognl.parseExpression("{'a','ruby','b','tom'}");
         final OgnlValueStack stack = ActionContext.getContext().getValueStack();
 
         Object result = Ognl.getValue(OgnlUtil.compile("{\"foo\",'ruby','b','tom'}"), context, foo);
-        foo.setIncludes((Collection) result);
+        foo.setIncludes((List)result);
 
         assertEquals(4, foo.getIncludes().size());
         assertEquals("foo", foo.getIncludes().toArray()[0]);
         assertEquals("tom", foo.getIncludes().toArray()[3]);
 
         result = ActionContext.getContext().getValueStack().findValue("{\"foo\",'ruby','b','tom'}");
-
-        foo.setIncludes((Collection) result);
+        foo.setIncludes((List) result);
         assertEquals(ArrayList.class, result.getClass());
 
         assertEquals(4, foo.getIncludes().size());
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.