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.beans.PropertyDescriptor;
24 import java.util.Set;
25 import java.util.TreeSet;
26
27 import ognl.OgnlRuntime;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32 import com.opensymphony.xwork2.ObjectFactory;
33 import com.opensymphony.xwork2.config.entities.ActionConfig;
34
35 /***
36 * ShowConfigAction
37 */
38 public class ShowConfigAction extends ActionNamesAction {
39
40 private static final long serialVersionUID = -1630527489407671652L;
41
42 private static final PropertyDescriptor[] PDSAT = new PropertyDescriptor[0];
43
44 private String namespace;
45 private String actionName;
46 private ActionConfig config;
47 private Set actionNames;
48 private String detailView = "results";
49 private PropertyDescriptor[] properties;
50 private static Log log = LogFactory.getLog(ShowConfigAction.class);
51
52 public String getDetailView() {
53 return detailView;
54 }
55
56 public void setDetailView(String detailView) {
57 this.detailView = detailView;
58 }
59
60 public Set getActionNames() {
61 return actionNames;
62 }
63
64 public String getNamespace() {
65 return namespace;
66 }
67
68 public String stripPackage(Class clazz) {
69 return clazz.getName().substring(clazz.getName().lastIndexOf('.') + 1);
70 }
71
72 public void setNamespace(String namespace) {
73 this.namespace = namespace;
74 }
75
76 public String getActionName() {
77 return actionName;
78 }
79
80 public void setActionName(String actionName) {
81 this.actionName = actionName;
82 }
83
84 public ActionConfig getConfig() {
85 return config;
86 }
87
88 public PropertyDescriptor[] getProperties() {
89 return properties;
90 }
91
92 public String execute() throws Exception {
93 super.execute();
94 config = ConfigurationHelper.getActionConfig(namespace, actionName);
95 actionNames =
96 new TreeSet(ConfigurationHelper.getActionNames(namespace));
97 try {
98 Class clazz = ObjectFactory.getObjectFactory().getClassInstance(getConfig().getClassName());
99 java.util.Collection pds = OgnlRuntime.getPropertyDescriptors(clazz).values();
100 properties = (PropertyDescriptor[]) pds.toArray(PDSAT);
101 } catch (Exception e) {
102 log.error("Unable to get properties for action " + actionName, e);
103 addActionError("Unable to retrieve action properties: " + e.toString());
104 }
105
106 if (hasErrors())
107 return ERROR;
108 else
109 return SUCCESS;
110 }
111 }
112