|
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 java.io.IOException; |
|
23 |
| import java.io.Writer; |
|
24 |
| import java.text.SimpleDateFormat; |
|
25 |
| import java.util.Date; |
|
26 |
| import java.util.Locale; |
|
27 |
| import java.util.TimeZone; |
|
28 |
| |
|
29 |
| import javax.servlet.ServletException; |
|
30 |
| import javax.servlet.http.HttpServletRequest; |
|
31 |
| import javax.servlet.http.HttpServletResponse; |
|
32 |
| |
|
33 |
| import org.apache.xindice.core.Collection; |
|
34 |
| import org.apache.xindice.core.DBException; |
|
35 |
| import org.apache.xindice.webadmin.viewer.HtmlCollectionViewer; |
|
36 |
| import org.apache.xindice.webadmin.viewer.HtmlViewerComponent; |
|
37 |
| import org.apache.xindice.util.StringUtilities; |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| public class ListCollectionViewer extends HtmlViewerComponent implements HtmlCollectionViewer { |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| public static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz"; |
|
51 |
| |
|
52 |
0
| public void execute(HttpServletRequest req, HttpServletResponse res, Collection col)
|
|
53 |
| throws ServletException, IOException { |
|
54 |
| |
|
55 |
0
| String path = col.getCanonicalName();
|
|
56 |
0
| String title = "List contents for " + path;
|
|
57 |
| |
|
58 |
0
| TableRow row = new TableRow();
|
|
59 |
0
| Writer output = startViewer(title, path, res);
|
|
60 |
0
| printStartTable(row.getTitles(), output);
|
|
61 |
| |
|
62 |
| |
|
63 |
0
| printTableRow(row.getParentCollection(), output);
|
|
64 |
| |
|
65 |
| |
|
66 |
0
| String[] childCol;
|
|
67 |
0
| try {
|
|
68 |
0
| childCol = col.listCollections();
|
|
69 |
| } catch (DBException e) { |
|
70 |
0
| childCol = new String[0];
|
|
71 |
| } |
|
72 |
0
| for (int i = 0; i < childCol.length; i++) {
|
|
73 |
0
| printTableRow(row.getCollection(childCol[i]), output);
|
|
74 |
| } |
|
75 |
| |
|
76 |
| |
|
77 |
0
| String[] childRes;
|
|
78 |
0
| try {
|
|
79 |
0
| childRes = col.listDocuments();
|
|
80 |
| } catch (Exception e) { |
|
81 |
0
| childRes = new String[0];
|
|
82 |
| } |
|
83 |
| |
|
84 |
0
| for (int i = 0; i < childRes.length; i++) {
|
|
85 |
0
| String date;
|
|
86 |
0
| try {
|
|
87 |
0
| long modificationDate = col.getEntryMeta(childRes[i]).getModificationTime();
|
|
88 |
0
| if (modificationDate != 0) {
|
|
89 |
0
| SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT, Locale.US);
|
|
90 |
0
| formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
91 |
0
| date = formatter.format(new Date(modificationDate));
|
|
92 |
| } else { |
|
93 |
0
| date = "";
|
|
94 |
| } |
|
95 |
| } catch (DBException e) { |
|
96 |
0
| date = "";
|
|
97 |
| } |
|
98 |
0
| printTableRow(row.getResource(childRes[i], date), output);
|
|
99 |
| } |
|
100 |
0
| printEndTable(output);
|
|
101 |
0
| finishViewer(output);
|
|
102 |
| } |
|
103 |
| |
|
104 |
0
| protected String getName() {
|
|
105 |
0
| return "list";
|
|
106 |
| } |
|
107 |
| |
|
108 |
| |
|
109 |
| protected class TableRow { |
|
110 |
| |
|
111 |
| protected final String[] titles = {"Name", "Type", "Last Modification", "Source", "Delete"}; |
|
112 |
| |
|
113 |
| protected String[] content; |
|
114 |
| |
|
115 |
0
| TableRow() {
|
|
116 |
0
| content = new String[titles.length];
|
|
117 |
0
| reset();
|
|
118 |
| } |
|
119 |
| |
|
120 |
0
| protected String[] getTitles() {
|
|
121 |
0
| return titles;
|
|
122 |
| } |
|
123 |
| |
|
124 |
0
| protected void reset() {
|
|
125 |
0
| for (int i = 0; i < content.length; i++) {
|
|
126 |
0
| content[i] = null;
|
|
127 |
| } |
|
128 |
| } |
|
129 |
| |
|
130 |
0
| protected String[] getCollection(String name) {
|
|
131 |
0
| reset();
|
|
132 |
0
| String encName = StringUtilities.escapePath(name);
|
|
133 |
0
| content[0] = createLink(encName + "/?viewer=list", name);
|
|
134 |
0
| content[1] = "collection";
|
|
135 |
0
| content[3] = " ";
|
|
136 |
0
| content[4] = createLink(encName + "/?viewer=delete&redirect=../?viewer=list", "delete");
|
|
137 |
0
| return content;
|
|
138 |
| } |
|
139 |
| |
|
140 |
0
| protected String[] getResource(String name, String date) {
|
|
141 |
0
| reset();
|
|
142 |
0
| String encName = StringUtilities.escapePath(name);
|
|
143 |
0
| content[0] = createLink(encName + "?viewer=default", name);
|
|
144 |
0
| content[1] = "resource";
|
|
145 |
0
| content[2] = date;
|
|
146 |
0
| content[3] = createLink(encName, "src");
|
|
147 |
0
| content[4] = createLink(encName + "?viewer=delete&redirect=./?viewer=list", "delete");
|
|
148 |
0
| return content;
|
|
149 |
| } |
|
150 |
| |
|
151 |
0
| protected String[] getParentCollection() {
|
|
152 |
0
| reset();
|
|
153 |
0
| content[0] = createLink("../?viewer=list", "up to parent collection");
|
|
154 |
0
| content[1] = "collection";
|
|
155 |
0
| return content;
|
|
156 |
| } |
|
157 |
| |
|
158 |
0
| protected String createLink(String link, String name) {
|
|
159 |
0
| return "<a href=\"" + link + "\">" + name + "</a>";
|
|
160 |
| } |
|
161 |
| } |
|
162 |
| } |