You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by Robert Owen <eu...@sas.com> on 2001/08/23 17:36:29 UTC

Status for properties in multistatus

In the Slide webdav client, I am getting -1 for the status for properties
returned in a PROPFIND or PROPPATCH (getStatus on
org.apache.webdav.lib.Property). The problem is that the multistatus can
have a status element at the same level as href[Rob]  (as per RFC2518), but
for these methods usually has the status value in a propstat element (a
combined status for a number of properties). The code in
ResponseWithinMultiStatus in XMLResponseMethodBase only looks for a status
element on the same level as href with getFirstElement[Rob] , doesn't find
it and returns -1. 

This may not be the best way of fixing this (using XPath might also be an
option), and I'm not sure what impact changing the interface in BaseProperty
will have on things that I am not using, but this is now working for me.

XMLResponseMethodBase.java
--- XMLResponseMethodBase_1.19.java	Tue Jul 24 18:05:52 2001
+++ XMLResponseMethodBase.java	Tue Jul 24 17:15:53 2001
@@ -395,7 +395,37 @@
             }
         }
 
-        public String getHref() {
+         public int getStatusCode(Element property)
+        {
+           try
+           {
+              // We should be able to go up to find the <D:prop> element
and once more to find the
+              // <D:propstat> element and this shoud have a <D:status>
element which gives us the
+              // status for this property
+              org.w3c.dom.Element propElement =
(org.w3c.dom.Element)property.getParentNode();
+              // ASSERT (propElement.getLocalName().equals("prop"))
+              org.w3c.dom.Element propstatElement =
(org.w3c.dom.Element)propElement.getParentNode();
+              // ASSERT
(propstatElement.getLocalName().equals("propstat"));
+              NodeList list = propstatElement.getChildNodes();
+              org.w3c.dom.Element statusElement = null;
+              for (int i=0; i<list.getLength(); i++)
+              {
+                 if (list.item(i) instanceof org.w3c.dom.Element)
+                 {
+                    statusElement = (org.w3c.dom.Element)list.item(i);
+                    if (statusElement.getLocalName().equals("status") &&
statusElement.getNamespaceURI().equals("DAV:"))
+                    {
+                       Node statusNode = statusElement.getFirstChild();
+                       return
DOMUtils.parseStatus(((org.w3c.dom.Text)statusNode).getData());
+                    }
+                 }
+              }
+           }
+           catch (ClassCastException e) {}
+           return -1;
+        }
+
+       public String getHref() {
             Element href = getFirstElement("DAV:", "href");
             if (href != null) {
                 return getState().URLDecode(DOMUtils.getTextValue(href));
@@ -438,6 +468,10 @@
         }
 
         public int getStatusCode() {
+            return this.statusCode;
+        }
+
+        public int getStatusCode(org.w3c.dom.Element element) {
             return this.statusCode;
         }




--- BaseProperty_1.1.java	Tue Jul 24 17:52:45 2001
+++ BaseProperty.java	Tue Jul 10 16:01:31 2001
@@ -169,7 +169,14 @@
      * This method returns the status code associated with the property.
      */
     public int getStatusCode() {
-        return response.getStatusCode();
+        int sc = response.getStatusCode();
+        if (sc == -1)
+        {
+			// find the status code for this property
+			sc = response.getStatusCode(this.element);
+		}
+		return sc;
+      // return response.getStatusCode();
     }
 



--- ResponseEntity_1.1.java	Tue Jul 24 17:52:57 2001
+++ ResponseEntity.java	Tue Jul 10 15:58:18 2001
@@ -99,6 +99,15 @@
      */
     public int getStatusCode();
 
+    /**
+     * Get the status code in context for the element within 207
(Multi-Status).
+     *
+     * Unless explicitly prohibited any 2/3/4/5xx series
+     * response code may be used in a Multi-Status response.
+     *
+     * @return the status code.
+     */
+    public int getStatusCode(org.w3c.dom.Element element);
 
     /**
      * Get the properties in the response XML element.


Re: Status for properties in multistatus

Posted by Dirk Verbeeck <di...@pandora.be>.
Robert Owen wrote:

> In the Slide webdav client, I am getting -1 for the status for properties
> returned in a PROPFIND or PROPPATCH (getStatus on
> org.apache.webdav.lib.Property). The problem is that the multistatus can
> have a status element at the same level as href[Rob]  (as per RFC2518), but
> for these methods usually has the status value in a propstat element (a
> combined status for a number of properties). The code in
> ResponseWithinMultiStatus in XMLResponseMethodBase only looks for a status
> element on the same level as href with getFirstElement[Rob] , doesn't find
> it and returns -1.
>
> This may not be the best way of fixing this (using XPath might also be an
> option), and I'm not sure what impact changing the interface in BaseProperty
> will have on things that I am not using, but this is now working for me.

Nice catch,

I don't want to introduce a depecdency between BaseProperty and
ResponseWithinMultistatus
therefor I'm solving it in a different way.

I'm also changing the ResponseWithinMultistatus.getStatusCode to return the
status code of the first propstat, I think this is what people expect and the
most common case will be one popstat anyway.


Dirk