juergen     2002/08/09 02:16:44

  Modified:    src/webdav/server/org/apache/slide/webdav/method
                        PropPatchMethod.java
  Log:
  Send a <responsedescription> element in case of an error.
  Check values for properties that have a restricted set of supported values.
  (ralf)
  
  Revision  Changes    Path
  1.60      +84 -22    
jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java
  
  Index: PropPatchMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- PropPatchMethod.java      8 Aug 2002 10:34:17 -0000       1.59
  +++ PropPatchMethod.java      9 Aug 2002 09:16:43 -0000       1.60
  @@ -309,7 +309,7 @@
               while (propertyIterator.hasNext()) {
                   
                   currentProperty = (PropPatchProperty)propertyIterator.next();
  -                if (checkPropertyModification(currentProperty, revisionDescriptor)) 
{
  +                if (checkPropertyModification(currentProperty, revisionDescriptor, 
resourceKind)) {
                       NodeProperty newProperty =
                           new NodeProperty(currentProperty.getName(),
                                            currentProperty.getValue(),
  @@ -326,7 +326,7 @@
               while (propertyIterator.hasNext()) {
                   
                   currentProperty = (PropPatchProperty)propertyIterator.next();
  -                if (checkPropertyModification(currentProperty, revisionDescriptor)) 
{
  +                if (checkPropertyModification(currentProperty, revisionDescriptor, 
resourceKind)) {
                       revisionDescriptor.removeProperty(currentProperty.getName(),
                                                         
currentProperty.getNamespace());
                   }
  @@ -405,8 +405,9 @@
        *
        * @param property The property object
        * @param rd the revision descriptor containing all properties
  +     * @param resourceKind  the kind of the resource to patch.
        */
  -    private boolean checkPropertyModification(PropPatchProperty property, 
NodeRevisionDescriptor rd) {
  +    private boolean checkPropertyModification(PropPatchProperty property, 
NodeRevisionDescriptor rd, ResourceKind resourceKind) {
           
           boolean result = false;
           ViolatedPrecondition violatedPrecondition = 
getPropertySpecificPreconditionViolation(property);
  @@ -423,6 +424,17 @@
                   result = !originalProperty.isProtected();
               }
               
  +            if ( ! result ) {
  +                property.setErrorMessage("Property " + 
property.getQualifiedNameAsElementString() + " is protected");
  +            }
  +            
  +            if ( result && (property.getValue() != null) ) {
  +                if ( ! resourceKind.isSupportedPropertyValue(property.getName(), 
property.getValue()) ) {
  +                    property.setErrorMessage("Value " + property.getValue() + " is 
not supported by property " + property.getQualifiedNameAsElementString());
  +                    result = false;
  +                }
  +            }
  +            
               if (!result) property.setStatusCode(WebdavStatus.SC_CONFLICT);
           }
           return result;
  @@ -480,7 +492,14 @@
               Element propstat = createPropstatElement(property);
               response.addContent(propstat);
               if (property.getViolatedPrecondition() != null) {
  -                
propstat.addContent(getPreconditionViolationResponseDescription(property.getViolatedPrecondition()));
  +                Element responseDescription = new Element(E_RESPONSEDESCRIPTION, 
NamespaceCache.DEFAULT_NAMESPACE);
  +                
responseDescription.addContent(getPreconditionViolationError(property.getViolatedPrecondition()));
  +                propstat.addContent(responseDescription);
  +            }
  +            else if (property.getErrorMessage() != null) {
  +                Element responseDescription = new Element(E_RESPONSEDESCRIPTION, 
NamespaceCache.DEFAULT_NAMESPACE);
  +                responseDescription.addContent(property.getErrorMessage());
  +                propstat.addContent(responseDescription);
               }
           }
       }
  @@ -607,21 +626,6 @@
           return null;
       }
       
  -    /**
  -     * Generate &lt;responsedescription&gt; for the given precondition violation.
  -     *
  -     * @param preconditionViolation  the precondition that has been violated.
  -     *
  -     * @return the &lt;responsedescription&gt; for the given precondition violation.
  -     */
  -    protected Element 
getPreconditionViolationResponseDescription(ViolatedPrecondition 
preconditionViolation) {
  -        
  -        Element responseDescription = new Element(E_RESPONSEDESCRIPTION, 
NamespaceCache.DEFAULT_NAMESPACE);
  -        
responseDescription.addContent(getPreconditionViolationError(preconditionViolation));
  -        return responseDescription;
  -    }
  -    
  -    
       
       
       /**
  @@ -697,6 +701,20 @@
            */
           protected ViolatedPrecondition violatedPrecondition = null;
           
  +        /**
  +         * If the code returned by {@link #getStatusCode getStatusCode} is not
  +         * <code>200 (OK)</code> this String provides more details about the error.
  +         */
  +        protected String errorMessage = null;
  +        
  +        /**
  +         * Provides the qualified name of the property as an Element String,
  +         * i.e. if the name of the property is <code>munster</code> with
  +         * the namespace <code>DAV:</code> this String is
  +         * <code>&lt;munster xmlns="DAV:" /&gt;</code>.
  +         */
  +        protected String qualifiedNameAsElement = null;
  +        
           
           /**
            * Constructs a PropPatchProperty using the default namespace as defined
  @@ -759,6 +777,27 @@
           }
           
           /**
  +         * Sets the error message of this property.
  +         *
  +         * @param      errorMessage  the error message.
  +         *
  +         * @see #getErrorMessage
  +         */
  +        public void setErrorMessage(String errorMessage) {
  +            this.errorMessage = errorMessage;
  +        }
  +        
  +        /**
  +         * If the code returned by {@link #getStatusCode getStatusCode} is not
  +         * <code>200 (OK)</code> this String provides more details about the error.
  +         *
  +         * @return     the error message.
  +         */
  +        public String getErrorMessage() {
  +            return errorMessage;
  +        }
  +        
  +        /**
            * Sets the precondition that has been violated when trying to patch this
            * property. If the <code>violatedPrecondition</code> is not 
<code>null</code>
            * the status will be set to those of the ViolatedPrecondition.
  @@ -784,6 +823,29 @@
               return violatedPrecondition;
           }
           
  +        /**
  +         * Provides the qualified name of the property as an Element String,
  +         * i.e. if the name of the property is <code>munster</code> with
  +         * the namespace <code>DAV:</code> this method returns
  +         * <code>&lt;munster xmlns="DAV:" /&gt;</code>.
  +         *
  +         * @return     the qualified name of the property as an Element String
  +         */
  +        public String getQualifiedNameAsElementString() {
  +            if (qualifiedNameAsElement == null) {
  +                StringBuffer buffer = new StringBuffer();
  +                buffer.append("<");
  +                buffer.append(getName());
  +                if ( (getNamespace() != null) && (getNamespace().length() > 0) ) {
  +                    buffer.append(" xmlns=\"");
  +                    buffer.append(getNamespace());
  +                    buffer.append("\"");
  +                    buffer.append(" />");
  +                }
  +                qualifiedNameAsElement = buffer.toString();
  +            }
  +            return qualifiedNameAsElement;
  +        }
           
           /**
            * Returns a String representation of this instance.
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to