remm        01/07/24 00:01:48

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        LockMethod.java
  Log:
  - Return a multistatus when there is a problem locking a collection using a
    infinite depth lock.
  - Catch ObjectLockedException, which can occur when creating the
    lock-null resource.
  - Hack: Use max timeout when creating a lock-null resource (since they can't be
    automatically removed).
  
  Revision  Changes    Path
  1.15      +42 -7     
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LockMethod.java
  
  Index: LockMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LockMethod.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- LockMethod.java   2001/07/18 15:11:52     1.14
  +++ LockMethod.java   2001/07/24 07:01:48     1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LockMethod.java,v
 1.14 2001/07/18 15:11:52 juergen Exp $
  - * $Revision: 1.14 $
  - * $Date: 2001/07/18 15:11:52 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/LockMethod.java,v
 1.15 2001/07/24 07:01:48 remm Exp $
  + * $Revision: 1.15 $
  + * $Date: 2001/07/24 07:01:48 $
    *
    * ====================================================================
    *
  @@ -87,7 +87,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
    */
  -public class LockMethod extends WebdavMethod {
  +public class LockMethod extends AbstractMultistatusResponseMethod {
       
       
       // -------------------------------------------------------------- Constants
  @@ -419,6 +419,9 @@
           throws WebdavException {
           
           SubjectNode toLockSubject = null;
  +        boolean isCollection = isCollection(lockInfo_lockSubject);
  +        boolean inheritance = false;
  +        Date lockDate = null;
           
           switch (lockType) {
               
  @@ -454,6 +457,13 @@
                       content.create(slideToken, lockInfo_lockSubject,
                                      revisionDescriptor, null);
                       
  +                    // HACK
  +                    // Setting a max timeout when creating a lock-null
  +                    // resource because the associated lock-null wouldn't
  +                    // be automatically removed when the lock expires
  +                    lockDate = new Date((new Date()).getTime()
  +                                        + (MAX_TIMEOUT * 1000));
  +                    
                   }
                   
                   SubjectNode credentialsSubject =
  @@ -464,12 +474,13 @@
                   
                   NodeLock lockToken = null;
                   
  -                boolean inheritance = (depth != 0);
  +                inheritance = (depth != 0);
                   boolean exclusive =
                       !(lockInfo_lockScope.equals("<shared/>"));
                   
  -                Date lockDate = new Date((new Date()).getTime()
  -                                         + (lockDuration * 1000));
  +                if (lockDate == null) 
  +                    lockDate = new Date((new Date()).getTime()
  +                                        + (lockDuration * 1000));
                   
                   lockToken =
                       new NodeLock(toLockSubject, credentialsSubject,
  @@ -544,6 +555,30 @@
                   showLockDiscoveryInfo(lockToken);
                   
               } catch (ObjectIsAlreadyLockedException e) {
  +                if (isCollection && inheritance) {
  +                    // error is on the resource which we attempted to lock
  +                    String errorMessage = generateErrorMessage(e);
  +                    // Write it on the servlet writer
  +                    resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
  +                    try {
  +                        resp.getWriter().write(errorMessage);
  +                    } catch(IOException ex) {
  +                        // Critical error ... Servlet container is dead or something
  +                        ex.printStackTrace();
  +                        throw new 
WebdavException(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                    }
  +                } else {
  +                    // Returning 207 on non-collection requests is generally
  +                    // considered bad. So let's not do it, since this way
  +                    // makes clients generally behave better.
  +                    resp.setStatus(WebdavStatus.SC_LOCKED);
  +                }
  +                //
  +                // make sure the transaction is aborted
  +                // throw any WebDAV exception to indicate the transaction wants to 
be aborted
  +                //
  +                throw new WebdavException(WebdavStatus.SC_ACCEPTED, false);
  +            } catch (ObjectLockedException e) {
                   resp.setStatus(WebdavStatus.SC_LOCKED);
                   //
                   // make sure the transaction is aborted
  
  
  

Reply via email to