jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r368683 [4/8] - in /incubator/jackrabbit/trunk/contrib/jcr-server: client/ client/src/java/org/apache/jackrabbit/webdav/client/methods/ server/ server/src/java/org/apache/jackrabbit/server/ server/src/java/org/apache/jackrabbit/server/io/ s...
Date Fri, 13 Jan 2006 11:13:30 GMT
Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavException.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavException.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavException.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavException.java Fri Jan 13 03:11:35 2006
@@ -16,7 +16,9 @@
 package org.apache.jackrabbit.webdav;
 
 import org.apache.log4j.Logger;
-import org.jdom.Element;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 import java.util.Properties;
 import java.io.IOException;
@@ -27,7 +29,7 @@
  * of WebDAV requests and provides possibility to retrieve an Xml representation
  * of the error.
  */
-public class DavException extends Exception {
+public class DavException extends Exception implements XmlSerializable {
 
     private static Logger log = Logger.getLogger(DavException.class);
     private static Properties statusPhrases = new Properties();
@@ -39,10 +41,9 @@
         }
     }
 
-    private static final String XML_ERROR = "error";
+    public static final String XML_ERROR = "error";
 
     private int errorCode = DavServletResponse.SC_INTERNAL_SERVER_ERROR;
-    private Element conditionElement;
 
     /**
      * Create a new <code>DavException</code>.
@@ -68,20 +69,6 @@
     }
 
     /**
-     * Create a new <code>DavException</code>.
-     *
-     * @param errorCode integer specifying any of the status codes defined by
-     * {@link DavServletResponse}.
-     * @param message
-     * @param conditionElement
-     */
-    public DavException(int errorCode, String message, Element conditionElement) {
-        this(errorCode, message);
-        this.conditionElement = conditionElement;
-        log.debug("DavException: (" + errorCode + ") " + conditionElement.toString());
-    }
-
-    /**
      * Return the error code attached to this <code>DavException</code>.
      *
      * @return errorCode
@@ -91,21 +78,6 @@
     }
 
     /**
-     * Returns the Xml representation of this <code>DavException</code>. In case
-     * no {@link Element} has been passed to the constructor, an empty DAV:error
-     * element is returned.
-     *
-     * @return Xml representation of this exception.
-     */
-    public Element getError() {
-        Element error = new Element(XML_ERROR, DavConstants.NAMESPACE);
-        if (conditionElement != null) {
-            error.addContent(conditionElement);
-        }
-        return error;
-    }
-
-    /**
      * Return the status phrase corresponding to the error code attached to
      * this <code>DavException</code>.
      *
@@ -125,4 +97,23 @@
     public static String getStatusPhrase(int errorCode) {
         return statusPhrases.getProperty(errorCode+"");
     }
+
+    /**
+     * @return Always false
+     */
+    public boolean hasErrorCondition() {
+        return false;
+    }
+
+    /**
+     * Returns <code>null</code>
+     *
+     * @param document
+     * @return <code>null</code>
+     * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(Document)
+     */
+    public Element toXml(Document document) {
+        return null;
+    }
+
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavMethods.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavMethods.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavMethods.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavMethods.java Fri Jan 13 03:11:35 2006
@@ -38,6 +38,11 @@
     private static int[] labelMethods;
 
     /**
+     * An array of method codes defined by RFC 3253 (deltaV)
+     */
+    private static int[] deltaVMethods;
+
+    /**
      * The webdav OPTIONS method and public constant
      */
     public static final int DAV_OPTIONS = 1;
@@ -234,6 +239,20 @@
     public static final String METHOD_MKWORKSPACE = "MKWORKSPACE";
 
     /**
+     * The webdav BASELINE-CONTROL method and public constant defined by
+     * <a href="http://www.ietf.org/rfc/rfc3253.txt">RFC 3253</a>
+     */
+    public static final int DAV_BASELINE_CONTROL = DAV_MKWORKSPACE + 1;
+    public static final String METHOD_BASELINE_CONTROL = "BASELINE-CONTROL";
+
+    /**
+     * The webdav MKACTIVITY method and public constant defined by
+     * <a href="http://www.ietf.org/rfc/rfc3253.txt">RFC 3253</a>
+     */
+    public static final int DAV_MKACTIVITY = DAV_BASELINE_CONTROL + 1;
+    public static final String METHOD_MKACTIVITY = "MKACTIVITY";
+
+    /**
      * Returns webdav method type code, error result <= 0
      * Valid type codes > 0
      */
@@ -283,9 +302,16 @@
         addMethodCode(METHOD_MERGE, DAV_MERGE);
         addMethodCode(METHOD_UPDATE, DAV_UPDATE);
         addMethodCode(METHOD_MKWORKSPACE, DAV_MKWORKSPACE);
+        addMethodCode(METHOD_BASELINE_CONTROL, DAV_BASELINE_CONTROL);
+        addMethodCode(METHOD_MKACTIVITY, DAV_MKACTIVITY);
 
         labelMethods = new int[] { DAV_GET, DAV_HEAD, DAV_OPTIONS, DAV_PROPFIND,
                                    DAV_LABEL, DAV_COPY };
+
+        deltaVMethods = new int[] { DAV_REPORT, DAV_VERSION_CONTROL, DAV_CHECKIN,
+                                    DAV_CHECKOUT, DAV_UNCHECKOUT, DAV_LABEL,
+                                    DAV_MERGE, DAV_UPDATE, DAV_MKWORKSPACE,
+                                    DAV_BASELINE_CONTROL, DAV_MKACTIVITY };
     }
 
    /**
@@ -324,6 +350,22 @@
         int code = getMethodCode(request.getMethod());
         for (int i = 0; i < labelMethods.length; i++) {
             if (code == labelMethods[i]) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns true, if the specified method is defined by RFC 3253
+     *
+     * @param request
+     * @return true, if the specified method is defined by RFC 3253
+     */
+    public static boolean isDeltaVMethod(DavServletRequest request) {
+        int code = getMethodCode(request.getMethod());
+        for (int i = 0; i < deltaVMethods.length; i++) {
+            if (code == deltaVMethods[i]) {
                 return true;
             }
         }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavResource.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavResource.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavResource.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavResource.java Fri Jan 13 03:11:35 2006
@@ -15,10 +15,17 @@
  */
 package org.apache.jackrabbit.webdav;
 
-import org.apache.jackrabbit.webdav.property.*;
-import org.apache.jackrabbit.webdav.lock.*;
 import org.apache.jackrabbit.webdav.io.InputContext;
 import org.apache.jackrabbit.webdav.io.OutputContext;
+import org.apache.jackrabbit.webdav.lock.ActiveLock;
+import org.apache.jackrabbit.webdav.lock.LockInfo;
+import org.apache.jackrabbit.webdav.lock.LockManager;
+import org.apache.jackrabbit.webdav.lock.Scope;
+import org.apache.jackrabbit.webdav.lock.Type;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.property.DavPropertySet;
 
 import java.io.IOException;
 

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletRequest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletRequest.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletRequest.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletRequest.java Fri Jan 13 03:11:35 2006
@@ -18,7 +18,7 @@
 import org.apache.jackrabbit.webdav.property.DavPropertySet;
 import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
 import org.apache.jackrabbit.webdav.lock.LockInfo;
-import org.jdom.Document;
+import org.w3c.dom.Document;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -115,7 +115,7 @@
     public long getTimeout();
 
     /**
-     * Parse the Xml request body and return a {@link org.jdom.Document}.
+     * Parse the Xml request body and return a {@link org.w3c.dom.Document}.
      * If the request body can not be parsed <code>null</code> is returned.
      *
      * @return Document representing the Xml request body or <code>null</code>.
@@ -131,7 +131,7 @@
      * @see DavConstants#PROPFIND_BY_PROPERTY
      * @see DavConstants#PROPFIND_PROPERTY_NAMES
      */
-    public int getPropFindType();
+    public int getPropFindType() throws DavException;
 
     /**
      * Return the set of properties the client requested with a PROPFIND request
@@ -140,7 +140,7 @@
      *
      * @return set of properties the client requested with a PROPFIND request
      */
-    public DavPropertyNameSet getPropFindProperties();
+    public DavPropertyNameSet getPropFindProperties() throws DavException;
 
     /**
      * Return the set of properties the client wanted to modify / create with a
@@ -150,7 +150,7 @@
      * @return set of properties the client wanted to modify / create with a
      * PROPPATCH request.
      */
-    public DavPropertySet getPropPatchSetProperties();
+    public DavPropertySet getPropPatchSetProperties() throws DavException;
 
     /**
      * Return the set of property names the client wanted to remove with a
@@ -164,7 +164,7 @@
      * @return set of property names the client wanted to remove with a
      * PROPPATCH request.
      */
-    public DavPropertyNameSet getPropPatchRemoveProperties();
+    public DavPropertyNameSet getPropPatchRemoveProperties() throws DavException;
 
     /**
      * Return the parsed 'lockinfo' request body, the {@link DavConstants#HEADER_TIMEOUT

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletResponse.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletResponse.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletResponse.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavServletResponse.java Fri Jan 13 03:11:35 2006
@@ -16,7 +16,7 @@
 package org.apache.jackrabbit.webdav;
 
 import org.apache.jackrabbit.webdav.lock.ActiveLock;
-import org.jdom.Document;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
@@ -41,8 +41,13 @@
     int SC_MULTI_STATUS = 207;
 
     /**
-     * Status code (422) indicating the entity body submitted with
-     * the PATCH method was not understood by the resource.
+     * The 422 (Unprocessable Entity) status code means the server understands
+     * the content type of the request entity (hence a 415(Unsupported Media Type)
+     * status code is inappropriate), and the syntax of the request entity is
+     * correct (thus a 400 (Bad Request) status code is inappropriate) but was
+     * unable to process the contained instructions. For example, this error
+     * condition may occur if an XML request body contains well-formed (i.e.,
+     * syntactically correct), but semantically erroneous XML instructions.
      */
     int SC_UNPROCESSABLE_ENTITY = 422;
 
@@ -116,9 +121,10 @@
     /**
      * Generic method to return an Xml response body.
      *
-     * @param xmlDoc Xml document representing the response body.
+     * @param serializable object that can be converted to the root Xml element
+     * of the document to be sent as response body.
      * @param status Status code to be used with {@link #setStatus(int)}.
      * @throws IOException
      */
-    public void sendXmlResponse(Document xmlDoc, int status) throws IOException;
+    public void sendXmlResponse(XmlSerializable serializable, int status) throws IOException;
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatus.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatus.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatus.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatus.java Fri Jan 13 03:11:35 2006
@@ -15,21 +15,35 @@
  */
 package org.apache.jackrabbit.webdav;
 
-import org.jdom.Document;
-import org.jdom.Element;
 import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.xml.ElementIterator;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
-import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.List;
+import java.util.HashMap;
 
 /**
  * MultiStatus representing the content of a multistatus response body and
  * allows to retrieve the Xml representation.
  */
-public class MultiStatus implements DavConstants {
+public class MultiStatus implements DavConstants, XmlSerializable {
 
-    private ArrayList responses = new ArrayList();
+    /**
+     * Map collecting the responses for this multistatus, where every href must
+     * only occure one single time.
+     */
+    private HashMap responses = new HashMap();
+
+    /**
+     * A general response description at the multistatus top level is used to
+     * provide a general message describing the overarching nature of the response.
+     * If this value is available an application may use it instead of
+     * presenting the individual response descriptions contained within the
+     * responses.
+     */
     private String responseDescription;
 
     /**
@@ -94,7 +108,7 @@
      * @param response
      */
     public void addResponse(MultiStatusResponse response) {
-	responses.add(response);
+	responses.put(response.getHref(), response);
     }
 
     /**
@@ -104,7 +118,7 @@
      * multistatus.
      */
     public MultiStatusResponse[] getResponses() {
-	return (MultiStatusResponse[]) responses.toArray(new MultiStatusResponse[responses.size()]);
+	return (MultiStatusResponse[]) responses.values().toArray(new MultiStatusResponse[responses.size()]);
     }
 
     /**
@@ -129,48 +143,45 @@
      * Return the Xml representation of this <code>MultiStatus</code>.
      *
      * @return Xml document
+     * @param document
      */
-    public Document toXml() {
-	Element multistatus = new Element(XML_MULTISTATUS, NAMESPACE);
-        Iterator it = responses.iterator();
+    public Element toXml(Document document) {
+	Element multistatus = DomUtil.createElement(document, XML_MULTISTATUS, NAMESPACE);
+        Iterator it = responses.values().iterator();
 	while(it.hasNext()) {
-	    multistatus.addContent(((MultiStatusResponse)it.next()).toXml());
+	    multistatus.appendChild(((MultiStatusResponse)it.next()).toXml(document));
 	}
         if (responseDescription != null) {
-            multistatus.addContent(new Element(XML_RESPONSEDESCRIPTION, NAMESPACE).setText(responseDescription));
+            Element respDesc = DomUtil.createElement(document, XML_RESPONSEDESCRIPTION, NAMESPACE, responseDescription);
+            multistatus.appendChild(respDesc);
         }
-	return new Document(multistatus);
+	return multistatus;
     }
 
     /**
-     * Build a <code>MultiStatus</code> from the specified xml document.
+     * Build a <code>MultiStatus</code> from the specified xml element.
      *
-     * @param multistatusDocument
+     * @param multistatusElement
      * @return new <code>MultiStatus</code> instance.
      * @throws IllegalArgumentException if the given document is <code>null</code>
      * or does not provide the required element.
      */
-    public static MultiStatus createFromXml(Document multistatusDocument) {
-        if (multistatusDocument == null) {
-	    throw new IllegalArgumentException("Cannot create a MultiStatus object from a null xml document.");
-	}
-
-	Element msElem = multistatusDocument.getRootElement();
-	if (!(XML_MULTISTATUS.equals(msElem.getName()) && NAMESPACE.equals(msElem.getNamespace()))) {
+    public static MultiStatus createFromXml(Element multistatusElement) {
+	if (!DomUtil.matches(multistatusElement, XML_MULTISTATUS, NAMESPACE)) {
 	    throw new IllegalArgumentException("DAV:multistatus element expected.");
 	}
 
         MultiStatus multistatus = new MultiStatus();
 
-	List respList = msElem.getChildren(XML_RESPONSE, NAMESPACE);
-	Iterator it = respList.iterator();
+        ElementIterator it = DomUtil.getChildren(multistatusElement, XML_RESPONSE, NAMESPACE);
 	while (it.hasNext()) {
-            MultiStatusResponse response = MultiStatusResponse.createFromXml((Element)it.next());
+            Element respElem = it.nextElement();
+            MultiStatusResponse response = MultiStatusResponse.createFromXml(respElem);
             multistatus.addResponse(response);
 	}
 
 	// optional response description on the multistatus element
-	multistatus.setResponseDescription(msElem.getChildText(XML_RESPONSEDESCRIPTION, NAMESPACE));
+	multistatus.setResponseDescription(DomUtil.getChildText(multistatusElement, XML_RESPONSEDESCRIPTION, NAMESPACE));
         return multistatus;
     }
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatusResponse.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatusResponse.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatusResponse.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatusResponse.java Fri Jan 13 03:11:35 2006
@@ -15,22 +15,35 @@
  */
 package org.apache.jackrabbit.webdav;
 
-import org.jdom.Element;
-import org.apache.jackrabbit.webdav.property.*;
-import org.apache.jackrabbit.webdav.util.XmlUtil;
-import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.xml.ElementIterator;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.property.PropContainer;
+import org.apache.jackrabbit.webdav.property.DavPropertyIterator;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameIterator;
+import org.apache.jackrabbit.webdav.property.DavPropertySet;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 import java.util.HashMap;
 import java.util.Iterator;
 
 /**
- * The <code>WebdavMultistatusResponse</code> class implements a structure that
- * hold a WebDAV multistatus response. Properties can be added to this response
- * with the respective error/status code.
+ * <code>Response</code>...
  */
-public class MultiStatusResponse implements DavConstants {
+public class MultiStatusResponse implements XmlSerializable, DavConstants {
 
-    private static Logger log = Logger.getLogger(MultiStatusResponse.class);
+    private static final int TYPE_PROPSTAT = 0;
+    private static final int TYPE_HREFSTATUS = 1;
+
+    /**
+     * The type of MultiStatusResponse
+     */
+    private final int type;
 
     /**
      * The content the 'href' element for this response
@@ -38,34 +51,78 @@
     private final String href;
 
     /**
-     * The '200' set (since this is used very often)
+     * An optional response description.
      */
-    private final Element status200;
+    private final String responseDescription;
 
     /**
-     * The '404' set (since this is used very often)
+     * Type of MultiStatus response: Href + Status
      */
-    private final Element status404;
+    private Status status;
 
     /**
+     * Type of MultiStatus response: PropStat
      * Hashmap containing all status
      */
-    private final HashMap statusMap = new HashMap();
+    private HashMap statusMap = new HashMap();
+
+    private MultiStatusResponse(String href, String responseDescription, int type) {
+        if (!isValidHref(href)) {
+            throw new IllegalArgumentException("Invalid href ('" + href + "')");
+        }
+        this.href = href;
+        this.responseDescription = responseDescription;
+        this.type = type;
+    }
 
     /**
-     * An optional response description.
+     * Constructs an WebDAV multistatus response
+     *
+     * @param href
+     * @param status
+     * @param responseDescription
      */
-    private String responseDescription;
+    public MultiStatusResponse(String href, Status status, String responseDescription) {
+        this(href, responseDescription, TYPE_HREFSTATUS);
+        if (status == null) {
+            throw new IllegalArgumentException("Status must not be null in case of a multistatus reponse that consists of href + status only.");
+        }
+        this.status = status;
+    }
 
     /**
-     * Constructs an empty WebDAV multistatus response
+     * Constructs an WebDAV multistatus response for a given resource. This
+     * would be used by COPY, MOVE, DELETE, LOCK that require a multistatus
+     * in case of error with a resource other than the resource identified in the
+     * Request-URI.<br>
+     * The response description is set to <code>null</code>.
+     *
+     * @param href
+     * @param statusCode
      */
-    public MultiStatusResponse(String href) {
-        this.href = href;
-        status200 = new Element(XML_PROP, NAMESPACE);
-        status404 = new Element(XML_PROP, NAMESPACE);
-        statusMap.put(new Integer(DavServletResponse.SC_OK), status200);
-        statusMap.put(new Integer(DavServletResponse.SC_NOT_FOUND), status404);
+    public MultiStatusResponse(String href, int statusCode) {
+        this(href, statusCode, null);
+    }
+
+    /**
+     * Constructs an WebDAV multistatus response for a given resource. This
+     * would be used by COPY, MOVE, DELETE, LOCK that require a multistatus
+     * in case of error with a resource other than the resource identified in the
+     * Request-URI.
+     *
+     * @param href
+     * @param statusCode
+     * @param responseDescription
+     */
+    public MultiStatusResponse(String href, int statusCode, String responseDescription) {
+        this(href, new Status(statusCode), responseDescription);
+    }
+
+    /**
+     * Constructs an empty WebDAV multistatus response of type 'PropStat'
+     */
+    public MultiStatusResponse(String href, String responseDescription) {
+        this(href, responseDescription, TYPE_PROPSTAT);
     }
 
     /**
@@ -94,80 +151,103 @@
      */
     public MultiStatusResponse(DavResource resource, DavPropertyNameSet propNameSet,
                                int propFindType) {
-        this(resource.getHref());
+        this(resource.getHref(), null, TYPE_PROPSTAT);
 
         // only property names requested
         if (propFindType == PROPFIND_PROPERTY_NAMES) {
+            PropContainer status200 = getPropContainer(DavServletResponse.SC_OK, true);
             DavPropertyName[] propNames = resource.getPropertyNames();
             for (int i = 0; i < propNames.length; i++) {
-                status200.addContent(propNames[i].toXml());
+                status200.addContent(propNames[i]);
             }
             // all or a specified set of property and their values requested.
         } else {
+            PropContainer status200 = getPropContainer(DavServletResponse.SC_OK, false);
             // clone set of property, since several resources could use this again
             propNameSet = new DavPropertyNameSet(propNameSet);
             // Add requested properties or all non-protected properties
             DavPropertyIterator iter = resource.getProperties().iterator();
             while (iter.hasNext()) {
-                DavProperty wdp = iter.nextProperty();
-                if ((propFindType == PROPFIND_ALL_PROP && !wdp.isProtected()) || propNameSet.remove(wdp.getName())) {
-                    status200.addContent(wdp.toXml());
+                DavProperty property = iter.nextProperty();
+                if ((propFindType == PROPFIND_ALL_PROP && !property.isProtected()) || propNameSet.remove(property.getName())) {
+                    status200.addContent(property);
                 }
             }
 
-            if (propFindType != PROPFIND_ALL_PROP) {
-                Iterator iter1 = propNameSet.iterator();
+            if (!propNameSet.isEmpty() && propFindType != PROPFIND_ALL_PROP) {
+                PropContainer status404 = getPropContainer(DavServletResponse.SC_NOT_FOUND, true);
+                DavPropertyNameIterator iter1 = propNameSet.iterator();
                 while (iter1.hasNext()) {
-                    DavPropertyName propName = (DavPropertyName) iter1.next();
-                    status404.addContent(propName.toXml());
+                    DavPropertyName propName = iter1.nextPropertyName();
+                    status404.addContent(propName);
                 }
             }
         }
     }
 
     /**
-     * Constructs an WebDAV multistatus response for a given resource. This
-     * would be used by COPY, MOVE, DELETE, LOCK that require a multistatus
-     * in case of error with a resource other than the resource identified in the
-     * Request-URI.
-     */
-    public MultiStatusResponse(String href, int status) {
-        this(href);
-        statusMap.put(new Integer(status), null);
-    }
-
-    /**
      * Returns the href
      *
      * @return href
+     * @see MultiStatusResponse#getHref()
      */
     public String getHref() {
         return href;
     }
 
     /**
-     * Adds a JDOM element to this response
-     *
-     * @param propElem the property to add
-     * @param status   the status of the response set to select
+     * @return responseDescription
+     * @see MultiStatusResponse#getResponseDescription()
      */
-    private void add(Element propElem, int status) {
-        Integer statusKey = new Integer(status);
-        Object propsContainer = statusMap.get(statusKey);
-        if (propsContainer == null) {
-            propsContainer = new Element(XML_PROP, NAMESPACE);
-            statusMap.put(statusKey, propsContainer);
-        }
-        ((Element) propsContainer).addContent(propElem.detach());
+    public String getResponseDescription() {
+        return responseDescription;
     }
 
     /**
+     * @see org.apache.jackrabbit.webdav.xml.XmlSerializable#toXml(org.w3c.dom.Document)
+     * @param document
+     */
+    public Element toXml(Document document) {
+        Element response = DomUtil.createElement(document, XML_RESPONSE, NAMESPACE);
+        // add '<href>'
+        response.appendChild(DomUtil.hrefToXml(getHref(), document));
+        if (type == TYPE_PROPSTAT) {
+            // add '<propstat>' elements
+            Iterator iter = statusMap.keySet().iterator();
+            while (iter.hasNext()) {
+                Integer statusKey = (Integer) iter.next();
+                Status status = new Status(statusKey.intValue());
+                PropContainer propCont = (PropContainer) statusMap.get(statusKey);
+
+                Element propstat = DomUtil.createElement(document, XML_PROPSTAT, NAMESPACE);
+                propstat.appendChild(propCont.toXml(document));
+                propstat.appendChild(status.toXml(document));
+                response.appendChild(propstat);
+            }
+        } else {
+            // add a single '<status>' element
+            // NOTE: a href+status response cannot be created with 'null' status
+            response.appendChild(status.toXml(document));
+        }
+        // add the optional '<responsedescription>' element
+        String description = getResponseDescription();
+        if (description != null) {
+            Element desc = DomUtil.createElement(document, XML_RESPONSEDESCRIPTION, NAMESPACE);
+            DomUtil.setText(desc, description);
+            response.appendChild(desc);
+        }
+        return response;
+    }
+    //----------------------------------------------< type specific methods >---
+    /**
      * Adds a property to this response '200' propstat set.
      *
      * @param property the property to add
      */
     public void add(DavProperty property) {
-        status200.addContent(property.toXml());
+        checkType(TYPE_PROPSTAT);
+        PropContainer status200 = getPropContainer(DavServletResponse.SC_OK, false);
+        status200.addContent(property);
     }
 
     /**
@@ -176,7 +256,9 @@
      * @param propertyName the property name to add
      */
     public void add(DavPropertyName propertyName) {
-        status200.addContent(propertyName.toXml());
+        checkType(TYPE_PROPSTAT);
+        PropContainer status200 = getPropContainer(DavServletResponse.SC_OK, true);
+        status200.addContent(propertyName);
     }
 
     /**
@@ -186,7 +268,9 @@
      * @param status   the status of the response set to select
      */
     public void add(DavProperty property, int status) {
-        add(property.toXml(), status);
+        checkType(TYPE_PROPSTAT);
+        PropContainer propCont = getPropContainer(status, false);
+        propCont.addContent(property);
     }
 
     /**
@@ -196,117 +280,75 @@
      * @param status       the status of the response set to select
      */
     public void add(DavPropertyName propertyName, int status) {
-        add(propertyName.toXml(), status);
+        checkType(TYPE_PROPSTAT);
+        PropContainer propCont = getPropContainer(status, true);
+        propCont.addContent(propertyName);
     }
 
     /**
-     * Get properties present in this response for the given status code.
      *
      * @param status
-     * @return property set
+     * @return
      */
-    public DavPropertySet getProperties(int status) {
-        DavPropertySet set = new DavPropertySet();
-        Integer key = new Integer(status);
-        if (statusMap.containsKey(key)) {
-            Object mapEntry = statusMap.get(key);
-            if (mapEntry != null) {
-                Element propElem = (Element) mapEntry;
-                Iterator it = propElem.getChildren().iterator();
-                while (it.hasNext()) {
-                    Element propEntry = (Element) it.next();
-                    DavProperty prop = DefaultDavProperty.createFromXml(propEntry);
-                    set.add(prop);
+    private PropContainer getPropContainer(int status, boolean forNames) {
+        Integer statusKey = new Integer(status);
+        PropContainer propContainer;
+        Object entry = statusMap.get(statusKey);
+        if (entry == null) {
+            if (forNames) {
+                propContainer = new DavPropertyNameSet();
+            } else {
+                propContainer = new DavPropertySet();
+            }
+            statusMap.put(statusKey, propContainer);
+        } else {
+            propContainer = (PropContainer) entry;
                 }
+        return propContainer;
             }
+
+    private void checkType(int type) {
+        if (this.type != type) {
+            throw new IllegalStateException("The given MultiStatusResponse is not of the required type.");
         }
-        return set;
     }
 
     /**
-     * Get property names present in this response for the given status code.
+     * Get properties present in this response for the given status code. In case
+     * this MultiStatusResponse does not represent a 'propstat' response, always
+     * an empty {@link DavPropertySet} will be returned.
      *
      * @param status
-     * @return property names
+     * @return property set
      */
-    public DavPropertyNameSet getPropertyNames(int status) {
-        DavPropertyNameSet set = new DavPropertyNameSet();
+    public DavPropertySet getProperties(int status) {
         Integer key = new Integer(status);
         if (statusMap.containsKey(key)) {
             Object mapEntry = statusMap.get(key);
-            if (mapEntry != null) {
-                Element propElem = (Element) mapEntry;
-                Iterator it = propElem.getChildren().iterator();
-                while (it.hasNext()) {
-                    Element propEntry = (Element) it.next();
-                    set.add(DavPropertyName.createFromXml(propEntry));
-                }
+            if (mapEntry != null && mapEntry instanceof DavPropertySet) {
+                return (DavPropertySet)mapEntry;
             }
         }
-        return set;
-    }
-
-    /**
-     * @return responseDescription
-     */
-    public String getResponseDescription() {
-        return responseDescription;
+        return new DavPropertySet();
     }
 
     /**
-     * Set the content of the optional response description element, which is
-     * intended to contain a message that can be displayed to the user
-     * explaining the nature of this response.
+     * Get property names present in this response for the given status code. In case
+     * this MultiStatusResponse does not represent a 'propstat' response, always
+     * an empty {@link DavPropertyNameSet} will be returned.
      *
-     * @param responseDescription
-     */
-    public void setResponseDescription(String responseDescription) {
-        this.responseDescription = responseDescription;
-    }
-
-    /**
-     * Creates the JDOM element for this reponse.
-     *
-     * @return A JDOM element of this response
+     * @param status
+     * @return property names
      */
-    public Element toXml() {
-        // don't create empty 'href' responses
-        if ("".equals(href)) {
-            return null;
+    public DavPropertyNameSet getPropertyNames(int status) {
+        Integer key = new Integer(status);
+        if (statusMap.containsKey(key)) {
+            Object mapEntry = statusMap.get(key);
+            if (mapEntry != null && mapEntry instanceof DavPropertyNameSet) {
+                return (DavPropertyNameSet)mapEntry;
         }
-        Element response = new Element(XML_RESPONSE, NAMESPACE);
-        // add '<href>'
-        response.addContent(XmlUtil.hrefToXml(href));
-        // add '<propstat>' elements or a single '<status>' element
-        Iterator iter = statusMap.keySet().iterator();
-        while (iter.hasNext()) {
-            Integer statusKey = (Integer) iter.next();
-            Object mapEntry = statusMap.get(statusKey);
-            Status status = new Status(statusKey.intValue());
-            if (mapEntry != null) {
-                Element prop = (Element) mapEntry;
-                if (XML_PROP.equals(prop.getName())) {
-                    // do not add empty propstat elements
-                    if (prop.getContentSize() > 0) {
-                        Element propstat = new Element(XML_PROPSTAT, NAMESPACE);
-                        propstat.addContent(prop);
-                        propstat.addContent(status.toXml());
-                        response.addContent(propstat);
                     }
-                } else {
-                    response.addContent(status.toXml());
-                }
-            } else {
-                response.addContent(status.toXml());
-            }
-        }
-        // add the optional '<responsedescription>' element
-        if (responseDescription != null) {
-            Element desc = new Element(XML_RESPONSEDESCRIPTION, NAMESPACE);
-            desc.setText(responseDescription);
-            response.addContent(desc);
-        }
-        return response;
+        return new DavPropertyNameSet();
     }
 
     /**
@@ -315,117 +357,60 @@
      * @param responseElement
      * @return new <code>MultiStatusResponse</code> instance
      * @throws IllegalArgumentException if the specified element is <code>null</code>
+     * or not a DAV:response element or if the mandatory DAV:href child is
+     * missing.
      */
     public static MultiStatusResponse createFromXml(Element responseElement) {
-        if (responseElement == null) {
-            throw new IllegalArgumentException("The response element must not be null.");
+        if (!DomUtil.matches(responseElement, XML_RESPONSE, NAMESPACE)) {
+            throw new IllegalArgumentException("DAV:response element required.");
         }
-        String href = XmlUtil.hrefFromXml(responseElement.getChild(XML_HREF, NAMESPACE));
-        String statusLine = responseElement.getChildText(XML_STATUS, NAMESPACE);
-        MultiStatusResponse response = (statusLine != null) ? new MultiStatusResponse(href, Status.createFromStatusLine(statusLine).getStatusCode()) : new MultiStatusResponse(href);
-
+        String href = DomUtil.getChildTextTrim(responseElement, XML_HREF, NAMESPACE);
+        if (href == null) {
+            throw new IllegalArgumentException("DAV:response element must contain a DAV:href element expected.");
+        }
+        String statusLine = DomUtil.getChildText(responseElement, XML_STATUS, NAMESPACE);
+        String responseDescription = DomUtil.getChildText(responseElement, XML_RESPONSEDESCRIPTION, NAMESPACE);
+
+        MultiStatusResponse response;
+        if (statusLine != null) {
+            Status status = Status.parse(statusLine);
+            response = new MultiStatusResponse(href, status, responseDescription);
+        } else {
+            response = new MultiStatusResponse(href, responseDescription, TYPE_PROPSTAT);
         // read propstat elements
-        Iterator it = responseElement.getChildren(XML_PROPSTAT, NAMESPACE).iterator();
+            ElementIterator it = DomUtil.getChildren(responseElement, XML_PROPSTAT, NAMESPACE);
         while (it.hasNext()) {
-            Element propstat = (Element) it.next();
-            Element prop = propstat.getChild(XML_PROP, NAMESPACE);
-            String propstatus = propstat.getChildText(XML_STATUS, NAMESPACE);
-            if (propstatus != null) {
-                Status st = Status.createFromStatusLine(propstatus);
-                Element[] propertyElems = (Element[]) prop.getChildren().toArray(new Element[0]);
-                for (int i = 0; i < propertyElems.length; i++) {
-                    response.add(propertyElems[i], st.getStatusCode());
+                Element propstat = it.nextElement();
+                String propstatus = DomUtil.getChildText(propstat, XML_STATUS, NAMESPACE);
+                Element prop = DomUtil.getChildElement(propstat, XML_PROP, NAMESPACE);
+                if (propstatus != null && prop != null) {
+                    int statusCode = Status.parse(propstatus).getStatusCode();
+                    ElementIterator propIt = DomUtil.getChildren(prop);
+                    while (propIt.hasNext()) {
+                        Element el = propIt.nextElement();
+                        // current elem is now either a dav property xml representation
+                        // or the xml representation of a davpropertyname
+                        if (DomUtil.hasContent(el)) {
+                            // property
+                            DavProperty property = DefaultDavProperty.createFromXml(el);
+                            response.add(property, statusCode);
+                        } else {
+                            // property-name only
+                            DavPropertyName propName = DavPropertyName.createFromXml(el);
+                            response.add(propName, statusCode);
+                        }
+                    }
                 }
             }
-        // TODO: propstat may also contain a responsedescription
         }
-
-        response.setResponseDescription(responseElement.getChildText(XML_RESPONSEDESCRIPTION, NAMESPACE));
         return response;
     }
 
     /**
-     * Inner class encapsulating the 'status' present in the multistatus response.
+     * @param href
+     * @return false if the given href is <code>null</code> or empty string.
      */
-    private static class Status {
-
-        private String version = "HTTP/1.1";
-        private int code;
-        private String phrase = "";
-
-        private Status(int code) {
-            this.code = code;
-            phrase = DavException.getStatusPhrase(code);
-        }
-
-        private Status(String version, int code, String phrase) {
-            this.version = version;
-            this.code = code;
-            this.phrase = phrase;
-        }
-
-        private int getStatusCode() {
-            return code;
-        }
-
-        private Element toXml() {
-            String statusLine = version + " " + code + " " + phrase;
-            return new Element(XML_STATUS, NAMESPACE).setText(statusLine);
-        }
-
-        private static Status createFromStatusLine(String statusLine) {
-            if (statusLine == null) {
-                throw new IllegalArgumentException("Unable to parse status line from null xml element.");
-            }
-            Status status;
-
-            // code copied from org.apache.commons.httpclient.StatusLine
-            int length = statusLine.length();
-            int at = 0;
-            int start = 0;
-            try {
-                while (Character.isWhitespace(statusLine.charAt(at))) {
-                    ++at;
-                    ++start;
-                }
-                if (!"HTTP".equals(statusLine.substring(at, at += 4))) {
-                    log.warn("Status-Line '" + statusLine + "' does not start with HTTP");
-                }
-                //handle the HTTP-Version
-                at = statusLine.indexOf(" ", at);
-                if (at <= 0) {
-                    log.warn("Unable to parse HTTP-Version from the status line: '" + statusLine + "'");
-                }
-                String version = (statusLine.substring(start, at)).toUpperCase();
-                //advance through spaces
-                while (statusLine.charAt(at) == ' ') {
-                    at++;
-                }
-                //handle the Status-Code
-                int to = statusLine.indexOf(" ", at);
-                if (to < 0) {
-                    to = length;
-                }
-                try {
-                    int code = Integer.parseInt(statusLine.substring(at, to));
-                    status = new Status(code);
-                } catch (NumberFormatException e) {
-                    throw new IllegalArgumentException("Unable to parse status code from status line: '" + statusLine + "'");
-                }
-                //handle the Reason-Phrase
-                String phrase = "";
-                at = to + 1;
-                if (at < length) {
-                    phrase = statusLine.substring(at).trim();
-                }
-
-                status.version = version;
-                status.phrase = phrase;
-
-            } catch (StringIndexOutOfBoundsException e) {
-                throw new IllegalArgumentException("Status-Line '" + statusLine + "' is not valid");
-            }
-            return status;
-        }
+    private static boolean isValidHref(String href) {
+        return href != null && !"".equals(href);
     }
 }

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/Status.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/Status.java?rev=368683&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/Status.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/Status.java Fri Jan 13 03:11:35 2006
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.webdav;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+
+/**
+ * <code>Status</code> encapsulating the 'status' present in multistatus
+ * responses.
+ */
+public class Status implements DavConstants, XmlSerializable{
+
+    private static Logger log = Logger.getLogger(Status.class);
+
+    private final String version;
+    private final int code;
+    private final String phrase;
+
+    public Status(int code) {
+        version = "HTTP/1.1";
+        this.code = code;
+        phrase = DavException.getStatusPhrase(code);
+    }
+
+    public Status(String version, int code, String phrase) {
+        this.version = version;
+        this.code = code;
+        this.phrase = phrase;
+    }
+
+    public int getStatusCode() {
+        return code;
+    }
+
+    /**
+     * @see XmlSerializable#toXml(Document)
+     */
+    public Element toXml(Document document) {
+        String statusLine = version + " " + code + " " + phrase;
+        Element e = DomUtil.createElement(document, XML_STATUS, NAMESPACE);
+        DomUtil.setText(e, statusLine);
+        return e;
+    }
+
+    /**
+     * Parse the given status line and return a new <code>Status</code> object.
+     *
+     * @param statusLine
+     * @return a new <code>Status</code>
+     */
+    public static Status parse(String statusLine) {
+        if (statusLine == null) {
+            throw new IllegalArgumentException("Unable to parse status line from null xml element.");
+        }
+        Status status;
+
+        // code copied from org.apache.commons.httpclient.StatusLine
+        int length = statusLine.length();
+        int at = 0;
+        int start = 0;
+        try {
+            while (Character.isWhitespace(statusLine.charAt(at))) {
+                ++at;
+                ++start;
+            }
+            if (!"HTTP".equals(statusLine.substring(at, at += 4))) {
+                log.warn("Status-Line '" + statusLine + "' does not start with HTTP");
+            }
+            //handle the HTTP-Version
+            at = statusLine.indexOf(" ", at);
+            if (at <= 0) {
+                log.warn("Unable to parse HTTP-Version from the status line: '" + statusLine + "'");
+            }
+            String version = (statusLine.substring(start, at)).toUpperCase();
+            //advance through spaces
+            while (statusLine.charAt(at) == ' ') {
+                at++;
+            }
+            //handle the Status-Code
+            int code;
+            int to = statusLine.indexOf(" ", at);
+            if (to < 0) {
+                to = length;
+            }
+            try {
+                code = Integer.parseInt(statusLine.substring(at, to));
+            } catch (NumberFormatException e) {
+                throw new IllegalArgumentException("Unable to parse status code from status line: '" + statusLine + "'");
+            }
+            //handle the Reason-Phrase
+            String phrase = "";
+            at = to + 1;
+            if (at < length) {
+                phrase = statusLine.substring(at).trim();
+            }
+
+            status = new Status(version, code, phrase);
+
+        } catch (StringIndexOutOfBoundsException e) {
+            throw new IllegalArgumentException("Status-Line '" + statusLine + "' is not valid");
+        }
+        return status;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/Status.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/Status.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java Fri Jan 13 03:11:35 2006
@@ -18,6 +18,9 @@
 import org.apache.jackrabbit.webdav.header.CodedUrlHeader;
 import org.apache.jackrabbit.webdav.header.DepthHeader;
 import org.apache.jackrabbit.webdav.header.IfHeader;
+import org.apache.jackrabbit.webdav.header.LabelHeader;
+import org.apache.jackrabbit.webdav.header.OverwriteHeader;
+import org.apache.jackrabbit.webdav.header.TimeoutHeader;
 import org.apache.jackrabbit.webdav.lock.LockInfo;
 import org.apache.jackrabbit.webdav.lock.Scope;
 import org.apache.jackrabbit.webdav.lock.Type;
@@ -26,31 +29,33 @@
 import org.apache.jackrabbit.webdav.ordering.OrderPatch;
 import org.apache.jackrabbit.webdav.ordering.OrderingConstants;
 import org.apache.jackrabbit.webdav.ordering.Position;
+import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
 import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
 import org.apache.jackrabbit.webdav.property.DavPropertySet;
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
-import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.transaction.TransactionConstants;
 import org.apache.jackrabbit.webdav.transaction.TransactionInfo;
-import org.apache.jackrabbit.webdav.version.DeltaVConstants;
 import org.apache.jackrabbit.webdav.version.LabelInfo;
 import org.apache.jackrabbit.webdav.version.MergeInfo;
 import org.apache.jackrabbit.webdav.version.OptionsInfo;
 import org.apache.jackrabbit.webdav.version.UpdateInfo;
 import org.apache.jackrabbit.webdav.version.report.ReportInfo;
-import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.webdav.xml.DomUtil;
+import org.apache.jackrabbit.webdav.xml.ElementIterator;
 import org.apache.log4j.Logger;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
 
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletInputStream;
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
@@ -60,7 +65,6 @@
 import java.security.Principal;
 import java.util.Enumeration;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
@@ -70,6 +74,7 @@
 public class WebdavRequestImpl implements WebdavRequest, DavConstants {
 
     private static Logger log = Logger.getLogger(WebdavRequestImpl.class);
+    private static final DocumentBuilderFactory BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
 
     private final HttpServletRequest httpRequest;
     private final DavLocatorFactory factory;
@@ -186,12 +191,7 @@
      * @see DavServletRequest#isOverwrite()
      */
     public boolean isOverwrite() {
-        boolean doOverwrite = true;
-        String overwriteHeader = httpRequest.getHeader(HEADER_OVERWRITE);
-        if (overwriteHeader != null && !overwriteHeader.equalsIgnoreCase(NO_OVERWRITE)) {
-            doOverwrite = false;
-        }
-        return doOverwrite;
+        return new OverwriteHeader(httpRequest).isOverwrite();
     }
 
     /**
@@ -209,37 +209,16 @@
     }
 
     /**
-     * Parse the request timeout header and convert the timeout value
-     * into a long indicating the number of milliseconds until expiration time
-     * is reached.<br>
-     * NOTE: If the requested timeout is 'infinite' {@link Long.MAX_VALUE}
-     * is returned.
+     * Parse the Timeout header and return a long representing the value.
+     * {@link #UNDEFINED_TIMEOUT} is used as default value if no header
+     * is available or if the parsing fails.
      *
-     * @return milliseconds the lock is requested to live.
+     * @return milliseconds indicating length of the timeout.
      * @see DavServletRequest#getTimeout()
+     * @see TimeoutHeader#parse(javax.servlet.http.HttpServletRequest, long)
      */
     public long getTimeout() {
-        String timeoutStr = httpRequest.getHeader(HEADER_TIMEOUT);
-        long timeout = UNDEFINED_TIMEOUT;
-        if (timeoutStr != null && timeoutStr.length() > 0) {
-            int secondsInd = timeoutStr.indexOf("Second-");
-            if (secondsInd >= 0) {
-                secondsInd += 7; // read over "Second-"
-                int i = secondsInd;
-                while (i < timeoutStr.length() && Character.isDigit(timeoutStr.charAt(i))) {
-                    i++;
-                }
-                try {
-                    timeout = 1000L * Long.parseLong(timeoutStr.substring(secondsInd, i));
-                } catch (NumberFormatException ignore) {
-                    // ignore an let the lock define the default timeout
-                    log.error("Invalid timeout format: " + timeoutStr);
-                }
-            } else if (timeoutStr.equalsIgnoreCase(TIMEOUT_INFINITE)) {
-                timeout = INFINITE_TIMEOUT;
-            }
-        }
-        return timeout;
+        return TimeoutHeader.parse(httpRequest, UNDEFINED_TIMEOUT).getTimeout();
     }
 
     /**
@@ -260,21 +239,32 @@
      */
     public Document getRequestDocument() {
         Document requestDocument = null;
+        /*
+        Don't attempt to parse the body if the contentlength header is 0
+        NOTE: a value of -1 indicates that the length is unknown, thus we have to parse the body.
+        NOTE that http1.1 request using chunked transfer coding will therefore not be detected here
+        */
+        if (httpRequest.getContentLength() == 0) {
+            return requestDocument;
+        }
             // try to parse the request body
             try {
                 InputStream in = httpRequest.getInputStream();
                 if (in != null) {
-                    SAXBuilder builder = new SAXBuilder(false);
-                    requestDocument = builder.build(in);
+                BUILDER_FACTORY.setNamespaceAware(true);
+                DocumentBuilder docBuilder = BUILDER_FACTORY.newDocumentBuilder();
+                requestDocument = docBuilder.parse(in);
                 }
             } catch (IOException e) {
                 if (log.isDebugEnabled()) {
                     log.debug("Unable to build an XML Document from the request body: " + e.getMessage());
                 }
-            } catch (JDOMException e) {
+        } catch (ParserConfigurationException e) {
                 if (log.isDebugEnabled()) {
                     log.debug("Unable to build an XML Document from the request body: " + e.getMessage());
             }
+        } catch (SAXException e) {
+            log.debug("Unable to build an XML Document from the request body: " + e.getMessage());
         }
         return requestDocument;
     }
@@ -285,7 +275,7 @@
      * @return type of the PROPFIND request. Default value is {@link #PROPFIND_ALL_PROP allprops}
      * @see DavServletRequest#getPropFindType()
      */
-    public int getPropFindType() {
+    public int getPropFindType() throws DavException {
         if (propfindProps == null) {
             parsePropFindRequest();
         }
@@ -300,7 +290,7 @@
      * @return set of properties requested by the PROPFIND body or an empty set.
      * @see DavServletRequest#getPropFindProperties()
      */
-    public DavPropertyNameSet getPropFindProperties() {
+    public DavPropertyNameSet getPropFindProperties() throws DavException {
         if (propfindProps == null) {
             parsePropFindRequest();
         }
@@ -313,28 +303,26 @@
      * NOTE: An empty 'propfind' request body will be treated as request for all
      * property according to the specification.
      */
-    private void parsePropFindRequest() {
-
+    private void parsePropFindRequest() throws DavException {
         propfindProps = new DavPropertyNameSet();
         Document requestDocument = getRequestDocument();
-
         // propfind httpRequest with empty body or invalid Xml >> retrieve all property
-        // TODO: spec requires a 'BAD REQUEST' error code
+        // TODO: invalid XML -> spec requires a 'BAD REQUEST' error code
         if (requestDocument == null) {
             return;
         }
 
-        // propfind httpRequest with invalid body >> treat as if empty body
-        Element root = requestDocument.getRootElement();
-        if (!root.getName().equals(XML_PROPFIND)) {
+        // propfind httpRequest with invalid body
+        Element root = requestDocument.getDocumentElement();
+        if (!XML_PROPFIND.equals(root.getLocalName())) {
             log.info("PropFind-Request has no <profind> tag.");
-            return;
+            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "PropFind-Request has no <profind> tag.");
         }
 
-        List childList = root.getChildren();
-        for (int i = 0; i < childList.size(); i++) {
-            Element child = (Element) childList.get(i);
-            String nodeName = child.getName();
+        ElementIterator it = DomUtil.getChildren(root);
+        while (it.hasNext()) {
+            Element child = it.nextElement();
+            String nodeName = child.getLocalName();
             if (XML_PROP.equals(nodeName)) {
                 propfindType = PROPFIND_BY_PROPERTY;
                 propfindProps = new DavPropertyNameSet(child);
@@ -357,7 +345,7 @@
      * @return the list of 'set' entries in the PROPPATCH request body
      * @see DavServletRequest#getPropPatchSetProperties()
      */
-    public DavPropertySet getPropPatchSetProperties() {
+    public DavPropertySet getPropPatchSetProperties() throws DavException {
         if (proppatchSet == null) {
             parsePropPatchRequest();
         }
@@ -372,7 +360,7 @@
      * @return the list of 'remove' entries in the PROPPATCH request body
      * @see DavServletRequest#getPropPatchRemoveProperties()
      */
-    public DavPropertyNameSet getPropPatchRemoveProperties() {
+    public DavPropertyNameSet getPropPatchRemoveProperties() throws DavException {
         if (proppatchRemove == null) {
             parsePropPatchRequest();
         }
@@ -382,46 +370,42 @@
     /**
      * Parse the PROPPATCH request body.
      */
-    private void parsePropPatchRequest() {
+    private void parsePropPatchRequest() throws DavException {
 
         proppatchSet = new DavPropertySet();
         proppatchRemove = new DavPropertyNameSet();
         Document requestDocument = getRequestDocument();
 
         if (requestDocument == null) {
-            return;
+            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Invalid request body.");
         }
 
-        Element root = requestDocument.getRootElement();
-        if (!root.getName().equals(XML_PROPERTYUPDATE)) {
+        Element root = requestDocument.getDocumentElement();
+        if (!DomUtil.matches(root, XML_PROPERTYUPDATE, NAMESPACE)) {
             // we should also check for correct namespace
             log.warn("PropPatch-Request has no <propertyupdate> tag.");
-            return;
+            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "PropPatch-Request has no <propertyupdate> tag.");
         }
 
-        List setList = root.getChildren(XML_SET, NAMESPACE);
-        if (!setList.isEmpty()) {
-            Iterator setIter = setList.iterator();
-            while (setIter.hasNext()) {
-                Element propElem = ((Element) setIter.next()).getChild(XML_PROP, NAMESPACE);
-                Iterator it = propElem.getChildren().iterator();
+        ElementIterator it = DomUtil.getChildren(root, XML_SET, NAMESPACE);
                 while (it.hasNext()) {
-                    Element propertyElem = (Element) it.next();
-                    proppatchSet.add(DefaultDavProperty.createFromXml(propertyElem));
+            Element propEl = DomUtil.getChildElement(it.nextElement(), XML_PROP, NAMESPACE);
+            if (propEl != null) {
+                ElementIterator properties = DomUtil.getChildren(propEl);
+                while (properties.hasNext()) {
+                   proppatchSet.add(DefaultDavProperty.createFromXml(properties.nextElement()));
                 }
             }
         }
 
         // get <remove> properties
-        List removeList = root.getChildren(XML_REMOVE, NAMESPACE);
-        if (!removeList.isEmpty()) {
-            Iterator removeIter = removeList.iterator();
-            while (removeIter.hasNext()) {
-                Element propElem = ((Element) removeIter.next()).getChild(XML_PROP, NAMESPACE);
-                Iterator it = propElem.getChildren().iterator();
+        it = DomUtil.getChildren(root, XML_REMOVE, NAMESPACE);
                 while (it.hasNext()) {
-                    Element propertyElem = (Element) it.next();
-                    proppatchRemove.add(DavPropertyName.createFromXml(propertyElem));
+            Element propEl = DomUtil.getChildElement(it.nextElement(), XML_PROP, NAMESPACE);
+            if (propEl != null) {
+                ElementIterator names = DomUtil.getChildren(propEl);
+                while (names.hasNext()) {
+                    proppatchRemove.add(DavPropertyName.createFromXml(names.nextElement()));
                 }
             }
         }
@@ -445,8 +429,8 @@
         // check if XML request body is present. It SHOULD have one for
         // 'create Lock' request and missing for a 'refresh Lock' request
         if (requestDocument != null) {
-            Element root = requestDocument.getRootElement();
-            if (root.getName().equals(XML_LOCKINFO)) {
+            Element root = requestDocument.getDocumentElement();
+            if (root.getLocalName().equals(XML_LOCKINFO)) {
                 lockInfo = new LockInfo(root, getTimeout(), isDeep);
             } else {
                 log.debug("Lock-Request has no <lockinfo> tag.");
@@ -544,7 +528,7 @@
         Document requestDocument = getRequestDocument();
         if (requestDocument != null) {
             try {
-                return new TransactionInfo(requestDocument.getRootElement());
+                return new TransactionInfo(requestDocument.getDocumentElement());
             } catch (IllegalArgumentException e) {
                 log.error(e.getMessage());
             }
@@ -566,8 +550,8 @@
     public SubscriptionInfo getSubscriptionInfo() {
         Document requestDocument = getRequestDocument();
         if (requestDocument != null) {
-            Element root = requestDocument.getRootElement();
-            if (ObservationConstants.XML_SUBSCRIPTIONINFO.equals(root.getName())) {
+            Element root = requestDocument.getDocumentElement();
+            if (ObservationConstants.XML_SUBSCRIPTIONINFO.equals(root.getLocalName())) {
                 int depth = getDepth(DEPTH_0);
                 return new SubscriptionInfo(root, getTimeout(), depth == DEPTH_INFINITY);
             }
@@ -607,21 +591,16 @@
      *         body or <code>null</code> if the
      * @see org.apache.jackrabbit.webdav.ordering.OrderingDavServletRequest#getOrderPatch()
      */
-    public OrderPatch getOrderPatch() {
+    public OrderPatch getOrderPatch() throws DavException {
         OrderPatch op = null;
         Document requestDocument = getRequestDocument();
         if (requestDocument != null) {
-            Element root = requestDocument.getRootElement();
-            if (!OrderingConstants.XML_ORDERPATCH.equals(root.getName()) ||
-                    root.getChild(OrderingConstants.XML_ORDERING_TYPE) == null) {
-                log.error("ORDERPATH request body must start with an 'orderpatch' element, which must contain an 'ordering-type' child element.");
-                return op;
-            }
-
+            Element root = requestDocument.getDocumentElement();
             try {
-                op = new OrderPatch(root);
+                op = OrderPatch.createFromXml(root);
             } catch (IllegalArgumentException e) {
                 log.error(e.getMessage());
+                throw new DavException(DavServletResponse.SC_BAD_REQUEST);
             }
         } else {
             log.error("Error while building xml document from ORDERPATH request body.");
@@ -634,11 +613,11 @@
      * @see org.apache.jackrabbit.webdav.version.DeltaVServletRequest#getLabel()
      */
     public String getLabel() {
-        String label = getHeader(DeltaVConstants.HEADER_LABEL);
+        LabelHeader label = LabelHeader.parse(this);
         if (label != null) {
-            label = Text.unescape(label);
+            return label.getLabel();
         }
-        return label;
+        return null;
     }
 
     /**
@@ -648,7 +627,7 @@
         LabelInfo lInfo = null;
         Document requestDocument = getRequestDocument();
         if (requestDocument != null) {
-            Element root = requestDocument.getRootElement();
+            Element root = requestDocument.getDocumentElement();
             int depth = getDepth(DEPTH_0);
             try {
                 lInfo = new LabelInfo(root, depth);
@@ -667,7 +646,7 @@
         Document requestDocument = getRequestDocument();
         if (requestDocument != null) {
             try {
-                mInfo = new MergeInfo(requestDocument.getRootElement());
+                mInfo = new MergeInfo(requestDocument.getDocumentElement());
             } catch (IllegalArgumentException e) {
                 log.error(e.getMessage());
             }
@@ -683,7 +662,7 @@
         Document requestDocument = getRequestDocument();
         if (requestDocument != null) {
             try {
-                uInfo = new UpdateInfo(requestDocument.getRootElement());
+                uInfo = new UpdateInfo(requestDocument.getDocumentElement());
             } catch (IllegalArgumentException e) {
                 log.error(e.getMessage());
             }
@@ -698,7 +677,7 @@
         ReportInfo rInfo = null;
         Document requestDocument = getRequestDocument();
         if (requestDocument != null) {
-            rInfo = new ReportInfo(requestDocument.getRootElement(), getDepth(DEPTH_0));
+            rInfo = new ReportInfo(requestDocument.getDocumentElement(), getDepth(DEPTH_0));
         }
         return rInfo;
     }
@@ -710,7 +689,7 @@
         OptionsInfo info = null;
         Document requestDocument = getRequestDocument();
         if (requestDocument != null) {
-            info = new OptionsInfo(requestDocument.getRootElement());
+            info = OptionsInfo.createFromXml(requestDocument.getDocumentElement());
         }
         return info;
     }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavResponseImpl.java Fri Jan 13 03:11:35 2006
@@ -15,20 +15,26 @@
  */
 package org.apache.jackrabbit.webdav;
 
-import org.jdom.Element;
-import org.jdom.Document;
-import org.jdom.output.XMLOutputter;
-import org.jdom.output.Format;
 import org.apache.log4j.Logger;
-import org.apache.jackrabbit.webdav.lock.*;
-import org.apache.jackrabbit.webdav.observation.*;
+import org.apache.jackrabbit.webdav.xml.XmlSerializable;
+import org.apache.jackrabbit.webdav.property.DavPropertySet;
+import org.apache.jackrabbit.webdav.lock.ActiveLock;
+import org.apache.jackrabbit.webdav.lock.LockDiscovery;
+import org.apache.jackrabbit.webdav.observation.Subscription;
+import org.apache.jackrabbit.webdav.observation.SubscriptionDiscovery;
+import org.apache.jackrabbit.webdav.observation.EventDiscovery;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.w3c.dom.Document;
 
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.Cookie;
 import javax.servlet.ServletOutputStream;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.DocumentBuilderFactory;
 import java.io.IOException;
-import java.io.ByteArrayOutputStream;
 import java.io.PrintWriter;
+import java.io.ByteArrayOutputStream;
 import java.util.Locale;
 
 /**
@@ -38,6 +44,8 @@
 
     private static Logger log = Logger.getLogger(WebdavResponseImpl.class);
 
+    private static final DocumentBuilderFactory BUILDER_FACTORY = DocumentBuilderFactory.newInstance();
+
     private HttpServletResponse httpResponse;
 
     /**
@@ -46,26 +54,40 @@
      * @param httpResponse
      */
     public WebdavResponseImpl(HttpServletResponse httpResponse) {
-        this.httpResponse = httpResponse;
+        this(httpResponse, false);
+    }
 
-        /* set cache control headers in order to deal with non-webdav complient
-        * http1.1 or http1.0 proxies. >> see RFC2518 9.4.5 */
+    /**
+     * Create a new <code>WebdavResponse</code>
+     *
+     * @param httpResponse
+     * @param noCache
+     */
+    public WebdavResponseImpl(HttpServletResponse httpResponse, boolean noCache) {
+        this.httpResponse = httpResponse;
+        if (noCache) {
+            /* set cache control headers */
         addHeader("Pragma", "No-cache");  // http1.0
         addHeader("Cache-Control", "no-cache"); // http1.1
     }
+    }
 
     /**
+     * If the specifid exception provides an error condition an Xml response body
+     * is sent providing more detailed information about the error. Otherwise only
+     * the error code and status phrase is sent back.
      *
      * @param exception
      * @throws IOException
      * @see DavServletResponse#sendError(org.apache.jackrabbit.webdav.DavException)
+     * @see #sendError(int, String)
+     * @see #sendXmlResponse(XmlSerializable, int)
      */
     public void sendError(DavException exception) throws IOException {
-        Element errorElem = exception.getError();
-        if (errorElem == null || errorElem.getChildren().size() == 0) {
+        if (!exception.hasErrorCondition()) {
             httpResponse.sendError(exception.getErrorCode(), exception.getStatusPhrase());
         } else {
-            sendXmlResponse(new Document(exception.getError()), exception.getErrorCode());
+            sendXmlResponse(exception, exception.getErrorCode());
         }
     }
 
@@ -77,7 +99,7 @@
      * @see DavServletResponse#sendMultiStatus(org.apache.jackrabbit.webdav.MultiStatus)
      */
     public void sendMultiStatus(MultiStatus multistatus) throws IOException {
-        sendXmlResponse(multistatus.toXml(), SC_MULTI_STATUS);
+        sendXmlResponse(multistatus, SC_MULTI_STATUS);
     }
 
     /**
@@ -89,10 +111,9 @@
      */
     public void sendLockResponse(ActiveLock lock) throws IOException {
         httpResponse.setHeader(DavConstants.HEADER_LOCK_TOKEN, "<" + lock.getToken() + ">");
-
-        Element propElem = new Element(DavConstants.XML_PROP, DavConstants.NAMESPACE);
-	propElem.addContent(new LockDiscovery(lock).toXml());
-	sendXmlResponse(new Document(propElem), SC_OK);
+	DavPropertySet propSet = new DavPropertySet();
+        propSet.add(new LockDiscovery(lock));
+        sendXmlResponse(propSet, SC_OK);
     }
 
     /**
@@ -104,32 +125,41 @@
      * @see DavServletResponse#sendRefreshLockResponse(org.apache.jackrabbit.webdav.lock.ActiveLock[])
      */
     public void sendRefreshLockResponse(ActiveLock[] locks) throws IOException {
-        Element propElem = new Element(DavConstants.XML_PROP, DavConstants.NAMESPACE);
-        propElem.addContent(new LockDiscovery(locks).toXml());
-        sendXmlResponse(new Document(propElem), SC_OK);
+        DavPropertySet propSet = new DavPropertySet();
+        propSet.add(new LockDiscovery(locks));
+        sendXmlResponse(propSet, SC_OK);
     }
 
     /**
      * Send Xml response body.
      *
-     * @param xmlDoc
+     * @param serializable
      * @param status
      * @throws IOException
-     * @see DavServletResponse#sendXmlResponse(Document, int);
+     * @see DavServletResponse#sendXmlResponse(XmlSerializable, int);
      */
-    public void sendXmlResponse(Document xmlDoc, int status) throws IOException {
+    public void sendXmlResponse(XmlSerializable serializable, int status) throws IOException {
         httpResponse.setStatus(status);
-        if (xmlDoc != null) {
+        if (serializable != null) {
             ByteArrayOutputStream out = new ByteArrayOutputStream();
-            // Write dom tree into byte array output stream
-            XMLOutputter xmli = new XMLOutputter(Format.getRawFormat());
-            xmli.output(xmlDoc, out);
+            try {
+                Document doc = BUILDER_FACTORY.newDocumentBuilder().newDocument();
+                doc.appendChild(serializable.toXml(doc));
+                
+                OutputFormat format = new OutputFormat("xml", "UTF-8", true);
+                XMLSerializer serializer = new XMLSerializer(out, format);
+                serializer.setNamespaces(true);
+                serializer.asDOMSerializer().serialize(doc);
+
             byte[] bytes = out.toByteArray();
             httpResponse.setContentType("text/xml; charset=UTF-8");
             httpResponse.setContentLength(bytes.length);
             httpResponse.getOutputStream().write(bytes);
-            out.close();
-            out.flush();
+
+            } catch (ParserConfigurationException e) {
+                log.error(e.getMessage());
+                throw new IOException(e.getMessage());
+            }
         }
     }
 
@@ -141,10 +171,9 @@
      * @see org.apache.jackrabbit.webdav.observation.ObservationDavServletResponse#sendSubscriptionResponse(org.apache.jackrabbit.webdav.observation.Subscription)
      */
     public void sendSubscriptionResponse(Subscription subscription) throws IOException {
-        Element propElem = new Element(DavConstants.XML_PROP, DavConstants.NAMESPACE);
-	propElem.addContent(new SubscriptionDiscovery(subscription).toXml());
-	Document doc = new Document(propElem);
-	sendXmlResponse(doc, SC_OK);
+	DavPropertySet propSet = new DavPropertySet();
+        propSet.add(new SubscriptionDiscovery(subscription));
+        sendXmlResponse(propSet, SC_OK);
     }
 
     /**
@@ -154,8 +183,7 @@
      * @see org.apache.jackrabbit.webdav.observation.ObservationDavServletResponse#sendPollResponse(org.apache.jackrabbit.webdav.observation.EventDiscovery)
      */
     public void sendPollResponse(EventDiscovery eventDiscovery) throws IOException {
-        Document pollDoc = new Document(eventDiscovery.toXml());
-        sendXmlResponse(pollDoc, SC_OK);
+        sendXmlResponse(eventDiscovery, SC_OK);
     }
 
     //--------------------------------------< HttpServletResponse interface >---

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/CodedUrlHeader.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/CodedUrlHeader.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/CodedUrlHeader.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/CodedUrlHeader.java Fri Jan 13 03:11:35 2006
@@ -23,7 +23,7 @@
 /**
  * <code>CodedUrlHeader</code>...
  */
-public class CodedUrlHeader {
+public class CodedUrlHeader implements Header {
 
     private static Logger log = Logger.getLogger(CodedUrlHeader.class);
 
@@ -42,6 +42,7 @@
      * Return the name of the header
      *
      * @return header name
+     * @see Header#getHeaderName()
      */
     public String getHeaderName() {
 	return headerName;
@@ -51,6 +52,7 @@
      * Return the value of the header
      *
      * @return value
+     * @see Header#getHeaderValue()
      */
     public String getHeaderValue() {
         return headerValue;

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/DepthHeader.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/DepthHeader.java?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/DepthHeader.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/DepthHeader.java Fri Jan 13 03:11:35 2006
@@ -24,7 +24,7 @@
 /**
  * <code>DepthHeader</code>...
  */
-public class DepthHeader implements DavConstants {
+public class DepthHeader implements Header, DavConstants {
 
     private static Logger log = Logger.getLogger(DepthHeader.class);
 
@@ -36,7 +36,7 @@
      * @param depth
      */
     public DepthHeader(int depth) {
-	if (depth == DavConstants.DEPTH_0 || depth == DavConstants.DEPTH_1 || depth == DavConstants.DEPTH_INFINITY) {
+	if (depth == DEPTH_0 || depth == DEPTH_1 || depth == DEPTH_INFINITY) {
 	    this.depth = depth;
 	} else {
 	    throw new IllegalArgumentException("Invalid depth: " + depth);
@@ -44,6 +44,16 @@
     }
 
     /**
+     * Create a new <code>DepthHeader</code> with either value {@link #DEPTH_0 0}
+     * or {@link #DEPTH_INFINITY infinity}.
+     * 
+     * @param isDeep
+     */
+    public DepthHeader(boolean isDeep) {
+        this.depth = (isDeep) ? DEPTH_INFINITY : DEPTH_0;
+    }
+
+    /**
      * @return integer representation of the depth indicated by the given header.
      */
     public int getDepth() {
@@ -55,6 +65,7 @@
      *
      * @return {@link DavConstants#HEADER_DEPTH Depth}
      * @see DavConstants#HEADER_DEPTH
+     * @see Header#getHeaderName()
      */
     public String getHeaderName() {
 	return DavConstants.HEADER_DEPTH;
@@ -64,6 +75,7 @@
      * Returns the header value.
      *
      * @return header value
+     * @see Header#getHeaderValue()
      */
     public String getHeaderValue() {
         if (depth == DavConstants.DEPTH_0 || depth == DavConstants.DEPTH_1) {

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/Header.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/Header.java?rev=368683&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/Header.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/Header.java Fri Jan 13 03:11:35 2006
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.webdav.header;
+
+/**
+ * <code>Header</code>...
+ */
+public interface Header {
+
+    public String getHeaderName();
+
+    public String getHeaderValue();
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/Header.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/Header.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url



Mime
View raw message