juergen 02/03/24 22:42:34
Modified: src/webdav/server/org/apache/slide/webdav/util
VersioningHelper.java
Log:
Fixed bugs in precodition checks.
(ralf)
Revision Changes Path
1.14 +79 -31
jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java
Index: VersioningHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- VersioningHelper.java 22 Mar 2002 06:40:55 -0000 1.13
+++ VersioningHelper.java 25 Mar 2002 06:42:34 -0000 1.14
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
1.13 2002/03/22 06:40:55 juergen Exp $
- * $Revision: 1.13 $
- * $Date: 2002/03/22 06:40:55 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
1.14 2002/03/25 06:42:34 juergen Exp $
+ * $Revision: 1.14 $
+ * $Date: 2002/03/25 06:42:34 $
*
* ====================================================================
*
@@ -352,7 +352,7 @@
NodeRevisionDescriptors cinNrds = content.retrieve(sToken, cinUri);
NodeRevisionDescriptor cinNrd = content.retrieve(sToken, cinNrds,
cinNrn);
- ViolatedPrecondition violatedPrecondition =
getCheckoutPreconditionViolation(cinNrd, cinNrds, forkOk);
+ ViolatedPrecondition violatedPrecondition =
getCheckoutPreconditionViolation(cinNrds, cinNrd, forkOk);
if (violatedPrecondition != null) {
throw new PreconditionViolationException(violatedPrecondition);
}
@@ -391,14 +391,14 @@
* the <code>CHECKOUT</code> methods has been violated, otherwise
* <code>null</code>.
*
- * @param cinNrd the NodeRevisionDescriptor of the VR to checkout.
* @param cinNrds the NodeRevisionDescriptors of the VR to checkout.
+ * @param cinNrd the NodeRevisionDescriptor of the VR to checkout.
* @param isForkOk indicates if <code><fork-ok></code> is set in
* the request content.
*
* @return the ViolatedPrecondition (if any).
*/
- private ViolatedPrecondition
getCheckoutPreconditionViolation(NodeRevisionDescriptor cinNrd,
NodeRevisionDescriptors cinNrds, boolean isForkOk) throws IllegalArgumentException,
IOException, JDOMException {
+ protected ViolatedPrecondition
getCheckoutPreconditionViolation(NodeRevisionDescriptors cinNrds,
NodeRevisionDescriptor cinNrd, boolean isForkOk) throws IllegalArgumentException,
IOException, JDOMException {
ViolatedPrecondition violatedPrecondition = null;
@@ -408,7 +408,8 @@
if (checkoutForkElement != null) {
// check if the version has successors
- if
(cinNrds.getSuccessors(cinNrd.getRevisionNumber()).hasMoreElements()) {
+ Enumeration successors =
cinNrds.getSuccessors(cinNrd.getRevisionNumber());
+ if ( (successors != null) && successors.hasMoreElements()) {
// check precondition
C_CHECKOUT_OF_VERSION_WITH_DESCENDANT_IS_FORBIDDEN
if (E_FORBIDDEN.equals(checkoutForkElement.getName())) {
@@ -634,7 +635,7 @@
*
* @return the ViolatedPrecondition (if any).
*/
- private ViolatedPrecondition getCheckinPreconditionViolation(NodeProperty
predSetProp, NodeRevisionDescriptors vhrNrds, boolean isForkOk) throws
LinkedObjectNotFoundException, ServiceAccessException, ObjectLockedException,
RevisionDescriptorNotFoundException, JDOMException, IllegalArgumentException,
ObjectNotFoundException, AccessDeniedException {
+ protected ViolatedPrecondition getCheckinPreconditionViolation(NodeProperty
predSetProp, NodeRevisionDescriptors vhrNrds, boolean isForkOk) throws
LinkedObjectNotFoundException, ServiceAccessException, ObjectLockedException,
RevisionDescriptorNotFoundException, JDOMException, IllegalArgumentException,
ObjectNotFoundException, AccessDeniedException {
ViolatedPrecondition violatedPrecondition = null;
@@ -651,7 +652,7 @@
// check precondition C_VERSION_HISTORY_IS_TREE
if ( !predecessorUriHandler.isVersionUri() ||
!vhrNrds.getUri().equals(predecessorUriHandler.getAssociatedHistoryUri()) ) {
- violatedPrecondition = new
ViolatedPrecondition(C_VERSION_HISTORY_IS_TREE, WebdavStatus.SC_FORBIDDEN);
+ return new ViolatedPrecondition(C_VERSION_HISTORY_IS_TREE,
WebdavStatus.SC_FORBIDDEN);
}
NodeRevisionNumber predecessorNrn = new
NodeRevisionNumber(predecessorUriHandler.getVersionName());
@@ -662,16 +663,19 @@
if (predecessorCheckinForkProperty != null) {
Enumeration predecessorSuccessors =
vhrNrds.getSuccessors(predecessorNrn);
- if ( (predecessorSuccessors != null) &&
(predecessorSuccessors.hasMoreElements()) ) {
+ if ( (predecessorSuccessors != null) &&
+ (predecessorSuccessors.hasMoreElements()) &&
+ (predecessorCheckinForkProperty.getValue() != null)
) {
+ String checkinFork =
getElementName(predecessorCheckinForkProperty.getValue().toString());
// check precondition C_CHECKIN_FORK_FORBIDDEN
- if
(E_FORBIDDEN.equals(predecessorCheckinForkProperty.getValue())) {
- violatedPrecondition = new
ViolatedPrecondition(C_CHECKIN_FORK_FORBIDDEN, WebdavStatus.SC_FORBIDDEN);
+ if (E_FORBIDDEN.equals(checkinFork)) {
+ return new
ViolatedPrecondition(C_CHECKIN_FORK_FORBIDDEN, WebdavStatus.SC_FORBIDDEN);
}
// check precondition C_CHECKIN_FORK_DISCOURAGED
- else if
(E_DISCOURAGED.equals(predecessorCheckinForkProperty.getValue()) && !isForkOk ) {
- violatedPrecondition = new
ViolatedPrecondition(C_CHECKIN_FORK_FORBIDDEN, WebdavStatus.SC_CONFLICT);
+ else if (E_DISCOURAGED.equals(checkinFork) && !isForkOk
) {
+ return new
ViolatedPrecondition(C_CHECKIN_FORK_DISCOURAGED, WebdavStatus.SC_CONFLICT);
}
}
}
@@ -692,7 +696,7 @@
* @throws JDOMException if parsing the <code><checkout-set></code>
* failed.
*/
- protected void addUriToCheckoutSet(NodeRevisionDescriptor nrd, String uri)
throws JDOMException {
+ protected static void addUriToCheckoutSet(NodeRevisionDescriptor nrd, String
uri) throws JDOMException {
NodeProperty checkoutSetProperty = nrd.getProperty(P_CHECKOUT_SET);
if (checkoutSetProperty == null) {
@@ -727,7 +731,7 @@
* @throws JDOMException if parsing the <code><checkout-set></code>
* failed.
*/
- protected void removeUriFromCheckoutSet(NodeRevisionDescriptor nrd, String uri)
throws JDOMException {
+ protected static void removeUriFromCheckoutSet(NodeRevisionDescriptor nrd,
String uri) throws JDOMException {
NodeProperty checkoutSetProperty = nrd.getProperty(P_CHECKOUT_SET);
if (checkoutSetProperty != null) {
@@ -750,28 +754,72 @@
}
/**
- ** Expects a String containing an XML Element like
- ** <code><example>value</example></code>
- ** and returns the text <code>value</code> of this element.
- ** If the String is not of the expected format, <code>null</code> is returned.
- **
- ** @pre true
- ** @post true
- **
- ** @param elementString the String containing an XML Element like
- **
<code><example>value</example></code>.
- **
- ** @return the text value of the Element given by the XML String.
- **/
+ * Expects a String containing an XML Element like
+ * <code><example>value</example></code>
+ * and returns the text <code>value</code> of this element.
+ * If the String is not of the expected format, <code>null</code> is returned.
+ *
+ * @pre true
+ * @post true
+ *
+ * @param elementString the String containing an XML Element like
+ * <code><example>value</example></code>.
+ *
+ * @return the text value of the Element given by the XML String.
+ */
public static String getElementValue(String elementString) {
String text = null;
+ Element element = getElement(elementString);
+ if (element != null) {
+ text = element.getText();
+ }
+ return text;
+ }
+
+ /**
+ * Expects a String containing an XML Element and returns the
+ * <code>name</code> of this element.
+ * If the String is not of the expected format, <code>null</code> is returned.
+ *
+ * @pre true
+ * @post true
+ *
+ * @param elementString the String containing an XML Element like
+ * <code><example>value</example></code>.
+ *
+ * @return the name of the Element given by the XML String.
+ */
+ public static String getElementName(String elementString) {
+
+ String name = null;
+ Element element = getElement(elementString);
+ if (element != null) {
+ name = element.getName();
+ }
+ return name;
+ }
+
+ /**
+ * Expects a String containing at least one XML Element and returns this
Element.
+ * If the String is not of the expected format, <code>null</code> is returned.
+ *
+ * @pre true
+ * @post true
+ *
+ * @param elementString the String containing an XML Element.
+ *
+ * @return the Element given by the XML String.
+ */
+ public static Element getElement(String elementString) {
+
+ Element element = null;
try {
Document document = getSAXBuilder().build(new
StringReader(elementString));
- text = document.getRootElement().getText();
+ element = document.getRootElement();
}
catch (JDOMException e) {}
- return text;
+ return element;
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>