juergen     02/03/08 03:59:05

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        VersioningHelper.java
  Log:
  Maintain <checkout-set> property (instead of computing it).
  (ralf)
  
  Revision  Changes    Path
  1.4       +133 -16   
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- VersioningHelper.java     1 Mar 2002 16:49:04 -0000       1.3
  +++ VersioningHelper.java     8 Mar 2002 11:59:05 -0000       1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
 1.3 2002/03/01 16:49:04 pnever Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/03/01 16:49:04 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
 1.4 2002/03/08 11:59:05 juergen Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/03/08 11:59:05 $
    *
    * ====================================================================
    *
  @@ -66,9 +66,12 @@
   import java.io.*;
   import java.util.*;
   
  +import org.jdom.Document;
   import org.jdom.Element;
   import org.jdom.JDOMException;
   
  +import org.jdom.input.SAXBuilder;
  +
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   
  @@ -114,6 +117,11 @@
           return new VersioningHelper( sToken, nsaToken, req, resp, sConf );
       }
       
  +    /**
  +     ** The SAXBuilder used to create JDOM Documents.
  +     **/
  +    protected static SAXBuilder saxBuilder = null;
  +    
       private Content content = null;
       private Structure structure = null;
       private HttpServletRequest req = null;
  @@ -218,6 +226,8 @@
               if( !vrNrd.exists(p.getName()) )
                   vrNrd.setProperty( p );
           }
  +        // Copy content-type VCR->VR
  +        vrNrd.setContentType(rNrd.getContentType()); // P_GETCONTENTTYPE
           
           // Set initial VHR properties
           NodeRevisionNumber vhrNrn = new NodeRevisionNumber( 0, 0 ); //major=0; 
minor=0
  @@ -267,22 +277,12 @@
           vhrNrd.setName( (String)pHelp.createCdataValue(vhrUh.getHistoryName()) ); 
// P_DISPLAYNAME
           vhrNrd.setProperty(
               new NodeProperty(P_VERSION_SET, pHelp.createHrefValue(vrUri)) );
  -        /* Content Type --start-- */
  -        String contentType = req.getContentType();
  -        if (contentType == null) {
  -            contentType = sConf.getServletContext()
  -                .getMimeType(resourcePath);
  -        }
  -        if (contentType == null) {
  -            contentType = sConf.getDefaultMimeType();
  -        }
  -        vrNrd.setContentType(contentType); // P_GETCONTENTTYPE
  -        /* Content Type --end-- */
           vrNrd.setName( (String)pHelp.createCdataValue(vrUh.getVersionName()) ); // 
P_DISPLAYNAME
           vrNrd.setETag( vrUri.hashCode()+"_"+req.getContentLength() ); // P_GETETAG
           vrNrd.setCreationDate( new Date() ); // P_CREATIONDATE
           vrNrd.setProperty(
               new NodeProperty(P_VERSION_NAME, vrUh.getVersionName()) );
  +        vrNrd.setProperty(new NodeProperty(P_CHECKOUT_SET, null));
           
           // Store changes
           content.store( sToken, resourcePath, rNrd, null ); //revisionContent=null
  @@ -294,7 +294,7 @@
        * Checkout the specified resource
        */
       public void checkout( String resourcePath, boolean forkOk, boolean 
applyToVersion )
  -    throws SlideException {
  +        throws SlideException, JDOMException {
           
           NodeRevisionDescriptors rNrds = retrieveRevisionDescriptors( resourcePath );
           NodeRevisionDescriptor rNrd = retrieveLatestRevisionDescriptor( 
resourcePath, rNrds );
  @@ -306,7 +306,7 @@
        */
       public void checkout( NodeRevisionDescriptors rNrds,
       NodeRevisionDescriptor rNrd, boolean forkOk, boolean applyToVersion )
  -    throws SlideException {
  +        throws SlideException, JDOMException {
           
           Iterator i;
           ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
  @@ -323,13 +323,23 @@
           }
           
           if( rRk instanceof CheckedInVersionControlled ) {
  +            
  +            // get checked-in VR
               NodeProperty cinProp = rNrd.getProperty( P_CHECKED_IN );
  +            String cinHref = getElementValue((String)cinProp.getValue());
  +            UriHandler cinUriHandler = UriHandler.getUriHandler(nsaToken, cinHref);
  +            String cinUri = cinUriHandler.getAssociatedHistoryUri();
  +            NodeRevisionNumber cinNrn = new 
NodeRevisionNumber(cinUriHandler.getVersionName());
  +            NodeRevisionDescriptors cinNrds = content.retrieve(sToken, cinUri);
  +            NodeRevisionDescriptor cinNrd = content.retrieve(sToken, cinNrds, 
cinNrn);
               
               // TODO: check precondition 
C_CHECKOUT_OF_VERSION_WITH_DESCENDANT_IS_FORBIDDEN
               // TODO: check precondition 
C_CHECKOUT_OF_VERSION_WITH_DESCENDANT_IS_DISCOURAGED
               // TODO: check precondition 
C_CHECKOUT_OF_CHECKED_OUT_VERSION_IS_FORBIDDEN
               // TODO: check precondition 
C_CHECKOUT_OF_CHECKED_OUT_VERSION_IS_DISCOURAGED
               
  +            addUriToCheckoutSet(cinNrd, rNrds.getUri());
  +            
               // do the checkout
               rNrd.removeProperty( cinProp );
               rNrd.setProperty(
  @@ -407,6 +417,8 @@
               NodeRevisionDescriptor vrNrdOld =
                   retrieveLatestRevisionDescriptor( vrUriOld, vhrNrds );
               
  +            removeUriFromCheckoutSet(vrNrdOld, rNrds.getUri());
  +            
               // Create new VR in the MAIN branch
               NodeRevisionDescriptor vrNrdNew =
                   new NodeRevisionDescriptor(req.getContentLength());
  @@ -470,5 +482,110 @@
               return;
           }
       }
  +    
  +    /**
  +     * Adds the given <code>uri</code> to the <code>&lt;checkout-set&gt;</code>
  +     * property of the VR's NodeRevisionDescriptor (if not already contained).
  +     *
  +     * @param      nrd  the NodeRevisionDescriptor of the VR for which to update
  +     *                  the <code>&lt;checkout-set&gt;</code>.
  +     * @param      uri  the uri to add.
  +     *
  +     * @throws     JDOMException if parsing the <code>&lt;checkout-set&gt;</code>
  +     *             failed.
  +     */
  +    protected void addUriToCheckoutSet(NodeRevisionDescriptor nrd, String uri) 
throws JDOMException {
  +        
  +        NodeProperty checkoutSetProperty = nrd.getProperty(P_CHECKOUT_SET);
  +        if (checkoutSetProperty == null) {
  +            checkoutSetProperty = new NodeProperty(P_CHECKOUT_SET, null);
  +        }
  +        XMLValue xmlValue = new XMLValue((String)checkoutSetProperty.getValue());
  +        Iterator iterator = xmlValue.iterator();
  +        boolean alreadyContained = false;
  +        Element element = null;
  +        while (iterator.hasNext() && !alreadyContained) {
  +            element = (Element)iterator.next();
  +            if (element.getName().equals(E_HREF) && element.getText().equals(uri)) {
  +                alreadyContained = true;
  +            }
  +        }
  +        if (!alreadyContained) {
  +            element = new Element(E_HREF);
  +            element.setText(uri);
  +            xmlValue.add(element);
  +        }
  +    }
  +    
  +    /**
  +     * Removes the given <code>uri</code> from the <code>&lt;checkout-set&gt;</code>
  +     * property of the VR's NodeRevisionDescriptor (if contained).
  +     *
  +     * @param      nrd  the NodeRevisionDescriptor of the VR for which to update
  +     *                  the <code>&lt;checkout-set&gt;</code>.
  +     * @param      uri  the uri to remove.
  +     *
  +     * @throws     JDOMException if parsing the <code>&lt;checkout-set&gt;</code>
  +     *             failed.
  +     */
  +    protected void removeUriFromCheckoutSet(NodeRevisionDescriptor nrd, String uri) 
throws JDOMException {
  +        
  +        NodeProperty checkoutSetProperty = nrd.getProperty(P_CHECKOUT_SET);
  +        if (checkoutSetProperty != null) {
  +
  +            XMLValue xmlValue = new 
XMLValue((String)checkoutSetProperty.getValue());
  +            Iterator iterator = xmlValue.iterator();
  +            boolean found = false;
  +            Element element = null;
  +            while (iterator.hasNext() && !found) {
  +                element = (Element)iterator.next();
  +                if (element.getName().equals(E_HREF) && 
element.getText().equals(uri)) {
  +                    found = true;
  +                    iterator.remove();
  +                }
  +            }
  +            if (found) {
  +                checkoutSetProperty = new NodeProperty(P_CHECKOUT_SET, 
xmlValue.toString());
  +            }
  +        }
  +    }
  +    
  +    /**
  +     ** Expects a String containing an XML Element like
  +     ** <code>&lt;example&gt;value&lt;/example&gt;</code>
  +     ** and returns the text <code>value</code> of this element.
  +     ** If the String is not of the expected format, <code>null</code> is returned.
  +     **
  +     ** @pre        true
  +     ** @post       true
  +     **
  +     ** @param      elementString  the String containing an XML Element like
  +     **                            
<code>&lt;example&gt;value&lt;/example&gt;</code>.
  +     **
  +     ** @return     the text value of the Element given by the XML String.
  +     **/
  +    public static String getElementValue(String elementString) {
  +        
  +        String text = null;
  +        try {
  +            Document document = getSAXBuilder().build(new 
StringReader(elementString));
  +            text = document.getRootElement().getText();
  +        }
  +        catch (JDOMException e) {}
  +        return text;
  +    }
  +    
  +    /**
  +     * Returns the SAXBuilder used by various methods to create JDOM Documents.
  +     *
  +     * @return     the SAXBuilder used to create JDOM Documents.
  +     */
  +    protected static SAXBuilder getSAXBuilder() {
  +        if (saxBuilder == null) {
  +            saxBuilder = new SAXBuilder();
  +        }
  +        return saxBuilder;
  +    }
  +    
   }
   
  
  
  

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

Reply via email to