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/04 08:26:35 UTC

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

juergen     02/04/03 22:26:35

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        MoveMethod.java
  Log:
  Implemented precondition check for Deltav.
  (ralf)
  
  Revision  Changes    Path
  1.22      +69 -7     jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java
  
  Index: MoveMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- MoveMethod.java	28 Mar 2002 06:12:12 -0000	1.21
  +++ MoveMethod.java	4 Apr 2002 06:26:35 -0000	1.22
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v 1.21 2002/03/28 06:12:12 jericho Exp $
  - * $Revision: 1.21 $
  - * $Date: 2002/03/28 06:12:12 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v 1.22 2002/04/04 06:26:35 juergen Exp $
  + * $Revision: 1.22 $
  + * $Date: 2002/04/04 06:26:35 $
    *
    * ====================================================================
    *
  @@ -77,6 +77,12 @@
   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.jdom.output.XMLOutputter;
   
   /**
    * MOVE Method.
  @@ -84,7 +90,7 @@
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @author Juergen Pill
    */
  -public class MoveMethod extends AbstractMultistatusResponseMethod {
  +public class MoveMethod extends AbstractMultistatusResponseMethod implements CopyListener {
       
       
       
  @@ -129,7 +135,7 @@
           }
           
           try {
  -            macro.move(slideToken, sourceUri, destinationUri, macroParameters);
  +            macro.move(slideToken, sourceUri, destinationUri, macroParameters, this, null);
               if (overwrite) {
                   resp.setStatus(WebdavStatus.SC_NO_CONTENT);
               } else {
  @@ -141,6 +147,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
  @@ -151,8 +158,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)e.enumerateExceptions().nextElement()));
  +                SlideException exception = (SlideException)e.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 +194,48 @@
           } catch (SlideException e) {
               return super.getErrorCode(e);
           }
  +    }
  +    
  +    /**
  +     * 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.isVersionUri()) {
  +            throw new PreconditionViolationException(new ViolatedPrecondition(DeltavConstants.C_CANNOT_RENAME_VERSION,
  +                                                                              WebdavStatus.SC_FORBIDDEN),
  +                                                     sourceUri);
  +        }
  +        if (uriHandler.isHistoryUri()) {
  +            throw new PreconditionViolationException(new ViolatedPrecondition(DeltavConstants.C_CANNOT_RENAME_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 {
  +        
       }
       
       
  
  
  

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