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 ib...@apache.org on 2004/07/02 13:32:21 UTC

cvs commit: jakarta-slide/webdavclient/clientlib/src/java/org/apache/util WebdavStatus.java

ib          2004/07/02 04:32:21

  Modified:    webdavclient/clientlib/src/java/org/apache/webdav/lib/methods
                        UnbindMethod.java RebindMethod.java BindMethod.java
               webdavclient/clientlib/src/java/org/apache/webdav/lib
                        WebdavResource.java
               webdavclient/clientlib/src/java/org/apache/util
                        WebdavStatus.java
  Log:
  Add support for WebDAV Bindings
  
  Revision  Changes    Path
  1.3       +73 -7     jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/UnbindMethod.java
  
  Index: UnbindMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/UnbindMethod.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnbindMethod.java	11 Feb 2004 11:30:52 -0000	1.2
  +++ UnbindMethod.java	2 Jul 2004 11:32:21 -0000	1.3
  @@ -5,7 +5,7 @@
    *
    * ====================================================================
    *
  - * Copyright 1999-2002 The Apache Software Foundation 
  + * Copyright 1999-2002 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.
  @@ -23,12 +23,32 @@
   
   package org.apache.webdav.lib.methods;
   
  +import org.apache.util.XMLPrinter;
   
   /**
  - * 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.
    *
  - * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
  + * 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>
  + *
  + * >> 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:rkedia@gmail.com">Ritu Kedia</a>
    */
   public class UnbindMethod
       extends XMLResponseMethodBase {
  @@ -36,6 +56,8 @@
   
       public static final String NAME = "UNBIND";
   
  +    private String segment = null;
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -45,8 +67,52 @@
       public UnbindMethod() {
       }
   
  +    public UnbindMethod(String binding) {
  +        super(binding.substring(0, binding.lastIndexOf('/')));
  +        this.segment = binding.substring(binding.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 segment resource name to be unbound
  +     */
  +    public void setSegment(String segment) {
  +        this.segment = segment;
  +    }
  +
   }
   
  
  
  
  1.3       +147 -7    jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/RebindMethod.java
  
  Index: RebindMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/RebindMethod.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RebindMethod.java	11 Feb 2004 11:30:52 -0000	1.2
  +++ RebindMethod.java	2 Jul 2004 11:32:21 -0000	1.3
  @@ -5,7 +5,7 @@
    *
    * ====================================================================
    *
  - * Copyright 1999-2002 The Apache Software Foundation 
  + * Copyright 1999-2002 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.
  @@ -23,12 +23,42 @@
   
   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;
   
   /**
  - * 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.
    *
  - * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
  + * 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:rkedia@gmail.com">Ritu Kedia</a>
    */
   public class RebindMethod
       extends XMLResponseMethodBase {
  @@ -36,6 +66,10 @@
   
       public static final String NAME = "REBIND";
   
  +    private boolean overwrite = true;
  +    private String segment = null;
  +    private String href = null;
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -45,8 +79,114 @@
       public RebindMethod() {
       }
   
  +    public RebindMethod(String existingBinding, String newBinding) {
  +        super(newBinding.substring(0, newBinding.lastIndexOf('/')));
  +        this.href = existingBinding;
  +        this.segment = newBinding.substring(newBinding.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 the current value of the overwrite flag
  +     */
  +    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;
  +    }
  +
  +
  +    /**
  +     * 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 href path of the resource to be rebound
  +     */
  +    public void setHref(String href) {
  +        this.href = href;
  +    }
  +
  +    /**
  +     * @param segment new resource name
  +     */
  +    public void setSegment(String segment) {
  +        this.segment = segment;
  +    }
  +
   }
   
  
  
  
  1.3       +143 -8    jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/BindMethod.java
  
  Index: BindMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/BindMethod.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BindMethod.java	11 Feb 2004 11:30:51 -0000	1.2
  +++ BindMethod.java	2 Jul 2004 11:32:21 -0000	1.3
  @@ -5,7 +5,7 @@
    *
    * ====================================================================
    *
  - * Copyright 1999-2002 The Apache Software Foundation 
  + * Copyright 1999-2002 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.
  @@ -23,19 +23,48 @@
   
   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;
   
   /**
  - * 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.
    *
  - * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
  + * 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>
  + *
  + * >> 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:rkedia@gmail.com">Ritu Kedia</a>
    */
   public class BindMethod
       extends XMLResponseMethodBase {
   
   
       public static final String NAME = "BIND";
  -    
  +
  +    private boolean overwrite = true;
  +    private String segment = null;
  +    private String href = null;
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -45,8 +74,114 @@
       public BindMethod() {
       }
   
  +    public BindMethod(String existingBinding, String newBinding) {
  +        super(newBinding.substring(0, newBinding.lastIndexOf('/')));
  +        this.href = existingBinding;
  +        this.segment = newBinding.substring(newBinding.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 the current value of the overwrite flag
  +     */
  +    public boolean isOverwrite() {
  +        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 href path of the resource to be bound
  +     */
  +    public void setHref(String href) {
  +        this.href = href;
  +    }
  +
  +    /**
  +     * @param segment new resource name
  +     */
  +    public void setSegment(String segment) {
  +        this.segment = segment;
  +    }
  +
   }
   
  
  
  
  1.19      +210 -75   jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java
  
  Index: WebdavResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/WebdavResource.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- WebdavResource.java	1 Jul 2004 16:44:55 -0000	1.18
  +++ WebdavResource.java	2 Jul 2004 11:32:21 -0000	1.19
  @@ -5,7 +5,7 @@
    *
    * ====================================================================
    *
  - * Copyright 1999-2002 The Apache Software Foundation 
  + * Copyright 1999-2002 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.
  @@ -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;
  @@ -1056,10 +1059,10 @@
                   char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/")
                                      + URIUtil.encodePath(getName(href))
                       ).toCharArray();
  -		 HttpURL childURL = httpURL instanceof HttpsURL
  +         HttpURL childURL = httpURL instanceof HttpsURL
                                              ? new HttpsURL(childURI)
  -		                           : new HttpURL(childURI);
  -		childURL.setRawAuthority(httpURL.getRawAuthority());						  
  +                                   : new HttpURL(childURI);
  +        childURL.setRawAuthority(httpURL.getRawAuthority());
                   workingResource.setHttpURL( childURL,
                                              NOACTION, defaultDepth);
                   workingResource.setExistence(true);
  @@ -1922,10 +1925,11 @@
   
   
       /**
  -     * Set the overwrite flag for COPY and MOVE.
  +     * Set the overwrite flag for COPY, MOVE, BIND and REBIND.
        * Should be set before the method is executed.
        *
        * @param overwrite the overwrite flag
  +     * @see #getOverwrite()
        */
       public void setOverwrite(boolean overwrite) {
           this.overwrite = overwrite;
  @@ -1933,9 +1937,11 @@
   
   
       /**
  -     * Get the current value of the overwrite flag for COPY and MOVE.
  +     * Get the current value of the overwrite flag for COPY, MOVE, BIND and
  +     * REBIND.
        *
        * @return true if the current flag is overwriting.
  +     * @see #setOverwrite(boolean)
        */
       public boolean getOverwrite() {
           return overwrite;
  @@ -2109,7 +2115,7 @@
                   String[] longFormat = new String[5];
                   // displayname.
                   longFormat[0] = currentResource.getDisplayName();
  -                
  +
   
                   long length = currentResource.getGetContentLength();
                   // getcontentlength
  @@ -2129,11 +2135,11 @@
                       // Print the local fancy date format.
                       DateFormat.getDateTimeInstance().format(date);
                   hrefList.addElement(longFormat);
  -                
  +
                   // real name of componente
                   longFormat[4] = currentResource.getName();
   
  -                
  +
               } catch (Exception e) {
                   // FIXME: After if's gotten an exception, any solution?
                   if (debug > 0)
  @@ -2209,7 +2215,7 @@
           setClient();
   
           AclMethod method = new AclMethod(URIUtil.encodePath(path));
  -        method.setDebug(debug);                                            
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -2299,7 +2305,7 @@
           PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
                                                      DepthSupport.DEPTH_0,
                                                      properties.elements());
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
           client.executeMethod(method);
   
  @@ -2352,7 +2358,7 @@
           PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
                                                      DepthSupport.DEPTH_0,
                                                      properties.elements());
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
           client.executeMethod(method);
   
  @@ -2492,10 +2498,10 @@
           int statusCode = client.executeMethod(method);
   
           setStatusCode(statusCode);
  -        
  +
           // get the file only if status is any kind of OK
           if (statusCode >= 200 && statusCode < 300) {
  -            
  +
               // Do a simple little loop to read the response back into the passed
               // file parameter.
               InputStream inStream = method.getResponseBodyAsStream();
  @@ -2508,14 +2514,14 @@
               }
               inStream.close();
               fos.close();
  -            
  +
               return true;
  -            
  +
           } else {
               return false;
   
           }
  -        
  +
   
      }
   
  @@ -2774,10 +2780,9 @@
               method = new OptionsMethod("*");
           else
               method = new OptionsMethod(URIUtil.encodePath(path));
  -            
  -        method.setDebug(debug); 
  +
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
  -    
           int statusCode = client.executeMethod(method);
   
           setStatusCode(statusCode);
  @@ -2832,7 +2837,7 @@
           HttpClient client = getSessionInstance(httpURL, true);
   
           OptionsMethod method = new OptionsMethod(httpURL.getEscapedPath());
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           client.executeMethod(method);
  @@ -2890,9 +2895,9 @@
   
           OptionsMethod method = new OptionsMethod(httpURL.getEscapedPath(),
                                                    type);
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
  -                                                 
  +
           client.executeMethod(method);
   
           Vector options = new Vector();
  @@ -2943,9 +2948,9 @@
   
           OptionsMethod method = new OptionsMethod(URIUtil.encodePath(path),
                                                    type);
  -        method.setDebug(debug); 
  -        method.setFollowRedirects(this.followRedirects);                                                 
  -                                                 
  +        method.setDebug(debug);
  +        method.setFollowRedirects(this.followRedirects);
  +
           client.executeMethod(method);
   
           Vector options = new Vector();
  @@ -3028,7 +3033,7 @@
           setClient();
           LabelMethod method = new LabelMethod(URIUtil.encodePath(path),
                                                labeltype, labelname);
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           int statusCode = client.executeMethod(method);
  @@ -3047,7 +3052,7 @@
           // Default depth=0, type=by_name
           ReportMethod method = new ReportMethod(httpURL.getEscapedPath(),
                                                  depth);
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
           client.executeMethod(method);
   
  @@ -3085,7 +3090,7 @@
           ReportMethod method =
               new ReportMethod(httpURL.getEscapedPath(), DepthSupport.DEPTH_0,
                                properties.elements());
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
           client.executeMethod(method);
   
  @@ -3100,7 +3105,7 @@
           // Default depth=0, type=by_name
           ReportMethod method = new ReportMethod(httpURL.getEscapedPath(), depth,
                                                  properties.elements());
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
           client.executeMethod(method);
   
  @@ -3152,7 +3157,7 @@
           ReportMethod method = new ReportMethod(httpURL.getEscapedPath(), depth,
                                                  properties.elements(),
                                                  histUri.elements());
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
           client.executeMethod(method);
   
  @@ -3189,7 +3194,7 @@
           ReportMethod method = new ReportMethod(httpURL.getEscapedPath(), depth,
                                                  sQuery);
   
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
           client.executeMethod(method);
   
  @@ -3261,13 +3266,13 @@
       public Enumeration propfindMethod(String path, int depth)
           throws HttpException, IOException {
   
  -        setClient(); 
  +        setClient();
           // Change the depth for allprop
           PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
                                                      depth);
  -                                                   
  -        method.setDebug(debug);                                            
  -                                                   
  +
  +        method.setDebug(debug);
  +
           // Default depth=infinity, type=allprop
           int status = client.executeMethod(method);
   
  @@ -3339,10 +3344,9 @@
           PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
                                                      depth,
                                                      properties.elements());
  -                                                   
  -        method.setDebug(debug); 
  +
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
  -                                                   
           int status = client.executeMethod(method);
   
           // Set status code for this resource.
  @@ -3439,9 +3443,8 @@
           PropFindMethod method = new PropFindMethod(URIUtil.encodePath(path),
                                                      DepthSupport.DEPTH_0,
                                                      properties.elements());
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
  -                                                   
           int status = client.executeMethod(method);
   
           // Also accept OK sent by buggy servers.
  @@ -3731,7 +3734,7 @@
   
           setClient();
           PropPatchMethod method = new PropPatchMethod(URIUtil.encodePath(path));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -3843,7 +3846,7 @@
   
           setClient();
           DeleteMethod method = new DeleteMethod(URIUtil.encodePath(path));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -3890,9 +3893,8 @@
           setClient();
           MoveMethod method = new MoveMethod(URIUtil.encodePath(source),
                                              URIUtil.encodePath(destination));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
  -                                           
           generateIfHeader(method);
           method.setOverwrite(overwrite);
           int statusCode = client.executeMethod(method);
  @@ -3938,7 +3940,7 @@
           setClient();
           CopyMethod method = new CopyMethod(URIUtil.encodePath(source),
                                              URIUtil.encodePath(destination));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -4071,10 +4073,10 @@
        */
       public boolean lockMethod(String path, String owner, int timeout)
           throws HttpException, IOException {
  -            
  -        return lockMethod(path, owner, timeout, LockMethod.SCOPE_EXCLUSIVE);    
  -    }        
  -    
  +
  +        return lockMethod(path, owner, timeout, LockMethod.SCOPE_EXCLUSIVE);
  +    }
  +
       /**
        * Execute the LOCK method for the given path. This method tries to acquire
        * an exclusive write lock with the given timeout value.
  @@ -4088,18 +4090,18 @@
        * @exception IOException
        */
       public boolean lockMethod(String path, String owner, int timeout, short lockType)
  -        throws HttpException, IOException {            
  +        throws HttpException, IOException {
   
           setClient();
  -        
  +
           if (owner == null) {
               owner = (httpURL.getUser() != null) ? httpURL.getUser() : defaultOwner;
           }
  -                    
  +
           // default lock type setting
           LockMethod method = new LockMethod(URIUtil.encodePath(path), owner,
                                              lockType, timeout);
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -4194,21 +4196,21 @@
           throws HttpException, IOException {
   
           setClient();
  -        
  +
           if (owner == null) {
               owner = (httpURL.getUser() != null) ? httpURL.getUser() : defaultOwner;
           }
  - 
  +
           // Get the lock for the given path.
           WebdavState state = (WebdavState) client.getState();
           // Discover the locktoken from the given lock owner
  -        
  +
           state = discoverLock(owner, path, state);
           String lock = state.getLock(path);
           if (lock == null) return false;
           // unlock for the given path.
           UnlockMethod method = new UnlockMethod(URIUtil.encodePath(path));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -4259,11 +4261,11 @@
           } catch (Exception e) {
               return state;
           }
  - 
  +
   
           if (lockDiscovery == null) return state;
           Lock[] activeLocks = lockDiscovery.getActiveLocks();
  -        
  +
           if (activeLocks == null) return state;
           for (int i = 0; i < activeLocks.length; i++) {
               String activeLockOwner = activeLocks[i].getOwner();
  @@ -4307,7 +4309,7 @@
           setClient();
           UpdateMethod method = new UpdateMethod(URIUtil.encodePath(path),
                                                  URIUtil.encodePath(target));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -4326,9 +4328,8 @@
   
           VersionControlMethod method = new VersionControlMethod(
                                               URIUtil.encodePath(path));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
  -            
           generateIfHeader(method);
           int statusCode = client.executeMethod(method);
   
  @@ -4346,7 +4347,7 @@
           VersionControlMethod method = new VersionControlMethod(
                                        URIUtil.encodePath(path),
                                        URIUtil.encodePath(target));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -4390,9 +4391,8 @@
           setClient();
           MkWorkspaceMethod method =
               new MkWorkspaceMethod(URIUtil.encodePath(path));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
  -            
           generateIfHeader(method);
           int statusCode = client.executeMethod(method);
   
  @@ -4519,7 +4519,7 @@
   
           setClient();
           CheckinMethod method = new CheckinMethod(URIUtil.encodePath(path));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -4558,7 +4558,7 @@
   
           setClient();
           CheckoutMethod method = new CheckoutMethod(URIUtil.encodePath(path));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -4600,7 +4600,7 @@
           setClient();
           UncheckoutMethod method =
               new UncheckoutMethod(URIUtil.encodePath(path));
  -        method.setDebug(debug); 
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
   
           generateIfHeader(method);
  @@ -4707,10 +4707,9 @@
                   properties,
                   DepthSupport.DEPTH_INFINITY,
                   reportType);
  - 
  -        method.setDebug(debug); 
  +
  +        method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
  -                
           int status = client.executeMethod(method);
   
           // Set status code for this resource.
  @@ -4731,6 +4730,142 @@
           return method.getResponses();
       }
   
  +
  +    /**
  +     * Execute the BIND method for this WebdavResource, given
  +     * an existing path to bind with.
  +     *
  +     * @param newBinding  the new binding as a server relative path
  +     * @return true if the method is succeeded.
  +     * @exception HttpException
  +     * @exception IOException
  +     * @see #setOverwrite(boolean)
  +     */
  +    public boolean bindMethod(String newBinding)
  +        throws HttpException, IOException {
  +        return bindMethod(httpURL.getPath(), newBinding);
  +    }
  +
  +    /**
  +     * Execute the BIND method given the new path to bind to an existing path.
  +     *
  +     * @param existingBinding  the existing binding as a server relative path
  +     * @param newBinding       the new binding as a server relative path
  +     * @return true if the method is succeeded.
  +     * @exception HttpException
  +     * @exception IOException
  +     * @see #setOverwrite(boolean)
  +     */
  +    public boolean bindMethod(String existingBinding, String newBinding)
  +        throws HttpException, IOException {
  +
  +        setClient();
  +        BindMethod method =
  +            new BindMethod(URIUtil.encodePath(existingBinding),
  +                           URIUtil.encodePath(newBinding));
  +        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;
  +    }
  +
  +    /**
  +     * Execute the UNBIND method for this WebdavResource.
  +     *
  +     * @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 binding  the server relative path of the resource to unbind
  +     * @return true if the method is succeeded.
  +     * @exception HttpException
  +     * @exception IOException
  +     */
  +    public boolean unbindMethod(String binding)
  +        throws HttpException, IOException {
  +
  +        setClient();
  +        UnbindMethod method =
  +            new UnbindMethod(URIUtil.encodePath(binding));
  +        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;
  +    }
  +
  +    /**
  +     * 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.
  +     *
  +     * @param newBinding the new binding as a server relative path
  +     * @return true if the method is succeeded.
  +     * @exception HttpException
  +     * @exception IOException
  +     * @see #setOverwrite(boolean)
  +     */
  +    public boolean rebindMethod(String newBinding)
  +        throws HttpException, IOException {
  +        boolean result = rebindMethod(httpURL.getPath(), newBinding);
  +        if (result) {
  +            httpURL.setPath(newBinding);
  +            refresh();
  +        }
  +
  +        return result;
  +    }
  +
  +    /**
  +     * 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 existingBinding  the existing binding as a server relative path
  +     * @param newBinding       the new binding as a server relative path
  +     * @return true if the method is succeeded.
  +     * @exception HttpException
  +     * @exception IOException
  +     * @see #setOverwrite(boolean)
  +     */
  +    public boolean rebindMethod(String existingBinding, String newBinding)
  +        throws HttpException, IOException {
  +
  +        setClient();
  +        RebindMethod method =
  +            new RebindMethod(URIUtil.encodePath(existingBinding),
  +                             URIUtil.encodePath(newBinding));
  +        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;
  +    }
   
       private static String getName(String uri) {
           String escapedName = URIUtil.getName(
  
  
  
  1.3       +40 -37    jakarta-slide/webdavclient/clientlib/src/java/org/apache/util/WebdavStatus.java
  
  Index: WebdavStatus.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/util/WebdavStatus.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WebdavStatus.java	11 Feb 2004 11:30:51 -0000	1.2
  +++ WebdavStatus.java	2 Jul 2004 11:32:21 -0000	1.3
  @@ -5,7 +5,7 @@
    *
    * ====================================================================
    *
  - * Copyright 1999-2002 The Apache Software Foundation 
  + * Copyright 1999-2002 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.
  @@ -19,52 +19,52 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    *
  - */ 
  + */
   
   package org.apache.util;
   
   import java.util.Hashtable;
   
   public class WebdavStatus {
  -    
  -    
  +
  +
       // -------------------------------------------------------------- Variables
  -    
  -    
  +
  +
       private static Hashtable mapStatusCodes = new Hashtable();
  -    
  -    
  +
  +
       // --------------------------------------------------------- Public Methods
  -    
  -    
  +
  +
       public static String getStatusText(int nHttpStatusCode) {
           Integer intKey = new Integer(nHttpStatusCode);
  -        
  +
           if (!mapStatusCodes.containsKey(intKey)) {
               // No information
               return null;
  -            
  +
           } else {
               return (String) mapStatusCodes.get(intKey);
           }
       }
  -    
  -    
  +
  +
       // -------------------------------------------------------- Private Methods
  -    
  -    
  +
  +
       private static void addStatusCodeMap(int nKey, String strVal) {
           mapStatusCodes.put(new Integer(nKey), strVal);
       }
  -    
  -    
  +
  +
       // -------------------------------------------------------------- Constants
  -    
  -    
  +
  +
       public static final int SC_CONTINUE = 100;
       public static final int SC_SWITCHING_PROTOCOLS = 101;
       public static final int SC_PROCESSING = 102;
  -    
  +
       public static final int SC_OK = 200;
       public static final int SC_CREATED = 201;
       public static final int SC_ACCEPTED = 202;
  @@ -75,14 +75,15 @@
       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;
       public static final int SC_MOVED_TEMPORARILY = 302;
       public static final int SC_SEE_OTHER = 303;
       public static final int SC_NOT_MODIFIED = 304;
       public static final int SC_USE_PROXY = 305;
  -    
  +
       public static final int SC_BAD_REQUEST = 400;
       public static final int SC_UNAUTHORIZED = 401;
       public static final int SC_PAYMENT_REQUIRED = 402;
  @@ -110,19 +111,20 @@
       public static final int SC_UNPROCESSABLE_ENTITY = 422;
       public static final int SC_LOCKED = 423;
       public static final int SC_FAILED_DEPENDENCY = 424;
  -    
  +
       public static final int SC_INTERNAL_SERVER_ERROR = 500;
       public static final int SC_NOT_IMPLEMENTED = 501;
       public static final int SC_BAD_GATEWAY = 502;
       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_LOOP_DETECTED = 506;
       public static final int SC_INSUFFICIENT_STORAGE = 507;
  -    
  -    
  +
  +
       // ----------------------------------------------------- Static Initializer
  -    
  -    
  +
  +
       static {
           // HTTP 1.0 Server status codes -- see RFC 1945
           addStatusCodeMap(SC_OK, "OK");
  @@ -140,7 +142,7 @@
           addStatusCodeMap(SC_NOT_IMPLEMENTED, "Not Implemented");
           addStatusCodeMap(SC_BAD_GATEWAY, "Bad Gateway");
           addStatusCodeMap(SC_SERVICE_UNAVAILABLE, "Service Unavailable");
  -        
  +
           // HTTP 1.1 Server status codes -- see RFC 2048
           addStatusCodeMap(SC_CONTINUE, "Continue");
           addStatusCodeMap(SC_METHOD_NOT_ALLOWED, "Method Not Allowed");
  @@ -148,7 +150,7 @@
           addStatusCodeMap(SC_PRECONDITION_FAILED, "Precondition Failed");
           addStatusCodeMap(SC_REQUEST_TOO_LONG, "Request Too Long");
           addStatusCodeMap(SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
  -        
  +
           addStatusCodeMap(SC_SWITCHING_PROTOCOLS, "Switching Protocols");
           addStatusCodeMap(SC_NON_AUTHORITATIVE_INFORMATION,
                            "Non Authoritative Information");
  @@ -156,18 +158,19 @@
           addStatusCodeMap(SC_GATEWAY_TIMEOUT, "Gateway Timeout");
           addStatusCodeMap(SC_HTTP_VERSION_NOT_SUPPORTED,
                            "Http Version Not Supported");
  -        
  +
           // WebDAV Server-specific status codes
           addStatusCodeMap(SC_PROCESSING, "Processing");
           addStatusCodeMap(SC_MULTI_STATUS, "Multi-Status");
           addStatusCodeMap(SC_UNPROCESSABLE_ENTITY, "Unprocessable Entity");
  -        addStatusCodeMap(SC_INSUFFICIENT_SPACE_ON_RESOURCE, 
  +        addStatusCodeMap(SC_INSUFFICIENT_SPACE_ON_RESOURCE,
                            "Insufficient Space On Resource");
           addStatusCodeMap(SC_METHOD_FAILURE, "Method Failure");
           addStatusCodeMap(SC_LOCKED, "Locked");
  +        addStatusCodeMap(SC_LOOP_DETECTED, "Loop Detected");
           addStatusCodeMap(SC_INSUFFICIENT_STORAGE , "Insufficient Storage");
           addStatusCodeMap(SC_FAILED_DEPENDENCY, "Failed Dependency");
       }
  -    
  -    
  +
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org