Commits

Anonymous committed f51124d

Issue number: WW-1284
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk/src@1017e221344d-f017-0410-9bd5-d282ab1896d7

Comments (0)

Files changed (2)

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

     public void setExcludeMethods(String excludeMethods) {
         this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods);
     }
+    
+    public Set getExcludeMethodsSet() {
+    	return excludeMethods;
+    }
 
     public void setIncludeMethods(String includeMethods) {
         this.includeMethods = TextParseUtil.commaDelimitedStringToSet(includeMethods);
     }
+    
+    public Set getIncludeMethodsSet() {
+    	return includeMethods;
+    }
 
     public String intercept(ActionInvocation invocation) throws Exception {
         if (applyInterceptor(invocation)) {
             return doIntercept(invocation);
         } 
-        
         return invocation.invoke();
     }
 
     protected boolean applyInterceptor(ActionInvocation invocation) {
         String method = invocation.getProxy().getMethod();
         // ValidationInterceptor
-        if (((excludeMethods.contains("*") && !includeMethods.contains("*"))
-                || excludeMethods.contains(method))
-                && !includeMethods.contains(method)) {
-            if (log.isDebugEnabled()) log.debug("Skipping Interceptor... Method [" + method + "] found in exclude list.");
-            return false;
+        boolean applyMethod = MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, method);
+        if (log.isDebugEnabled()) {
+        	if (!applyMethod) {
+        		log.debug("Skipping Interceptor... Method [" + method + "] found in exclude list.");
+        	}
         }
-
-        return includeMethods.size() == 0 || includeMethods.contains(method) || includeMethods.contains("*");
-
+        return applyMethod;
     }
-
+    
     /**
      * Subclasses must override to implement the interceptor logic.
      * 

java/com/opensymphony/xwork/interceptor/MethodFilterInterceptorUtil.java

+/*
+ * Copyright (c) 2002-2006 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.interceptor;
+
+import java.util.Set;
+
+import com.opensymphony.xwork.util.TextParseUtil;
+
+/**
+ * Utility class contains common methods used by 
+ * {@link com.opensymphony.xwork.interceptor.MethodFilterInterceptorterceptor}
+ * and {@link org.apache.struts.action2.components.Form}.
+ * 
+ * @author tm_jee
+ * @version $Date$ $Id$
+ */
+public class MethodFilterInterceptorUtil {
+	/**
+     * Static method to decide if the specified <code>method</code> should be
+     * apply (not filtered) depending on the set of <code>excludeMethods</code> and 
+     * <code>includeMethods</code>. 
+     * 
+     * <p/>
+     * 
+     * <ul>
+     * <li>
+     * 	<code>excludeMethods</code> takes precedence over <code>includeMethods</code>
+     * </li>
+     * 
+     * <p/>
+     * 
+     * asterict '*' could be used to indicate all methods.
+     * 
+     * 
+     * @param excludeMethods
+     * @param includeMethods
+     * @return boolean
+     */
+    public static boolean applyMethod(Set excludeMethods, Set includeMethods, String method) {
+    	if (((excludeMethods.contains("*") && !includeMethods.contains("*"))
+                || excludeMethods.contains(method))
+                && !includeMethods.contains(method)) {
+            return false;
+        }
+        return includeMethods.size() == 0 || includeMethods.contains(method) || includeMethods.contains("*");
+    }
+    
+    /**
+     * Same as {@link #isMethodFiltered(Set, Set, String)}, except that <code>excludeMethods</code>
+     * and <code>includeMethods</code> are supplied as comma separated string.
+     * 
+     * @param excludeMethods
+     * @param includeMethods
+     * @param method
+     * @return
+     */
+    public static boolean applyMethod(String excludeMethods, String includeMethods, String method) {
+    	Set includeMethodsSet = TextParseUtil.commaDelimitedStringToSet(includeMethods == null? "" : includeMethods);
+    	Set excludeMethodsSet = TextParseUtil.commaDelimitedStringToSet(excludeMethods == null? "" : excludeMethods);
+    	
+    	return applyMethod(excludeMethodsSet, includeMethodsSet, method);
+    }
+}
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.