From 0437efc6f91c2b78d84f673a63d45ef2765782db Mon Sep 17 00:00:00 2001 From: Yasser Zamani Date: Fri, 3 Feb 2017 02:01:50 +0330 Subject: [PATCH] [WW-4528] handling ChainingInterceptor excludes and includes lists as comma separated String like ParameterFilterInterceptor do --- .../interceptor/ChainingInterceptor.java | 24 +++++++++++++++++-- .../interceptor/ChainingInterceptorTest.java | 12 ++++------ .../xwork2/ognl/OgnlUtilTest.java | 4 ++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java index 93bae6d02..27a0f6861 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ChainingInterceptor.java @@ -21,6 +21,7 @@ import com.opensymphony.xwork2.Result; import com.opensymphony.xwork2.Unchainable; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.CompoundRoot; +import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.ValueStack; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -210,12 +211,21 @@ public class ChainingInterceptor extends AbstractInterceptor { return excludes; } + /** + * Sets the list of parameter names to exclude from copying (all others will be included). + * + * @param excludes the excludes list as comma separated String + */ + public void setExcludes(String excludes) { + this.excludes = TextParseUtil.commaDelimitedStringToSet(excludes); + } + /** * Sets the list of parameter names to exclude from copying (all others will be included). * * @param excludes the excludes list */ - public void setExcludes(Collection excludes) { + public void setExcludesCollection(Collection excludes) { this.excludes = excludes; } @@ -228,12 +238,22 @@ public class ChainingInterceptor extends AbstractInterceptor { return includes; } + /** + * Sets the list of parameter names to include when copying (all others will be excluded). + * + * @param includes the includes list as comma separated String + */ + public void setIncludes(String includes) { + this.includes = TextParseUtil.commaDelimitedStringToSet(includes); + } + + /** * Sets the list of parameter names to include when copying (all others will be excluded). * * @param includes the includes list */ - public void setIncludes(Collection includes) { + public void setIncludesCollection(Collection includes) { this.includes = includes; } diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java index 1b842090f..8c18ee5c6 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/ChainingInterceptorTest.java @@ -103,8 +103,7 @@ public class ChainingInterceptorTest extends XWorkTestCase { interceptor.setCopyErrors("true"); interceptor.setCopyMessages("true"); - Collection excludes = new ArrayList<>(); - excludes.add("count"); + String excludes = "count"; interceptor.setExcludes(excludes); interceptor.intercept(invocation); @@ -112,7 +111,7 @@ public class ChainingInterceptorTest extends XWorkTestCase { assertEquals(bean.getBirth(), action.getBirth()); assertEquals(bean.getName(), action.getName()); assertEquals(0, action.getCount()); - assertEquals(excludes, interceptor.getExcludes()); + assertEquals(interceptor.getExcludes().iterator().next(), "count"); } public void testTwoExcludesPropertiesChained() throws Exception { @@ -125,15 +124,14 @@ public class ChainingInterceptorTest extends XWorkTestCase { stack.push(bean); stack.push(action); - Collection excludes = new ArrayList<>(); - excludes.add("name"); - excludes.add("count"); + 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(interceptor.getExcludes().iterator().next(), "count"); + assertEquals(interceptor.getExcludes().iterator().next(), "name"); } public void testNullCompoundRootElementAllowsProcessToContinue() throws Exception { diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java index 4fdf742a0..a8bc7da83 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java @@ -454,7 +454,7 @@ public class OgnlUtilTest extends XWorkTestCase { final ValueStack stack = ActionContext.getContext().getValueStack(); Object result = Ognl.getValue(ognlUtil.compile("{\"foo\",'ruby','b','tom'}"), context, foo); - foo.setIncludes((Collection) result); + foo.setIncludesCollection((Collection) result); assertEquals(4, foo.getIncludes().size()); assertEquals("foo", foo.getIncludes().toArray()[0]); @@ -473,7 +473,7 @@ public class OgnlUtilTest extends XWorkTestCase { result = ActionContext.getContext().getValueStack().findValue("{\"foo\",'ruby','b','tom'}"); - foo.setIncludes((Collection) result); + foo.setIncludesCollection((Collection) result); assertEquals(ArrayList.class, result.getClass()); assertEquals(4, foo.getIncludes().size());