View Javadoc

1   package com.atlassian.xwork.interceptors;
2   
3   import com.opensymphony.xwork.interceptor.Interceptor;
4   import com.opensymphony.xwork.ActionInvocation;
5   import com.opensymphony.xwork.Action;
6   import com.opensymphony.xwork.ValidationAware;
7   import com.opensymphony.xwork.Validateable;
8   
9   /**
10   * Very simple validation interceptor. If an action implements both Validateable
11   * and ValidationAware, the interceptor will call the actions Validateable#validate() method,
12   * and abort processing of the action (returning INPUT) if the validation results in errors.
13   */
14  public class SimpleValidationInterceptor implements Interceptor
15  {
16      public String intercept(ActionInvocation invocation) throws Exception
17      {
18          Action action = invocation.getAction();
19          if (action instanceof ValidationAware && action instanceof Validateable)
20          {
21              ((Validateable)action).validate();
22              if (((ValidationAware)action).hasErrors())
23              {
24                  return Action.INPUT;
25              }
26          }
27  
28          return invocation.invoke();
29      }
30  
31      ///CLOVER:OFF
32      public void destroy()
33      {
34      }
35  
36      public void init()
37      {
38      }
39  }