jakarta-slide-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pne...@apache.org
Subject cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/util VersioningHelper.java
Date Fri, 12 Apr 2002 15:41:33 GMT
pnever      02/04/12 08:41:33

  Modified:    src/webdav/server/org/apache/slide/webdav/util
                        VersioningHelper.java
  Log:
  (1) Added versionControl() method for existing version history and (2) some changes to the
updateVCR() method
  
  Revision  Changes    Path
  1.27      +119 -22   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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- VersioningHelper.java	11 Apr 2002 12:54:20 -0000	1.26
  +++ VersioningHelper.java	12 Apr 2002 15:41:33 -0000	1.27
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
1.26 2002/04/11 12:54:20 juergen Exp $
  - * $Revision: 1.26 $
  - * $Date: 2002/04/11 12:54:20 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
1.27 2002/04/12 15:41:33 pnever Exp $
  + * $Revision: 1.27 $
  + * $Date: 2002/04/12 15:41:33 $
    *
    * ====================================================================
    *
  @@ -240,13 +240,12 @@
           
           if( !rRk.isSupportedMethod(req.getMethod()) ) {
               resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
  -            return;
  +            throw new WebdavException( WebdavStatus.SC_BAD_REQUEST );
           }
           
           // Check for rRk = K_VERSION_CONTROLLED*
           if( rRk instanceof VersionControlled ) {
               // nothing to do
  -            resp.setStatus(WebdavStatus.SC_OK);
               return;
           }
           
  @@ -331,6 +330,86 @@
       }
       
       /**
  +     * Create new VCR for an existing version history.
  +     * @pre   existingVersionPath != null
  +     *
  +     * @param resourcePath the URI of the resource to version-control
  +     * @param existingVersionPath the URI of the VR on which the new VCR will be based
  +     * @throws SlideException
  +     */
  +    public void versionControl( String resourcePath, String existingVersionPath ) throws
SlideException {
  +        Iterator i;
  +        
  +        UriHandler rUh = UriHandler.getUriHandler( nsaToken, resourcePath );
  +        UriHandler evUh = UriHandler.getUriHandler( nsaToken, existingVersionPath );
  +        NodeRevisionDescriptors rNrds = null;
  +        NodeRevisionDescriptor rNrd = null;
  +        NodeRevisionDescriptors vcrNrds = null;
  +        NodeRevisionDescriptor vcrNrd = null;
  +        NodeRevisionDescriptors evNrds = null;
  +        NodeRevisionDescriptor evNrd = null;
  +        
  +        try {
  +            rNrds = retrieveRevisionDescriptors( resourcePath );
  +            rNrd = retrieveLatestRevisionDescriptor( resourcePath, rNrds );
  +        }
  +        catch( ObjectNotFoundException e ) {}; // can be ignored here!
  +        try {
  +            evNrds = retrieveRevisionDescriptors( existingVersionPath );
  +            evNrd = retrieveLatestRevisionDescriptor( existingVersionPath, evNrds );
  +        }
  +        catch( ObjectNotFoundException e ) {}; // can be ignored here!
  +        
  +        ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
  +        ResourceKind evRk = AbstractResourceKind.determineResourceKind( evNrd );
  +        
  +        if( !(rRk instanceof DeltavCompliantUnmappedUrl) ) {
  +            throw new PreconditionViolationException(
  +                new ViolatedPrecondition(C_CANNOT_ADD_TO_EXISTING_HISTORY, WebdavStatus.SC_CONFLICT),
resourcePath);
  +        }
  +        if( !(evRk instanceof Version) || evNrd == null) {
  +            throw new PreconditionViolationException(
  +                new ViolatedPrecondition(C_MUST_BE_VERSION, WebdavStatus.SC_CONFLICT),
resourcePath);
  +        }
  +        
  +        // create the VCR
  +        String vcrUri = String.valueOf(rUh);
  +        String evUri = String.valueOf(evUh);
  +        UriHandler vcrUh = UriHandler.getUriHandler( nsaToken, vcrUri );
  +        vcrNrd = new NodeRevisionDescriptor(0);
  +        i = pHelp.createInitialProperties(VersionControlledImpl.getInstance()).iterator();
  +        while( i.hasNext() )
  +            vcrNrd.setProperty( (NodeProperty)i.next() );
  +        
  +        // Set specific properties
  +        vcrNrd.setETag( vcrNrd.hashCode()+"_"+evNrd.getContentLength() ); // P_GETETAG
  +        vcrNrd.setLastModified( new Date() ); //P_GETLASTMODIFIED
  +        vcrNrd.setContentLength( evNrd.getContentLength() ); // P_GETCONTENTLENGTH
  +        vcrNrd.setContentType( evNrd.getContentType() ); // P_GETCONTENTTYPE
  +        String[] utok = vcrUh.getUriTokens();
  +        vcrNrd.setName( utok[utok.length - 1] ); // P_DISPLAYNAME
  +        vcrNrd.setCreationDate( new Date() ); // P_CREATIONDATE
  +        vcrNrd.setProperty( new NodeProperty(P_CHECKED_IN,
  +                                             pHelp.createHrefValue(evUri)) );
  +        // set workspace
  +        String wsUri = vcrUh.getAssociatedWorkspaceUri();
  +        if( wsUri != null ) {
  +            vcrNrd.setProperty(
  +                new NodeProperty(P_WORKSPACE, pHelp.createHrefValue(wsUri)) );
  +        }
  +        
  +        // store
  +        SubjectNode vcrNode = new SubjectNode();
  +        structure.create( sToken, vcrNode, vcrUri );
  +        NodeRevisionContent evContent =
  +            content.retrieve( sToken, evNrds, evNrd );
  +        content.create( sToken, vcrUri, vcrNrd, evContent );
  +        
  +        // Set status created
  +        resp.setStatus( WebdavStatus.SC_CREATED );
  +    }
  +    
  +    /**
        * Create the specified workspace.
        *
        * @param resourcePath the URI of the workspace to create
  @@ -351,13 +430,11 @@
           
           if( !(rRk instanceof DeltavCompliantUnmappedUrl) ) {
               throw new PreconditionViolationException(
  -                new ViolatedPrecondition(
  -                    C_RESOURCE_MUST_BE_NULL, WebdavStatus.SC_CONFLICT), resourcePath);
  +                new ViolatedPrecondition(C_RESOURCE_MUST_BE_NULL, WebdavStatus.SC_CONFLICT),
resourcePath);
           }
           if( !rUh.isWorkspaceUri() ) {
               throw new PreconditionViolationException(
  -                new ViolatedPrecondition(
  -                    C_WORKSPACE_LOCATION_OK, WebdavStatus.SC_CONFLICT), resourcePath);
  +                new ViolatedPrecondition(C_WORKSPACE_LOCATION_OK, WebdavStatus.SC_CONFLICT),
resourcePath);
           }
           if( !rRk.isSupportedMethod(req.getMethod()) ) {
               resp.setStatus( WebdavStatus.SC_BAD_REQUEST );
  @@ -852,6 +929,8 @@
        * of the VR specified by the given <code>vrRevisionDescriptors</code>
        * and <code>vrRevisionDescriptor</code>.
        *
  +     * @pre        (AbstractResourceKind.determineResourceKind(vrRevisionDescriptor) instanceof
Version)
  +     *
        * @param      vcrRevisionDescriptors  the NodeRevisionDescriptors of the VCR to update.
        * @param      vcrRevisionDescriptor   the NodeRevisionDescriptor of the VCR to update.
        * @param      vrRevisionDescriptors   the NodeRevisionDescriptors of the VR from
  @@ -863,24 +942,37 @@
        */
       protected void updateVCR(NodeRevisionDescriptors vcrRevisionDescriptors, NodeRevisionDescriptor
vcrRevisionDescriptor, NodeRevisionDescriptors vrRevisionDescriptors, NodeRevisionDescriptor
vrRevisionDescriptor) throws SlideException {
           
  -        ResourceKind vrResourceKind = AbstractResourceKind.determineResourceKind(vrRevisionDescriptor);
  -        
  -        // remove all VCR properties first
  -        Enumeration propertyEnum = vcrRevisionDescriptor.enumerateProperties();
  +        ResourceKind vrResourceKind = VersionImpl.getInstance();
  +        String vcrUri = getUri(vcrRevisionDescriptors, vcrRevisionDescriptor);
  +        Enumeration propertyEnum;
  +        
  +        // Remove all VCR properties first
  +        // Well, almost all ... a property named xdavContentId will be skipped ...
  +        // This is Tamino-specific but shouldn't hurt others.
  +        // Sorry for this :-) !!
  +        propertyEnum = vcrRevisionDescriptor.enumerateProperties();
           while (propertyEnum.hasMoreElements()) {
  -            vcrRevisionDescriptor.removeProperty((NodeProperty)propertyEnum.nextElement());
  +            NodeProperty p = (NodeProperty)propertyEnum.nextElement();
  +            if( p.getName().equals("xdavContentId") )
  +                continue;
  +            vcrRevisionDescriptor.removeProperty(p);
           }
           
  -        // set initial properties
  -        Iterator iterator = pHelp.createInitialProperties(VersionImpl.getInstance()).iterator();
  +        // set initial VCR properties
  +        Iterator iterator = pHelp.createInitialProperties(VersionControlledImpl.getInstance()).iterator();
           while (iterator.hasNext()) {
               vcrRevisionDescriptor.setProperty((NodeProperty)iterator.next());
           }
           
  -        // copy dead properties of VR to VCR
  +        // Copy all dead properties of VR to VCR
  +        // Well, almost all ... a property named xdavContentId will be skipped ...
  +        // Again, this is Tamino-specific but shouldn't hurt others.
  +        // Sorry again for this :-) !!
           propertyEnum = vrRevisionDescriptor.enumerateProperties();
           while (propertyEnum.hasMoreElements()) {
               NodeProperty p = (NodeProperty)propertyEnum.nextElement();
  +            if( p.getName().equals("xdavContentId") )
  +                continue;
               if( ! vrResourceKind.isSupportedLiveProperty(p.getName()) ) {
                   vcrRevisionDescriptor.setProperty(p);
               }
  @@ -895,14 +987,19 @@
           vcrRevisionDescriptor.setContentType(vrRevisionDescriptor.getContentType());
           vcrRevisionDescriptor.setETag(vcrRevisionDescriptors.getUri().hashCode()+
                                             "_"+vcrRevisionDescriptor.getContentLength());
  +        // set workspace
  +        UriHandler vcrUh = UriHandler.getUriHandler( nsaToken, vcrUri );
  +        String wsUri = vcrUh.getAssociatedWorkspaceUri();
  +        if( wsUri != null ) {
  +            vcrRevisionDescriptor.setProperty(
  +                new NodeProperty(P_WORKSPACE, pHelp.createHrefValue(wsUri)) );
  +        }
           
  -        // update content
  +        // get the VR content
           NodeRevisionContent vrContent = content.retrieve(sToken, vrRevisionDescriptors,
vrRevisionDescriptor);
  -        NodeRevisionContent vcrContent = new NodeRevisionContent();
  -        vcrContent.setContent(vrContent.getContentBytes());
           
  -        // Store changes
  -        content.store( sToken, vcrRevisionDescriptors.getUri(), vcrRevisionDescriptor,
vcrContent);
  +        // store the content
  +        content.store( sToken, vcrUri, vcrRevisionDescriptor, vrContent );
       }
       
       
  
  
  

--
To unsubscribe, e-mail:   <mailto:slide-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:slide-dev-help@jakarta.apache.org>


Mime
View raw message