|
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 |
| import java.util.Map; |
|
24 |
| import java.util.Iterator; |
|
25 |
| |
|
26 |
| import javax.servlet.ServletException; |
|
27 |
| |
|
28 |
| import org.apache.xindice.core.Collection; |
|
29 |
| import org.apache.xindice.core.DBException; |
|
30 |
| import org.apache.xindice.core.FaultCodes; |
|
31 |
| import org.apache.xindice.webadmin.util.DAVOperations; |
|
32 |
| import org.apache.xindice.webadmin.webdav.WebdavStatus; |
|
33 |
| import org.apache.xindice.webadmin.webdav.DAVRequest; |
|
34 |
| import org.apache.xindice.webadmin.webdav.DAVResponse; |
|
35 |
| import org.apache.xindice.webadmin.PartialResponse; |
|
36 |
| import org.apache.xindice.webadmin.Location; |
|
37 |
| import org.apache.commons.logging.Log; |
|
38 |
| import org.apache.commons.logging.LogFactory; |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| public class Move implements DAVComponent { |
|
77 |
| private static final Log log = LogFactory.getLog(Move.class); |
|
78 |
| |
|
79 |
10
| public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
|
|
80 |
10
| if (target.isRoot()) {
|
|
81 |
0
| res.setStatus(WebdavStatus.SC_FORBIDDEN);
|
|
82 |
0
| return;
|
|
83 |
| } |
|
84 |
| |
|
85 |
10
| Collection col = target.getCollection();
|
|
86 |
10
| String name = target.getName();
|
|
87 |
| |
|
88 |
10
| if (col == null) {
|
|
89 |
1
| res.setStatus(WebdavStatus.SC_NOT_FOUND);
|
|
90 |
1
| return;
|
|
91 |
| } |
|
92 |
| |
|
93 |
9
| String dest = req.getDestinationPath();
|
|
94 |
9
| if (dest == null) {
|
|
95 |
2
| res.setStatus(WebdavStatus.SC_BAD_REQUEST);
|
|
96 |
2
| return;
|
|
97 |
| } |
|
98 |
| |
|
99 |
7
| if (dest.equals(req.getPath())) {
|
|
100 |
2
| res.setStatus(WebdavStatus.SC_FORBIDDEN);
|
|
101 |
2
| return;
|
|
102 |
| } |
|
103 |
| |
|
104 |
5
| int depth = req.getDepth();
|
|
105 |
5
| if (depth != DAVRequest.DEPTH_INFINITY) {
|
|
106 |
0
| res.setStatus(WebdavStatus.SC_BAD_REQUEST);
|
|
107 |
0
| return;
|
|
108 |
| } |
|
109 |
| |
|
110 |
5
| if (name == null) {
|
|
111 |
2
| try {
|
|
112 |
2
| Map results = DAVOperations.copy(col, req.getDestinationPath(), req.getOverwrite(), true);
|
|
113 |
2
| interpretResults(results, res, dest, col);
|
|
114 |
| } catch (DBException e) { |
|
115 |
0
| log.error("Failed to move collection " + col.getCanonicalName(), e);
|
|
116 |
0
| throw new ServletException(e);
|
|
117 |
| } |
|
118 |
| } else { |
|
119 |
3
| try {
|
|
120 |
3
| int status = DAVOperations.copy(col, name, req.getDestinationPath(), req.getOverwrite());
|
|
121 |
3
| if (status == WebdavStatus.SC_NO_CONTENT || status == WebdavStatus.SC_CREATED) {
|
|
122 |
1
| col.remove(name);
|
|
123 |
| } |
|
124 |
3
| res.setStatus(status);
|
|
125 |
| } catch (DBException e) { |
|
126 |
0
| log.error("Failed to move resource " + name + " from collection " + col.getCanonicalName(), e);
|
|
127 |
0
| throw new ServletException(e);
|
|
128 |
| } |
|
129 |
| } |
|
130 |
| } |
|
131 |
| |
|
132 |
2
| private void interpretResults(Map results, DAVResponse res, String dest, Collection col) throws IOException {
|
|
133 |
2
| for (Iterator i = results.keySet().iterator(); i.hasNext(); ) {
|
|
134 |
2
| String url = (String) i.next();
|
|
135 |
2
| int status = ((Integer) results.get(url)).intValue();
|
|
136 |
2
| if (url.equals(dest)) {
|
|
137 |
2
| if (status == WebdavStatus.SC_CREATED || status == WebdavStatus.SC_NO_CONTENT) {
|
|
138 |
1
| try {
|
|
139 |
1
| col.getDatabase().dropCollection(col);
|
|
140 |
| } catch (DBException e) { |
|
141 |
0
| if (e.faultCode == FaultCodes.COL_CANNOT_DROP) {
|
|
142 |
| |
|
143 |
0
| status = WebdavStatus.SC_FORBIDDEN;
|
|
144 |
0
| } else if (e.faultCode != FaultCodes.COL_COLLECTION_NOT_FOUND) {
|
|
145 |
0
| status = WebdavStatus.SC_INTERNAL_SERVER_ERROR;
|
|
146 |
| } |
|
147 |
| } |
|
148 |
| } |
|
149 |
| |
|
150 |
2
| res.setStatus(status);
|
|
151 |
2
| return;
|
|
152 |
| } |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
0
| PartialResponse part = new PartialResponse(dest);
|
|
160 |
0
| String st = res.getProtocol() + " " + status + " " + WebdavStatus.getStatusText(status);
|
|
161 |
0
| part.addContent("status", st);
|
|
162 |
0
| res.sendMultiStatusResponse(part);
|
|
163 |
| } |
|
164 |
| |
|
165 |
0
| res.closeMultistatusResponse();
|
|
166 |
| } |
|
167 |
| } |