001: package com.ibm.webdav.protocol.http;
002:
003: /*
004: * (C) Copyright IBM Corp. 2000 All rights reserved.
005: *
006: * The program is provided "AS IS" without any warranty express or
007: * implied, including the warranty of non-infringement and the implied
008: * warranties of merchantibility and fitness for a particular purpose.
009: * IBM will not be liable for any damages suffered by you as a result
010: * of using the Program. In no event will IBM be liable for any
011: * special, indirect or consequential damages or lost profits even if
012: * IBM has been advised of the possibility of their occurrence. IBM
013: * will not be liable for any third party claims against you.
014: *
015: * Portions Copyright (C) Simulacra Media Ltd, 2004.
016: */
017: import java.io.*;
018: import java.util.*;
019: import java.util.logging.*;
020:
021: import javax.servlet.http.*;
022:
023: import org.w3c.dom.*;
024:
025: import com.ibm.webdav.*;
026: import com.ibm.webdav.impl.*;
027:
028: /** Executes the WebDAV DELETE method.
029: * @author Jim Amsden <jamsden@us.ibm.com>
030: */
031: public class DeleteMethod extends WebDAVMethod {
032:
033: private static Logger m_logger = Logger
034: .getLogger(DeleteMethod.class.getName());
035:
036: /** Construct a DeleteMethod.
037: * @param request the servlet request
038: * @param response the servlet response
039: * @exception com.ibm.webdav.WebDAVException
040: * @exception IOException
041: */
042: public DeleteMethod(HttpServletRequest request,
043: HttpServletResponse response) throws WebDAVException {
044: super (request, response);
045: methodName = "DELETE";
046: }
047:
048: /** Execute the method.
049: * @return the result status code
050: */
051: public WebDAVStatus execute() {
052: setStatusCode(WebDAVStatus.SC_NO_CONTENT); // the default status code
053: try {
054: MultiStatus multiStatus = resource.delete(context);
055: Enumeration responses = multiStatus.getResponses();
056: if (responses.hasMoreElements()) {
057: MethodResponse methodResponse = (MethodResponse) responses
058: .nextElement();
059: if (responses.hasMoreElements()) {
060: // there's more than one response, so return a multistatus
061: context.getResponseContext()
062: .contentType("text/xml");
063: setStatusCode(WebDAVStatus.SC_MULTI_STATUS);
064: setResponseHeaders();
065:
066: // output the multiStatus results as an XML document
067: Document results = multiStatus.asXML();
068: //((Document) results).setEncoding(getResponseCharset());
069: if (ResourceImpl.debug) {
070: System.err.println("delete results:");
071: PrintWriter pout = new PrintWriter(System.err);
072: pout.print(XMLUtility.printNode(results
073: .getDocumentElement()));
074: //((Document) results).printWithFormat(pout);
075: }
076: PrintWriter pout = new PrintWriter(response
077: .getWriter(), false);
078: pout.print(XMLUtility.printNode(results
079: .getDocumentElement()));
080: //((Document) results).print(pout);
081: pout.close();
082: } else {
083: // there was just one MethodResponse, so return it directly instead
084: // of wrapped in a multistatus
085: setStatusCode(methodResponse.getStatus());
086: setResponseHeaders();
087: }
088: } else {
089: // there was nothing in the MultiStatus (shouldn't happen), so default
090: setStatusCode(WebDAVStatus.SC_NO_CONTENT);
091: setResponseHeaders();
092: }
093: } catch (WebDAVException exc) {
094: m_logger.log(Level.INFO, exc.getLocalizedMessage() + " - "
095: + request.getQueryString());
096: setStatusCode(exc.getStatusCode());
097: } catch (Exception exc) {
098: m_logger.log(Level.WARNING, exc.getMessage(), exc);
099: setStatusCode(WebDAVStatus.SC_INTERNAL_SERVER_ERROR);
100: }
101: return context.getStatusCode();
102: }
103: }
|