KickJava   Java API By Example, From Geeks To Geeks.

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


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 DELETE method.
29  * @author Jim Amsden <jamsden@us.ibm.com>
30  */

31 public class DeleteMethod extends WebDAVMethod {
32     
33     private static Logger m_logger = Logger.getLogger(DeleteMethod.class.getName());
34
35 /** Construct a DeleteMethod.
36 * @param request the servlet request
37 * @param response the servlet response
38 * @exception com.ibm.webdav.WebDAVException
39 * @exception IOException
40 */

41 public DeleteMethod(HttpServletRequest request, HttpServletResponse response) throws WebDAVException {
42     super(request, response);
43     methodName = "DELETE";
44 }
45 /** Execute the method.
46 * @return the result status code
47 */

48 public WebDAVStatus execute() {
49     setStatusCode(WebDAVStatus.SC_NO_CONTENT); // the default status code
50
try {
51         MultiStatus multiStatus = resource.delete(context);
52         Enumeration responses = multiStatus.getResponses();
53         if (responses.hasMoreElements()) {
54             MethodResponse methodResponse = (MethodResponse) responses.nextElement();
55             if (responses.hasMoreElements()) {
56                 // there's more than one response, so return a multistatus
57
context.getResponseContext().contentType("text/xml");
58                 setStatusCode(WebDAVStatus.SC_MULTI_STATUS);
59                 setResponseHeaders();
60
61                 // output the multiStatus results as an XML document
62
Document results = multiStatus.asXML();
63                 //((Document) results).setEncoding(getResponseCharset());
64
if (ResourceImpl.debug) {
65                     System.err.println("delete results:");
66                     PrintWriter pout = new PrintWriter(System.err);
67                     pout.print(XMLUtility.printNode(results.getDocumentElement()));
68                                         //((Document) results).printWithFormat(pout);
69
}
70                 PrintWriter pout = new PrintWriter(response.getWriter(), false);
71                 pout.print(XMLUtility.printNode(results.getDocumentElement()));
72                                 //((Document) results).print(pout);
73
pout.close();
74             } else {
75                 // there was just one MethodResponse, so return it directly instead
76
// of wrapped in a multistatus
77
setStatusCode(methodResponse.getStatus());
78                 setResponseHeaders();
79             }
80         } else {
81             // there was nothing in the MultiStatus (shouldn't happen), so default
82
setStatusCode(WebDAVStatus.SC_NO_CONTENT);
83             setResponseHeaders();
84         }
85     } catch (WebDAVException exc) {
86         m_logger.log(Level.INFO, exc.getLocalizedMessage() + " - " + request.getQueryString());
87         setStatusCode(exc.getStatusCode());
88     } catch (Exception JavaDoc exc) {
89         m_logger.log(Level.WARNING, exc.getMessage(), exc);
90         setStatusCode(WebDAVStatus.SC_INTERNAL_SERVER_ERROR);
91     }
92     return context.getStatusCode();
93 }
94 }
95
Popular Tags