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