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 |
| |
25 |
| import javax.servlet.ServletException; |
26 |
| import javax.servlet.http.HttpServletRequest; |
27 |
| import javax.servlet.http.HttpServletResponse; |
28 |
| |
29 |
| import org.apache.xindice.core.DBException; |
30 |
| import org.apache.xindice.core.Collection; |
31 |
| import org.apache.xindice.webadmin.viewer.*; |
32 |
| import org.apache.xindice.webadmin.viewer.HtmlViewerComponent; |
33 |
| import org.apache.commons.logging.Log; |
34 |
| import org.apache.commons.logging.LogFactory; |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| public class DeleteCollectionViewer extends HtmlViewerComponent implements HtmlCollectionViewer { |
43 |
| private static final Log log = LogFactory.getLog(DeleteCollectionViewer.class); |
44 |
| |
45 |
0
| public void execute(HttpServletRequest req, HttpServletResponse res, Collection col) throws ServletException, IOException {
|
46 |
| |
47 |
0
| String colName = col.getName();
|
48 |
0
| String path = col.getCanonicalName();
|
49 |
| |
50 |
0
| String title = "Delete Collection " + colName;
|
51 |
| |
52 |
0
| String action = req.getParameter("action");
|
53 |
0
| String redirect = req.getParameter("redirect");
|
54 |
0
| if (redirect == null) {
|
55 |
0
| redirect = "";
|
56 |
| } |
57 |
0
| if (!"yes".equals(action)) {
|
58 |
0
| Writer output = startViewer(title, path, res);
|
59 |
0
| printStartTable(title, output);
|
60 |
0
| printStartSingleTableBox(output);
|
61 |
0
| output.write("Do you really want to delete the collection ");
|
62 |
0
| output.write(colName);
|
63 |
0
| output.write("? <a href=\"javascript:history.back()\">no</a> ");
|
64 |
0
| output.write(" <a href=\"?viewer=delete&action=yes&redirect=");
|
65 |
0
| output.write(redirect);
|
66 |
0
| output.write("\">yes</a>");
|
67 |
0
| printEndSingleTableBox(output);
|
68 |
0
| printEndTable(output);
|
69 |
0
| finishViewer(output);
|
70 |
| } else { |
71 |
0
| try {
|
72 |
| |
73 |
0
| if (col.getParentCollection() == null) {
|
74 |
0
| Writer output = startViewer(title, path, res);
|
75 |
0
| title = "Error while deleting Collection!";
|
76 |
0
| printStartTable(title, output);
|
77 |
0
| printStartSingleTableBox(output);
|
78 |
0
| output.write("<b>Database cannot be deleted. Please manually change configuration files to delete or add a database.");
|
79 |
0
| output.write("</b><br />");
|
80 |
0
| printEndSingleTableBox(output);
|
81 |
0
| printEndTable(output);
|
82 |
0
| finishViewer(output);
|
83 |
0
| return;
|
84 |
| } |
85 |
| |
86 |
| |
87 |
0
| col.getParentCollection().dropCollection(col);
|
88 |
| |
89 |
| |
90 |
0
| if (redirect.length() > 0) {
|
91 |
0
| res.sendRedirect(redirect);
|
92 |
| } else { |
93 |
0
| Writer output = startViewer(title, path, res);
|
94 |
0
| printStartTable(title, output);
|
95 |
0
| printStartSingleTableBox(output);
|
96 |
0
| output.write("<a href=\"../?viewer=default\">up to parent collection</a>");
|
97 |
0
| printEndSingleTableBox(output);
|
98 |
0
| printStartSingleTableBox(output);
|
99 |
0
| output.write("<b>Collection ");
|
100 |
0
| output.write(colName);
|
101 |
0
| output.write(" deleted!</b>");
|
102 |
0
| printEndSingleTableBox(output);
|
103 |
0
| printEndTable(output);
|
104 |
0
| finishViewer(output);
|
105 |
| } |
106 |
| } catch (DBException e) { |
107 |
0
| log.error(e);
|
108 |
| |
109 |
0
| Writer output = startViewer(title, path, res);
|
110 |
0
| printStartTable(title, output);
|
111 |
0
| printStartSingleTableBox(output);
|
112 |
0
| output.write("<a href=\"../../?viewer=default\">up to parent collection</a>");
|
113 |
0
| printEndSingleTableBox(output);
|
114 |
0
| printStartSingleTableBox(output);
|
115 |
0
| output.write("Cannot delete Collection");
|
116 |
0
| output.write(colName);
|
117 |
0
| output.write("! <br />");
|
118 |
0
| output.write(e.getMessage());
|
119 |
0
| printEndSingleTableBox(output);
|
120 |
0
| printEndTable(output);
|
121 |
0
| finishViewer(output);
|
122 |
| } |
123 |
| } |
124 |
| |
125 |
| } |
126 |
| |
127 |
0
| protected String getName() {
|
128 |
0
| return "delete";
|
129 |
| } |
130 |
| |
131 |
| } |