KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > webdav > protocol > http > OptionsMethod


1 package com.ibm.webdav.protocol.http;
2
3 /*
4  * (C) Copyright IBM Corp. 2000 All rights reserved.
5  *
6  * The program is provided "AS IS" without any warranty express or
7  * implied, including the warranty of non-infringement and the implied
8  * warranties of merchantibility and fitness for a particular purpose.
9  * 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
25 /** Executes the WebDAV OPTIONS method.
26  * @author Jim Amsden <jamsden@us.ibm.com>
27  */

28 public class OptionsMethod extends WebDAVMethod
29 {
30     private static Logger m_logger = Logger.getLogger(OptionsMethod.class.getName());
31
32     
33 /** Construct an OptionsMethod.
34 * @param request the servlet request
35 * @param response the servlet response
36 * @exception com.ibm.webdav.WebDAVException
37 */

38 public OptionsMethod(HttpServletRequest request, HttpServletResponse response) throws WebDAVException {
39     super(request, response);
40     methodName = "OPTIONS";
41 }
42 /** Execute the method.
43 * @return the result status code
44 */

45 public WebDAVStatus execute() {
46     try {
47         context.getResponseContext().put("Allow", getCommaSeparatedString(resource.getAllowedMethods()));
48         context.getResponseContext().DAV("1, 2, binding"); // level 2 compliant, see section 15
49

50         setResponseHeaders();
51         setStatusCode(WebDAVStatus.SC_OK);
52
53                 /*PrintWriter out = response.getWriter();
54
55                 out.print("<D:multistatus xmlns:D=\"DAV:\"><D:response></D:response></D:multistatus>");
56             out.close();*/

57         } catch (Exception JavaDoc exc) {
58         m_logger.log(Level.WARNING, exc.getMessage(), exc);
59         setStatusCode(WebDAVStatus.SC_INTERNAL_SERVER_ERROR);
60     }
61     return context.getStatusCode();
62 }
63
64 /**
65  * Returns a comma separated list of values taken from the given <code>List</code> as a <code>String</code>
66  *
67  * @param allowedMethods
68  * @return
69  */

70 private String JavaDoc getCommaSeparatedString(List allowedMethods) {
71     Iterator iter = allowedMethods.iterator();
72     StringBuffer JavaDoc strbuf = new StringBuffer JavaDoc();
73     while(iter.hasNext()) {
74         strbuf.append(iter.next());
75         if(iter.hasNext()) {
76             strbuf.append(",");
77         }
78     }
79     
80     return strbuf.toString();
81 }
82 }
83
Popular Tags