|
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.viewer; |
|
21 |
| |
|
22 |
| import java.io.IOException; |
|
23 |
| import java.io.OutputStreamWriter; |
|
24 |
| import java.io.Writer; |
|
25 |
| import java.util.HashMap; |
|
26 |
| import java.util.Map; |
|
27 |
| |
|
28 |
| import javax.servlet.ServletException; |
|
29 |
| import javax.servlet.http.HttpServletResponse; |
|
30 |
| |
|
31 |
| import org.apache.xindice.server.Xindice; |
|
32 |
| import org.apache.xindice.webadmin.WebAdminManager; |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| public abstract class HtmlViewerComponent { |
|
41 |
| |
|
42 |
| static final Object[][] entitiesArray = |
|
43 |
| {{"quot", new Integer(34)}, |
|
44 |
| {"amp", new Integer(38)}, |
|
45 |
| {"lt", new Integer(60)}, |
|
46 |
| {"gt", new Integer(62)}, |
|
47 |
| {"nbsp", new Integer(160)}, |
|
48 |
| {"copy", new Integer(169)}, |
|
49 |
| {"reg", new Integer(174)}, |
|
50 |
| {"Agrave", new Integer(192)}, |
|
51 |
| {"Aacute", new Integer(193)}, |
|
52 |
| {"Acirc", new Integer(194)}, |
|
53 |
| {"Atilde", new Integer(195)}, |
|
54 |
| {"Auml", new Integer(196)}, |
|
55 |
| {"Aring", new Integer(197)}, |
|
56 |
| {"AElig", new Integer(198)}, |
|
57 |
| {"Ccedil", new Integer(199)}, |
|
58 |
| {"Egrave", new Integer(200)}, |
|
59 |
| {"Eacute", new Integer(201)}, |
|
60 |
| {"Ecirc", new Integer(202)}, |
|
61 |
| {"Euml", new Integer(203)}, |
|
62 |
| {"Igrave", new Integer(204)}, |
|
63 |
| {"Iacute", new Integer(205)}, |
|
64 |
| {"Icirc", new Integer(206)}, |
|
65 |
| {"Iuml", new Integer(207)}, |
|
66 |
| {"ETH", new Integer(208)}, |
|
67 |
| {"Ntilde", new Integer(209)}, |
|
68 |
| {"Ograve", new Integer(210)}, |
|
69 |
| {"Oacute", new Integer(211)}, |
|
70 |
| {"Ocirc", new Integer(212)}, |
|
71 |
| {"Otilde", new Integer(213)}, |
|
72 |
| {"Ouml", new Integer(214)}, |
|
73 |
| {"Oslash", new Integer(216)}, |
|
74 |
| {"Ugrave", new Integer(217)}, |
|
75 |
| {"Uacute", new Integer(218)}, |
|
76 |
| {"Ucirc", new Integer(219)}, |
|
77 |
| {"Uuml", new Integer(220)}, |
|
78 |
| {"Yacute", new Integer(221)}, |
|
79 |
| {"THORN", new Integer(222)}, |
|
80 |
| {"szlig", new Integer(223)}, |
|
81 |
| {"agrave", new Integer(224)}, |
|
82 |
| {"aacute", new Integer(225)}, |
|
83 |
| {"acirc", new Integer(226)}, |
|
84 |
| {"atilde", new Integer(227)}, |
|
85 |
| {"auml", new Integer(228)}, |
|
86 |
| {"aring", new Integer(229)}, |
|
87 |
| {"aelig", new Integer(230)}, |
|
88 |
| {"ccedil", new Integer(231)}, |
|
89 |
| {"egrave", new Integer(232)}, |
|
90 |
| {"eacute", new Integer(233)}, |
|
91 |
| {"ecirc", new Integer(234)}, |
|
92 |
| {"euml", new Integer(235)}, |
|
93 |
| {"igrave", new Integer(236)}, |
|
94 |
| {"iacute", new Integer(237)}, |
|
95 |
| {"icirc", new Integer(238)}, |
|
96 |
| {"iuml", new Integer(239)}, |
|
97 |
| {"igrave", new Integer(236)}, |
|
98 |
| {"iacute", new Integer(237)}, |
|
99 |
| {"icirc", new Integer(238)}, |
|
100 |
| {"iuml", new Integer(239)}, |
|
101 |
| {"eth", new Integer(240)}, |
|
102 |
| {"ntilde", new Integer(241)}, |
|
103 |
| {"ograve", new Integer(242)}, |
|
104 |
| {"oacute", new Integer(243)}, |
|
105 |
| {"ocirc", new Integer(244)}, |
|
106 |
| {"otilde", new Integer(245)}, |
|
107 |
| {"ouml", new Integer(246)}, |
|
108 |
| {"oslash", new Integer(248)}, |
|
109 |
| {"ugrave", new Integer(249)}, |
|
110 |
| {"uacute", new Integer(250)}, |
|
111 |
| {"ucirc", new Integer(251)}, |
|
112 |
| {"uuml", new Integer(252)}, |
|
113 |
| {"yacute", new Integer(253)}, |
|
114 |
| {"thorn", new Integer(254)}, |
|
115 |
| {"yuml", new Integer(255)}, |
|
116 |
| {"euro", new Integer(8364)}, |
|
117 |
| }; |
|
118 |
| static Map entities = new HashMap(); |
|
119 |
| |
|
120 |
| static { |
|
121 |
1
| for (int i = 0; i < entitiesArray.length; ++i) {
|
|
122 |
74
| entities.put(entitiesArray[i][1], entitiesArray[i][0]);
|
|
123 |
| } |
|
124 |
| } |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
0
| public static String htmlescape(String unescaped) {
|
|
133 |
0
| return htmlescape(unescaped, false);
|
|
134 |
| } |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
0
| public static String htmlescape(String unescaped, boolean brake) {
|
|
144 |
0
| StringBuffer buf = new StringBuffer();
|
|
145 |
0
| for (int i = 0; i < unescaped.length(); ++i) {
|
|
146 |
0
| char ch = unescaped.charAt(i);
|
|
147 |
0
| String entity = (String) entities.get(new Integer((int) ch));
|
|
148 |
0
| if (entity == null) {
|
|
149 |
0
| if (((int) ch) > 128) {
|
|
150 |
0
| buf.append("&#").append ((int) ch).append(";");
|
|
151 |
| } else { |
|
152 |
0
| buf.append(ch);
|
|
153 |
| } |
|
154 |
| } else { |
|
155 |
0
| buf.append("&").append(entity).append(";");
|
|
156 |
| } |
|
157 |
0
| if (brake && ch == '>') {
|
|
158 |
0
| buf.append("\n");
|
|
159 |
| } |
|
160 |
| } |
|
161 |
0
| return buf.toString();
|
|
162 |
| } |
|
163 |
| |
|
164 |
| protected abstract String getName(); |
|
165 |
| |
|
166 |
0
| protected Writer startViewer(String title, String path, HttpServletResponse res)
|
|
167 |
| throws ServletException, IOException { |
|
168 |
| |
|
169 |
0
| res.setContentType("text/html; charset=utf-8");
|
|
170 |
0
| Writer output = new OutputStreamWriter(res.getOutputStream(), "utf-8");
|
|
171 |
0
| printHeader(output, title);
|
|
172 |
0
| printTabs(output, path);
|
|
173 |
0
| return output;
|
|
174 |
| } |
|
175 |
| |
|
176 |
0
| protected void finishViewer(Writer output) throws IOException {
|
|
177 |
0
| output.write(FOOTER);
|
|
178 |
0
| output.write(HTML_TAIL_SECTION);
|
|
179 |
0
| output.flush();
|
|
180 |
| } |
|
181 |
| |
|
182 |
0
| protected void printHeader(Writer output, String title) throws IOException {
|
|
183 |
0
| output.write(HTML_HEADER_SECTION);
|
|
184 |
0
| output.write(title);
|
|
185 |
0
| output.write(END_HTML_HEADER_SECTION);
|
|
186 |
0
| output.write(LOGO_SECTION);
|
|
187 |
| } |
|
188 |
| |
|
189 |
0
| protected void printTabs(Writer output, String path) throws IOException {
|
|
190 |
| |
|
191 |
0
| output.write(START_TABS_SECTION);
|
|
192 |
| |
|
193 |
0
| String[] viewers = new String[]{};
|
|
194 |
0
| if (this instanceof HtmlCollectionViewer) {
|
|
195 |
0
| viewers = WebAdminManager.getCollectionViewers();
|
|
196 |
0
| } else if (this instanceof HtmlResourceViewer) {
|
|
197 |
0
| viewers = WebAdminManager.getResourceViewers();
|
|
198 |
0
| } else if (this instanceof HtmlDatabaseViewer) {
|
|
199 |
0
| viewers = WebAdminManager.getDatabaseViewers();
|
|
200 |
| } |
|
201 |
| |
|
202 |
0
| for (int i = 0; i < viewers.length; i++) {
|
|
203 |
0
| if (viewers[i].equals(getName())) {
|
|
204 |
0
| if (i > 0) {
|
|
205 |
0
| output.write(TAB_SPACE_SELECTED);
|
|
206 |
| } |
|
207 |
0
| output.write(START_TAB_SELECTED);
|
|
208 |
0
| output.write(getName());
|
|
209 |
0
| output.write(END_TAB);
|
|
210 |
| } else { |
|
211 |
0
| if (i > 0) {
|
|
212 |
0
| output.write(TAB_SPACE);
|
|
213 |
| } |
|
214 |
0
| output.write(START_TAB);
|
|
215 |
0
| if (viewers[i].length() > 0) {
|
|
216 |
0
| output.write("<a href=\"?viewer=");
|
|
217 |
0
| output.write(viewers[i]);
|
|
218 |
0
| output.write("\" class=\"unselected\">");
|
|
219 |
0
| output.write(viewers[i]);
|
|
220 |
0
| output.write("</a>");
|
|
221 |
| } else { |
|
222 |
0
| output.write(" ");
|
|
223 |
| } |
|
224 |
0
| output.write(END_TAB);
|
|
225 |
| } |
|
226 |
| } |
|
227 |
0
| output.write(END_TABS_SECTION);
|
|
228 |
| |
|
229 |
| |
|
230 |
0
| output.write(LEFT_PATH_SECTION);
|
|
231 |
0
| if (path != null && path.length() > 1) {
|
|
232 |
0
| output.write(path);
|
|
233 |
| } else { |
|
234 |
0
| output.write("/");
|
|
235 |
| } |
|
236 |
0
| output.write(RIGHT_PATH_SECTION);
|
|
237 |
0
| output.write(" ");
|
|
238 |
0
| output.write(END_PATH_SECTION);
|
|
239 |
| } |
|
240 |
| |
|
241 |
0
| protected void printStartTable(String title, Writer output) throws IOException {
|
|
242 |
0
| String[] titles = {title};
|
|
243 |
0
| printStartTable(titles, output);
|
|
244 |
| } |
|
245 |
| |
|
246 |
0
| protected void printStartTable(String[] titles, Writer output) throws IOException {
|
|
247 |
0
| output.write(START_TABLE);
|
|
248 |
0
| output.write(START_TABLE_ROW);
|
|
249 |
| |
|
250 |
0
| for (int i = 0; i < titles.length; i++) {
|
|
251 |
0
| output.write(START_TABLE_BOX_TITLE);
|
|
252 |
0
| if (titles[i].length() > 0) {
|
|
253 |
0
| output.write(titles[i]);
|
|
254 |
| } else { |
|
255 |
0
| output.write(" ");
|
|
256 |
| } |
|
257 |
0
| output.write(END_TABLE_BOX);
|
|
258 |
| } |
|
259 |
| |
|
260 |
0
| output.write(END_TABLE_ROW);
|
|
261 |
| } |
|
262 |
| |
|
263 |
0
| protected void printEndTable(Writer output) throws IOException {
|
|
264 |
0
| output.write(END_TABLE);
|
|
265 |
| } |
|
266 |
| |
|
267 |
0
| protected void printTableRow(String content, Writer output) throws IOException {
|
|
268 |
0
| String[] contents = {content};
|
|
269 |
0
| printTableRow(contents, output);
|
|
270 |
| } |
|
271 |
| |
|
272 |
0
| protected void printTableRow(String[] contents, Writer output) throws IOException {
|
|
273 |
0
| output.write(START_TABLE_ROW);
|
|
274 |
| |
|
275 |
0
| for (int i = 0; i < contents.length; i++) {
|
|
276 |
0
| output.write(START_TABLE_BOX);
|
|
277 |
0
| if (contents[i] != null && contents[i].length() > 0) {
|
|
278 |
0
| output.write(contents[i]);
|
|
279 |
| } else { |
|
280 |
0
| output.write(" ");
|
|
281 |
| } |
|
282 |
0
| output.write(END_TABLE_BOX);
|
|
283 |
| } |
|
284 |
| |
|
285 |
0
| output.write(END_TABLE_ROW);
|
|
286 |
| } |
|
287 |
| |
|
288 |
0
| protected void printStartSingleTableBox(Writer output) throws IOException {
|
|
289 |
0
| output.write(START_TABLE_ROW);
|
|
290 |
0
| output.write(START_TABLE_BOX);
|
|
291 |
| } |
|
292 |
| |
|
293 |
0
| protected void printEndSingleTableBox(Writer output) throws IOException {
|
|
294 |
0
| output.write(END_TABLE_BOX);
|
|
295 |
0
| output.write(END_TABLE_ROW);
|
|
296 |
| } |
|
297 |
| |
|
298 |
0
| protected void printSearchFromRow(String viewer, String query, String[] ns, Writer output)
|
|
299 |
| throws IOException { |
|
300 |
| |
|
301 |
0
| query = query.replaceAll("\"", """);
|
|
302 |
| |
|
303 |
0
| output.write(START_TABLE_ROW);
|
|
304 |
0
| output.write(START_TABLE_BOX);
|
|
305 |
0
| output.write(START_SEARCH_FORM);
|
|
306 |
0
| output.write(SEARCH_FROM_START_HIDDEN_VIEWER);
|
|
307 |
0
| output.write(viewer);
|
|
308 |
0
| output.write(SEARCH_FROM_END_HIDDEN_VIEWER);
|
|
309 |
0
| output.write(SEARCH_FROM_START_QUERY);
|
|
310 |
0
| output.write(query);
|
|
311 |
0
| output.write(SEARCH_FROM_END_QUERY);
|
|
312 |
0
| output.write(SEARCH_FROM_START_NS_HEADER);
|
|
313 |
| |
|
314 |
0
| int nsSize = ns.length / 2;
|
|
315 |
0
| for (int i = 1; i < 10; i++) {
|
|
316 |
0
| if (i == nsSize) {
|
|
317 |
0
| output.write(SEARCH_FROM_START_NS_HEADER_OPT_SEL);
|
|
318 |
| } else { |
|
319 |
0
| output.write(SEARCH_FROM_START_NS_HEADER_OPT);
|
|
320 |
| } |
|
321 |
0
| output.write(i);
|
|
322 |
0
| output.write(SEARCH_FROM_END_NS_HEADER_OPT);
|
|
323 |
| } |
|
324 |
| |
|
325 |
0
| output.write(SEARCH_FROM_END_NS_HEADER);
|
|
326 |
| |
|
327 |
0
| int thisNs = 1;
|
|
328 |
0
| for (int i = 0; i < ns.length; i++) {
|
|
329 |
0
| output.write(SEARCH_FROM_START_NS);
|
|
330 |
0
| output.write(thisNs);
|
|
331 |
0
| output.write(SEARCH_FROM_START_NS_PREFIX);
|
|
332 |
0
| output.write(thisNs);
|
|
333 |
0
| output.write(SEARCH_FROM_END_NS_PREFIX);
|
|
334 |
0
| output.write(ns[i]);
|
|
335 |
0
| i++;
|
|
336 |
0
| output.write(SEARCH_FROM_START_NS_URI);
|
|
337 |
0
| output.write(thisNs);
|
|
338 |
0
| output.write(SEARCH_FROM_MIDDLE_NS_URI);
|
|
339 |
0
| output.write(ns[i]);
|
|
340 |
0
| output.write(SEARCH_FROM_END_NS_URI);
|
|
341 |
0
| thisNs++;
|
|
342 |
| } |
|
343 |
0
| output.write(END_SEARCH_FORM);
|
|
344 |
0
| output.write(END_TABLE_BOX);
|
|
345 |
0
| output.write(END_TABLE_ROW);
|
|
346 |
| } |
|
347 |
| |
|
348 |
| |
|
349 |
| |
|
350 |
| protected static final String HTML_HEADER_SECTION = |
|
351 |
| "<html> \n" |
|
352 |
| + "<head> \n" |
|
353 |
| + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" |
|
354 |
| + "<style type=\"text/css\"><!-- \n" |
|
355 |
| + "small { \n" |
|
356 |
| + " font-family: verdana,sans-serif; \n" |
|
357 |
| + " font-size: 8px; \n" |
|
358 |
| + "} \n" |
|
359 |
| + ".logo { \n" |
|
360 |
| + " font-family: verdana,sans-serif; \n" |
|
361 |
| + " text-align: center; \n" |
|
362 |
| + " font-weight: bold; \n" |
|
363 |
| + " font-size: 50px; \n" |
|
364 |
| + " color: #294563; \n" |
|
365 |
| + " margin-right: 5px; \n" |
|
366 |
| + "} \n" |
|
367 |
| + ".smallLogo { \n" |
|
368 |
| + " font-family: verdana,sans-serif; \n" |
|
369 |
| + " text-align: center; \n" |
|
370 |
| + " font-weight: normal; \n" |
|
371 |
| + " font-size: 12px; \n" |
|
372 |
| + " color: #294563; \n" |
|
373 |
| + " margin-top: -7px; \n" |
|
374 |
| + "} \n" |
|
375 |
| + ".tabs { \n" |
|
376 |
| + " background: #f0f0ff; \n" |
|
377 |
| + " color: #294563; \n" |
|
378 |
| + " border-width: 0px; \n" |
|
379 |
| + " padding: 0px 0px 0px 0px; \n" |
|
380 |
| + " margin: 0px 0px 0px 0px; \n" |
|
381 |
| + "} \n" |
|
382 |
| + ".unselected { \n" |
|
383 |
| + " width: 70px; \n" |
|
384 |
| + " background: #f0f0ff; \n" |
|
385 |
| + " color: #294563; \n" |
|
386 |
| + " font-family: verdana,sans-serif; \n" |
|
387 |
| + " text-align: center; \n" |
|
388 |
| + " font-size: 12px; \n" |
|
389 |
| + "} \n" |
|
390 |
| + ".selected { \n" |
|
391 |
| + " width: 70px; \n" |
|
392 |
| + " background: #294563; \n" |
|
393 |
| + " color: #f0f0ff; \n" |
|
394 |
| + " font-family: verdana,sans-serif; \n" |
|
395 |
| + " font-weight: bold; \n" |
|
396 |
| + " text-align: center; \n" |
|
397 |
| + " font-size: 12px; \n" |
|
398 |
| + "} \n" |
|
399 |
| + ".misc { \n" |
|
400 |
| + " background: #294563; \n" |
|
401 |
| + " color: #f0f0ff; \n" |
|
402 |
| + " font-family: verdana,sans-serif; \n" |
|
403 |
| + " font-weight: bold; \n" |
|
404 |
| + " text-align: left; \n" |
|
405 |
| + " font-size: 12px; \n" |
|
406 |
| + "} \n" |
|
407 |
| + ".misc-right { \n" |
|
408 |
| + " background: #294563; \n" |
|
409 |
| + " color: #f0f0ff; \n" |
|
410 |
| + " font-family: verdana,sans-serif; \n" |
|
411 |
| + " font-weight: bold; \n" |
|
412 |
| + " text-align: right; \n" |
|
413 |
| + " font-size: 12px; \n" |
|
414 |
| + "} \n" |
|
415 |
| + ".contents { \n" |
|
416 |
| + " width: 100%; \n" |
|
417 |
| + " border-width: 1px; \n" |
|
418 |
| + " border-style: solid; \n" |
|
419 |
| + " border-color: #294563; \n" |
|
420 |
| + "} \n" |
|
421 |
| + ".contents td { \n" |
|
422 |
| + " border-width: 1px; \n" |
|
423 |
| + " border-style: solid; \n" |
|
424 |
| + " border-color: #294563; \n" |
|
425 |
| + " font-family: verdana,sans-serif; \n" |
|
426 |
| + " text-align: left; \n" |
|
427 |
| + " font-size: 12px; \n" |
|
428 |
| + "} \n" |
|
429 |
| + ".title { \n" |
|
430 |
| + " background: #4C6C8F; \n" |
|
431 |
| + " color: #f0f0ff; \n" |
|
432 |
| + " font-family: verdana,sans-serif; \n" |
|
433 |
| + " font-weight: bold; \n" |
|
434 |
| + " text-align: left; \n" |
|
435 |
| + " font-size: 12px; \n" |
|
436 |
| + "} \n" |
|
437 |
| + |
|
438 |
| |
|
439 |
| ".xml-misc, .xml-element-name, .xml-attribute-name, .xml-attribute-content, " |
|
440 |
| + ".xml-element-content, .xml-comment, .xml-processing, .xml-cdata { \n" |
|
441 |
| + " font-family: verdana,sans-serif; \n" |
|
442 |
| + " font-size: 12px; \n" |
|
443 |
| + "} \n" |
|
444 |
| + ".xml-misc { \n" |
|
445 |
| + " color: #000000; \n" |
|
446 |
| + "} \n" |
|
447 |
| + ".xml-element-name { \n" |
|
448 |
| + " color: #cc0000; \n" |
|
449 |
| + "} \n" |
|
450 |
| + ".xml-attribute-name { \n" |
|
451 |
| + " color: #660099; \n" |
|
452 |
| + "} \n" |
|
453 |
| + ".xml-attribute-content { \n" |
|
454 |
| + " color: #000099; \n" |
|
455 |
| + "} \n" |
|
456 |
| + ".xml-element-content { \n" |
|