|
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.webdav.components; |
|
21 |
| |
|
22 |
| import java.io.IOException; |
|
23 |
| |
|
24 |
| import javax.servlet.ServletException; |
|
25 |
| |
|
26 |
| import org.apache.xindice.core.Collection; |
|
27 |
| import org.apache.xindice.core.DBException; |
|
28 |
| import org.apache.xindice.core.FaultCodes; |
|
29 |
| import org.apache.xindice.core.Database; |
|
30 |
| import org.apache.xindice.webadmin.webdav.WebdavStatus; |
|
31 |
| import org.apache.xindice.webadmin.webdav.DAVResponse; |
|
32 |
| import org.apache.xindice.webadmin.webdav.DAVRequest; |
|
33 |
| import org.apache.xindice.webadmin.Location; |
|
34 |
| import org.apache.commons.logging.Log; |
|
35 |
| import org.apache.commons.logging.LogFactory; |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| public class Delete implements DAVComponent { |
|
52 |
| private final Log log = LogFactory.getLog(Delete.class); |
|
53 |
| |
|
54 |
5
| public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
|
|
55 |
5
| if (target.isRoot()) {
|
|
56 |
0
| res.setStatus(WebdavStatus.SC_FORBIDDEN);
|
|
57 |
0
| return;
|
|
58 |
| } |
|
59 |
| |
|
60 |
5
| Collection col = target.getCollection();
|
|
61 |
5
| String name = target.getName();
|
|
62 |
| |
|
63 |
5
| if (col == null) {
|
|
64 |
1
| res.setStatus(WebdavStatus.SC_NOT_FOUND);
|
|
65 |
1
| return;
|
|
66 |
| } |
|
67 |
| |
|
68 |
4
| if (col instanceof Database) {
|
|
69 |
0
| res.setStatus(WebdavStatus.SC_FORBIDDEN);
|
|
70 |
0
| return;
|
|
71 |
| } |
|
72 |
| |
|
73 |
4
| if (req.getDepth() != DAVRequest.DEPTH_INFINITY) {
|
|
74 |
1
| res.setStatus(WebdavStatus.SC_BAD_REQUEST);
|
|
75 |
1
| return;
|
|
76 |
| } |
|
77 |
| |
|
78 |
| |
|
79 |
3
| if (name == null) {
|
|
80 |
1
| try {
|
|
81 |
1
| col.getDatabase().dropCollection(col);
|
|
82 |
| } catch (DBException e) { |
|
83 |
0
| log.error("Failed to delete collection " + col.getCanonicalName(), e);
|
|
84 |
0
| throw new ServletException(e);
|
|
85 |
| } |
|
86 |
| } else { |
|
87 |
2
| try {
|
|
88 |
2
| col.remove(name);
|
|
89 |
1
| if (log.isDebugEnabled()) {
|
|
90 |
0
| log.debug("entry " + name + " deleted");
|
|
91 |
| } |
|
92 |
| } catch (DBException e) { |
|
93 |
1
| if (e.faultCode == FaultCodes.COL_DOCUMENT_NOT_FOUND) {
|
|
94 |
1
| res.setStatus(WebdavStatus.SC_NOT_FOUND);
|
|
95 |
1
| return;
|
|
96 |
| } else { |
|
97 |
0
| log.error("Failed to delete resource " + name + " from collection " + col.getCanonicalName(), e);
|
|
98 |
0
| throw new ServletException(e);
|
|
99 |
| } |
|
100 |
| } |
|
101 |
| } |
|
102 |
| |
|
103 |
2
| res.setStatus(WebdavStatus.SC_NO_CONTENT);
|
|
104 |
| } |
|
105 |
| } |