jakarta-slide-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From juer...@apache.org
Subject cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method AbstractMultistatusResponseMethod.java
Date Wed, 03 Apr 2002 11:58:21 GMT
juergen     02/04/03 03:58:21

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        AbstractMultistatusResponseMethod.java
  Log:
  Added support for precondition violation error response.
  (ralf)
  
  Revision  Changes    Path
  1.16      +73 -24    jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractMultistatusResponseMethod.java
  
  Index: AbstractMultistatusResponseMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractMultistatusResponseMethod.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- AbstractMultistatusResponseMethod.java	28 Mar 2002 06:12:12 -0000	1.15
  +++ AbstractMultistatusResponseMethod.java	3 Apr 2002 11:58:21 -0000	1.16
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractMultistatusResponseMethod.java,v
1.15 2002/03/28 06:12:12 jericho Exp $
  - * $Revision: 1.15 $
  - * $Date: 2002/03/28 06:12:12 $
  + * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/AbstractMultistatusResponseMethod.java,v
1.16 2002/04/03 11:58:21 juergen Exp $
  + * $Revision: 1.16 $
  + * $Date: 2002/04/03 11:58:21 $
    *
    * ====================================================================
    *
  @@ -78,6 +78,16 @@
   import org.apache.slide.security.AccessDeniedException;
   import org.apache.slide.structure.*;
   import org.apache.slide.webdav.util.WebdavUtils;
  +import org.apache.slide.webdav.util.PreconditionViolationException;
  +import org.apache.slide.webdav.util.ViolatedPrecondition;
  +import org.apache.slide.webdav.util.WebdavConstants;
  +
  +import org.jdom.Element;
  +import org.jdom.Document;
  +import org.jdom.Namespace;
  +import org.jdom.JDOMException;
  +
  +import org.jdom.output.XMLOutputter;
   
   /**
    * Abstract class for methods which return a multistatus error report, like
  @@ -86,7 +96,7 @@
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @author Juergen Pill
    */
  -public abstract class AbstractMultistatusResponseMethod extends WebdavMethod {
  +public abstract class AbstractMultistatusResponseMethod extends WebdavMethod implements
WebdavConstants  {
       
       
       // ----------------------------------------------------- Instance Variables
  @@ -228,28 +238,32 @@
       protected String generateErrorMessage
           (NestedSlideException nestedException) {
           
  -        XMLPrinter errorMessage = new XMLPrinter();
  -        
  -        errorMessage.writeXMLHeader();
  -        errorMessage.writeElement("d", NodeProperty.DEFAULT_NAMESPACE,
  -                                  "multistatus", XMLPrinter.OPENING);
  +        Element multistatus = new Element(E_MULTISTATUS,  Namespace.getNamespace(DEFAULT_NAMESPACE));
           
           Enumeration nestedExceptionsList =
               nestedException.enumerateExceptions();
           while (nestedExceptionsList.hasMoreElements()) {
               
  -            errorMessage.writeElement("d", "response", XMLPrinter.OPENING);
  +            Element response = new Element(E_RESPONSE,  Namespace.getNamespace(DEFAULT_NAMESPACE));
  +            multistatus.addContent(response);
               SlideException ex =
                   (SlideException) nestedExceptionsList.nextElement();
  -            generateStatusText(errorMessage, getErrorMessage(ex),
  +            generateStatusText(response, getErrorMessage(ex),
                                  getErrorCode(ex));
  -            errorMessage.writeElement("d", "response", XMLPrinter.CLOSING);
  +            if (ex instanceof PreconditionViolationException) {
  +                multistatus.addContent(getPreconditionViolationResponseDescription((PreconditionViolationException)ex));
  +            }
               
           }
           
  -        errorMessage.writeElement("d", "multistatus", XMLPrinter.CLOSING);
  -        
  -        return errorMessage.toString();
  +        StringWriter stringWriter = new StringWriter();
  +        try {
  +            new XMLOutputter().output(multistatus, stringWriter);
  +        }
  +        catch (IOException e) {
  +            Domain.log(e);
  +        }
  +        return stringWriter.toString();
           
       }
       
  @@ -257,19 +271,52 @@
       /**
        * Generate status text.
        *
  -     * @param printer XML Printer
  +     * @param parentElement  the parent Element to append to.
        * @param href Uri of the object
        * @param statusCode HTTP status code of the error
        */
  -    protected void generateStatusText(XMLPrinter printer, String href,
  -                                      int statusCode) {
  -        printer.writeElement("d", "href", XMLPrinter.OPENING);
  -        printer.writeText(WebdavUtils.encodeURL(href));
  -        printer.writeElement("d", "href", XMLPrinter.CLOSING);
  -        printer.writeElement("d", "status", XMLPrinter.OPENING);
  -        printer.writeText("HTTP/1.1 " + statusCode + " "
  +    protected void generateStatusText(Element parentElement, String href, int statusCode)
{
  +        
  +        Element hrefElement = new Element(E_HREF, Namespace.getNamespace(DEFAULT_NAMESPACE));
  +        parentElement.addContent(hrefElement);
  +        hrefElement.setText(WebdavUtils.encodeURL(href));
  +        Element statusElement = new Element(E_STATUS, Namespace.getNamespace(DEFAULT_NAMESPACE));
  +        parentElement.addContent(statusElement);
  +        statusElement.setText("HTTP/1.1 " + statusCode + " "
                                 + WebdavStatus.getStatusText(statusCode));
  -        printer.writeElement("d", "status", XMLPrinter.CLOSING);
  +    }
  +    
  +    
  +    /**
  +     * Generate &lt;responsedescription&gt; for the given precondition violation.
  +     *
  +     * @param pve the ProconditionViolationException that describes the violated
  +     *            precondition.
  +     *
  +     * @return the &lt;responsedescription&gt; for the given precondition violation.
  +     */
  +    protected Element getPreconditionViolationResponseDescription(PreconditionViolationException
pve) {
  +        
  +        Element responseDescription = new Element(E_RESPONSEDESCRIPTION, Namespace.getNamespace(DEFAULT_NAMESPACE));
  +        responseDescription.addContent(getPreconditionViolationError(pve));
  +        return responseDescription;
  +    }
  +    
  +    /**
  +     * Generate &lt;error&gt; for the given precondition violation.
  +     *
  +     * @param pve the ProconditionViolationException that describes the violated
  +     *            precondition.
  +     *
  +     * @return the &lt;error&gt; for the given precondition violation.
  +     */
  +    protected Element getPreconditionViolationError(PreconditionViolationException pve)
{
  +        
  +        Element error = new Element(E_ERROR, Namespace.getNamespace(DEFAULT_NAMESPACE));
  +        Element violatedPrecondition = new Element(pve.getViolatedPrecondition().getPrecondition(),
  +                                                   Namespace.getNamespace(DEFAULT_NAMESPACE));
  +        error.addContent(violatedPrecondition);
  +        return error;
       }
       
       
  @@ -338,6 +385,8 @@
           } catch(RevisionNotFoundException e) {
               return e.getObjectUri();
           } catch(ObjectLockedException e) {
  +            return e.getObjectUri();
  +        } catch(PreconditionViolationException e) {
               return e.getObjectUri();
           } catch(SlideException e) {
               return e.getMessage();
  
  
  

--
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