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 je...@apache.org on 2002/04/25 21:38:53 UTC

cvs commit: jakarta-slide/src/webdav/client/src/org/apache/webdav/lib WebdavResource.java

jericho     02/04/25 12:38:52

  Modified:    src/webdav/client/src/org/apache/webdav/lib
                        WebdavResource.java
  Log:
  - Unlock a resource automatically using lockdiscovery property,
     once it was locked by an authenticated user before.
  - Don't make locking owner restrict to the specific host.   Also default owner.
  - Patched by "Brian Olore" <bo...@us.ibm.com>
  
  Revision  Changes    Path
  1.37      +54 -20    jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java
  
  Index: WebdavResource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- WebdavResource.java	28 Mar 2002 06:12:09 -0000	1.36
  +++ WebdavResource.java	25 Apr 2002 19:38:52 -0000	1.37
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v 1.36 2002/03/28 06:12:09 jericho Exp $
  - * $Revision: 1.36 $
  - * $Date: 2002/03/28 06:12:09 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/client/src/org/apache/webdav/lib/WebdavResource.java,v 1.37 2002/04/25 19:38:52 jericho Exp $
  + * $Revision: 1.37 $
  + * $Date: 2002/04/25 19:38:52 $
    *
    * ====================================================================
    *
  @@ -3323,12 +3323,8 @@
       public boolean lockMethod()
           throws HttpException, IOException {
           
  -        String owner = null;
  -        if (httpURL.getUserName() != null) {
  -            owner = httpURL.getUserName() + "@" + httpURL.getHost();
  -        } else {
  -            owner = defaultOwner + "@" + httpURL.getHost();
  -        }
  +        String owner = (httpURL.getUserName() != null) ?
  +            httpURL.getUserName() : defaultOwner;
           
           boolean result = lockMethod(httpURL.getPath(), owner, 120);
           if (result)
  @@ -3368,12 +3364,8 @@
       public boolean lockMethod(String path)
           throws HttpException, IOException {
           
  -        String owner = null;
  -        if (httpURL.getUserName() != null) {
  -            owner = httpURL.getUserName() + "@" + httpURL.getHost();
  -        } else {
  -            owner = defaultOwner + "@" + httpURL.getHost();
  -        }
  +        String owner = (httpURL.getUserName() != null) ?
  +            httpURL.getUserName() : defaultOwner;
           
           return lockMethod(path, owner, 120);
       }
  @@ -3452,10 +3444,9 @@
        * @exception HttpException
        * @exception IOException
        */
  -    public boolean unlockMethod()
  -        throws HttpException, IOException {
  +    public boolean unlockMethod() throws HttpException, IOException {
           
  -        boolean result = unlockMethod(httpURL.getPath());
  +        boolean result = unlockMethod(httpURL.getPath(), defaultOwner);
           if (result)
               refresh();
           return result;
  @@ -3463,6 +3454,21 @@
       
       
       /*
  +     * Execute the Unlock method with the given owner.
  +     *
  +     * @param owner the specified owner.
  +     * @return true if the method is succeeded.
  +     * @exception HttpException
  +     * @exception IOException
  +     */
  +    public boolean unlockMethod(String owner)
  +    throws HttpException, IOException {
  +
  +        return unlockMethod(httpURL.getPath(), owner);
  +    }
  +
  +
  +    /*
        * Execute the Unlock method for the given path.
        *
        * @param path the specified path.
  @@ -3470,18 +3476,19 @@
        * @exception HttpException
        * @exception IOException
        */
  -    public boolean unlockMethod(String path)
  +    public boolean unlockMethod(String path, String owner)
           throws HttpException, IOException {
           
           setClient();
           // Get the lock for the given path.
           WebdavState state = (WebdavState) client.getState();
  +        // Discover the locktoken from the given lock owner
  +        discoverLock(owner, path, state);
           // Check the given path is alright.
           path = HttpURL.getPath(path);
           String lock = state.getLock(path);
           if (lock == null)
               return false;
  -        
           // unlock for the given path.
           UnlockMethod method = new UnlockMethod(path);
           generateIfHeader(method);
  @@ -3499,6 +3506,33 @@
           
           return false;
       }
  +    
  +
  +    /**
  +     * Discover the given owner and locktoken and set the locktoken
  +     *
  +     * @param owner the activelock owner
  +     * @param path the path
  +     * @param state the state to save the locktoken
  +     * @return true, if the lock of the given owner is discovered
  +     */
  +    public boolean discoverLock(String owner, String path, WebdavState state) {
  +        if (lockDiscovery == null)
  +            return false;
  +        Lock[] activeLocks = lockDiscovery.getActiveLocks();
  +        if (activeLocks == null)
  +            return false;
  +        for (int i = 0; i < activeLocks.length; i++) {
  +            String activeLockOwner = activeLocks[i].getOwner();
  +            if (activeLockOwner.equals(owner)) {
  +                String locktoken = activeLocks[i].getLockToken();
  +                state.addLock(path, locktoken);
  +                return true;
  +            }
  +        }
  +        return false;
  +    }
  +
       
       public boolean versionControlMethod(String path)
           throws HttpException, IOException {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>