|
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.webadmin.util.CollectionConfigurationHelper; |
|
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 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| public class Mkcol implements DAVComponent { |
|
72 |
| private final Log log = LogFactory.getLog(Mkcol.class); |
|
73 |
| |
|
74 |
4
| public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
|
|
75 |
4
| if (target.isRoot()) {
|
|
76 |
0
| res.setStatus(WebdavStatus.SC_METHOD_NOT_ALLOWED);
|
|
77 |
0
| return;
|
|
78 |
| } |
|
79 |
| |
|
80 |
4
| Collection col = target.getCollection();
|
|
81 |
4
| String name = target.getName();
|
|
82 |
| |
|
83 |
4
| if (name != null && req.getRequestDoc() != null) {
|
|
84 |
| |
|
85 |
1
| res.setStatus(WebdavStatus.SC_UNSUPPORTED_MEDIA_TYPE);
|
|
86 |
1
| return;
|
|
87 |
| } |
|
88 |
| |
|
89 |
3
| if (col == null) {
|
|
90 |
1
| res.setStatus(WebdavStatus.SC_CONFLICT);
|
|
91 |
1
| return;
|
|
92 |
| } |
|
93 |
| |
|
94 |
2
| if (name == null) {
|
|
95 |
1
| if (log.isDebugEnabled()) {
|
|
96 |
0
| log.debug("Collection already exists");
|
|
97 |
| } |
|
98 |
1
| res.setStatus(WebdavStatus.SC_METHOD_NOT_ALLOWED);
|
|
99 |
| } else { |
|
100 |
1
| try {
|
|
101 |
1
| res.setStatus(createCollection(col, name));
|
|
102 |
| } catch (DBException e) { |
|
103 |
0
| log.error("Failed to create collection " + col.getCanonicalName() + "/" + name, e);
|
|
104 |
0
| throw new ServletException(e);
|
|
105 |
| } |
|
106 |
| } |
|
107 |
| } |
|
108 |
| |
|
109 |
1
| private int createCollection(Collection parent, String name) throws DBException {
|
|
110 |
1
| try {
|
|
111 |
1
| parent.createCollection(name, CollectionConfigurationHelper.createDefaultConfiguration(name));
|
|
112 |
1
| if (log.isDebugEnabled()) {
|
|
113 |
0
| log.debug("Collection " + name + " created");
|
|
114 |
| } |
|
115 |
| |
|
116 |
| |
|
117 |
| } catch (DBException e) { |
|
118 |
0
| if (e.faultCode == FaultCodes.COL_DUPLICATE_COLLECTION) {
|
|
119 |
0
| return WebdavStatus.SC_METHOD_NOT_ALLOWED;
|
|
120 |
0
| } else if (e.faultCode == FaultCodes.COL_COLLECTION_NOT_FOUND) {
|
|
121 |
0
| return WebdavStatus.SC_METHOD_NOT_ALLOWED;
|
|
122 |
0
| } else if (e.faultCode == FaultCodes.COL_CANNOT_CREATE) {
|
|
123 |
0
| return WebdavStatus.SC_FORBIDDEN;
|
|
124 |
| } |
|
125 |
| |
|
126 |
0
| throw e;
|
|
127 |
| } |
|
128 |
| |
|
129 |
1
| return WebdavStatus.SC_CREATED;
|
|
130 |
| } |
|
131 |
| } |