ozeigermann    2004/04/29 03:18:12

  Modified:    webdavclient/commandline/src/java/org/apache/webdav/cmd
                        ClientLexer.java ClientParser.java Client.g
                        SlideTokenTypes.java Client.java
               webdavclient/clientlib/src/java/org/apache/webdav/lib
                        WebdavResource.java
  Log:
  Applied patch by Thomas Bernert to add more complete lock support as decribed in bug 
#28649
  
  Revision  Changes    Path
  1.6       +39 -34    
jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/ClientLexer.java
  
  Index: ClientLexer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/ClientLexer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ClientLexer.java  21 Apr 2004 08:39:48 -0000      1.5
  +++ ClientLexer.java  29 Apr 2004 10:18:11 -0000      1.6
  @@ -183,13 +183,13 @@
                                case 'O':  case 'P':  case 'Q':  case 'R':
                                case 'S':  case 'T':  case 'U':  case 'V':
                                case 'W':  case 'X':  case 'Y':  case 'Z':
  -                             case '\\':  case 'a':  case 'b':  case 'c':
  -                             case 'd':  case 'e':  case 'f':  case 'g':
  -                             case 'h':  case 'i':  case 'j':  case 'k':
  -                             case 'l':  case 'm':  case 'n':  case 'o':
  -                             case 'p':  case 'q':  case 'r':  case 's':
  -                             case 't':  case 'u':  case 'v':  case 'w':
  -                             case 'x':  case 'y':  case 'z':
  +                             case '\\':  case '_':  case 'a':  case 'b':
  +                             case 'c':  case 'd':  case 'e':  case 'f':
  +                             case 'g':  case 'h':  case 'i':  case 'j':
  +                             case 'k':  case 'l':  case 'm':  case 'n':
  +                             case 'o':  case 'p':  case 'q':  case 'r':
  +                             case 's':  case 't':  case 'u':  case 'v':
  +                             case 'w':  case 'x':  case 'y':  case 'z':
                                {
                                        mSTRING(true);
                                        theRetToken=_returnToken;
  @@ -299,17 +299,17 @@
                
                match('-');
                {
  -             int _cnt103=0;
  -             _loop103:
  +             int _cnt107=0;
  +             _loop107:
                do {
                        if ((_tokenSet_0.member(LA(1)))) {
                                mCHARS(false);
                        }
                        else {
  -                             if ( _cnt103>=1 ) { break _loop103; } else {throw new 
NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
  +                             if ( _cnt107>=1 ) { break _loop107; } else {throw new 
NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
                        }
                        
  -                     _cnt103++;
  +                     _cnt107++;
                } while (true);
                }
                if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
  @@ -414,6 +414,11 @@
                        match('\\');
                        break;
                }
  +             case '_':
  +             {
  +                     match('_');
  +                     break;
  +             }
                default:
                {
                        throw new NoViableAltForCharException((char)LA(1), 
getFilename(), getLine(), getColumn());
  @@ -445,17 +450,17 @@
                case 'P':  case 'Q':  case 'R':  case 'S':
                case 'T':  case 'U':  case 'V':  case 'W':
                case 'X':  case 'Y':  case 'Z':  case '\\':
  -             case 'a':  case 'b':  case 'c':  case 'd':
  -             case 'e':  case 'f':  case 'g':  case 'h':
  -             case 'i':  case 'j':  case 'k':  case 'l':
  -             case 'm':  case 'n':  case 'o':  case 'p':
  -             case 'q':  case 'r':  case 's':  case 't':
  -             case 'u':  case 'v':  case 'w':  case 'x':
  -             case 'y':  case 'z':
  +             case '_':  case 'a':  case 'b':  case 'c':
  +             case 'd':  case 'e':  case 'f':  case 'g':
  +             case 'h':  case 'i':  case 'j':  case 'k':
  +             case 'l':  case 'm':  case 'n':  case 'o':
  +             case 'p':  case 'q':  case 'r':  case 's':
  +             case 't':  case 'u':  case 'v':  case 'w':
  +             case 'x':  case 'y':  case 'z':
                {
                        mCHARS(false);
                        {
  -                     _loop107:
  +                     _loop111:
                        do {
                                switch ( LA(1)) {
                                case '!':  case '#':  case '$':  case '%':
  @@ -470,13 +475,13 @@
                                case 'P':  case 'Q':  case 'R':  case 'S':
                                case 'T':  case 'U':  case 'V':  case 'W':
                                case 'X':  case 'Y':  case 'Z':  case '\\':
  -                             case 'a':  case 'b':  case 'c':  case 'd':
  -                             case 'e':  case 'f':  case 'g':  case 'h':
  -                             case 'i':  case 'j':  case 'k':  case 'l':
  -                             case 'm':  case 'n':  case 'o':  case 'p':
  -                             case 'q':  case 'r':  case 's':  case 't':
  -                             case 'u':  case 'v':  case 'w':  case 'x':
  -                             case 'y':  case 'z':
  +                             case '_':  case 'a':  case 'b':  case 'c':
  +                             case 'd':  case 'e':  case 'f':  case 'g':
  +                             case 'h':  case 'i':  case 'j':  case 'k':
  +                             case 'l':  case 'm':  case 'n':  case 'o':
  +                             case 'p':  case 'q':  case 'r':  case 's':
  +                             case 't':  case 'u':  case 'v':  case 'w':
  +                             case 'x':  case 'y':  case 'z':
                                {
                                        mCHARS(false);
                                        break;
  @@ -488,7 +493,7 @@
                                }
                                default:
                                {
  -                                     break _loop107;
  +                                     break _loop111;
                                }
                                }
                        } while (true);
  @@ -501,13 +506,13 @@
                        match('"');
                        text.setLength(_saveIndex);
                        {
  -                     _loop109:
  +                     _loop113:
                        do {
                                if ((_tokenSet_1.member(LA(1)))) {
                                        matchNot('"');
                                }
                                else {
  -                                     break _loop109;
  +                                     break _loop113;
                                }
                                
                        } while (true);
  @@ -689,7 +694,7 @@
        private static final long[] mk_tokenSet_0() {
                long[] data = new long[1025];
                data[0]=576403002173161472L;
  -             data[1]=576460744116142078L;
  +             data[1]=576460746263625726L;
                return data;
        }
        public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
  
  
  
  1.6       +132 -18   
jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/ClientParser.java
  
  Index: ClientParser.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/ClientParser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ClientParser.java 21 Apr 2004 08:39:48 -0000      1.5
  +++ ClientParser.java 29 Apr 2004 10:18:11 -0000      1.6
  @@ -519,13 +519,13 @@
                cmd = LT(1);
                match(STRING);
                {
  -             _loop92:
  +             _loop96:
                do {
                        if ((LA(1)==STRING)) {
                                match(STRING);
                        }
                        else {
  -                             break _loop92;
  +                             break _loop96;
                        }
                        
                } while (true);
  @@ -1411,6 +1411,9 @@
        public final void lock() throws RecognitionException, TokenStreamException {
                
                Token  path = null;
  +             Token  os1 = null;
  +             Token  os2 = null;
  +             Token  os3 = null;
                
                try {      // for error handling
                        match(LOCK);
  @@ -1423,6 +1426,61 @@
                                break;
                        }
                        case EOL:
  +                     case OPTIONSTRING:
  +                     {
  +                             break;
  +                     }
  +                     default:
  +                     {
  +                             throw new NoViableAltException(LT(1), getFilename());
  +                     }
  +                     }
  +                     }
  +                     {
  +                     switch ( LA(1)) {
  +                     case OPTIONSTRING:
  +                     {
  +                             os1 = LT(1);
  +                             match(OPTIONSTRING);
  +                             {
  +                             switch ( LA(1)) {
  +                             case OPTIONSTRING:
  +                             {
  +                                     os2 = LT(1);
  +                                     match(OPTIONSTRING);
  +                                     {
  +                                     switch ( LA(1)) {
  +                                     case OPTIONSTRING:
  +                                     {
  +                                             os3 = LT(1);
  +                                             match(OPTIONSTRING);
  +                                             break;
  +                                     }
  +                                     case EOL:
  +                                     {
  +                                             break;
  +                                     }
  +                                     default:
  +                                     {
  +                                             throw new NoViableAltException(LT(1), 
getFilename());
  +                                     }
  +                                     }
  +                                     }
  +                                     break;
  +                             }
  +                             case EOL:
  +                             {
  +                                     break;
  +                             }
  +                             default:
  +                             {
  +                                     throw new NoViableAltException(LT(1), 
getFilename());
  +                             }
  +                             }
  +                             }
  +                             break;
  +                     }
  +                     case EOL:
                        {
                                break;
                        }
  @@ -1434,7 +1492,36 @@
                        }
                        match(EOL);
                        
  -                     client.lock(text(path));
  +                     
  +                                     String[] opt = {text(os1), text(os2), 
text(os3), null};
  +                                     
  +                                     int parNr[]  = {3, 3, 3};
  +                                     String err = null;
  +                                         
  +                                     for (int i = 0 ; i< opt.length ;i++) {
  +                                         
  +                                         if (opt[i] != null) {
  +                     
  +                                             if ( 
opt[i].toLowerCase().startsWith("-t")) {
  +                                                 parNr[0] = i;
  +                                             } else
  +                     
  +                                             if ( 
opt[i].toLowerCase().startsWith("-s")) {
  +                                                 parNr[1] = i;
  +                                             } else
  +                                             
  +                                             if ( 
opt[i].toLowerCase().startsWith("-o")) {
  +                                                 parNr[2] = i;
  +                                             } else {
  +                                                 err = "Wrong parameter: "+ opt[i];
  +                                             }
  +                                         }
  +                                     }
  +                     
  +                                     if (err == null)
  +                             client.lock(text(path), opt[parNr[0]], opt[parNr[1]], 
opt[parNr[2]]);
  +                     else
  +                             client.print(err);      
                        
                }
                catch (RecognitionException ex) {
  @@ -1447,6 +1534,7 @@
        public final void unlock() throws RecognitionException, TokenStreamException {
                
                Token  path = null;
  +             Token  os = null;
                
                try {      // for error handling
                        match(UNLOCK);
  @@ -1459,6 +1547,25 @@
                                break;
                        }
                        case EOL:
  +                     case OPTIONSTRING:
  +                     {
  +                             break;
  +                     }
  +                     default:
  +                     {
  +                             throw new NoViableAltException(LT(1), getFilename());
  +                     }
  +                     }
  +                     }
  +                     {
  +                     switch ( LA(1)) {
  +                     case OPTIONSTRING:
  +                     {
  +                             os = LT(1);
  +                             match(OPTIONSTRING);
  +                             break;
  +                     }
  +                     case EOL:
                        {
                                break;
                        }
  @@ -1470,7 +1577,14 @@
                        }
                        match(EOL);
                        
  -                     client.unlock(text(path));
  +                     String owner = text(os);
  +                     String err = null;
  +                             
  +                     
  +                                     if ((owner != null) && 
(!owner.toLowerCase().startsWith("-o")) ) {
  +                     err = "Wrong parameter: "+ owner;
  +                     }
  +                     client.unlock(text(path), owner);
                        
                }
                catch (RecognitionException ex) {
  @@ -1931,8 +2045,8 @@
                        Vector properties = new Vector();
                        
                        {
  -                     int _cnt84=0;
  -                     _loop84:
  +                     int _cnt88=0;
  +                     _loop88:
                        do {
                                switch ( LA(1)) {
                                case STRING:
  @@ -1955,10 +2069,10 @@
                                }
                                default:
                                {
  -                                     if ( _cnt84>=1 ) { break _loop84; } else 
{throw new NoViableAltException(LT(1), getFilename());}
  +                                     if ( _cnt88>=1 ) { break _loop88; } else 
{throw new NoViableAltException(LT(1), getFilename());}
                                }
                                }
  -                             _cnt84++;
  +                             _cnt88++;
                        } while (true);
                        }
                        match(ON);
  @@ -1966,8 +2080,8 @@
                        Vector historyUris = new Vector();
                        
                        {
  -                     int _cnt86=0;
  -                     _loop86:
  +                     int _cnt90=0;
  +                     _loop90:
                        do {
                                if ((LA(1)==STRING)) {
                                        uri = LT(1);
  @@ -1977,10 +2091,10 @@
                                        
                                }
                                else {
  -                                     if ( _cnt86>=1 ) { break _loop86; } else 
{throw new NoViableAltException(LT(1), getFilename());}
  +                                     if ( _cnt90>=1 ) { break _loop90; } else 
{throw new NoViableAltException(LT(1), getFilename());}
                                }
                                
  -                             _cnt86++;
  +                             _cnt90++;
                        } while (true);
                        }
                        match(EOL);
  @@ -2102,7 +2216,7 @@
                
                
                {
  -             _loop96:
  +             _loop100:
                do {
                        switch ( LA(1)) {
                        case STRING:
  @@ -2181,7 +2295,7 @@
                        }
                        default:
                        {
  -                             break _loop96;
  +                             break _loop100;
                        }
                        }
                } while (true);
  
  
  
  1.7       +49 -7     
jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/Client.g
  
  Index: Client.g
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/Client.g,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Client.g  26 Apr 2004 12:14:17 -0000      1.6
  +++ Client.g  29 Apr 2004 10:18:11 -0000      1.7
  @@ -618,9 +618,43 @@
   lock
       :   LOCK
           (path:STRING)?
  +        (os1:OPTIONSTRING
  +          (os2:OPTIONSTRING
  +            (os3:OPTIONSTRING)?
  +           )?
  +        )?
           EOL
           {
  -            client.lock(text(path));
  +
  +             String[] opt = {text(os1), text(os2), text(os3), null};
  +             
  +             int parNr[]  = {3, 3, 3};
  +             String err = null;
  +                 
  +             for (int i = 0 ; i< opt.length ;i++) {
  +                 
  +                 if (opt[i] != null) {
  +
  +                     if ( opt[i].toLowerCase().startsWith("-t")) {
  +                         parNr[0] = i;
  +                     } else
  +
  +                     if ( opt[i].toLowerCase().startsWith("-s")) {
  +                         parNr[1] = i;
  +                     } else
  +                     
  +                     if ( opt[i].toLowerCase().startsWith("-o")) {
  +                         parNr[2] = i;
  +                     } else {
  +                         err = "Wrong parameter: "+ opt[i];
  +                     }
  +                 }
  +             }
  +       
  +                     if (err == null)
  +             client.lock(text(path), opt[parNr[0]], opt[parNr[1]], opt[parNr[2]]);
  +            else
  +             client.print(err);      
           }
       ;
       exception
  @@ -632,9 +666,17 @@
   unlock
       :   UNLOCK
           (path:STRING)?
  +        (os:OPTIONSTRING)?
           EOL
           {
  -            client.unlock(text(path));
  +            String owner = text(os);
  +            String err = null;
  +             
  +        
  +             if ((owner != null) && (!owner.toLowerCase().startsWith("-o")) ) {
  +                err = "Wrong parameter: "+ owner;
  +            }
  +            client.unlock(text(path), owner);
           }
       ;
       exception
  
  
  
  1.5       +3 -3      
jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/SlideTokenTypes.java
  
  Index: SlideTokenTypes.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/SlideTokenTypes.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  
  
  
  1.14      +53 -14    
jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/Client.java
  
  Index: Client.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/webdavclient/commandline/src/java/org/apache/webdav/cmd/Client.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Client.java       26 Apr 2004 12:20:03 -0000      1.13
  +++ Client.java       29 Apr 2004 10:18:11 -0000      1.14
  @@ -54,6 +54,7 @@
   import org.apache.webdav.lib.ResponseEntity;
   import org.apache.webdav.lib.WebdavResource;
   import org.apache.webdav.lib.methods.DepthSupport;
  +import org.apache.webdav.lib.methods.LockMethod;
   import org.apache.webdav.lib.properties.AclProperty;
   import org.apache.webdav.lib.properties.LockDiscoveryProperty;
   import org.apache.webdav.lib.properties.PrincipalCollectionSetProperty;
  @@ -1068,12 +1069,32 @@
           }
       }
   
  -    void lock(String path)
  +    void lock(String path, String timeout, String scope, String owner)
       {
  -        try {
  +       try {
  +            // Test the parameter
  +            //
  +            // Timeout
  +            int to=0; 
  +            if ((timeout != null) && 
(timeout.toLowerCase().substring(0,5).equals("-tinf")) ) { //infinite
  +                to = LockMethod.TIMEOUT_INFINITY;   
  +            } else {
  +                to = (timeout == null)? 120 : 
Integer.parseInt(timeout.substring(2));
  +            }
  +            
  +            
  +            // scope
  +            short scopeType = ((scope != null) && 
(scope.substring(2).toLowerCase().equals("shared")) ) ?
  +                LockMethod.SCOPE_SHARED : LockMethod.SCOPE_EXCLUSIVE;
  +           
  +            // owner
  +            owner = (owner != null) ? (owner.substring(2)) : owner;
  + 
               path = checkUri(path);
  -            out.print("Locking '" + path + "': ");
  -            if (webdavResource.lockMethod(path)) {
  +            out.print("Locking '" + path + "' "); 
  +            out.print( (owner != null) ? "owner:'"+ owner + "' " : "");
  +            out.print("scope:" +scopeType+" timeout:"+to+ " :");
  +            if (webdavResource.lockMethod(path, owner, to, scopeType)) {
                   out.println("succeeded.");
               } else {
                   out.println("failed.");
  @@ -1085,12 +1106,19 @@
           }
       }
   
  -    void unlock(String path)
  +    
  +    void unlock(String path, String owner)
       {
           try {
  +            // Test the parameter
  +            //
  +            // owner
  +            owner = (owner != null) ? (owner.substring(2)) : owner;
  +            
               path = checkUri(path);
  -            out.print("Unlocking '" + path + "': ");
  -            if (webdavResource.unlockMethod(path)) {
  +            out.print("Unlocking '" + path + "'");
  +            out.print((owner!=null)? (" owner:"+owner+": ") : (": "));
  +            if (webdavResource.unlockMethod(path, owner)) {
                   out.println("succeeded.");
               } else {
                   out.println("failed.");
  @@ -1102,6 +1130,7 @@
           }
       }
   
  +
       void grant(String permission,String path, String principal)
       {
           grant(new QName("DAV:",permission),path,principal);
  @@ -1664,10 +1693,20 @@
               "Copy resource from source to destination path");
           out.println("  move source destination       " +
               "Move resource from source to destination path");
  -        out.println("  lock path                     " +
  -            "Lock specified resource");
  -        out.println("  unlock path                   " +
  -            "Unlock specified resource");
  +        out.println("  lock path [-t(xxx|inf)] "       +
  +            "[-s(SHARED|EXCLUSIVE)] [-oOWNER]\n"       +
  +            "                                "         +
  +            "Lock specified resource.\n"               +
  +            "                                "         +
  +            "default:\n"                               +
  +            "                                "         +
  +            "lock file -t120 -sexclusive with current owner");
  +        out.println("  unlock path [-oOWNER]         " +
  +            "Unlock specified resource.\n"+
  +            "                                "         +
  +            "default:\n"                               +
  +            "                                "         +
  +            "unlock file with current owner");
           out.println("  locks [<path>]                " +
               "Displays locks on specified resource");
           out.println("  propget path property ...     " +
  
  
  
  1.16      +35 -7     
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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- WebdavResource.java       26 Apr 2004 12:20:03 -0000      1.15
  +++ WebdavResource.java       29 Apr 2004 10:18:12 -0000      1.16
  @@ -2378,7 +2378,7 @@
           GetMethod method = new GetMethod(URIUtil.encodePathQuery(path));
   
           int statusCode = client.executeMethod(method);
  -        
  +
           setStatusCode(statusCode);
           
           // get the file only if status is any kind of OK
  @@ -2401,6 +2401,7 @@
               
           } else {
               return false;
  +
           }
           
   
  @@ -3944,10 +3945,32 @@
        */
       public boolean lockMethod(String path, String owner, int timeout)
           throws HttpException, IOException {
  +            
  +        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.
  +     *
  +     * @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)
  +        throws HttpException, IOException {            
   
           setClient();
  +        
  +        if (owner == null) {
  +            owner = (httpURL.getUser() != null) ? httpURL.getUser() : defaultOwner;
  +        }
  +                    
           // default lock type setting
  -        short lockType = LockMethod.SCOPE_EXCLUSIVE;
           LockMethod method = new LockMethod(URIUtil.encodePath(path), owner,
                                              lockType, timeout);
           method.setDebug(debug); 
  @@ -4044,6 +4067,11 @@
           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
  @@ -4098,13 +4126,13 @@
        */
       protected WebdavState discoverLock(String owner, String path,
                                          WebdavState state) {
  -
           try {
  -            if (lockDiscovery == null) 
lockDiscovery=lockDiscoveryPropertyFindMethod(path);
  +            lockDiscovery=lockDiscoveryPropertyFindMethod(path);
           } catch (Exception e) {
               return state;
           }
    
  +
           if (lockDiscovery == null) return state;
           Lock[] activeLocks = lockDiscovery.getActiveLocks();
           
  
  
  

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

Reply via email to