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/04/11 14:57:03 UTC

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

juergen     02/04/11 05:57:03

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        CopyMethod.java
  Log:
  Implemented pre- and postconditions for DeltaV.
  (ralf)
  
  Revision  Changes    Path
  1.23      +237 -5    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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- CopyMethod.java	28 Mar 2002 06:12:12 -0000	1.22
  +++ CopyMethod.java	11 Apr 2002 12:57:03 -0000	1.23
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v 1.22 2002/03/28 06:12:12 jericho Exp $
  - * $Revision: 1.22 $
  - * $Date: 2002/03/28 06:12:12 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v 1.23 2002/04/11 12:57:03 juergen Exp $
  + * $Revision: 1.23 $
  + * $Date: 2002/04/11 12:57:03 $
    *
    * ====================================================================
    *
  @@ -77,6 +77,21 @@
   import org.apache.slide.content.*;
   import org.apache.slide.security.AccessDeniedException;
   import org.apache.slide.structure.*;
  +import org.apache.slide.webdav.util.PreconditionViolationException;
  +import org.apache.slide.webdav.util.ViolatedPrecondition;
  +import org.apache.slide.webdav.util.UriHandler;
  +import org.apache.slide.webdav.util.DeltavConstants;
  +import org.apache.slide.webdav.util.XMLValue;
  +import org.apache.slide.webdav.util.VersioningHelper;
  +import org.apache.slide.webdav.util.PropertyHelper;
  +import org.apache.slide.webdav.util.resourcekind.ResourceKind;
  +import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
  +import org.apache.slide.webdav.util.resourcekind.CheckedInVersionControlled;
  +import org.apache.slide.webdav.util.resourcekind.CheckedOutVersionControlledImpl;
  +import org.apache.slide.webdav.util.resourcekind.DeltavCompliant;
  +import org.apache.slide.util.Configuration;
  +
  +import org.jdom.JDOMException;
   
   /**
    * COPY Method.
  @@ -84,10 +99,21 @@
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @author Juergen Pill
    */
  -public class CopyMethod extends AbstractMultistatusResponseMethod {
  +public class CopyMethod extends AbstractMultistatusResponseMethod implements DeltavConstants, CopyListener, DeleteListener {
       
       
       
  +    /**
  +     * The VersioningHelper used by this instance.
  +     */
  +    protected VersioningHelper versioningHelper = null;
  +    
  +    /**
  +     * Maps the URI of a checked-out destination to the value
  +     * of its <code>&lt;checked-out&gt;</code> property.
  +     * Used by {@link #beforeCopy beforeCopy()} and {@link #afterCopy afterCopy()}.
  +     */
  +    protected Map checkedOutDestinationsMap = new HashMap();
       
       // ----------------------------------------------------------- Constructors
       
  @@ -104,6 +130,11 @@
       public CopyMethod(NamespaceAccessToken token, HttpServletRequest req,
                         HttpServletResponse resp, WebdavServletConfig config) {
           super(token, req, resp, config);
  +        versioningHelper = VersioningHelper.getVersioningHelper(slideToken,
  +                                                                token,
  +                                                                req,
  +                                                                resp,
  +                                                                config);
       }
       
       
  @@ -133,7 +164,7 @@
           }
           
           try {
  -            macro.copy(slideToken, sourceUri, destinationUri, macroParameters);
  +            macro.copy(slideToken, sourceUri, destinationUri, macroParameters, this, this);
               if (overwrite) {
                   resp.setStatus(WebdavStatus.SC_NO_CONTENT);
               } else {
  @@ -182,7 +213,208 @@
           }
       }
       
  +    // ------------------------------------------------------ Interface CopyListener
  +    
  +    /**
  +     * This method is called prior to copying the resource associated by
  +     * the given <code>sourceUri</code>. The copy can be prohibited by
  +     * throwing a SlideException.
  +     *
  +     * @param      sourceUri       the Uri of the resource that will be copied.
  +     * @param      destinationUri  the Uri of the copy.
  +     *
  +     * @throws     SlideException  this Exception will be passed to the caller
  +     *                             of the Macro helper (contained in the
  +     *                             MacroDeleteException.
  +     */
  +    public void beforeCopy(String sourceUri, String destinationUri) throws SlideException {
  +        
  +        UriHandler uriHandler = UriHandler.getUriHandler(token, sourceUri);
  +        if (uriHandler.isHistoryUri()) {
  +            throw new PreconditionViolationException(new ViolatedPrecondition(DeltavConstants.C_CANNOT_COPY_HISTORY,
  +                                                                              WebdavStatus.SC_FORBIDDEN),
  +                                                     sourceUri);
  +        }
  +    }
  +    
  +    /**
  +     * This method is called after copying the resource to
  +     * the given <code>destinationUri</code>.
  +     *
  +     * @param      sourceUri       the Uri of the resource that has been copied.
  +     * @param      destinationUri  the Uri of the copy.
  +     *
  +     * @throws     SlideException  this Exception will be passed to the caller
  +     *                             of the Macro helper (contained in the
  +     *                             MacroDeleteException.
  +     */
  +    public void afterCopy(String sourceUri, String destinationUri) throws SlideException {
  +        
  +        if(Configuration.useVersionControl()) {
  +            
  +            NodeRevisionDescriptors revisionDescriptors = versioningHelper.retrieveRevisionDescriptors(destinationUri);
  +            NodeRevisionDescriptor revisionDescriptor = versioningHelper.retrieveLatestRevisionDescriptor(destinationUri, revisionDescriptors);
  +            ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(revisionDescriptor);
  +            
  +            String checkedOutPropertyValue = (String)checkedOutDestinationsMap.get(destinationUri);
  +            if (checkedOutPropertyValue != null) {
  +                // destination was checked-out, so copy must be a checked-out
  +                // resource too.
  +                resourceKind = CheckedOutVersionControlledImpl.getInstance();
  +            }
  +    
  +            if (resourceKind instanceof DeltavCompliant) {
  +                
  +                // DAV:must-not-copy-versioning-property
  +                PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(slideToken, token);
  +                Iterator initialPropertyIterator = propertyHelper.createInitialProperties(resourceKind).iterator();
  +                NodeProperty property = null;
  +                while (initialPropertyIterator.hasNext()) {
  +                    property = (NodeProperty)initialPropertyIterator.next();
  +                    if (DeltavConstants.DELTAV_PROPERTY_LIST.contains(property.getName())) {
  +                        if (checkedOutPropertyValue != null) {
  +                            // use initial value
  +                            revisionDescriptor.setProperty(property);
  +                        }
  +                        else {
  +                            revisionDescriptor.removeProperty(property);
  +                        }
  +                    }
  +                }
  +                // restore <checked-out> property
  +                if (checkedOutPropertyValue != null) {
  +                    revisionDescriptor.setProperty(new NodeProperty(P_CHECKED_OUT,
  +                                                                    checkedOutPropertyValue, true));
  +                }
  +                content.store(slideToken, revisionDescriptors.getUri(), revisionDescriptor, null);
  +                
  +                // checkin if necessary
  +                boolean mustCheckin = versioningHelper.mustCheckinAutoVersionedVCR(slideToken, revisionDescriptors, revisionDescriptor);
  +                if (mustCheckin) {
  +                    try {
  +                        versioningHelper.checkin(destinationUri, false, false ); //forkOk=false, keepCheckedOut=false
  +                    }
  +                    catch (IOException e) {
  +                        throw new SlideException("Checkin failed: " + e.getMessage());
  +                    }
  +                    catch (JDOMException e) {
  +                        throw new SlideException("Checkin failed: " + e.getMessage());
  +                    }
  +                }
  +            }
  +            
  +            
  +            // check if the resource should be put under version-control
  +            if (token.getNamespaceConfig().getAutoVersionControl() ) {
  +                versioningHelper.versionControl(destinationUri);
  +            }
  +        }
  +        
  +    }
  +    
  +    
  +    // ------------------------------------------------------ Interface DeleteListener
  +    
  +    /**
  +     * This method is called prior to deleting the resource associated by
  +     * the given <code>targetUri</code>. The deletion can be prohibited by
  +     * throwing a SlideException.
  +     *
  +     * @param      targetUri       the Uri of the resource that will be deleted.
  +     *
  +     * @throws     SlideException  this Exception will be passed to the caller
  +     *                             of the Macro helper (contained in the
  +     *                             MacroDeleteException.
  +     */
  +    public void beforeDelete(String targetUri) throws SlideException {
  +        
  +        if( Configuration.useVersionControl() ) {
  +            
  +            boolean destinationExists = false;
  +            NodeRevisionDescriptors revisionDescriptors = null;
  +            NodeRevisionDescriptor revisionDescriptor = null;
  +            try {
  +                revisionDescriptors = versioningHelper.retrieveRevisionDescriptors(targetUri);
  +                revisionDescriptor = versioningHelper.retrieveLatestRevisionDescriptor(targetUri, revisionDescriptors);
  +                destinationExists = true;
  +            }
  +            catch (ObjectNotFoundException e) {}
  +            
  +            if (destinationExists) {
  +                
  +                ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(revisionDescriptor);
  +                if (resourceKind instanceof CheckedInVersionControlled) {
  +                    
  +                    // check precondition DAV:cannot-modify-version-controlled-content
  +                    String autoVersion = versioningHelper.getAutoVersionElementName(revisionDescriptor);
  +                    if (autoVersion == null) {
  +                        autoVersion = "";
  +                    }
  +                    if ( !E_CHECKOUT_CHECKIN.equals(autoVersion) &&
  +                        !E_CHECKOUT_UNLOCKED_CHECKIN.equals(autoVersion) &&
  +                        !E_CHECKOUT.equals(autoVersion) &&
  +                        !E_LOCKED_CHECKOUT.equals(autoVersion) ) {
  +                        throw new PreconditionViolationException(new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION_CONTROLLED_CONTENT,
  +                                                                                          WebdavStatus.SC_FORBIDDEN), targetUri);
  +                    }
  +                    if ( E_LOCKED_CHECKOUT.equals(autoVersion) &&
  +                            ( !versioningHelper.isWriteLocked(slideToken, revisionDescriptors) ) ) {
  +                        throw new PreconditionViolationException(new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION_CONTROLLED_CONTENT,
  +                                                                                          WebdavStatus.SC_FORBIDDEN), targetUri);
  +                    }
  +                }
  +                
  +                // check precondition DAV:cannot-modify-version
  +                UriHandler uriHandler = UriHandler.getUriHandler(token, targetUri);
  +                if (uriHandler.isVersionUri()) {
  +                    throw new PreconditionViolationException(new ViolatedPrecondition(C_CANNOT_MODIFY_VERSION,
  +                                                                                      WebdavStatus.SC_FORBIDDEN), targetUri);
  +                }
  +                
  +                // checkout if necessary
  +                if( Configuration.useVersionControl() &&
  +                       (resourceKind instanceof CheckedInVersionControlled) &&
  +                   versioningHelper.mustCheckoutAutoVersionedVCR(revisionDescriptors, revisionDescriptor) ) {
  +                    
  +                    try {
  +                        versioningHelper.checkout(revisionDescriptors, revisionDescriptor, false, false, true );
  +                    }
  +                    catch (IOException e) {
  +                        throw new SlideException("Checkout failed: " + e.getMessage());
  +                    }
  +                    catch (JDOMException e) {
  +                        throw new SlideException("Checkout failed: " + e.getMessage());
  +                    }
  +                    catch (PreconditionViolationException e) {
  +                        e.printStackTrace();
  +                        System.out.println(e.getViolatedPrecondition());
  +                        throw e;
  +                    }
  +                }
  +                
  +                // store checked-out destinations in order to treat them correctly
  +                // in method afterCopy()
  +                NodeProperty checkedOutProperty = revisionDescriptor.getProperty(P_CHECKED_OUT);
  +                if ( (checkedOutProperty != null) && (checkedOutProperty.getValue() != null) ) {
  +                    checkedOutDestinationsMap.put(targetUri, checkedOutProperty.getValue().toString());
  +                }
  +            }
  +        }
  +    }
       
  +    /**
  +     * This method is called after deleting the resource associated by
  +     * the given <code>targetUri</code>.
  +     *
  +     * @param      targetUri       the Uri of the resource that has been deleted.
  +     *
  +     * @throws     SlideException  this Exception will be passed to the caller
  +     *                             of the Macro helper (contained in the
  +     *                     targetUricroDeleteException.
  +     */
  +    public void afterDelete(String targetUri) throws SlideException {
  +        
  +    }
   }
   
   
  
  
  

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