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 ju...@apache.org on 2002/04/09 10:12:33 UTC

cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method PropPatchMethod.java

juergen     02/04/09 01:12:33

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        PropPatchMethod.java
  Log:
  Implemented deltav precondition checks and the missing auto-versioning styles.
  (ralf)
  
  Revision  Changes    Path
  1.33      +109 -31   jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java
  
  Index: PropPatchMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- PropPatchMethod.java	3 Apr 2002 11:55:07 -0000	1.32
  +++ PropPatchMethod.java	9 Apr 2002 08:12:33 -0000	1.33
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v 1.32 2002/04/03 11:55:07 juergen Exp $
  - * $Revision: 1.32 $
  - * $Date: 2002/04/03 11:55:07 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v 1.33 2002/04/09 08:12:33 juergen Exp $
  + * $Revision: 1.33 $
  + * $Date: 2002/04/09 08:12:33 $
    *
    * ====================================================================
    *
  @@ -86,7 +86,7 @@
   import org.apache.slide.webdav.util.*;
   import org.apache.slide.webdav.util.resourcekind.ResourceKind;
   import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
  -import org.apache.slide.webdav.util.resourcekind.CheckedOutVersionControlled;
  +import org.apache.slide.webdav.util.resourcekind.CheckedInVersionControlled;
   import org.apache.slide.util.*;
   
   /**
  @@ -108,6 +108,11 @@
       
       
       /**
  +     * The VersioningHelper used by this instance.
  +     */
  +    protected VersioningHelper versioningHelper = null;
  +    
  +    /**
        * Properties to set. Vector of SlideProperty objects.
        */
       private Vector propertiesToSet;
  @@ -144,6 +149,11 @@
                              HttpServletResponse resp,
                              WebdavServletConfig config) {
           super(token, req, resp, config);
  +        versioningHelper = VersioningHelper.getVersioningHelper(slideToken,
  +                                                                token,
  +                                                                req,
  +                                                                resp,
  +                                                                config);
           readRequestContent();
       }
       
  @@ -255,7 +265,7 @@
        * @exception WebdavException
        */
       protected void executeRequest()
  -        throws WebdavException {
  +        throws WebdavException, IOException {
           
           boolean allOperationsExcecuted = true;
           
  @@ -309,28 +319,25 @@
               ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(revisionDescriptor);
   
               // check preconditions
  -            ViolatedPrecondition violatedPrecondition = null;
  -            // TODO: check DAV:cannot-modify-version-controlled-property
  -            // TODO: check DAV:cannot-modify-version
  -            // TODO: check DAV:cannot-modify-protected-property
  -            // TODO: check DAV:supported-live-property-set
  +            ViolatedPrecondition violatedPrecondition = getPreconditionViolation(revisionDescriptors, revisionDescriptor, resourceKind);
               if (violatedPrecondition != null) {
                   throw new PreconditionViolationException(violatedPrecondition, resourcePath);
               }
               
               // Changed for DeltaV --start--
               boolean mustCheckIn = false;
  -            if( Configuration.useVersionControl()  && !(resourceKind instanceof CheckedOutVersionControlled) ) {
  -                NodeProperty avProp =
  -                    revisionDescriptor.getProperty( P_AUTO_VERSION );
  -                
  -                if( avProp != null && avProp.getValue() != null
  -                   && ((String)avProp.getValue()).indexOf(E_CHECKOUT_CHECKIN) >= 0 ) {
  -                    
  -                    vHelp.checkout(
  -                        revisionDescriptors, revisionDescriptor, false, false ); //forkOk=false, applyToVersion=false
  -                    mustCheckIn = true;
  +            if( Configuration.useVersionControl() &&
  +                   (resourceKind instanceof CheckedInVersionControlled) &&
  +               versioningHelper.mustCheckoutAutoVersionedVCR(revisionDescriptors, revisionDescriptor) ) {
  +                
  +                vHelp.checkout(revisionDescriptors, revisionDescriptor, false, false ); //forkOk=false, applyToVersion=false
  +                if ( ! versioningHelper.mustCheckinAutoVersionedVCR(slideToken, revisionDescriptors, revisionDescriptor) ) {
  +                    NodeLock writeLock = versioningHelper.getWriteLock(slideToken, revisionDescriptors);
  +                    if (writeLock != null) {
  +                        revisionDescriptor.setProperty(new NodeProperty(VersioningHelper.P_CHECKIN_LOCKTOKEN, writeLock.getLockId(), true));
  +                    }
                   }
  +                mustCheckIn = versioningHelper.mustCheckinAutoVersionedVCR(slideToken, revisionDescriptors, revisionDescriptor);
               }
               
               // Modifying the properties
  @@ -379,23 +386,20 @@
                   content.store(slideToken, resourcePath, revisionDescriptor, null);
               
               // Changed for DeltaV --start--
  -            if( Configuration.useVersionControl() && mustCheckIn ) {
  -                NodeProperty avProp =
  -                    revisionDescriptor.getProperty( P_AUTO_VERSION );
  -                
  -                if( avProp != null && avProp.getValue() != null
  -                   && ((String)avProp.getValue()).indexOf(E_CHECKOUT_CHECKIN) >= 0 ) {
  -                    
  -                    vHelp.checkin(
  -                        revisionDescriptors, revisionDescriptor, false, false ); //forkOk=false, keepCheckedOut=false
  -                }
  +            if( Configuration.useVersionControl() && mustCheckIn) {
  +                revisionDescriptor.removeProperty(new NodeProperty(VersioningHelper.P_CHECKIN_LOCKTOKEN, null, true));
  +                vHelp.checkin(revisionDescriptors, revisionDescriptor, false, false ); //forkOk=false, keepCheckedOut=false
               }
               // Changed for DeltaV --end--
               
  -            resp.setContentType("text/xml; charset=UTF-8");
  +            resp.setContentType(TEXT_XML_UTF_8);
               
               resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
               
  +        }
  +        catch (PreconditionViolationException e) {
  +            sendPreconditionViolation(e);
  +            throw e;
           } catch (Exception e) {
   //          e.printStackTrace();
               resp.setStatus(getErrorCode(e));  // special handling needed
  @@ -634,6 +638,80 @@
        */
       protected boolean methodNeedsTransactionSupport() {
           return true;
  +    }
  +    
  +    
  +    /**
  +     * Checks the (DeltaV) preconditions
  +     * <ul>
  +     * <li>&lt;code&gt;DAV:cannot-modify-version-controlled-property&lt;/code&gt;</li>
  +     * <li>&lt;code&gt;DAV:cannot-modify-version&lt;/code&gt;</li>
  +     * <li>&lt;code&gt;DAV:cannot-modify-protected-property&lt;/code&gt;</li>
  +     * <li>&lt;code&gt;DAV:supported-live-property&lt;/code&gt;</li>
  +     * </ul>
  +     *
  +     * @param      revisionDescriptors  the NodeRevisionDescriptors of the resource
  +     *                                  to perform the <code>PUT</code> on.
  +     * @param      revisionDescriptor   the NodeRevisionDescriptor of the resource
  +     *                                  to perform the <code>PUT</code> on.
  +     * @param      resourceKind         the ResourceKind of the resource.
  +     *
  +     * @return     the precondition that has been violated (if any).
  +     */
  +    private ViolatedPrecondition getPreconditionViolation(NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor revisionDescriptor, ResourceKind resourceKind) {
  +        
  +        if( Configuration.useVersionControl() ) {
  +            
  +            if (resourceKind instanceof CheckedInVersionControlled) {
  +                
  +                // check precondition DAV:cannot-modify-version-controlled-property
  +                String autoVersion = versioningHelper.getAutoVersionValue(revisionDescriptor);
  +                if (autoVersion == null) {
  +                    autoVersion = "";
  +                }
  +                
  +                if ( (autoVersion.indexOf(E_CHECKOUT_CHECKIN) < 0) &&
  +                        (autoVersion.indexOf(E_CHECKOUT_UNLOCKED_CHECKIN) < 0) &&
  +                        (autoVersion.indexOf(E_CHECKOUT) < 0) &&
  +                        (autoVersion.indexOf(E_LOCKED_CHECKOUT) < 0) ) {
  +                    return new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION_CONTROLLED_PROPERTY,
  +                                                    WebdavStatus.SC_FORBIDDEN);
  +                }
  +                if (autoVersion.indexOf(E_LOCKED_CHECKOUT) > 0) {
  +                    if ( !versioningHelper.isWriteLocked(slideToken, revisionDescriptors) ) {
  +                        return new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION_CONTROLLED_PROPERTY,
  +                                                        WebdavStatus.SC_FORBIDDEN);
  +                    }
  +                }
  +            }
  +            
  +            // check precondition DAV:cannot-modify-version
  +            UriHandler uriHandler = UriHandler.getUriHandler(token, resourcePath);
  +            if (uriHandler.isVersionUri()) {
  +                return new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION,
  +                                                WebdavStatus.SC_FORBIDDEN);
  +            }
  +        }
  +        
  +        List propertyList = new ArrayList(propertiesToRemove.size() + propertiesToSet.size());
  +        propertyList.addAll(propertiesToRemove);
  +        propertyList.addAll(propertiesToSet);
  +        java.util.Iterator iterator = propertyList.iterator();
  +        Property property = null;
  +        while (iterator.hasNext()) {
  +            property = (Property)iterator.next();
  +            
  +            // check precondition DAV:cannot-modify-protected-property
  +            if (AbstractResourceKind.isProtectedProperty(property.name)) {
  +                return new ViolatedPrecondition(C_CANNOT_MODIFY_PROTECTED_PROPERTY,
  +                                                WebdavStatus.SC_FORBIDDEN);
  +            }
  +            
  +            // check precondition DAV:supported-live-property
  +            // ...is there any property to check here yet ?
  +        }
  +        
  +        return null;
       }
       
       
  
  
  

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