1 package org.javabb.interceptor; 2 3 import java.util.Iterator ; 4 import java.util.Map ; 5 6 import org.apache.commons.lang.StringUtils; 7 8 import com.opensymphony.xwork.ActionContext; 9 import com.opensymphony.xwork.ActionInvocation; 10 import com.opensymphony.xwork.interceptor.Interceptor; 11 12 27 28 32 public class ParameterInterceptor implements Interceptor { 33 34 String allowedBeans = ""; 35 36 39 public void setAllowedBeans(String [] allowedBeans) { 40 this.allowedBeans = StringUtils.join(allowedBeans, '|'); 41 } 42 43 46 public String intercept(ActionInvocation invocation) throws Exception { 47 String regex = "^(?:" + allowedBeans + ")?\\.?[^.]*$"; 48 49 Map parameters = ActionContext.getContext().getParameters(); 50 Iterator it = parameters.keySet().iterator(); 51 while (it.hasNext()) { 52 String param = (String ) it.next(); 53 if (!param.matches(regex)) { 54 it.remove(); 55 } 56 } 57 return invocation.invoke(); 58 } 59 60 63 public void destroy() { 64 } 66 67 70 public void init() { 71 } 73 } 74 | Popular Tags |