|
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.Iterator; |
|
24 |
| import java.util.Map; |
|
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.webadmin.util.DAVOperations; |
|
31 |
| import org.apache.xindice.webadmin.webdav.DAVRequest; |
|
32 |
| import org.apache.xindice.webadmin.webdav.DAVResponse; |
|
33 |
| import org.apache.xindice.webadmin.webdav.WebdavStatus; |
|
34 |
| import org.apache.xindice.webadmin.PartialResponse; |
|
35 |
| import org.apache.xindice.webadmin.Location; |
|
36 |
| import org.apache.commons.logging.Log; |
|
37 |
| import org.apache.commons.logging.LogFactory; |
|
38 |
| |
|
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 Copy implements DAVComponent { |
|
77 |
| private static final Log log = LogFactory.getLog(Copy.class); |
|
78 |
| |
|
79 |
11
| public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
|
|
80 |
11
| if (target.isRoot()) {
|
|
81 |
0
| res.setStatus(WebdavStatus.SC_FORBIDDEN);
|
|
82 |
0
| return;
|
|
83 |
| } |
|
84 |
| |
|
85 |
11
| Collection col = target.getCollection();
|
|
86 |
11
| String name = target.getName();
|
|
87 |
| |
|
88 |
11
| if (col == null) {
|
|
89 |
1
| res.setStatus(WebdavStatus.SC_NOT_FOUND);
|
|
90 |
1
| return;
|
|
91 |
| } |
|
92 |
| |
|
93 |
10
| String dest = req.getDestinationPath();
|
|
94 |
10
| if (dest == null) {
|
|
95 |
2
| res.setStatus(WebdavStatus.SC_BAD_REQUEST);
|
|
96 |
2
| return;
|
|
97 |
| } |
|
98 |
| |
|
99 |
8
| if (dest.equals(req.getPath())) {
|
|
100 |
2
| res.setStatus(WebdavStatus.SC_FORBIDDEN);
|
|
101 |
2
| return;
|
|
102 |
| } |
|
103 |
| |
|
104 |
6
| if (name == null) {
|
|
105 |
3
| try {
|
|
106 |
3
| boolean deep = req.getDepth() != 0;
|
|
107 |
3
| Map results = DAVOperations.copy(col, dest, req.getOverwrite(), deep);
|
|
108 |
3
| interpretResults(results, res, dest);
|
|
109 |
| |
|
110 |
| } catch (DBException e) { |
|
111 |
0
| log.error("Failed to copy collection " + col.getCanonicalName(), e);
|
|
112 |
0
| throw new ServletException(e);
|
|
113 |
| } |
|
114 |
| |
|
115 |
| } else { |
|
116 |
3
| try {
|
|
117 |
3
| int status = DAVOperations.copy(col, name, dest, req.getOverwrite());
|
|
118 |
3
| res.setStatus(status);
|
|
119 |
| } catch (DBException e) { |
|
120 |
0
| log.error("Failed to copy resource " + name + " from collection " + col.getCanonicalName(), e);
|
|
121 |
0
| throw new ServletException(e);
|
|
122 |
| } |
|
123 |
| } |
|
124 |
| |
|
125 |
| } |
|
126 |
| |
|
127 |
3
| private void interpretResults(Map results, DAVResponse res, String dest) throws IOException {
|
|
128 |
3
| for (Iterator i = results.keySet().iterator(); i.hasNext(); ) {
|
|
129 |
3
| String url = (String) i.next();
|
|
130 |
3
| int status = ((Integer) results.get(url)).intValue();
|
|
131 |
3
| if (url.equals(dest)) {
|
|
132 |
3
| res.setStatus(status);
|
|
133 |
3
| return;
|
|
134 |
| } |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
0
| PartialResponse part = new PartialResponse(dest);
|
|
142 |
0
| String st = res.getProtocol() + " " + status + " " + WebdavStatus.getStatusText(status);
|
|
143 |
0
| part.addContent("status", st);
|
|
144 |
0
| res.sendMultiStatusResponse(part);
|
|
145 |
| } |
|
146 |
| |
|
147 |
0
| res.closeMultistatusResponse();
|
|
148 |
| } |
|
149 |
| } |