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