struts選択ブロックのいくつかの方法

2761 ワード

public abstract class MethodFilterInterceptor extends AbstractInterceptor {  
    protected transient Logger log = LoggerFactory.getLogger(getClass());  
      
    protected Set<String> excludeMethods = Collections.emptySet();  
    protected Set<String> includeMethods = Collections.emptySet();  
 
    public void setExcludeMethods(String excludeMethods) {  
        this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods);  
    }  
      
    public Set<String> getExcludeMethodsSet() {  
        return excludeMethods;  
    }  
 
    public void setIncludeMethods(String includeMethods) {  
        this.includeMethods = TextParseUtil.commaDelimitedStringToSet(includeMethods);  
    }  
      
    public Set<String> getIncludeMethodsSet() {  
        return includeMethods;  
    }  
 
    @Override 
    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  
        boolean applyMethod = MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, method);  
        if (log.isDebugEnabled()) {  
            if (!applyMethod) {  
                log.debug("Skipping Interceptor... Method [" + method + "] found in exclude list.");  
            }  
        }  
        return applyMethod;  
    }  
      
    /**  
     * Subclasses must override to implement the interceptor logic.  
     *   
     * @param invocation the action invocation  
     * @return the result of invocation  
     * @throws Exception  
     */ 
    protected abstract String doIntercept(ActionInvocation invocation) throws Exception;  
      
}  


<!-- -->
            <interceptor-ref name="defaultStack"></interceptor-ref> 
            <interceptor-ref name="FilterInterceptor"> 
<!-- -->
                 <param name="includeMethods">method1</param>  
                 <param name="excludeMethods">method2</param>  
<!-- name -->
<param name="name">FilterMethod</param>
            </interceptor-ref>