You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2002/05/07 09:34:57 UTC

cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method CopyMethod.java

juergen     02/05/07 00:34:57

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        CopyMethod.java
  Log:
  Fixed implementation of Label header feature:
  Apply redriction of URI to all resources (if the Depth header is >0).
  Also there was a problem if the source is a VR.
  (ralf)
  
  Revision  Changes    Path
  1.32      +117 -25   jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java
  
  Index: CopyMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- CopyMethod.java	30 Apr 2002 12:59:37 -0000	1.31
  +++ CopyMethod.java	7 May 2002 07:34:57 -0000	1.32
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v 1.31 2002/04/30 12:59:37 juergen Exp $
  - * $Revision: 1.31 $
  - * $Date: 2002/04/30 12:59:37 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v 1.32 2002/05/07 07:34:57 juergen Exp $
  + * $Revision: 1.32 $
  + * $Date: 2002/05/07 07:34:57 $
    *
    * ====================================================================
    *
  @@ -73,6 +73,7 @@
   import org.apache.slide.common.*;
   import org.apache.slide.webdav.*;
   import org.apache.slide.macro.*;
  +import org.apache.slide.macro.CopyRouteRedirector.CopyRoute;
   import org.apache.slide.lock.*;
   import org.apache.slide.content.*;
   import org.apache.slide.security.AccessDeniedException;
  @@ -100,7 +101,7 @@
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @author Juergen Pill
    */
  -public class CopyMethod extends AbstractMultistatusResponseMethod implements DeltavConstants, CopyListener, DeleteListener {
  +public class CopyMethod extends AbstractMultistatusResponseMethod implements DeltavConstants, CopyListener, DeleteListener, CopyRouteRedirector {
       
       
       
  @@ -116,6 +117,13 @@
        */
       protected Map checkedOutDestinationsMap = new HashMap();
       
  +    /**
  +     * The value of the <code>Label</code> header.
  +     */
  +    protected String labelHeader = null;
  +    
  +    
  +    
       // ----------------------------------------------------------- Constructors
       
       
  @@ -148,26 +156,7 @@
        */
       protected void parseRequest() throws WebdavException, IOException {
           super.parseRequest();
  -    
  -        // evaluate "Label" header
  -        if (Configuration.useVersionControl()) {
  -            try {
  -                sourceUri = versioningHelper.getLabeledResourceUri(sourceUri,
  -                                                                   req.getHeader(DeltavConstants.H_LABEL));
  -            }
  -            catch (LabeledRevisionNotFoundException e) {
  -                ViolatedPrecondition violatedPrecondition =
  -                    new ViolatedPrecondition(DeltavConstants.C_MUST_SELECT_VERSION_IN_HISTORY,
  -                                             WebdavStatus.SC_CONFLICT);
  -                sendPreconditionViolation(new PreconditionViolationException(violatedPrecondition,
  -                                                                             sourceUri));
  -                throw new WebdavException(getErrorCode((Exception)e));
  -            }
  -            catch (SlideException e) {
  -                resp.sendError(getErrorCode((Exception)e));
  -                throw new WebdavException(getErrorCode((Exception)e));
  -            }
  -        }
  +        labelHeader = req.getHeader(DeltavConstants.H_LABEL);
       }
       
       /**
  @@ -199,7 +188,7 @@
           }
           
           try {
  -            macro.copy(slideToken, sourceUri, destinationUri, macroParameters, this, this);
  +            macro.copy(slideToken, sourceUri, destinationUri, macroParameters, this, this, null, this);
               if (overwrite) {
                   resp.setStatus(WebdavStatus.SC_NO_CONTENT);
               } else {
  @@ -259,6 +248,42 @@
           }
       }
       
  +    // ------------------------------------------------------ Interface CopyRouteRedirector
  +    
  +    /**
  +     * Returns the (redirected) CopyRoute to use. Must not be <code>null</code>.
  +     *
  +     * @param      the original CopyRoute.
  +     *
  +     * @return     the (redirected) CopyRoute to use.
  +     *
  +     * @throws     SlideException  this Exception will be passed to the caller
  +     *                             of the Macro helper (contained in the
  +     *                             MacroCopyException).
  +     */
  +    public CopyRoute getRedirectedCopyRoute(CopyRoute copyRoute) throws SlideException {
  +        
  +        if (Configuration.useVersionControl()) {
  +            
  +            String sourceUri = copyRoute.getSourceUri();
  +            String destinationUri = copyRoute.getDestinationUri();
  +            
  +            try {
  +                sourceUri = versioningHelper.getLabeledResourceUri(sourceUri, labelHeader);
  +            }
  +            catch (LabeledRevisionNotFoundException e) {
  +                ViolatedPrecondition violatedPrecondition =
  +                    new ViolatedPrecondition(DeltavConstants.C_MUST_SELECT_VERSION_IN_HISTORY,
  +                                             WebdavStatus.SC_CONFLICT);
  +                throw new PreconditionViolationException(violatedPrecondition, sourceUri);
  +            }
  +            
  +            copyRoute = new CopyRoute(sourceUri, destinationUri);
  +        }
  +        
  +        return copyRoute;
  +    }
  +    
       // ------------------------------------------------------ Interface CopyListener
       
       /**
  @@ -275,12 +300,30 @@
        */
       public void beforeCopy(String sourceUri, String destinationUri) throws SlideException {
           
  +        if(Configuration.useVersionControl()) {
  +            
           UriHandler uriHandler = UriHandler.getUriHandler(token, sourceUri);
           if (uriHandler.isHistoryUri()) {
               throw new PreconditionViolationException(new ViolatedPrecondition(DeltavConstants.C_CANNOT_COPY_HISTORY,
                                                                                 WebdavStatus.SC_FORBIDDEN),
                                                        sourceUri);
           }
  +            
  +            if (uriHandler.isVersionUri()) {
  +                
  +                // create a temporary NodeRevisionDescriptor(s) to be copied
  +                // by the Macro helper (will be deleted in afterCopy())
  +                NodeRevisionDescriptors historyDescriptors = versioningHelper.retrieveRevisionDescriptors(sourceUri);
  +                NodeRevisionDescriptor vrDescriptor = versioningHelper.retrieveLatestRevisionDescriptor(sourceUri, historyDescriptors);
  +                NodeRevisionContent vrContent = content.retrieve(slideToken, historyDescriptors, vrDescriptor);
  +                
  +                NodeRevisionDescriptor newRevisionDescriptor = cloneRevisionDescriptor(vrDescriptor, new NodeRevisionNumber(0, 0));
  +                NodeRevisionContent newRevisionContent = new NodeRevisionContent();
  +                newRevisionContent.setContent(vrContent.getContentBytes());
  +                content.create(slideToken, sourceUri, newRevisionDescriptor, newRevisionContent);
  +            }
  +            
  +        }
       }
       
       /**
  @@ -357,6 +400,16 @@
               if (token.getNamespaceConfig().getAutoVersionControl() ) {
                   versioningHelper.versionControl(destinationUri);
               }
  +            
  +            // if the source was a VR, we have to remove the NodeRevisionDescriptor(s)
  +            // which has been created temporarily for the Macro helper
  +            // (see beforeCopy())
  +            UriHandler uriHandler = UriHandler.getUriHandler(token, sourceUri);
  +            if ( uriHandler.isVersionUri() ) {
  +                NodeRevisionDescriptors vrRevisionDescriptors = content.retrieve(slideToken, sourceUri);
  +                content.remove(slideToken, vrRevisionDescriptors);
  +            }
  +            
           }
           
       }
  @@ -464,6 +517,45 @@
       public void afterDelete(String targetUri) throws SlideException {
           
       }
  +    
  +    
  +    
  +    /**
  +     * 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.
  +     */
  +    protected static 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 clone = new NodeRevisionDescriptor(revisionNumber, branchName, labels, properties);
  +        return clone;
  +    }
  +    
  +    
   }
   
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>