|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.apache.xindice.webadmin.webdav; |
|
19 |
| |
|
20 |
| import org.apache.commons.logging.Log; |
|
21 |
| import org.apache.commons.logging.LogFactory; |
|
22 |
| import org.apache.xindice.webadmin.PartialResponse; |
|
23 |
| |
|
24 |
| import javax.servlet.ServletOutputStream; |
|
25 |
| import javax.servlet.http.HttpServletResponse; |
|
26 |
| |
|
27 |
| import java.io.IOException; |
|
28 |
| import java.io.Writer; |
|
29 |
| import java.io.OutputStreamWriter; |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| public class DAVResponse { |
|
37 |
| public static final String DAV_NS = "DAV:"; |
|
38 |
| |
|
39 |
| private static final Log log = LogFactory.getLog(DAVResponse.class); |
|
40 |
| |
|
41 |
| private final HttpServletResponse response; |
|
42 |
| |
|
43 |
| protected final Writer out; |
|
44 |
| private boolean isMultistatus; |
|
45 |
| private String protocol; |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
36
| public DAVResponse(HttpServletResponse response) throws IOException {
|
|
54 |
36
| this.response = response;
|
|
55 |
36
| this.out = new OutputStreamWriter(response.getOutputStream(), "utf-8");
|
|
56 |
| } |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
12
| public void sendMultiStatusResponse(PartialResponse res) throws IOException {
|
|
66 |
12
| if (!isMultistatus) {
|
|
67 |
4
| if (log.isDebugEnabled()) {
|
|
68 |
0
| log.debug("Sending response for HREF " + res.getHref());
|
|
69 |
| } |
|
70 |
4
| response.setStatus(WebdavStatus.SC_MULTI_STATUS);
|
|
71 |
4
| out.write("<?xml version='1.0' encoding='utf-8'?>\n");
|
|
72 |
4
| out.write("<multistatus xmlns='DAV:'>\n");
|
|
73 |
4
| isMultistatus = true;
|
|
74 |
| } |
|
75 |
| |
|
76 |
12
| out.write(res.toString());
|
|
77 |
12
| out.write("\n");
|
|
78 |
| } |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
5
| public void closeMultistatusResponse() throws IOException {
|
|
88 |
5
| if (isMultistatus) {
|
|
89 |
4
| out.write("</multistatus>");
|
|
90 |
4
| out.write("\n");
|
|
91 |
4
| out.flush();
|
|
92 |
| } |
|
93 |
| } |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
38
| public void setStatus(int status) {
|
|
100 |
38
| response.setStatus(status);
|
|
101 |
| } |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
0
| public void sendError(int status) throws IOException {
|
|
109 |
0
| response.sendError(status);
|
|
110 |
| } |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
0
| public void addHeader(String header, String value) {
|
|
118 |
0
| response.addHeader(header, value);
|
|
119 |
| } |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
0
| public void addDateHeader(String header, long date) {
|
|
127 |
0
| response.addDateHeader(header, date);
|
|
128 |
| } |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
0
| public void setContentType(String mimeType) {
|
|
135 |
0
| response.setContentType(mimeType);
|
|
136 |
| } |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
0
| public void setContentLength(int contentLength) {
|
|
143 |
0
| response.setContentLength(contentLength);
|
|
144 |
| } |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
0
| public ServletOutputStream getOutputStream() throws IOException {
|
|
152 |
0
| return response.getOutputStream();
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
0
| public void sendRedirect(String redirect) throws IOException {
|
|
161 |
0
| response.sendRedirect(redirect);
|
|
162 |
| } |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
5
| public void setProtocol(String protocol) {
|
|
170 |
5
| this.protocol = protocol;
|
|
171 |
| } |
|
172 |
| |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| |
|
177 |
16
| public String getProtocol() {
|
|
178 |
16
| return protocol;
|
|
179 |
| } |
|
180 |
| } |