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