juergen 02/05/27 00:34:02
Modified: src/webdav/server/org/apache/slide/webdav/method
PropPatchMethod.java
Log:
Fixed bug:
Send DeltaV precondition violation in a <responsedescription> element as part of the
multistatus response.
(ralf)
Revision Changes Path
1.49 +97 -48
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.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- PropPatchMethod.java 24 May 2002 05:19:40 -0000 1.48
+++ PropPatchMethod.java 27 May 2002 07:34:02 -0000 1.49
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v
1.48 2002/05/24 05:19:40 juergen Exp $
- * $Revision: 1.48 $
- * $Date: 2002/05/24 05:19:40 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/PropPatchMethod.java,v
1.49 2002/05/27 07:34:02 juergen Exp $
+ * $Revision: 1.49 $
+ * $Date: 2002/05/27 07:34:02 $
*
* ====================================================================
*
@@ -420,8 +420,15 @@
* @param rd the revision descriptor containing all properties
*/
private boolean checkPropertyModification(PropPatchProperty property,
NodeRevisionDescriptor rd) {
+
+ boolean result = false;
+ ViolatedPrecondition violatedPrecondition =
getPropertySpecificPreconditionViolation(property);
+ if (violatedPrecondition != null) {
+ property.setViolatedPrecondition(violatedPrecondition);
+ }
+ else {
+
NodeProperty originalProperty = rd.getProperty(property.getName(),
property.getNamespace());
- boolean result;
if (originalProperty == null) {
// those virtual live properties can not be modified
result = (!property.getName().equals(P_LOCKDISCOVERY)) &&
@@ -430,9 +437,9 @@
else {
result = !originalProperty.isProtected();
}
- if (!result) property.setStatus(WebdavStatus.SC_CONFLICT);
+ if (!result) property.setStatusCode(WebdavStatus.SC_CONFLICT);
+ }
return result;
-
}
@@ -451,21 +458,8 @@
response.addContent(href);
// Parse the two properties list, and printout their status
- Iterator propertyIterator = propertiesToSet.iterator();
-
- while(propertyIterator.hasNext()) {
- PropPatchProperty property = (PropPatchProperty)
propertyIterator.next();
- Element propstat = createPropstatElement(property);
- response.addContent(propstat);
- }
-
- propertyIterator = propertiesToRemove.iterator();
-
- while(propertyIterator.hasNext()) {
- PropPatchProperty property = (PropPatchProperty)
propertyIterator.next();
- Element propstat = createPropstatElement(property);
- response.addContent(propstat);
- }
+ addPropstatElements(propertiesToSet, response);
+ addPropstatElements(propertiesToRemove, response);
try {
resp.setContentType(TEXT_XML_UTF_8);
@@ -481,6 +475,29 @@
}
/**
+ * Adds the <code><propstat></code> elements for the given
+ * <code>properties</code> to the given <code><response></code>
+ * element.
+ *
+ * @param properties the PropPatchProperties for which to add the
+ * <code><propstat></code> elements.
+ * @param response the <code><response></code> element to add
+ * the <code><propstat></code> elements to.
+ */
+ private void addPropstatElements(PropPatchProperties properties, Element
response) {
+
+ Iterator propertyIterator = properties.iterator();
+ while(propertyIterator.hasNext()) {
+ PropPatchProperty property = (PropPatchProperty)
propertyIterator.next();
+ Element propstat = createPropstatElement(property);
+ response.addContent(propstat);
+ if (property.getViolatedPrecondition() != null) {
+
propstat.addContent(getPreconditionViolationResponseDescription(property.getViolatedPrecondition()));
+ }
+ }
+ }
+
+ /**
* Creates a <code><propstat></code> element for the given
* <code>property</code>.
*
@@ -503,8 +520,8 @@
prop.addContent(propertyElement);
Element status = new Element(E_STATUS, NamespaceCache.DEFAULT_NAMESPACE);
- status.setText("HTTP/1.1 " + property.status + " "
- + WebdavStatus.getStatusText(property.status));
+ status.setText("HTTP/1.1 " + property.statusCode + " "
+ + WebdavStatus.getStatusText(property.statusCode));
propstat.addContent(status);
return propstat;
}
@@ -572,17 +589,6 @@
}
}
- ViolatedPrecondition violatedPrecondition =
- checkPropertySpecificPreconditions(propertiesToSet);
- if (violatedPrecondition != null) {
- return violatedPrecondition;
- }
- violatedPrecondition =
- checkPropertySpecificPreconditions(propertiesToRemove);
- if (violatedPrecondition != null) {
- return violatedPrecondition;
- }
-
return null;
}
@@ -593,17 +599,12 @@
* <li><DAV:supported-live-property></li>
* </ul>
*
- * @param properties the PropPatchProperties to check.
+ * @param property the PropPatchProperty to check.
*
* @return the precondition that has been violated (if any,
* otherwise <code>null</code>).
*/
- private ViolatedPrecondition
checkPropertySpecificPreconditions(PropPatchProperties properties) {
-
- Iterator iterator = properties.iterator();
- PropPatchProperty property = null;
- while (iterator.hasNext()) {
- property = (PropPatchProperty)iterator.next();
+ private ViolatedPrecondition
getPropertySpecificPreconditionViolation(PropPatchProperty property) {
// check precondition DAV:cannot-modify-protected-property
if ( AbstractResourceKind.isProtectedProperty(property.getName()) &&
@@ -614,12 +615,27 @@
// check precondition DAV:supported-live-property
// ...is there any property to check here yet ?
- }
return null;
+ }
+
+ /**
+ * Generate <responsedescription> for the given precondition violation.
+ *
+ * @param preconditionViolation the precondition that has been violated.
+ *
+ * @return the <responsedescription> 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;
}
+
+
/**
* An extension of the RequestedProperties class manages PropPatchProperty
* instead of RequestedProperty.
@@ -683,7 +699,13 @@
/**
* The status of the PropPatch operation on this property.
*/
- protected int status = WebdavStatus.SC_OK;
+ protected int statusCode = WebdavStatus.SC_OK;
+
+ /**
+ * The precondition that has been violated when trying to patch this
+ * property.
+ */
+ protected ViolatedPrecondition violatedPrecondition = null;
/**
@@ -730,10 +752,11 @@
/**
* Sets the status of the PropPatch operation on this property.
*
- * @param status the status of the PropPatch operation on this
property.
+ * @param statusCode the status code of the PropPatch operation
+ * on this property.
*/
- public void setStatus(int status) {
- this.status = status;
+ public void setStatusCode(int statusCode) {
+ this.statusCode = statusCode;
}
/**
@@ -741,8 +764,34 @@
*
* @return the status of the PropPatch operation on this property.
*/
- public int getStatus() {
- return status;
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ /**
+ * 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.
+ *
+ * @param violatedPrecondition the precondition that has been violated
+ * when trying to patch this property.
+ */
+ public void setViolatedPrecondition(ViolatedPrecondition
violatedPrecondition) {
+ this.violatedPrecondition = violatedPrecondition;
+ if (violatedPrecondition != null) {
+ setStatusCode(violatedPrecondition.getStatusCode());
+ }
+ }
+
+ /**
+ * Returns the precondition that has been violated when trying to patch
+ * this property.
+ *
+ * @return the precondition that has been violated when trying to
+ * patch this property.
+ */
+ public ViolatedPrecondition getViolatedPrecondition() {
+ return violatedPrecondition;
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>