juergen     02/03/19 06:10:54

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        VersioningHelper.java
  Log:
  Added method uncheckout().
  Fixed bug in <checkout-set> maintenance.
  (ralf)
  
  Revision  Changes    Path
  1.11      +104 -4    
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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- VersioningHelper.java     15 Mar 2002 12:44:54 -0000      1.10
  +++ VersioningHelper.java     19 Mar 2002 14:10:54 -0000      1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
 1.10 2002/03/15 12:44:54 juergen Exp $
  - * $Revision: 1.10 $
  - * $Date: 2002/03/15 12:44:54 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
 1.11 2002/03/19 14:10:54 juergen Exp $
  + * $Revision: 1.11 $
  + * $Date: 2002/03/19 14:10:54 $
    *
    * ====================================================================
    *
  @@ -352,7 +352,9 @@
                   throw new PreconditionViolationException(violatedPrecondition);
               }
               
  +            // update <checkout-set>
               addUriToCheckoutSet(cinNrd, rNrds.getUri());
  +            content.store(sToken, cinNrds.getUri(), cinNrd, null);
               
               // do the checkout
               rNrd.removeProperty( cinProp );
  @@ -435,6 +437,65 @@
       }
       
       /**
  +     * Uncheckout the specified resource.
  +     *
  +     * @param     resourcePath  the path of the resource to uncheckout.
  +     */
  +    public void uncheckout(String resourcePath) throws SlideException, 
JDOMException, IOException, PreconditionViolationException  {
  +        
  +        NodeRevisionDescriptors rNrds = retrieveRevisionDescriptors( resourcePath );
  +        NodeRevisionDescriptor rNrd = retrieveLatestRevisionDescriptor( 
resourcePath, rNrds );
  +        uncheckout( rNrds, rNrd);
  +    }
  +    
  +    /**
  +     * Uncheckout the specified resource.
  +     *
  +     * @param     rNrds  the NodeRevisionDescriptors of the resource to uncheckout.
  +     * @param     rNrd   the NodeRevisionDescriptor of the resource to uncheckout.
  +     */
  +    public void uncheckout( NodeRevisionDescriptors rNrds, NodeRevisionDescriptor 
rNrd)
  +        throws SlideException, JDOMException, IOException, 
PreconditionViolationException  {
  +        
  +        Iterator i;
  +        ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
  +        
  +        // check precondition C_MUST_BE_CHECKED_OUT_VERSION_CONTROLLED_RESOURCE
  +        if ( ! (rRk instanceof CheckedOutVersionControlled) ) {
  +            throw new PreconditionViolationException(new 
ViolatedPrecondition(C_MUST_BE_CHECKED_OUT_VERSION_CONTROLLED_RESOURCE, 
WebdavStatus.SC_CONFLICT));
  +        }
  +        
  +        if( !rRk.isSupportedMethod(req.getMethod()) ) {
  +            resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  +            return;
  +        }
  +        
  +        // get checked-out VR
  +        NodeProperty coutProp = rNrd.getProperty( P_CHECKED_OUT );
  +        String coutHref = getElementValue((String)coutProp.getValue());
  +        UriHandler coutUriHandler = UriHandler.getUriHandler(nsaToken, coutHref);
  +        String coutUri = coutUriHandler.getAssociatedHistoryUri();
  +        NodeRevisionNumber coutNrn = new 
NodeRevisionNumber(coutUriHandler.getVersionName());
  +        NodeRevisionDescriptors coutNrds = content.retrieve(sToken, coutUri);
  +        NodeRevisionDescriptor coutNrd = content.retrieve(sToken, coutNrds, 
coutNrn);
  +        NodeRevisionContent coutNrc = content.retrieve( sToken, coutNrds, coutNrd );
  +        
  +        // update <checkout-set>
  +        removeUriFromCheckoutSet(coutNrd, rNrds.getUri());
  +        content.store( sToken, coutNrds.getUri(), coutNrd, null);
  +        
  +        // restore revision descriptor from the checked-in one
  +        restoreRevisionDescriptor(coutNrd, rNrd);
  +        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);
  +    }
  +    
  +    /**
        * Checkin the specified resource
        */
       public void checkin( String resourcePath, boolean forkOk, boolean 
keepCheckedOut )
  @@ -488,7 +549,9 @@
                   throw new PreconditionViolationException(violatedPrecondition);
               }
               
  +            // update <checkout-set>
               removeUriFromCheckoutSet(vrNrdOld, rNrds.getUri());
  +            content.store( sToken, vhrNrds.getUri(), vrNrdOld, null);
               
               // Create new VR in the MAIN branch
               NodeRevisionDescriptor vrNrdNew =
  @@ -640,6 +703,7 @@
               element.setText(uri);
               xmlValue.add(element);
           }
  +        nrd.setProperty(P_CHECKOUT_SET, xmlValue.toString());
       }
       
       /**
  @@ -670,7 +734,7 @@
                   }
               }
               if (found) {
  -                checkoutSetProperty = new NodeProperty(P_CHECKOUT_SET, 
xmlValue.toString());
  +                nrd.setProperty(P_CHECKOUT_SET, xmlValue.toString());
               }
           }
       }
  @@ -710,6 +774,42 @@
               saxBuilder = new SAXBuilder();
           }
           return saxBuilder;
  +    }
  +    
  +    /**
  +     * Restores the <code>destination</code> NodeRevisionDescriptor from
  +     * the <code>source</code>.
  +     *
  +     * @param      source       the source NodeRevisionDescriptor.
  +     * @param      destination  the destination NodeRevisionDescriptor.
  +     */
  +    public static void restoreRevisionDescriptor(NodeRevisionDescriptor source, 
NodeRevisionDescriptor destination) {
  +        
  +        // remove all dead properties
  +        Enumeration propertyNames = destination.enumeratePropertiesName();
  +        NodeProperty property = null;
  +        if (propertyNames != null) {
  +            while (propertyNames.hasMoreElements()) {
  +                property = 
destination.getProperty(propertyNames.nextElement().toString());
  +                if ( ! property.isProtected() ) {
  +                    destination.removeProperty(property);
  +                }
  +            }
  +        }
  +        
  +        // copy dead properties
  +        propertyNames = source.enumeratePropertiesName();
  +        if (propertyNames != null) {
  +            while (propertyNames.hasMoreElements()) {
  +                property = 
source.getProperty(propertyNames.nextElement().toString());
  +                if ( ! property.isProtected() ) {
  +                    destination.setProperty(property);
  +                }
  +            }
  +        }
  +        destination.setContentLanguage(source.getContentLanguage());
  +        destination.setContentLength(source.getContentLength());
  +        destination.setContentType(source.getContentType());
       }
       
   }
  
  
  

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

Reply via email to