luetzkendorf    2004/10/08 07:59:59

  Modified:    webdavclient/clientlib/src/java/org/apache/webdav/lib
                        WebdavResource.java
  Log:
  patch by Warwick Burrows for bug 30900 (new discoverOwnLocks, new lockMethod
  with depth param, ...)
  
  Revision  Changes    Path
  1.33      +84 -28    
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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- WebdavResource.java       5 Oct 2004 21:24:21 -0000       1.32
  +++ WebdavResource.java       8 Oct 2004 14:59:59 -0000       1.33
  @@ -1003,37 +1003,55 @@
        */
       protected void setWebdavProperties(Enumeration responses)
           throws HttpException, IOException {
  -
  +    
           // Make the resources in the collection empty.
           childResources.removeAll();
           while (responses.hasMoreElements()) {
  -
  +    
               ResponseEntity response =
                   (ResponseEntity) responses.nextElement();
  -
  +    
               boolean itself = false;
               String href = response.getHref();
               if (!href.startsWith("/"))
                   href = URIUtil.getPath(href);
               href = decodeMarks(href);
  -            String httpURLPath = httpURL.getEscapedPath();
  -            if (httpURLPath.endsWith("/")) {
  -                int pathLength = httpURLPath.length();
  -                if (pathLength > 1) {
  -                    httpURLPath = httpURLPath.substring(0, pathLength - 1);
  +
  +            /*
  +             * Decode URIs to common (unescaped) format for comparison 
  +             * as HttpClient.URI.setPath() doesn't escape $ and : chars.
  +             */
  +            String httpURLPath = httpURL.getPath();
  +            String escapedHref = URIUtil.decode(href);
  +            
  +            // Normalize them to both have trailing slashes if they differ by one 
in length.
  +            int lenDiff = escapedHref.length() - httpURLPath.length();
  +            int compareLen = 0;
  +            
  +            if ( lenDiff == -1 && !escapedHref.endsWith("/")) {
  +                compareLen = escapedHref.length();
  +                lenDiff = 0;
  +            }
  +            else
  +            if ( lenDiff == 1 && !httpURLPath.endsWith("/")) {
  +                compareLen = httpURLPath.length();
  +                lenDiff = 0;
  +            }
  +
  +            // if they are the same length then compare them.
  +            if (lenDiff == 0) {
  +                if ((compareLen == 0 && httpURLPath.equals(escapedHref))
  +                    || httpURLPath.regionMatches(0, escapedHref, 0, compareLen))
  +                {
  +                    // escaped href and http path are the same
  +                    // Set the status code for this resource.
  +                    if (response.getStatusCode() > 0)
  +                        setStatusCode(response.getStatusCode());
  +                    setExistence(true);
  +                    itself = true;
                   }
               }
  -            // Compare with the href path and requested-path itself.
  -            if (httpURLPath.equals(href.endsWith("/") && href.length() > 1
  -                                   ? href.substring(0, href.length() - 1)
  -                                   : href)) {
  -                // Set the status code for this resource.
  -                if (response.getStatusCode() > 0)
  -                    setStatusCode(response.getStatusCode());
  -                setExistence(true);
  -                itself = true;
  -            }
  -
  +    
               // Get to know each resource.
               WebdavResource workingResource = null;
               if (itself) {
  @@ -1043,22 +1061,22 @@
                   workingResource = createWebdavResource(client);
                   workingResource.setDebug(debug);
               }
  -
  +    
               // clear the current lock set
               workingResource.setLockDiscovery(null);
  -
  +    
               // Process the resource's properties
               Enumeration properties = response.getProperties();
               while (properties.hasMoreElements()) {
  -
  +    
                   Property property = (Property) properties.nextElement();
  -
  +    
                   // ------------------------------  Checking WebDAV properties
                   workingResource.processProperty(property);
               }
  -
  +    
               String displayName = workingResource.getDisplayName();
  -
  +    
               if (displayName == null || displayName.trim().equals("")) {
                   displayName = getName(href);
               }
  @@ -1075,7 +1093,7 @@
                   workingResource.setOverwrite(getOverwrite());
               }
               workingResource.setDisplayName(displayName);
  -
  +    
               if (!itself)
                   childResources.addResource(workingResource);
           }
  @@ -4245,6 +4263,25 @@
       public boolean lockMethod(String path, String owner, int timeout, short 
lockType)
           throws HttpException, IOException {
   
  +        return lockMethod(path, owner, timeout, lockType, 
DepthSupport.DEPTH_INFINITY);    
  +    }    
  +    
  +
  +    /**
  +     * Execute the LOCK method for the given path. This method tries to acquire
  +     * an exclusive write lock with the given timeout value.
  +     *
  +     * @param path the server relative path of the resource to lock
  +     * @param owner The owner string.
  +     * @param timeout the timeout value.
  +     * @param locktype, the scope of lock.
  +     * @return true if the method is succeeded.
  +     * @exception HttpException
  +     * @exception IOException
  +     */
  +    public boolean lockMethod(String path, String owner, int timeout, short 
lockType, int depth)
  +        throws HttpException, IOException {            
  +
           setClient();
   
           if (owner == null) {
  @@ -4256,6 +4293,7 @@
                                              lockType, timeout);
           method.setDebug(debug);
           method.setFollowRedirects(this.followRedirects);
  +        method.setDepth(depth);        
   
           generateIfHeader(method);
           generateAdditionalHeaders(method);
  @@ -4507,6 +4545,24 @@
           setClient();
           String owner = (httpURL.getUser() != null) ?
               httpURL.getUser() : defaultOwner;
  +
  +        WebdavState state = (WebdavState) client.getState();
  +        state = discoverLock(owner, httpURL.getPath(), state);
  +        client.setState(state);
  +    }
  +
  +
  +    /**
  +     * Discover and refresh lock tokens for a specific owner.
  +     *
  +     * @param owner the owner who's locks are to be discovered.
  +     * @exception HttpException
  +     * @exception IOException
  +     */
  +    public void discoverOwnLocks(String owner)
  +    throws HttpException, IOException {
  +
  +        setClient();
   
           WebdavState state = (WebdavState) client.getState();
           state = discoverLock(owner, httpURL.getPath(), state);
  
  
  

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

Reply via email to