01: package com.ibm.webdav.protocol.http;
02:
03: /*
04: * (C) Copyright IBM Corp. 2000 All rights reserved.
05: *
06: * The program is provided "AS IS" without any warranty express or
07: * implied, including the warranty of non-infringement and the implied
08: * warranties of merchantibility and fitness for a particular purpose.
09: * IBM will not be liable for any damages suffered by you as a result
10: * of using the Program. In no event will IBM be liable for any
11: * special, indirect or consequential damages or lost profits even if
12: * IBM has been advised of the possibility of their occurrence. IBM
13: * will not be liable for any third party claims against you.
14: *
15: * Portions Copyright (C) Simulacra Media Ltd, 2004.
16: */
17: import java.util.*;
18: import java.util.logging.*;
19:
20: import javax.servlet.http.*;
21:
22: import com.ibm.webdav.*;
23:
24: /** Executes the WebDAV OPTIONS method.
25: * @author Jim Amsden <jamsden@us.ibm.com>
26: */
27: public class OptionsMethod extends WebDAVMethod {
28: private static Logger m_logger = Logger
29: .getLogger(OptionsMethod.class.getName());
30:
31: /** Construct an OptionsMethod.
32: * @param request the servlet request
33: * @param response the servlet response
34: * @exception com.ibm.webdav.WebDAVException
35: */
36: public OptionsMethod(HttpServletRequest request,
37: HttpServletResponse response) throws WebDAVException {
38: super (request, response);
39: methodName = "OPTIONS";
40: }
41:
42: /** Execute the method.
43: * @return the result status code
44: */
45: public WebDAVStatus execute() {
46: try {
47: context.getResponseContext().put(
48: "Allow",
49: getCommaSeparatedString(resource
50: .getAllowedMethods()));
51: context.getResponseContext().DAV("1, 2, binding"); // level 2 compliant, see section 15
52:
53: setResponseHeaders();
54: setStatusCode(WebDAVStatus.SC_OK);
55:
56: /*PrintWriter out = response.getWriter();
57:
58: out.print("<D:multistatus xmlns:D=\"DAV:\"><D:response></D:response></D:multistatus>");
59: out.close();*/
60: } catch (Exception exc) {
61: m_logger.log(Level.WARNING, exc.getMessage(), exc);
62: setStatusCode(WebDAVStatus.SC_INTERNAL_SERVER_ERROR);
63: }
64: return context.getStatusCode();
65: }
66:
67: /**
68: * Returns a comma separated list of values taken from the given <code>List</code> as a <code>String</code>
69: *
70: * @param allowedMethods
71: * @return
72: */
73: private String getCommaSeparatedString(List allowedMethods) {
74: Iterator iter = allowedMethods.iterator();
75: StringBuffer strbuf = new StringBuffer();
76: while (iter.hasNext()) {
77: strbuf.append(iter.next());
78: if (iter.hasNext()) {
79: strbuf.append(",");
80: }
81: }
82:
83: return strbuf.toString();
84: }
85: }
|