KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.getLogger(UnlockMethod.class.getName());
33
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, HttpServletResponse response) throws WebDAVException {
41     super(request, response);
42     methodName = "UNLOCK";
43 }
44 /** Execute the method.
45 * @return the result status code
46 */

47 public WebDAVStatus execute() {
48     try {
49         setStatusCode(WebDAVStatus.SC_NO_CONTENT);
50
51         // get the lock token and unlock it
52
String JavaDoc lockToken = context.getRequestContext().lockToken();
53         context.setMethodName(methodName);
54         MultiStatus multiStatus = resource.unlock(context, lockToken);
55         Enumeration responses = multiStatus.getResponses();
56         if (responses.hasMoreElements()) {
57             // there's a response (at least the lockdiscovery), so return a multistatus
58
resource.getResponseContext().contentType("text/xml");
59             setResponseHeaders();
60             setStatusCode(WebDAVStatus.SC_MULTI_STATUS);
61
62             // output the results as an XML document
63
Document results = multiStatus.asXML();
64             //((Document) results).setEncoding(getResponseCharset());
65
if (ResourceImpl.debug) {
66                 System.err.println("unlock results:");
67                 PrintWriter pout = new PrintWriter(System.err);
68                 pout.print(XMLUtility.printNode(results.getDocumentElement()));
69                                 //((Document) results).printWithFormat(pout);
70
}
71             PrintWriter pout = new PrintWriter(response.getWriter(), false);
72             pout.print(XMLUtility.printNode(results.getDocumentElement()));
73                         //((Document) results).print(pout);
74
pout.close();
75         } else {
76             setResponseHeaders();
77         }
78     } catch (WebDAVException exc) {
79         m_logger.log(Level.INFO, exc.getMessage() + " - " + request.getQueryString());
80         setStatusCode(exc.getStatusCode());
81     } catch (Exception JavaDoc exc) {
82         m_logger.log(Level.WARNING, exc.getMessage(), exc);
83         setStatusCode(WebDAVStatus.SC_INTERNAL_SERVER_ERROR);
84     }
85     return context.getStatusCode();
86 }
87 }
88
Popular Tags