pnever      02/04/26 05:46:37

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        VersioningHelper.java
  Log:
  Added checkout applied to a version (working resource feature)
  
  Revision  Changes    Path
  1.35      +92 -10    
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.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- VersioningHelper.java     25 Apr 2002 21:15:15 -0000      1.34
  +++ VersioningHelper.java     26 Apr 2002 12:46:37 -0000      1.35
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
 1.34 2002/04/25 21:15:15 jericho Exp $
  - * $Revision: 1.34 $
  - * $Date: 2002/04/25 21:15:15 $
  + * $Header: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
 1.35 2002/04/26 12:46:37 pnever Exp $
  + * $Revision: 1.35 $
  + * $Date: 2002/04/26 12:46:37 $
    *
    * ====================================================================
    *
  @@ -539,10 +539,18 @@
       public void checkout( String resourcePath, boolean forkOk, boolean 
applyToVersion, boolean isAutoVersionCheckout )
           throws SlideException, JDOMException, IOException, 
PreconditionViolationException  {
           
  +        UriHandler rUh = new UriHandler( nsaToken.getName(), resourcePath );
           NodeRevisionDescriptors rNrds = retrieveRevisionDescriptors( resourcePath );
           NodeRevisionDescriptor rNrd = retrieveLatestRevisionDescriptor( 
resourcePath, rNrds );
  +        
  +        if( rUh.isVersionUri() ) {
  +            NodeRevisionContent rNrc = content.retrieve( sToken, rNrds, rNrd );
  +            checkout( rNrds, rNrd, rNrc, forkOk, applyToVersion );
  +        }
  +        else {
           checkout( rNrds, rNrd, forkOk, applyToVersion, isAutoVersionCheckout);
       }
  +    }
       
       /**
        * Checkout the specified resource
  @@ -578,9 +586,9 @@
               NodeProperty cinProp = rNrd.getProperty( P_CHECKED_IN );
               String cinHref = getElementValue((String)cinProp.getValue());
               UriHandler cinUriHandler = UriHandler.getUriHandler(nsaToken, cinHref);
  -            String cinUri = cinUriHandler.getAssociatedHistoryUri();
  +            String cinhUri = cinUriHandler.getAssociatedHistoryUri();
               NodeRevisionNumber cinNrn = new 
NodeRevisionNumber(cinUriHandler.getVersionName());
  -            NodeRevisionDescriptors cinNrds = content.retrieve(sToken, cinUri);
  +            NodeRevisionDescriptors cinNrds = content.retrieve(sToken, cinhUri);
               NodeRevisionDescriptor cinNrd = content.retrieve(sToken, cinNrds, 
cinNrn);
               
               ViolatedPrecondition violatedPrecondition = 
getCheckoutPreconditionViolation(cinNrds, cinNrd, forkOk);
  @@ -588,7 +596,7 @@
                   throw new PreconditionViolationException(violatedPrecondition, 
rNrds.getUri());
               }
               
  -            NodeRevisionDescriptors vhrNrds = content.retrieve(sToken, cinUri);
  +            NodeRevisionDescriptors vhrNrds = content.retrieve(sToken, cinhUri);
               
               // update <checkout-set>
               PropertyHelper.addHrefToProperty(cinNrd, P_CHECKOUT_SET, 
rNrds.getUri());
  @@ -635,15 +643,89 @@
               // Store changes
               content.store( sToken, rNrds.getUri(), rNrd, null ); 
//revisionContent=null
           }
  -        else if( rRk instanceof Version ) {
  -            Domain.info(
  -                "Working resource feature NOT YET IMPLEMENTED" );
  +        else {
  +            Domain.warn(
  +                "Do not know how to checkout a '"+rRk+"' resource" );
  +            resp.setStatus(WebdavStatus.SC_CONFLICT);
  +            throw new WebdavException( WebdavStatus.SC_CONFLICT );
  +        }
  +    }
  +    
  +    /**
  +     * Checkout the specified version (workingresource feature)
  +     */
  +    public void checkout( NodeRevisionDescriptors rNrds, NodeRevisionDescriptor 
rNrd, NodeRevisionContent rNrc,
  +    boolean forkOk, boolean applyToVersion  )
  +    throws SlideException, JDOMException, IOException, 
PreconditionViolationException  {
  +        
  +        Iterator i;
  +        Enumeration j;
  +        ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
  +        
  +        if( !rRk.isSupportedMethod(req.getMethod()) ) {
  +            // check precondition C_MUST_BE_CHECKED_IN
  +            if( rRk instanceof CheckedOut ) {
  +                throw new PreconditionViolationException(new 
ViolatedPrecondition(C_MUST_BE_CHECKED_IN, WebdavStatus.SC_CONFLICT), rNrds.getUri());
  +            }
  +            resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  +            throw new WebdavException(WebdavStatus.SC_BAD_REQUEST);
  +        }
  +        
  +        if( rRk instanceof Version ) {
  +            
  +            String rUri = getUri( rNrds, rNrd );
  +            UriHandler rUh = new UriHandler( nsaToken.getName(), rUri );
  +            String vhUri = rUh.getAssociatedHistoryUri();
  +            
  +            ViolatedPrecondition violatedPrecondition = 
getCheckoutPreconditionViolation(rNrds, rNrd, forkOk);
  +            if (violatedPrecondition != null) {
  +                throw new PreconditionViolationException(violatedPrecondition, 
rNrds.getUri());
  +            }
  +            
  +            NodeRevisionDescriptors vhrNrds = content.retrieve(sToken, vhUri);
  +            
  +            // create the workingresource
  +            UriHandler wrUh = UriHandler.createNextWorkingresourceUri( sToken, 
nsaToken );
  +            String wrUri = String.valueOf( wrUh );
  +            SubjectNode wrNode = new SubjectNode();
  +            structure.create( sToken, wrNode, String.valueOf(wrUh) );
  +
  +            // set WR props
  +            NodeRevisionDescriptor wrNrd = new NodeRevisionDescriptor();
  +            i = pHelp.createInitialProperties(WorkingImpl.getInstance()).iterator();
  +            while( i.hasNext() )
  +                wrNrd.setProperty( (NodeProperty)i.next() );
  +
  +            // set specific live props
  +            wrNrd.setContentType(rNrd.getContentType()); // P_GETCONTENTTYPE
  +            wrNrd.setProperty(
  +                new NodeProperty(P_CHECKED_OUT, pHelp.createHrefValue(rUri)) );
  +            NodeProperty predsetProp = rNrd.getProperty( P_PREDECESSOR_SET );
  +            if( predsetProp != null )
  +                wrNrd.setProperty( predsetProp );
  +            NodeProperty coutfProp = rNrd.getProperty(P_CHECKOUT_FORK);
  +            if( coutfProp != null )
  +                wrNrd.setProperty( coutfProp );
  +            NodeProperty cinfProp = rNrd.getProperty(P_CHECKOUT_FORK);
  +            if( coutfProp != null )
  +                wrNrd.setProperty( coutfProp );
  +        
  +            // Copy dead properties VR -> WR
  +            j = rNrd.enumerateProperties();
  +            while( j.hasMoreElements() ) {
  +                NodeProperty p = (NodeProperty)j.nextElement();
  +                if( rRk.isSupportedLiveProperty(p.getName()) )
  +                    continue;
  +                wrNrd.setProperty( p );
  +            }
  +            
  +            content.create( sToken, wrUri, wrNrd, rNrc );
           }
           else {
               Domain.warn(
                   "Do not know how to checkout a '"+rRk+"' resource" );
               resp.setStatus(WebdavStatus.SC_CONFLICT);
  -            return;
  +            throw new WebdavException( WebdavStatus.SC_CONFLICT );
           }
       }
       
  
  
  

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

Reply via email to