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.io.*;
18: import java.util.*;
19: import java.util.logging.*;
20:
21: import javax.servlet.http.*;
22:
23: import org.w3c.dom.*;
24:
25: import com.ibm.webdav.*;
26: import com.ibm.webdav.impl.*;
27:
28: /** Executes the WebDAV UNLOCK method.
29: * @author Jim Amsden <jamsden@us.ibm.com>
30: */
31: public class UnlockMethod extends WebDAVMethod {
32: private static Logger m_logger = Logger
33: .getLogger(UnlockMethod.class.getName());
34:
35: /** Construct an UnlockMethod.
36: * @param request the servlet request
37: * @param response the servlet response
38: * @exception com.ibm.webdav.WebDAVException
39: */
40: public UnlockMethod(HttpServletRequest request,
41: HttpServletResponse response) throws WebDAVException {
42: super (request, response);
43: methodName = "UNLOCK";
44: }
45:
46: /** Execute the method.
47: * @return the result status code
48: */
49: public WebDAVStatus execute() {
50: try {
51: setStatusCode(WebDAVStatus.SC_NO_CONTENT);
52:
53: // get the lock token and unlock it
54: String lockToken = context.getRequestContext().lockToken();
55: context.setMethodName(methodName);
56: MultiStatus multiStatus = resource.unlock(context,
57: lockToken);
58: Enumeration responses = multiStatus.getResponses();
59: if (responses.hasMoreElements()) {
60: // there's a response (at least the lockdiscovery), so return a multistatus
61: resource.getResponseContext().contentType("text/xml");
62: setResponseHeaders();
63: setStatusCode(WebDAVStatus.SC_MULTI_STATUS);
64:
65: // output the results as an XML document
66: Document results = multiStatus.asXML();
67: //((Document) results).setEncoding(getResponseCharset());
68: if (ResourceImpl.debug) {
69: System.err.println("unlock results:");
70: PrintWriter pout = new PrintWriter(System.err);
71: pout.print(XMLUtility.printNode(results
72: .getDocumentElement()));
73: //((Document) results).printWithFormat(pout);
74: }
75: PrintWriter pout = new PrintWriter(
76: response.getWriter(), false);
77: pout.print(XMLUtility.printNode(results
78: .getDocumentElement()));
79: //((Document) results).print(pout);
80: pout.close();
81: } else {
82: setResponseHeaders();
83: }
84: } catch (WebDAVException exc) {
85: m_logger.log(Level.INFO, exc.getMessage() + " - "
86: + request.getQueryString());
87: setStatusCode(exc.getStatusCode());
88: } catch (Exception exc) {
89: m_logger.log(Level.WARNING, exc.getMessage(), exc);
90: setStatusCode(WebDAVStatus.SC_INTERNAL_SERVER_ERROR);
91: }
92: return context.getStatusCode();
93: }
94: }
|