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