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/03 14:01:38 UTC

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

juergen     02/04/03 04:01:38

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        DeleteMethod.java
  Log:
  Implemented deltaV precondition DAV:no-version-delete.
  (ralf)
  
  Revision  Changes    Path
  1.15      +86 -8     jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/DeleteMethod.java
  
  Index: DeleteMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/DeleteMethod.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DeleteMethod.java	28 Mar 2002 06:12:12 -0000	1.14
  +++ DeleteMethod.java	3 Apr 2002 12:01:38 -0000	1.15
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/DeleteMethod.java,v 1.14 2002/03/28 06:12:12 jericho Exp $
  - * $Revision: 1.14 $
  - * $Date: 2002/03/28 06:12:12 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/DeleteMethod.java,v 1.15 2002/04/03 12:01:38 juergen Exp $
  + * $Revision: 1.15 $
  + * $Date: 2002/04/03 12:01:38 $
    *
    * ====================================================================
    *
  @@ -76,14 +76,25 @@
   import org.apache.slide.lock.*;
   import org.apache.slide.content.*;
   import org.apache.slide.security.AccessDeniedException;
  +import org.apache.slide.security.NodePermission;
   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.jdom.Element;
  +import org.jdom.JDOMException;
  +
  +import org.jdom.output.XMLOutputter;
   
   /**
    * DELETE method.
    *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    */
  -public class DeleteMethod extends AbstractMultistatusResponseMethod {
  +public class DeleteMethod extends AbstractMultistatusResponseMethod implements DeltavConstants, DeleteListener {
       
       
       // ----------------------------------------------------- Instance Variables
  @@ -94,6 +105,21 @@
        */
       private String toDelete;
       
  +    /**
  +     * The NodeRevisionDescriptors of the history of the deleted version.
  +     */
  +    protected NodeRevisionDescriptors historyNrds = null;
  +    
  +    /**
  +     * Indicates if the resource to delete is a collection.
  +     */
  +    protected boolean isCollection = false;
  +    
  +    /**
  +     * The UriHandler used by method {@link #beforeDelete beforeDelete()} and
  +     * {@link #afterDelete afterDelete()}.
  +     */
  +    protected UriHandler uriHandler = null;
       
       // ----------------------------------------------------------- Constructors
       
  @@ -139,9 +165,9 @@
           // Prevent dirty reads
           slideToken.setForceStoreEnlistment(true);
           
  -        boolean isCollection = isCollection(toDelete);
  +        isCollection = isCollection(toDelete);
           try {
  -            macro.delete(slideToken, toDelete);
  +            macro.delete(slideToken, toDelete, this);
               resp.setStatus(WebdavStatus.SC_NO_CONTENT);
           } catch (DeleteMacroException dme) {
               // If it's not a collection, we don't want to give a 207,
  @@ -152,6 +178,7 @@
                   // Write it on the servlet writer
                   resp.setStatus(WebdavStatus.SC_MULTI_STATUS);
                   try {
  +                    resp.setContentType(TEXT_XML_UTF_8);
                       resp.getWriter().write(errorMessage);
                   } catch(IOException ex) {
                       // Critical error ... Servlet container is dead or something
  @@ -163,8 +190,21 @@
                   // Returning 207 on non-collection requests is generally
                   // considered bad. So let's not do it, since this way
                   // makes clients generally behave better.
  -                resp.setStatus(
  -                    getErrorCode((SlideException)dme.enumerateExceptions().nextElement()));
  +                SlideException exception = (SlideException)dme.enumerateExceptions().nextElement();
  +                resp.setStatus(getErrorCode(exception));
  +                if (exception instanceof PreconditionViolationException) {
  +                    try {
  +                        StringWriter stringWriter = new StringWriter();
  +                        new XMLOutputter().output(getPreconditionViolationError((PreconditionViolationException)exception), stringWriter);
  +                        resp.setContentType(TEXT_XML_UTF_8);
  +                        resp.getWriter().write(stringWriter.toString());
  +                    } catch(IOException ex) {
  +                        // Critical error ... Servlet container is dead or something
  +                        ex.printStackTrace();
  +                        throw new WebdavException
  +                            (WebdavStatus.SC_INTERNAL_SERVER_ERROR);
  +                    }
  +                }
               }
               //
               // make sure the transaction is aborted
  @@ -174,6 +214,44 @@
           }
           
       }
  +    
  +    // ------------------------------------------------------ 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 {
  +        
  +        uriHandler = UriHandler.getUriHandler(token, targetUri);
  +        if (uriHandler.isVersionUri() && !isCollection) {
  +            // delete of version is only allowed if the history collection is deleted
  +            throw new PreconditionViolationException(new ViolatedPrecondition(C_NO_VERSION_DELETE,
  +                                                                              WebdavStatus.SC_FORBIDDEN),
  +                                                     targetUri);
  +        }
  +    }
  +    
  +    /**
  +     * This method is called after deleting the resource associated by
  +     * the given <code>targetUri</code>.
  +     *
  +     * @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 afterDelete(String targetUri) throws SlideException {
  +    }
  +    
       
   
   }
  
  
  

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