juergen     02/04/05 05:06:20

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        VersioningHelper.java
  Log:
  Fix for uncheckout():
  We can not restore all properties from the associated VR, so reanimated the code 
which creates a backup in checkout() and restores from this backup in uncheckout().
  (ralf)
  
  Revision  Changes    Path
  1.20      +127 -9    
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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- VersioningHelper.java     5 Apr 2002 04:52:53 -0000       1.19
  +++ VersioningHelper.java     5 Apr 2002 13:06:20 -0000       1.20
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
 1.19 2002/04/05 04:52:53 juergen Exp $
  - * $Revision: 1.19 $
  - * $Date: 2002/04/05 04:52:53 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
 1.20 2002/04/05 13:06:20 juergen Exp $
  + * $Revision: 1.20 $
  + * $Date: 2002/04/05 13:06:20 $
    *
    * ====================================================================
    *
  @@ -124,9 +124,9 @@
   public class VersioningHelper extends AbstractWebdavHelper {
                           
       /**
  -     * The NodeRevisionNumber of the VHR backup needed for checkout-uncheckout.
  +     * The NodeRevisionNumber of the VCR backup needed for checkout-uncheckout.
        */
  -    public static final NodeRevisionNumber VHR_BACKUP_REVISION_NUMBER = new 
NodeRevisionNumber(0, 1);
  +    public static final NodeRevisionNumber VCR_BACKUP_REVISION_NUMBER = new 
NodeRevisionNumber(0, 1);
       
       /**
        * Factory method.
  @@ -315,7 +315,7 @@
                   throw new PreconditionViolationException(new 
ViolatedPrecondition(C_MUST_BE_CHECKED_IN, WebdavStatus.SC_CONFLICT), rNrds.getUri());
               }
               resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  -            return;
  +            throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
           }
           
           if( rRk instanceof CheckedInVersionControlled ) {
  @@ -341,6 +341,7 @@
               content.store(sToken, cinNrds.getUri(), cinNrd, null);
               
               // do the checkout
  +            backupProperties(rNrds, rNrd, vhrNrds);
               rNrd.removeProperty( cinProp );
               rNrd.setProperty(
                   new NodeProperty(P_CHECKED_OUT, cinProp.getValue()) );
  @@ -473,8 +474,15 @@
           PropertyHelper.removeHrefFromProperty(coutNrd, P_CHECKOUT_SET, 
rNrds.getUri());
           content.store( sToken, coutNrds.getUri(), coutNrd, null);
           
  -        // update properties and content
  -        updateVCR(rNrds, rNrd, coutNrds, coutNrd);
  +        // restore revision descriptor
  +        restoreProperties(rNrds, rNrd, vhrNrds);
  +        rNrd.setLastModified(new Date());
  +        rNrd.setProperty(new NodeProperty(P_CHECKED_IN, coutProp.getValue()) );
  +        NodeRevisionContent oldContent = new NodeRevisionContent();
  +        oldContent.setContent(coutNrc.getContentBytes());
  +        
  +        // Store changes
  +        content.store( sToken, rNrds.getUri(), rNrd, oldContent);
       }
       
       /**
  @@ -508,7 +516,7 @@
                                                            rNrds.getUri());
               }
               resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  -            return;
  +            throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
           }
           
           if( rRk instanceof CheckedOutVersionControlled ) {
  @@ -766,6 +774,116 @@
           content.store( sToken, vcrRevisionDescriptors.getUri(), 
vcrRevisionDescriptor, vcrContent);
       }
       
  +    
  +    /**
  +     * Backups the properties of the given <code>revisionDescriptor</code>
  +     * at the {@link #VCR_BACKUP_REVISION_NUMBER special revision} of the
  +     * NodeRevisionDescriptors of the VHR associated with the VCR.
  +     *
  +     * @param      revisionDescriptors         the NodeRevisionDescriptors of the
  +     *                                         VCR to backup.
  +     * @param      revisionDescriptor          the NodeRevisionDescriptor of the
  +     *                                         VCR to backup.
  +     * @param      historyRevisionDescriptors  the NodeRevisionDescriptors of the
  +     *                                         VHR associated with the VCR.
  +     *
  +     * @throws     SlideException
  +     */
  +    protected void backupProperties(NodeRevisionDescriptors revisionDescriptors, 
NodeRevisionDescriptor revisionDescriptor, NodeRevisionDescriptors 
historyRevisionDescriptors) throws SlideException {
  +        
  +        NodeRevisionDescriptor backup = cloneRevisionDescriptor(revisionDescriptor, 
VCR_BACKUP_REVISION_NUMBER);
  +        try {
  +            content.retrieve(sToken, historyRevisionDescriptors, 
backup.getRevisionNumber());
  +            content.store(sToken, historyRevisionDescriptors.getUri(), backup, 
null);
  +        }
  +        catch (RevisionDescriptorNotFoundException e) {
  +            content.create(sToken, historyRevisionDescriptors.getUri(),null,  
backup, null);
  +        }
  +    }
  +    
  +    /**
  +     * Restores the properties of the given <code>revisionDescriptor</code>
  +     * from the {@link #VCR_BACKUP_REVISION_NUMBER special revision} of the
  +     * NodeRevisionDescriptors of the VHR associated with the VCR.
  +     *
  +     * @param      revisionDescriptors         the NodeRevisionDescriptors of the
  +     *                                         VCR to restore.
  +     * @param      revisionDescriptor          the NodeRevisionDescriptor of the
  +     *                                         VCR to restore.
  +     * @param      historyRevisionDescriptors  the NodeRevisionDescriptors of the
  +     *                                         VHR associated with the VCR.
  +     *
  +     * @throws     SlideException
  +     */
  +    protected void restoreProperties(NodeRevisionDescriptors revisionDescriptors, 
NodeRevisionDescriptor revisionDescriptor, NodeRevisionDescriptors 
historyRevisionDescriptors) throws SlideException {
  +        
  +        NodeRevisionDescriptor backup = content.retrieve(sToken, 
historyRevisionDescriptors, VCR_BACKUP_REVISION_NUMBER);
  +        copyRevisionDescriptor(backup, revisionDescriptor);
  +        content.store(sToken, revisionDescriptors.getUri(), revisionDescriptor, 
null);
  +    }
  +    
  +    /**
  +     * Returns a clone of the given <code>revisionDescriptor</code> with
  +     * the given <code>revisionNumber</code>.
  +     *
  +     * @param      revisionDescriptor  the NodeRevisionDescriptor to clone.
  +     * @param      revisionNumber      the NodeRevsionNumber to use for the clone.
  +     *
  +     * @return     the cloned NodeRevisionDescriptor.
  +     */
  +    private NodeRevisionDescriptor cloneRevisionDescriptor(NodeRevisionDescriptor 
revisionDescriptor, NodeRevisionNumber revisionNumber) {
  +        
  +        String branchName = revisionDescriptor.getBranchName();
  +        Enumeration labelEnum = revisionDescriptor.enumerateLabels();
  +        Vector labels = new Vector();
  +        while (labelEnum.hasMoreElements()) {
  +            labels.add(labelEnum.nextElement());
  +        }
  +        Hashtable properties = new Hashtable();
  +        Enumeration propertiesEnum = revisionDescriptor.enumerateProperties();
  +        NodeProperty property = null;
  +        String name = null;
  +        String namespace = null;
  +        while (propertiesEnum.hasMoreElements()) {
  +            property = (NodeProperty)propertiesEnum.nextElement();
  +            name = property.getName();
  +            namespace = property.getNamespace();
  +            if (namespace != null) {
  +                name = namespace + name;
  +            }
  +            properties.put(name, property);
  +        }
  +        NodeRevisionDescriptor backup = new NodeRevisionDescriptor(revisionNumber, 
branchName, labels, properties);
  +        return backup;
  +    }
  +    
  +    /**
  +     * Copies the labels and properties of the given <code>source</code>
  +     * to the <code>destination</code> NodeRevisionDescriptor.
  +     *
  +     * @param      source       the NodeRevisionDescriptor to copy the labels
  +     *                          and properties from.
  +     * @param      destination  the NodeRevisionDescriptor to copy the labels
  +     *                          and properties to.
  +     */
  +    private void copyRevisionDescriptor(NodeRevisionDescriptor source, 
NodeRevisionDescriptor destination) {
  +        
  +        destination.removeLabels();
  +        Enumeration labelEnum = source.enumerateLabels();
  +        while (labelEnum.hasMoreElements()) {
  +            destination.addLabel((String)labelEnum.nextElement());
  +        }
  +        
  +        Enumeration propertiesEnum = destination.enumerateProperties();
  +        while (propertiesEnum.hasMoreElements()) {
  +            destination.removeProperty((NodeProperty)propertiesEnum.nextElement());
  +        }
  +        propertiesEnum = source.enumerateProperties();
  +        while (propertiesEnum.hasMoreElements()) {
  +            destination.setProperty((NodeProperty)propertiesEnum.nextElement());
  +        }
  +    }
  +
       
       /**
        * 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