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 |
| import javax.servlet.http.HttpServletResponse; |
26 |
| |
27 |
| import org.apache.xindice.core.Collection; |
28 |
| import org.apache.xindice.core.DBException; |
29 |
| import org.apache.xindice.core.data.Entry; |
30 |
| import org.apache.xindice.webadmin.util.MimeTable; |
31 |
| import org.apache.xindice.webadmin.webdav.DAVRequest; |
32 |
| import org.apache.xindice.webadmin.webdav.DAVResponse; |
33 |
| import org.apache.xindice.webadmin.Location; |
34 |
| import org.apache.xindice.xml.TextWriter; |
35 |
| import org.apache.commons.logging.LogFactory; |
36 |
| import org.apache.commons.logging.Log; |
37 |
| import org.w3c.dom.Document; |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| public class Head implements DAVComponent { |
48 |
| private static final Log log = LogFactory.getLog(Head.class); |
49 |
| |
50 |
0
| public void execute(DAVRequest req, DAVResponse res, Location target) throws ServletException, IOException {
|
51 |
0
| Collection col = target.getCollection();
|
52 |
0
| String name = target.getName();
|
53 |
| |
54 |
0
| if (target.isRoot() || (col != null && name == null)) {
|
55 |
0
| if (log.isDebugEnabled()) {
|
56 |
0
| log.debug("Method Head not allowed on collections!");
|
57 |
| } |
58 |
0
| res.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
|
59 |
0
| return;
|
60 |
| } |
61 |
| |
62 |
0
| if (col == null) {
|
63 |
0
| res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
64 |
0
| return;
|
65 |
| } |
66 |
| |
67 |
0
| try {
|
68 |
0
| Entry resource = col.getEntry(name);
|
69 |
| |
70 |
0
| if (resource != null) {
|
71 |
0
| byte[] resultBytes;
|
72 |
0
| if (resource.getEntryType() == Entry.DOCUMENT) {
|
73 |
0
| resultBytes = TextWriter.toString((Document) resource.getValue()).getBytes();
|
74 |
0
| res.setContentType(MimeTable.XML_MIME_TYPE);
|
75 |
| } else { |
76 |
0
| resultBytes = (byte[]) resource.getValue();
|
77 |
0
| res.setContentType(MimeTable.getMimeType(name));
|
78 |
| } |
79 |
| |
80 |
0
| if (resource.getModificationTime() != 0) {
|
81 |
0
| res.addDateHeader("Last-Modified", resource.getModificationTime());
|
82 |
| } |
83 |
0
| res.setContentLength(resultBytes.length);
|
84 |
| |
85 |
| } else { |
86 |
0
| res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
87 |
| } |
88 |
| } catch (DBException e) { |
89 |
0
| log.error("Could not get resource " + name + " from collection " + col.getCanonicalName(), e);
|
90 |
0
| res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
91 |
| } |
92 |
| } |
93 |
| } |