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.components; |
21 |
| |
22 |
| import org.apache.xindice.webadmin.viewer.HtmlViewerComponent; |
23 |
| import org.apache.xindice.webadmin.viewer.HtmlDatabaseViewer; |
24 |
| import org.apache.xindice.core.Database; |
25 |
| import org.apache.xindice.util.StringUtilities; |
26 |
| |
27 |
| import javax.servlet.http.HttpServletRequest; |
28 |
| import javax.servlet.http.HttpServletResponse; |
29 |
| import javax.servlet.ServletException; |
30 |
| import java.io.IOException; |
31 |
| import java.io.Writer; |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| public class ListDatabaseViewer extends HtmlViewerComponent implements HtmlDatabaseViewer { |
39 |
| |
40 |
0
| public void execute(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
|
41 |
| |
42 |
0
| String[] databases = Database.listDatabases();
|
43 |
| |
44 |
0
| String path = "/";
|
45 |
0
| String title = "List databases";
|
46 |
| |
47 |
0
| ListDatabaseViewer.TableRow row = new ListDatabaseViewer.TableRow();
|
48 |
0
| Writer output = startViewer(title, path, res);
|
49 |
0
| printStartTable(row.getTitles(), output);
|
50 |
| |
51 |
0
| for (int i = 0; i < databases.length; i++) {
|
52 |
0
| boolean metaEnabled = Database.getDatabase(databases[i]).isMetaEnabled();
|
53 |
0
| String dbRoot = Database.getDatabase(databases[i]).getCollectionRoot().getCanonicalPath();
|
54 |
0
| printTableRow(row.getDatabase(databases[i], metaEnabled, dbRoot), output);
|
55 |
| } |
56 |
| |
57 |
0
| printEndTable(output);
|
58 |
0
| finishViewer(output);
|
59 |
| } |
60 |
| |
61 |
0
| protected String getName() {
|
62 |
0
| return "list";
|
63 |
| } |
64 |
| |
65 |
| |
66 |
| protected class TableRow { |
67 |
| |
68 |
| protected final String[] titles = {"Name", "Type", "Meta-enabled", "DB root"}; |
69 |
| |
70 |
| protected String[] content; |
71 |
| |
72 |
0
| TableRow() {
|
73 |
0
| content = new String[titles.length];
|
74 |
0
| reset();
|
75 |
| } |
76 |
| |
77 |
0
| protected String[] getTitles() {
|
78 |
0
| return titles;
|
79 |
| } |
80 |
| |
81 |
0
| protected void reset() {
|
82 |
0
| for (int i = 0; i < content.length; i++) {
|
83 |
0
| content[i] = null;
|
84 |
| } |
85 |
| } |
86 |
| |
87 |
0
| protected String[] getDatabase(String name, boolean metaEnabled, String dbRoot) {
|
88 |
0
| reset();
|
89 |
0
| content[0] = createLink(StringUtilities.escapePath(name) + "/?viewer=list", name);
|
90 |
0
| content[1] = "database";
|
91 |
0
| content[2] = Boolean.toString(metaEnabled);
|
92 |
0
| content[3] = dbRoot;
|
93 |
0
| return content;
|
94 |
| } |
95 |
| |
96 |
0
| protected String createLink(String link, String name) {
|
97 |
0
| return "<a href=\"" + link + "\">" + name + "</a>";
|
98 |
| } |
99 |
| } |
100 |
| } |