Ingo,

Find attached my patch file.

Regards,
Ritu



-----Original Message-----
From: Ingo Brunberg [mailto:[EMAIL PROTECTED]
Sent: Monday, June 21, 2004 9:43 PM
To: [EMAIL PROTECTED]
Subject: Re: Bind/Unbind/Rebind support added to WebdavResource


To create a patch you should have an up to date CVS repository (take
CVS HEAD of jakarta-slide), apply your changes and do a "cvs diff -u"
optionally specifying a diretory to start from.

Ingo

> Thanks for the reply Ingo.
> 
> I haven't created a patch before. Could you please briefly state the steps
> to follow or point me to some document? And which branch should I use for
> creating the patch?
> 
> Regards,
> Ritu
> 
> 
> -----Original Message-----
> From: Ingo Brunberg [mailto:[EMAIL PROTECTED]
> Sent: Monday, June 21, 2004 8:22 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Bind/Unbind/Rebind support added to WebdavResource
> 
> 
> Sure, just post your patch and I will have a look at it.
> 
> Ingo
> 
> > I have added Bind/Unbind/Rebind support to WebdavResource. Would anyone
be
> > interested in it? Also could I submit this support to be part of Slide
> 2.1?
> > 
> > Regards,
> > Ritu


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Index: .project
===================================================================
RCS file: .project
diff -N .project
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ .project    22 Jun 2004 10:47:29 -0000
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>webdavclient</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+       </buildSpec>
+       <natures>
+       </natures>
+</projectDescription>
Index: clientlib/src/java/org/apache/util/WebdavStatus.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-slide/webdavclient/clientlib/src/java/org/apache/util/WebdavStatus.java,v
retrieving revision 1.2
diff -u -r1.2 WebdavStatus.java
--- clientlib/src/java/org/apache/util/WebdavStatus.java        11 Feb 2004 11:30:51 
-0000      1.2
+++ clientlib/src/java/org/apache/util/WebdavStatus.java        22 Jun 2004 10:47:29 
-0000
@@ -75,6 +75,7 @@
     public static final int SC_MULTI_STATUS = 207;
     // This one colides with HTTP 1.1
     // "207 Parital Update OK"
+       public static final int SC_ALREADY_REPORTED = 208;
     
     public static final int SC_MULTIPLE_CHOICES = 300;
     public static final int SC_MOVED_PERMANENTLY = 301;
@@ -117,7 +118,8 @@
     public static final int SC_SERVICE_UNAVAILABLE = 503;
     public static final int SC_GATEWAY_TIMEOUT = 504;
     public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
-    public static final int SC_INSUFFICIENT_STORAGE = 507;
+       public static final int SC_LOOP_DETECTED = 506;
+       public static final int SC_INSUFFICIENT_STORAGE = 507;
     
     
     // ----------------------------------------------------- Static Initializer
Index: clientlib/src/java/org/apache/webdav/lib/WebdavResource.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java,v
retrieving revision 1.17
diff -u -r1.17 WebdavResource.java
--- clientlib/src/java/org/apache/webdav/lib/WebdavResource.java        13 May 2004 
13:06:40 -0000      1.17
+++ clientlib/src/java/org/apache/webdav/lib/WebdavResource.java        22 Jun 2004 
10:47:32 -0000
@@ -75,6 +75,9 @@
 import org.apache.webdav.lib.methods.UnlockMethod;
 import org.apache.webdav.lib.methods.UpdateMethod;
 import org.apache.webdav.lib.methods.VersionControlMethod;
+import org.apache.webdav.lib.methods.BindMethod;
+import org.apache.webdav.lib.methods.UnbindMethod;
+import org.apache.webdav.lib.methods.RebindMethod;
 import org.apache.webdav.lib.properties.AclProperty;
 import org.apache.webdav.lib.properties.LockDiscoveryProperty;
 import org.apache.webdav.lib.properties.PrincipalCollectionSetProperty;
@@ -4595,6 +4598,176 @@
         return method.getResponses();
     }
 
+
+       /**
+        * Execute the BIND method for this WebdavResource, given 
+        * an existing path to bind with.
+        * Overwrite is defaulted to true.
+        *
+        * @param resourceToBindTo      the resource to bind with, 
+        *                                                      as a server relative 
path
+        * @return true if the method is succeeded.
+        * @exception HttpException
+        * @exception IOException
+        */
+       public boolean bindMethod(String resourceToBindTo)
+               throws HttpException, IOException {
+                       return bindMethod(httpURL.getPath(), resourceToBindTo);
+       }
+
+       /**
+        * Execute the BIND method given the new path to bind to an existing path.
+        * Overwrite is defaulted to true.
+        *
+        * @param resourceToBind        the new resource as a server relative path
+        * @param resourceToBindTo      the resource to bind with, 
+        *                                                      as a server relative 
path
+        * @return true if the method is succeeded.
+        * @exception HttpException
+        * @exception IOException
+        */
+       public boolean bindMethod(String resourceToBind, String resourceToBindTo)
+               throws HttpException, IOException {
+                       return bindMethod(resourceToBind, resourceToBindTo, true);
+       }
+
+       /**
+        * Execute the BIND method given the new path to bind to an existing path.
+        *
+        * @param resourceToBind        the new resource as a server relative path
+        * @param resourceToBindTo      the resource to bind with, 
+        *                                                      as a server relative 
path
+        * @param overwrite             true if the new resource should overwrite
+        *                                                      an existing resource 
in the same path   
+        * @return true if the method is succeeded.
+        * @exception HttpException
+        * @exception IOException
+        */
+       public boolean bindMethod(String resourceToBind, String resourceToBindTo, 
boolean overwrite)
+               throws HttpException, IOException {
+
+               setClient();
+               BindMethod method = new BindMethod(resourceToBind, resourceToBindTo);
+               method.setDebug(debug); 
+               method.setOverwrite(overwrite);
+               int statusCode = client.executeMethod(method);
+
+               // Possbile BIND Status Codes => SC_CREATED, SC_NO_CONTENT
+               // SC_FORBIDDEN, SC_CONFLICT, SC_PRECONDITION_FAILED,
+               // SC_LOCKED, SC_BAD_GATEWAY, SC_INSUFFICIENT_STORAGE, 
+               // SC_LOOP_DETECTED
+               setStatusCode(statusCode);
+               return (statusCode >= 200 && statusCode < 300) ? true : false;
+       }
+
+       /**
+        * Execute the UNBIND method for this WebdavResource.
+        *
+        * @param resourceToUnBind      the server relative path of the resource
+        *                                                      to unbind
+        * @return true if the method is succeeded.
+        * @exception HttpException
+        * @exception IOException
+        */
+       public boolean unbindMethod()
+               throws HttpException, IOException {
+               return unbindMethod(httpURL.getPath());
+       }
+
+       /**
+        * Execute the UNBIND method given the resource to Unbind.
+        *
+        * @param resourceToUnBind      the server relative path of the resource
+        *                                                      to unbind
+        * @return true if the method is succeeded.
+        * @exception HttpException
+        * @exception IOException
+        */
+       public boolean unbindMethod(String resourceToUnBind)
+               throws HttpException, IOException {
+
+               setClient();
+               UnbindMethod method = new UnbindMethod(resourceToUnBind);
+               method.setDebug(debug); 
+               int statusCode = client.executeMethod(method);
+
+               // Possbile BIND Status Codes => SC_CREATED, SC_NOT_FOUND
+               // WebdavStatus.SC_FORBIDDEN, SC_CONFLICT, SC_PRECONDITION_FAILED,
+               // SC_LOCKED, SC_BAD_GATEWAY
+               setStatusCode(statusCode);
+               return (statusCode >= 200 && statusCode < 300) ? true : false;
+       }
+
+       /**
+        * Execute the Rebind method for this WebdavResource given the new
+        * Resource to bind with.
+        * The REBIND method removes a binding to a resource from one collection, 
+        * and adds a binding to that resource into another collection. It is 
+        * effectively an atomic form of a MOVE request.
+        * Overwrite is defaulted to true.
+        *
+        * @param resourceToBind        the new resource as a server relative path
+        * @param resourceToBindTo      the resource to bind with, 
+        *                                                      as a server relative 
path
+        * @return true if the method is succeeded.
+        * @exception HttpException
+        * @exception IOException
+        */
+       public boolean rebindMethod(String resourceToBindTo)
+               throws HttpException, IOException {
+               return rebindMethod(httpURL.getPath(), resourceToBindTo);
+       }
+               
+       /**
+        * Execute the Rebind method given a resource to rebind and the new
+        * Resource to bind with.
+        * The REBIND method removes a binding to a resource from one collection, 
+        * and adds a binding to that resource into another collection. It is 
+        * effectively an atomic form of a MOVE request.
+        * Overwrite is defaulted to true.
+        *
+        * @param resourceToBind        the new resource as a server relative path
+        * @param resourceToBindTo      the resource to bind with, 
+        *                                                      as a server relative 
path
+        * @return true if the method is succeeded.
+        * @exception HttpException
+        * @exception IOException
+        */
+       public boolean rebindMethod(String resourceToRebind, String resourceToBindTo)
+               throws HttpException, IOException {
+               return rebindMethod(resourceToRebind, resourceToBindTo, true);
+       }
+
+       /**
+        * Execute the Rebind method given a resource to rebind and the new
+        * Resource to bind with.
+        * The REBIND method removes a binding to a resource from one collection, 
+        * and adds a binding to that resource into another collection. It is 
+        * effectively an atomic form of a MOVE request
+        *
+        * @param resourceToBind        the new resource as a server relative path
+        * @param resourceToBindTo      the resource to bind with, 
+        *                                                      as a server relative 
path
+        * @return true if the method is succeeded.
+        * @exception HttpException
+        * @exception IOException
+        */
+       public boolean rebindMethod(String resourceToRebind, String resourceToBindTo, 
boolean overwrite)
+               throws HttpException, IOException {
+
+               setClient();
+               RebindMethod method = new RebindMethod(resourceToRebind, 
resourceToBindTo);
+               method.setDebug(debug); 
+               method.setOverwrite(overwrite);
+               int statusCode = client.executeMethod(method);
+
+               // Possbile BIND Status Codes => SC_CREATED, SC_NO_CONTENT
+               // WebdavStatus.SC_FORBIDDEN, SC_CONFLICT, SC_PRECONDITION_FAILED,
+               // SC_LOCKED, SC_BAD_GATEWAY, SC_INSUFFICIENT_STORAGE,
+               // SC_LOOP_DETECTED
+               setStatusCode(statusCode);
+               return (statusCode >= 200 && statusCode < 300) ? true : false;
+       }
 
     private static String getName(String uri) {
         String escapedName = URIUtil.getName(
Index: clientlib/src/java/org/apache/webdav/lib/methods/BindMethod.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/BindMethod.java,v
retrieving revision 1.2
diff -u -r1.2 BindMethod.java
--- clientlib/src/java/org/apache/webdav/lib/methods/BindMethod.java    11 Feb 2004 
11:30:51 -0000      1.2
+++ clientlib/src/java/org/apache/webdav/lib/methods/BindMethod.java    22 Jun 2004 
10:47:32 -0000
@@ -23,30 +23,179 @@
 
 package org.apache.webdav.lib.methods;
 
+import java.io.IOException;
+import org.apache.commons.httpclient.HttpConnection;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.util.XMLPrinter;
+import org.apache.commons.httpclient.util.URIUtil;
+import org.apache.commons.httpclient.URIException;
 
 /**
- * BIND Method.
+ * The BIND method modifies the collection identified by the Request-URI, 
+ * by adding a new binding from the segment specified in the BIND body 
+ * to the resource identified in the BIND body.
+ * 
+ * BIND Method Example:
+ * >> Request:
+ *     BIND /CollY HTTP/1.1
+ *     Host: www.example.com
+ *     Content-Type: text/xml; charset="utf-8"
+ *     Content-Length: xxx
+ *     <?xml version="1.0" encoding="utf-8" ?>
+ *     <D:bind xmlns:D="DAV:">
+ *             <D:segment>bar.html</D:segment>
+ *             <D:href>http://www.example.com/CollX/foo.html</D:href>
+ *     </D:bind>
  *
- * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">B.C. Holmes</a>
+ * >> Response:
+ *     HTTP/1.1 201 Created
+ * The server added a new binding to the collection, "http://www.example.com/CollY";, 
+ * associating "bar.html" with the resource identified by the URI 
+ * "http://www.example.com/CollX/foo.html";. Clients can now use the URI 
+ * "http://www.example.com/CollY/bar.html";, to submit requests to that resource.
+ *  
+ * @author <a href="mailto:[EMAIL PROTECTED]">Ritu Kedia</a>
  */
 public class BindMethod
-    extends XMLResponseMethodBase {
+       extends XMLResponseMethodBase {
 
 
-    public static final String NAME = "BIND";
+       public static final String NAME = "BIND";
     
-    // ----------------------------------------------------------- Constructors
+       private boolean overwrite = true;
+       private String segment = null;
+       private String href = null;     
+
+       // ----------------------------------------------------------- Constructors
+
+
+       /**
+        * Method constructor.
+        */
+       public BindMethod() {
+       }
+
+       public BindMethod(String resourceToBind, String resourceToBindTo) throws 
URIException {
+               super(URIUtil.encodePath(resourceToBind.substring(0, 
resourceToBind.lastIndexOf('/'))));
+               this.href = URIUtil.encodePath(resourceToBindTo);
+               this.segment = 
resourceToBind.substring(resourceToBind.lastIndexOf('/') + 1);
+       }
+
+       public String getName() {
+               return NAME;
+       }
+    
+       /**
+        * By default, if there already is a binding for the specified segment 
+        * in the collection, the new binding replaces the existing binding. 
+        * This default binding replacement behavior can be overridden using 
+        * the Overwrite header.
+        *
+        * @param overwrite New overwrite value
+        */
+       public void setOverwrite(boolean overwrite) {
+               checkNotUsed();
+               this.overwrite = overwrite;
+       }
+
+
+       /**
+        * By default, if there already is a binding for the specified segment 
+        * in the collection, the new binding replaces the existing binding. 
+        * This default binding replacement behavior can be overridden using 
+        * the Overwrite header.
+        *
+        * @return boolean Overwrite value
+        */
+       public boolean isOverwrite() {
+               return overwrite;
+       }
+
+
+       /**
+        * By default, if there already is a binding for the specified segment 
+        * in the collection, the new binding replaces the existing binding. 
+        * This default binding replacement behavior can be overridden using 
+        * the Overwrite header.
+        *
+        * @return boolean Overwrite value
+        */
+       public boolean getOverwrite() {
+               return overwrite;
+       }
+
+       /**
+        * Generate additional headers needed by the request.
+        *
+        * @param state HttpState token
+        * @param conn The connection being used for the request.
+        */
+       public void addRequestHeaders(HttpState state, HttpConnection conn)
+       throws IOException, HttpException {
+
+               super.addRequestHeaders(state, conn);
 
+               if (!isOverwrite())
+                       super.setRequestHeader("Overwrite", "F");
+
+       }
+    
+       /**
+        * DAV requests that contain a body must override this function to
+        * generate that body.
+        *
+        * <p>The default behavior simply returns an empty body.</p>
+        */
+       protected String generateRequestBody() {
+
+               if (segment == null || href == null)
+                       throw new IllegalStateException
+                               ("Segment and Href must be set before " +
+                                "calling this function.");
+
+               XMLPrinter printer = new XMLPrinter();
+ 
+               printer.writeXMLHeader();
+               printer.writeElement("D", "DAV:", "bind", XMLPrinter.OPENING);
+               printer.writeElement("D", "segment", XMLPrinter.OPENING);
+               printer.writeText(segment);
+               printer.writeElement("D", "segment", XMLPrinter.CLOSING);
+               printer.writeElement("D", "href", XMLPrinter.OPENING);
+               printer.writeText(href);
+               printer.writeElement("D", "href", XMLPrinter.CLOSING);
+               printer.writeElement("D", "bind", XMLPrinter.CLOSING);
+
+               return printer.toString();
+       }
+       
+       /**
+        * @return path of the resource to be bound
+        */
+       public String getHref() {
+               return href;
+       }
+
+       /**
+        * @return new resource name
+        */
+       public String getSegment() {
+               return segment;
+       }
+
+       /**
+        * @param path of the resource to be bound
+        */
+       public void setHref(String href) {
+               this.href = href;
+       }
+
+       /**
+        * @param new resource name
+        */
+       public void setSegment(String segment) {
+               this.segment = segment;
+       }
 
-    /**
-     * Method constructor.
-     */
-    public BindMethod() {
-    }
-
-    public String getName() {
-        return NAME;
-    }
 }
 
Index: clientlib/src/java/org/apache/webdav/lib/methods/RebindMethod.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/RebindMethod.java,v
retrieving revision 1.2
diff -u -r1.2 RebindMethod.java
--- clientlib/src/java/org/apache/webdav/lib/methods/RebindMethod.java  11 Feb 2004 
11:30:52 -0000      1.2
+++ clientlib/src/java/org/apache/webdav/lib/methods/RebindMethod.java  22 Jun 2004 
10:47:32 -0000
@@ -23,30 +23,183 @@
 
 package org.apache.webdav.lib.methods;
 
+import java.io.IOException;
+import org.apache.commons.httpclient.HttpConnection;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.util.XMLPrinter;
+import org.apache.commons.httpclient.util.URIUtil;
+import org.apache.commons.httpclient.URIException;
 
 /**
- * REBIND Method.
+ * The REBIND method removes a binding to a resource from one collection, 
+ * and adds a binding to that resource into another collection. It is 
+ * effectively an atomic form of a MOVE request.
+ * 
+ * REBIND Method Example:
+ * >> Request:
+ *     REBIND /CollX HTTP/1.1
+ *     Host: www.example.com
+ *     Content-Type: text/xml; charset="utf-8"
+ *     Content-Length: xxx
+ *     <?xml version="1.0" encoding="utf-8" ?>
+ *     <D:rebind xmlns:D="DAV:">
+ *     <D:segment>foo.html</D:segment>
+ *             <D:href>http://www.example.com/CollY/bar.html</D:href>
+ *     </D:rebind>
+ * 
+ * >> Response:
+ *     HTTP/1.1 200 OK
+ * The server added a new binding to the collection, 
+ * "http://www.example.com/CollX";, associating "foo.html" with the resource 
+ * identified by the URI "http://www.example.com/CollY/bar.html";, 
+ * and removes the binding named "bar.html" from the collection identified 
+ * by the URI "http://www.example.com/CollY";. 
+ * Clients can now use the URI "http://www.example.com/CollX/foo.html"; to 
+ * submit requests to that resource, and requests on the URI 
+ * "http://www.example.com/CollY/bar.html"; will fail with a 404 (Not Found) 
+ * response.
  *
- * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">B.C. Holmes</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Ritu Kedia</a>
  */
 public class RebindMethod
-    extends XMLResponseMethodBase {
+       extends XMLResponseMethodBase {
 
 
-    public static final String NAME = "REBIND";
+       public static final String NAME = "REBIND";
 
-    // ----------------------------------------------------------- Constructors
+       private boolean overwrite = true;
+       private String segment = null;
+       private String href = null;     
+
+       // ----------------------------------------------------------- Constructors
+
+
+       /**
+        * Method constructor.
+        */
+       public RebindMethod() {
+       }
+
+       public RebindMethod(String resourceToRebind, String resourceToBindTo) throws 
URIException {
+               super(URIUtil.encodePath(resourceToRebind.substring(0, 
resourceToRebind.lastIndexOf('/'))));
+               this.href = URIUtil.encodePath(resourceToBindTo);
+               this.segment = 
resourceToRebind.substring(resourceToRebind.lastIndexOf('/') + 1);
+       }
+
+       public String getName() {
+               return NAME;
+       }
+
+       /**
+        * By default, if there already is a binding for the specified segment 
+        * in the collection, the new binding replaces the existing binding. 
+        * This default binding replacement behavior can be overridden using 
+        * the Overwrite header.
+        *
+        * @return boolean Overwrite value
+        */
+       public boolean isOverwrite() {
+               return overwrite;
+       }
+
+
+       /**
+        * By default, if there already is a binding for the specified segment 
+        * in the collection, the new binding replaces the existing binding. 
+        * This default binding replacement behavior can be overridden using 
+        * the Overwrite header.
+        *
+        * @param overwrite New overwrite value
+        */
+       public void setOverwrite(boolean overwrite) {
+               checkNotUsed();
+               this.overwrite = overwrite;
+       }
+
+       /**
+        * By default, if there already is a binding for the specified segment 
+        * in the collection, the new binding replaces the existing binding. 
+        * This default binding replacement behavior can be overridden using 
+        * the Overwrite header.
+        *
+        * @return boolean Overwrite value
+        */
+       public boolean getOverwrite() {
+               return overwrite;
+       }
+
+       /**
+        * Generate additional headers needed by the request.
+        *
+        * @param state HttpState token
+        * @param conn The connection being used for the request.
+        */
+       public void addRequestHeaders(HttpState state, HttpConnection conn)
+       throws IOException, HttpException {
+
+               super.addRequestHeaders(state, conn);
+
+               if (!isOverwrite())
+                       super.setRequestHeader("Overwrite", "F");
+
+       }
+    
+       /**
+        * DAV requests that contain a body must override this function to
+        * generate that body.
+        *
+        * <p>The default behavior simply returns an empty body.</p>
+        */
+       protected String generateRequestBody() {
+
+               if (segment == null || href == null)
+                       throw new IllegalStateException
+                               ("Segment and Href must be set before " +
+                                "calling this function.");
+
+               XMLPrinter printer = new XMLPrinter();
+ 
+               printer.writeXMLHeader();
+               printer.writeElement("D", "DAV:", "rebind", XMLPrinter.OPENING);
+               printer.writeElement("D", "segment", XMLPrinter.OPENING);
+               printer.writeText(segment);
+               printer.writeElement("D", "segment", XMLPrinter.CLOSING);
+               printer.writeElement("D", "href", XMLPrinter.OPENING);
+               printer.writeText(href);
+               printer.writeElement("D", "href", XMLPrinter.CLOSING);
+               printer.writeElement("D", "rebind", XMLPrinter.CLOSING);
+
+               return printer.toString();
+       }
+       
+       /**
+        * @return path of the resource to be rebound
+        */
+       public String getHref() {
+               return href;
+       }
+
+       /**
+        * @return new resource name
+        */
+       public String getSegment() {
+               return segment;
+       }
+
+       /**
+        * @param path of the resource to be rebound
+        */
+       public void setHref(String href) {
+               this.href = href;
+       }
+
+       /**
+        * @param new resource name
+        */
+       public void setSegment(String segment) {
+               this.segment = segment;
+       }
 
-
-    /**
-     * Method constructor.
-     */
-    public RebindMethod() {
-    }
-
-    public String getName() {
-        return NAME;
-    }
 }
 
Index: clientlib/src/java/org/apache/webdav/lib/methods/UnbindMethod.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/UnbindMethod.java,v
retrieving revision 1.2
diff -u -r1.2 UnbindMethod.java
--- clientlib/src/java/org/apache/webdav/lib/methods/UnbindMethod.java  11 Feb 2004 
11:30:52 -0000      1.2
+++ clientlib/src/java/org/apache/webdav/lib/methods/UnbindMethod.java  22 Jun 2004 
10:47:32 -0000
@@ -23,30 +23,102 @@
 
 package org.apache.webdav.lib.methods;
 
+import java.io.IOException;
+import org.apache.commons.httpclient.HttpConnection;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.util.XMLPrinter;
+import org.apache.commons.httpclient.util.URIUtil;
+import org.apache.commons.httpclient.URIException;
 
 /**
- * UNBIND Method.
+ * The UNBIND method modifies the collection identified by the Request-URI, 
+ * by removing the binding identified by the segment specified in the UNBIND 
+ * body.
+ * 
+ * UNBIND Method Example:
+ * >> Request:
+ *     UNBIND /CollX HTTP/1.1
+ *     Host: www.example.com
+ *     Content-Type: text/xml; charset="utf-8"
+ *     Content-Length: xxx
+ *     <?xml version="1.0" encoding="utf-8" ?>
+ *     <D:unbind xmlns:D="DAV:">
+ *             <D:segment>foo.html</D:segment>
+ *     </D:unbind>
  *
- * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">B.C. Holmes</a>
+ * >> Response:
+ *     HTTP/1.1 200 OK
+ * The server removed the binding named "foo.html" from the collection, 
+ * "http://www.example.com/CollX";. A request to the resource named 
+ * "http://www.example.com/CollX/foo.html"; will return a 404 (Not Found) 
+ * response.
+ * 
+ * @author <a href="mailto:[EMAIL PROTECTED]">Ritu Kedia</a>
  */
 public class UnbindMethod
-    extends XMLResponseMethodBase {
+       extends XMLResponseMethodBase {
 
 
-    public static final String NAME = "UNBIND";
+       public static final String NAME = "UNBIND";
 
-    // ----------------------------------------------------------- Constructors
+       private String segment = null;
 
+       // ----------------------------------------------------------- Constructors
 
-    /**
-     * Method constructor.
-     */
-    public UnbindMethod() {
-    }
 
-    public String getName() {
-        return NAME;
-    }
+       /**
+        * Method constructor.
+        */
+       public UnbindMethod() {
+       }
+
+       public UnbindMethod(String resourceToUnbind) throws URIException{
+               super(URIUtil.encodePath(resourceToUnbind.substring(0, 
resourceToUnbind.lastIndexOf('/'))));
+               this.segment = 
resourceToUnbind.substring(resourceToUnbind.lastIndexOf('/') + 1);
+       }
+
+       public String getName() {
+               return NAME;
+       }
+
+       /**
+        * DAV requests that contain a body must override this function to
+        * generate that body.
+        *
+        * <p>The default behavior simply returns an empty body.</p>
+        */
+       protected String generateRequestBody() {
+
+               if (segment == null)
+                       throw new IllegalStateException
+                               ("Segment must be set before calling this function.");
+
+               XMLPrinter printer = new XMLPrinter();
+ 
+               printer.writeXMLHeader();
+               printer.writeElement("D", "DAV:", "unbind", XMLPrinter.OPENING);
+               printer.writeElement("D", "segment", XMLPrinter.OPENING);
+               printer.writeText(segment);
+               printer.writeElement("D", "segment", XMLPrinter.CLOSING);
+               printer.writeElement("D", "unbind", XMLPrinter.CLOSING);
+
+               return printer.toString();
+       }
+
+       /**
+        * @return resource name to be unbound
+        */
+       public String getSegment() {
+               return segment;
+       }
+
+       /**
+        * @param resource name to be unbound
+        */
+       public void setSegment(String segment) {
+               this.segment = segment;
+       }
+
 }
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to