1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.config_browser;
22
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.apache.struts2.util.ClassLoaderUtils;
27
28 import com.opensymphony.xwork2.ActionContext;
29 import com.opensymphony.xwork2.ActionSupport;
30 import com.opensymphony.xwork2.validator.ActionValidatorManagerFactory;
31
32 /***
33 * ListValidatorsAction loads the validations for a given class and context
34 *
35 */
36 public class ListValidatorsAction extends ActionSupport {
37
38 private static final long serialVersionUID = 1L;
39
40 private String clazz;
41 private String context;
42 List validators = Collections.EMPTY_LIST;
43
44 public String getClazz() {
45 return clazz;
46 }
47
48 public void setClazz(String clazz) {
49 this.clazz = clazz;
50 }
51
52 public String stripPackage(Class clazz) {
53 return clazz.getName().substring(clazz.getName().lastIndexOf('.') + 1);
54 }
55
56 public String stripPackage(String clazz) {
57 return clazz.substring(clazz.lastIndexOf('.') + 1);
58 }
59
60 public String getContext() {
61 return context;
62 }
63
64 public void setContext(String context) {
65 this.context = context;
66 }
67
68 public List getValidators() {
69 return validators;
70 }
71
72 public String execute() throws Exception {
73 loadValidators();
74 return super.execute();
75 }
76
77 protected void loadValidators() {
78 Class value = getClassInstance();
79 if ( value != null ) {
80 validators = ActionValidatorManagerFactory.getInstance().getValidators(value, context);
81 }
82 }
83
84 private Class getClassInstance() {
85 try {
86 return ClassLoaderUtils.loadClass(clazz, ActionContext.getContext().getClass());
87 } catch (Exception e) {
88 LOG.error("Class '" + clazz + "' not found...",e);
89 }
90 return null;
91 }
92 }