|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| package org.apache.xindice.webadmin; |
|
21 |
| |
|
22 |
| import org.apache.commons.logging.Log; |
|
23 |
| import org.apache.commons.logging.LogFactory; |
|
24 |
| import org.apache.xindice.webadmin.viewer.HtmlCollectionViewer; |
|
25 |
| import org.apache.xindice.webadmin.viewer.HtmlDatabaseViewer; |
|
26 |
| import org.apache.xindice.webadmin.viewer.HtmlResourceViewer; |
|
27 |
| import org.apache.xindice.webadmin.webdav.components.DAVComponent; |
|
28 |
| |
|
29 |
| import org.w3c.dom.Element; |
|
30 |
| import org.w3c.dom.NamedNodeMap; |
|
31 |
| import org.w3c.dom.Node; |
|
32 |
| import org.w3c.dom.NodeList; |
|
33 |
| |
|
34 |
| import java.util.ArrayList; |
|
35 |
| import java.util.HashMap; |
|
36 |
| import java.util.Map; |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| public class WebAdminManager { |
|
54 |
| |
|
55 |
| private final Map methods = new HashMap(); |
|
56 |
| private final Map colViewers = new HashMap(); |
|
57 |
| private final Map resViewers = new HashMap(); |
|
58 |
| private final Map dbViewers = new HashMap(); |
|
59 |
| |
|
60 |
| private static String[] methodsList; |
|
61 |
| private static String[] colViewersList; |
|
62 |
| private static String[] resViewersList; |
|
63 |
| private static String[] dbViewersList; |
|
64 |
| |
|
65 |
| private static final Log log = LogFactory.getLog(WebAdminManager.class); |
|
66 |
| |
|
67 |
| |
|
68 |
1
| public WebAdminManager(Element config) {
|
|
69 |
1
| Node node = config.getElementsByTagName("methods").item(0);
|
|
70 |
1
| try {
|
|
71 |
1
| methodsList = processSection(node, "method", methods);
|
|
72 |
| } catch (Exception e) { |
|
73 |
0
| log.error("Failed to load WebDAV methods", e);
|
|
74 |
| } |
|
75 |
| |
|
76 |
1
| node = config.getElementsByTagName("colviewers").item(0);
|
|
77 |
1
| try {
|
|
78 |
1
| colViewersList = processSection(node, "viewer", colViewers);
|
|
79 |
| } catch (Exception e) { |
|
80 |
0
| log.error("Failed to load WebAdmin collection viewers", e);
|
|
81 |
| } |
|
82 |
| |
|
83 |
1
| node = config.getElementsByTagName("resviewers").item(0);
|
|
84 |
1
| try {
|
|
85 |
1
| resViewersList = processSection(node, "viewer", resViewers);
|
|
86 |
| } catch (Exception e) { |
|
87 |
0
| log.error("Failed to load WebAdmin resource viewers", e);
|
|
88 |
| } |
|
89 |
| |
|
90 |
1
| node = config.getElementsByTagName("dbviewers").item(0);
|
|
91 |
1
| try {
|
|
92 |
1
| dbViewersList = processSection(node, "viewer", dbViewers);
|
|
93 |
| } catch (Exception e) { |
|
94 |
0
| log.error("Failed to load WebAdmin DB viewers", e);
|
|
95 |
| } |
|
96 |
| } |
|
97 |
| |
|
98 |
4
| private String[] processSection(Node node, String name, Map storage) throws Exception {
|
|
99 |
4
| ArrayList list = new ArrayList();
|
|
100 |
| |
|
101 |
4
| NodeList nodes = ((Element) node).getElementsByTagName(name);
|
|
102 |
4
| for (int i = 0; i < nodes.getLength(); i++) {
|
|
103 |
25
| Node child = nodes.item(i);
|
|
104 |
25
| NamedNodeMap attrs = child.getAttributes();
|
|
105 |
| |
|
106 |
25
| String className = attrs.getNamedItem("class").getNodeValue();
|
|
107 |
25
| Object object = Class.forName(className).newInstance();
|
|
108 |
| |
|
109 |
25
| String id = attrs.getNamedItem("id").getNodeValue();
|
|
110 |
25
| if (id != null && id.length() > 0) {
|
|
111 |
25
| storage.put(id, object);
|
|
112 |
25
| list.add(id);
|
|
113 |
| } |
|
114 |
| } |
|
115 |
| |
|
116 |
4
| Node attr = node.getAttributes().getNamedItem("default");
|
|
117 |
4
| if (attr != null) {
|
|
118 |
4
| storage.put("default", storage.get(attr.getNodeValue()));
|
|
119 |
| } |
|
120 |
| |
|
121 |
4
| return (String[]) list.toArray(new String[0]);
|
|
122 |
| } |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
0
| public DAVComponent getMethod(String id) {
|
|
131 |
0
| return (DAVComponent) methods.get(id);
|
|
132 |
| } |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
0
| public HtmlCollectionViewer getCollectionViewer(String id) {
|
|
141 |
0
| if (id == null || id.length() == 0) {
|
|
142 |
0
| id = "default";
|
|
143 |
| } |
|
144 |
| |
|
145 |
0
| return (HtmlCollectionViewer) colViewers.get(id);
|
|
146 |
| } |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
0
| public HtmlResourceViewer getResourceViewer(String id) {
|
|
155 |
0
| if (id == null || id.length() == 0) {
|
|
156 |
0
| id = "default";
|
|
157 |
| } |
|
158 |
| |
|
159 |
0
| return (HtmlResourceViewer) resViewers.get(id);
|
|
160 |
| } |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
0
| public HtmlDatabaseViewer getDatabaseViewer(String id) {
|
|
169 |
0
| if (id == null || id.length() == 0) {
|
|
170 |
0
| id = "default";
|
|
171 |
| } |
|
172 |
| |
|
173 |
0
| return (HtmlDatabaseViewer) dbViewers.get(id);
|
|
174 |
| } |
|
175 |
| |
|
176 |
| |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
0
| public static String[] getMethods() {
|
|
182 |
0
| return methodsList;
|
|
183 |
| } |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
| |
|
188 |
| |
|
189 |
| |
|
190 |
0
| public static String[] getDatabaseViewers() {
|
|
191 |
0
| return dbViewersList;
|
|
192 |
| } |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
0
| public static String[] getCollectionViewers() {
|
|
200 |
0
| return colViewersList;
|
|
201 |
| } |
|
202 |
| |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
| |
|
208 |
0
| public static String[] getResourceViewers() {
|
|
209 |
0
| return resViewersList;
|
|
210 |
| } |
|
211 |
| } |