juergen     02/04/08 05:44:48

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        VersioningHelper.java
  Log:
  Added some utility methods for auto-versioning.
  (ralf)
  
  Revision  Changes    Path
  1.23      +154 -3    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java
  
  Index: VersioningHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- VersioningHelper.java     5 Apr 2002 16:12:14 -0000       1.22
  +++ VersioningHelper.java     8 Apr 2002 12:44:48 -0000       1.23
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
 1.22 2002/04/05 16:12:14 pnever Exp $
  - * $Revision: 1.22 $
  - * $Date: 2002/04/05 16:12:14 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
 1.23 2002/04/08 12:44:48 juergen Exp $
  + * $Revision: 1.23 $
  + * $Date: 2002/04/08 12:44:48 $
    *
    * ====================================================================
    *
  @@ -93,11 +93,15 @@
   import org.apache.slide.content.RevisionDescriptorNotFoundException;
   
   import org.apache.slide.lock.ObjectLockedException;
  +import org.apache.slide.lock.LockTokenNotFoundException;
  +import org.apache.slide.lock.NodeLock;
  +import org.apache.slide.lock.Lock;
   
   import org.apache.slide.security.AccessDeniedException;
   
   import org.apache.slide.structure.Structure;
   import org.apache.slide.structure.SubjectNode;
  +import org.apache.slide.structure.ActionNode;
   import org.apache.slide.structure.ObjectNotFoundException;
   import org.apache.slide.structure.LinkedObjectNotFoundException;
   
  @@ -129,6 +133,14 @@
       public static final NodeRevisionNumber VCR_BACKUP_REVISION_NUMBER = new 
NodeRevisionNumber(0, 1);
       
       /**
  +     * String constant for the name of the <code>&lt;checkin-locktoken&gt;</code>
  +     * property.
  +     */
  +    public static final String P_CHECKIN_LOCKTOKEN = "checkin-locktoken";
  +    
  +    
  +    
  +    /**
        * Factory method.
        */
       public static VersioningHelper
  @@ -145,12 +157,24 @@
       
       private Content content = null;
       private Structure structure = null;
  +    private Lock lock = null;
       private HttpServletRequest req = null;
       private HttpServletResponse resp = null;
       private WebdavServletConfig sConf = null;
       private PropertyHelper pHelp = null;
       
       /**
  +     * The URI of the <code>modifyRevisionMetadataAction</code>.
  +     */
  +    protected final String modifyMetadataUri;
  +    
  +    /**
  +     * The URI of the <code>modifyRevisionContentAction</code>.
  +     */
  +    protected final String modifyContentUri;
  +    
  +
  +    /**
        * Protected contructor
        */
       protected VersioningHelper( SlideToken sToken, NamespaceAccessToken nsaToken,
  @@ -161,7 +185,22 @@
           this.sConf = sConf;
           this.content = nsaToken.getContentHelper();
           this.structure = nsaToken.getStructureHelper();
  +        this.lock = nsaToken.getLockHelper();
           this.pHelp = PropertyHelper.getPropertyHelper( sToken,nsaToken );
  +        ActionNode actionNode = 
nsaToken.getNamespaceConfig().getModifyRevisionMetadataAction();
  +        if (actionNode != null) {
  +            modifyMetadataUri = actionNode.getUri();
  +        }
  +        else {
  +            modifyMetadataUri = "";
  +        }
  +        actionNode = nsaToken.getNamespaceConfig().getModifyRevisionContentAction();
  +        if (actionNode != null) {
  +            modifyContentUri = actionNode.getUri();
  +        }
  +        else {
  +            modifyContentUri = "";
  +        }
       }
       
       /**
  @@ -948,6 +987,118 @@
           }
       }
   
  +    /**
  +     * Returns the value of the <code>&lt;auto-version&gt;</code> property
  +     * of the given <code>revisionDescriptor</code>.
  +     *
  +     * @param      revisionDescriptor  the NodeRevisionDescriptor for which to
  +     *                                 return the value of the
  +     *                                 <code>&lt;auto-version&gt;</code> property.
  +     *
  +     * @return     the value of the <code>&lt;auto-version&gt;</code> property
  +     *             of the given <code>revisionDescriptor</code>.
  +     */
  +    public String getAutoVersionValue(NodeRevisionDescriptor revisionDescriptor) {
  +        
  +        String autoVersionValue = null;
  +        NodeProperty autoVersionProperty = 
revisionDescriptor.getProperty(DeltavConstants.P_AUTO_VERSION);
  +        if ( (autoVersionProperty != null) && (autoVersionProperty.getValue() != 
null) ) {
  +            autoVersionValue = autoVersionProperty.getValue().toString();
  +        }
  +        return autoVersionValue;
  +    }
  +    
  +    /**
  +     * Indicates if the (VCR) reource be checked out prior to modifying it
  +     * depending on its <code>&lt;auto-version&gt;</code> property.
  +     *
  +     * @param      revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     * @param      revisionDescriptor  the NodeRevisionDescriptor of the resource.
  +     *
  +     * @return     <code>true</code> if the resource must be checked out prior to
  +     *             modifying it.
  +     */
  +    public boolean mustCheckoutAutoVersionedVCR(NodeRevisionDescriptors 
revisionDescriptors, NodeRevisionDescriptor revisionDescriptor) {
  +        
  +        String autoVersionValue = getAutoVersionValue(revisionDescriptor);
  +        return ( (autoVersionValue != null) &&
  +                    ( (autoVersionValue.indexOf(DeltavConstants.E_CHECKOUT_CHECKIN) 
> 0) ||
  +                         
(autoVersionValue.indexOf(DeltavConstants.E_CHECKOUT_UNLOCKED_CHECKIN) > 0) ||
  +                         (autoVersionValue.indexOf(DeltavConstants.E_CHECKOUT) > 0) 
||
  +                         
(autoVersionValue.indexOf(DeltavConstants.E_LOCKED_CHECKOUT) > 0) ) );
  +    }
  +    
  +    /**
  +     * Indicates if the (VCR) reource be checked in after modifying it
  +     * depending on its <code>&lt;auto-version&gt;</code> property.
  +     *
  +     * @param      slideToken           the SlideToken to use.
  +     * @param      revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     * @param      revisionDescriptor  the NodeRevisionDescriptor of the resource.
  +     *
  +     * @return     <code>true</code> if the resource must be checked in after
  +     *             modifying it.
  +     */
  +    public boolean mustCheckinAutoVersionedVCR(SlideToken slideToken, 
NodeRevisionDescriptors revisionDescriptors, NodeRevisionDescriptor 
revisionDescriptor) {
  +        
  +        boolean checkin = false;
  +        String autoVersionValue = getAutoVersionValue(revisionDescriptor);
  +        if (autoVersionValue != null) {
  +            checkin = (autoVersionValue.indexOf(DeltavConstants.E_CHECKOUT_CHECKIN) 
> 0);
  +            if ( !checkin && 
(autoVersionValue.indexOf(DeltavConstants.E_CHECKOUT_UNLOCKED_CHECKIN) > 0)) {
  +                checkin = ! isWriteLocked(slideToken, revisionDescriptors);
  +            }
  +        }
  +        return checkin;
  +    }
  +    
  +    /**
  +     * Indicates if the resource specified by the given NodeRevisionDescriptors
  +     * is write locked.
  +     *
  +     * @param      slideToken           the SlideToken to use.
  +     * @param      revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     *
  +     * @return     <code>true</code> if the resource is write locked.
  +     */
  +    public boolean isWriteLocked(SlideToken slideToken, NodeRevisionDescriptors 
revisionDescriptors) {
  +        return (getWriteLock(slideToken, revisionDescriptors) != null);
  +    }
  +    
  +    /**
  +     * Returns the write lock of the resource specified by the given
  +     * NodeRevisionDescriptors if one exists, otherwise <code>null</code>.
  +     *
  +     * @param      slideToken           the SlideToken to use.
  +     * @param      revisionDescriptors  the NodeRevisionDescriptors of the resource.
  +     *
  +     * @return     the write lock of the resource.
  +     */
  +    public NodeLock getWriteLock(SlideToken slideToken, NodeRevisionDescriptors 
revisionDescriptors) {
  +        
  +        NodeLock writeLock = null;
  +        try {
  +            Enumeration lockEnum = lock.enumerateLocks(slideToken, 
revisionDescriptors.getUri());
  +            if (lockEnum != null) {
  +                String typeUri = null;
  +                NodeLock lock = null;
  +                while ( (writeLock == null) && lockEnum.hasMoreElements() ) {
  +                    lock = (NodeLock)lockEnum.nextElement();
  +                    typeUri = lock.getTypeUri();
  +                    if ( modifyContentUri.equals(typeUri) ||
  +                        modifyMetadataUri.equals(typeUri) ) {
  +                        writeLock = lock;
  +                    }
  +                }
  +            }
  +        }
  +        catch (ServiceAccessException e) {}
  +        catch (ObjectNotFoundException e) {}
  +        catch (LockTokenNotFoundException e) {}
  +        
  +        return writeLock;
  +    }
  +    
       
       /**
        * Expects a String containing an XML Element like
  
  
  

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

Reply via email to