juergen 2002/06/25 03:50:38
Modified: src/webdav/server/org/apache/slide/webdav/util
VersioningHelper.java
Log:
Implemented missing VERSION-CONTROL precondition
<DAV:one-version-controlled-resource-per-history-per-workspace>.
(ralf)
Revision Changes Path
1.58 +136 -13
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.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- VersioningHelper.java 24 Jun 2002 07:43:56 -0000 1.57
+++ VersioningHelper.java 25 Jun 2002 10:50:38 -0000 1.58
@@ -102,6 +102,12 @@
import org.apache.slide.macro.Macro;
import org.apache.slide.macro.DeleteMacroException;
+import org.apache.slide.search.Search;
+import org.apache.slide.search.SearchQuery;
+import org.apache.slide.search.SearchQueryResult;
+
+import org.apache.slide.search.basic.Literals;
+
import org.apache.slide.security.AccessDeniedException;
import org.apache.slide.structure.Structure;
@@ -163,6 +169,7 @@
private HttpServletResponse resp = null;
private WebdavServletConfig sConf = null;
private PropertyHelper pHelp = null;
+ private String serverURL = null;
/**
* The URI of the <code>modifyRevisionMetadataAction</code>.
@@ -203,6 +210,7 @@
else {
modifyContentUri = "";
}
+ serverURL = "http://" + req.getServerName()+ ":" + req.getServerPort();
}
/**
@@ -395,16 +403,16 @@
}
catch( ObjectNotFoundException e ) {}; // can be ignored here!
- ResourceKind rRk = AbstractResourceKind.determineResourceKind( nsaToken,
resourcePath, rNrd );
- ResourceKind evRk = AbstractResourceKind.determineResourceKind( nsaToken,
existingVersionPath, evNrd );
-
- if( !(rRk instanceof DeltavCompliantUnmappedUrl) ) {
- throw new PreconditionViolationException(
- new ViolatedPrecondition(C_CANNOT_ADD_TO_EXISTING_HISTORY,
WebdavStatus.SC_CONFLICT), resourcePath);
- }
- if( !(evRk instanceof Version) || evNrd == null) {
- throw new PreconditionViolationException(
- new ViolatedPrecondition(C_MUST_BE_VERSION,
WebdavStatus.SC_CONFLICT), resourcePath);
+ ViolatedPrecondition violatedPrecondition =
+ getVersionControlPreconditionViolation(resourcePath,
+ rNrd,
+ rUh,
+ existingVersionPath,
+ evNrd,
+ evUh);
+ if (violatedPrecondition != null) {
+ throw new PreconditionViolationException(violatedPrecondition,
+ resourcePath);
}
// create the VCR
@@ -438,6 +446,121 @@
// Set status created
resp.setStatus( WebdavStatus.SC_CREATED );
+ }
+
+ /**
+ * Returns the precondition that might have been violated on an attempt to
create
+ * a new VCR in a workspace for an existing version history.
+ * The following precondtions are checked:
+ * <ul>
+ * <li><DAV:cannot-add-to-existing-history></li>
+ * <li><DAV:must-be-version></li>
+ *
<li><DAV:one-version-controlled-resource-per-history-per-workspace></li>
+ * </ul>
+ *
+ * @param resourcePath the path of the resource.
+ * @param resourceNrd the NodeRevisionDescriptor of the
resource.
+ * @param resourceUriHandler the UriHandler of the resource.
+ * @param existingVersionPath the path of the existing version.
+ * @param existingVersionNrd the NodeRevisionDescriptor of the
existing version.
+ * @param existingVersionUriHandler the UriHandler of the existing
version.
+ *
+ * @return the precondition that has been violated (if any).
+ *
+ * @throws SlideException
+ */
+ public ViolatedPrecondition getVersionControlPreconditionViolation(String
resourcePath,
+
NodeRevisionDescriptor resourceNrd,
+ UriHandler
resourceUrihandler,
+ String
existingVersionPath,
+
NodeRevisionDescriptor existingVersionNrd,
+ UriHandler
existingVersionUrihandler) throws SlideException {
+
+ ResourceKind rRk = AbstractResourceKind.determineResourceKind( nsaToken,
resourcePath, resourceNrd );
+ ResourceKind evRk = AbstractResourceKind.determineResourceKind( nsaToken,
existingVersionPath, existingVersionNrd );
+
+ if( !(rRk instanceof DeltavCompliantUnmappedUrl) ) {
+ return new ViolatedPrecondition(C_CANNOT_ADD_TO_EXISTING_HISTORY,
WebdavStatus.SC_CONFLICT);
+ }
+ if( !(evRk instanceof Version) || existingVersionNrd == null) {
+ return new ViolatedPrecondition(C_MUST_BE_VERSION,
WebdavStatus.SC_CONFLICT);
+ }
+
+
+ Element basicSearch =
getResourcesWithVersionHistoryQueryElement(resourceUrihandler.getAssociatedWorkspaceUri(),
+
existingVersionUrihandler.getAssociatedHistoryUri());
+ String grammarNamespace = basicSearch.getNamespaceURI();
+ Search searchHelper = nsaToken.getSearchHelper();
+ SearchQuery searchQuery = searchHelper.createSearchQuery(grammarNamespace,
+ basicSearch,
+ sToken,
+ Integer.MAX_VALUE);
+ SearchQueryResult queryResult = searchHelper.search(sToken, searchQuery);
+ Iterator queryResultIterator = queryResult.iterator();
+ if (queryResultIterator.hasNext()) {
+ return new
ViolatedPrecondition(C_ONE_VERSION_CONTROLLED_RESOURCE_PER_HISTORY_PER_WORKSPACE,
+ WebdavStatus.SC_CONFLICT);
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the query document used to search all resources in the given
+ * <code>scope</code> that have either a <checked-in> or
<checked-out>
+ * property with a <href> value containing the URI that identifies a
+ * version of the given history.
+ *
+ * @param scope the scope of the search.
+ * @param historyPath the Uri of the history.
+ *
+ * @return the query document.
+ */
+ protected Element getResourcesWithVersionHistoryQueryElement(String scope,
String historyPath) {
+
+ Element resourcesWithVersionHistoryQueryElement = new
Element(DaslConstants.E_BASICSEARCH, NamespaceCache.DEFAULT_NAMESPACE);
+
+ Element select = new Element(DaslConstants.E_SELECT,
NamespaceCache.DEFAULT_NAMESPACE);
+ resourcesWithVersionHistoryQueryElement.addContent(select);
+ Element prop = new Element(E_PROP, NamespaceCache.DEFAULT_NAMESPACE);
+ select.addContent(prop);
+ Element checkedIn = new Element(P_CHECKED_IN,
NamespaceCache.DEFAULT_NAMESPACE);
+ prop.addContent(checkedIn);
+ Element checkedOut = new Element(P_CHECKED_OUT,
NamespaceCache.DEFAULT_NAMESPACE);
+ prop.addContent(checkedOut);
+
+ Element from = new Element(DaslConstants.E_FROM,
NamespaceCache.DEFAULT_NAMESPACE);
+ resourcesWithVersionHistoryQueryElement.addContent(from);
+ Element scopeElement = new Element(DaslConstants.E_SCOPE,
NamespaceCache.DEFAULT_NAMESPACE);
+ from.addContent(scopeElement);
+ Element href = new Element(E_HREF, NamespaceCache.DEFAULT_NAMESPACE);
+ scopeElement.addContent(href);
+ href.setText(scope);
+
+ Element where = new Element(DaslConstants.E_WHERE,
NamespaceCache.DEFAULT_NAMESPACE);
+ resourcesWithVersionHistoryQueryElement.addContent(where);
+ Element or = new Element(Literals.OR, NamespaceCache.DEFAULT_NAMESPACE);
+ where.addContent(or);
+
+ Element propcontains = new Element(DaslConstants.E_PROPCONTAINS,
NamespaceCache.SLIDE_NAMESPACE);
+ or.addContent(propcontains);
+ prop = new Element(E_PROP, NamespaceCache.DEFAULT_NAMESPACE);
+ propcontains.addContent(prop);
+ prop.addContent((Element)checkedIn.clone());
+ Element literal = new Element(DaslConstants.E_LITERAL,
NamespaceCache.DEFAULT_NAMESPACE);
+ propcontains.addContent(literal);
+ literal.setText(historyPath);
+
+ propcontains = new Element(DaslConstants.E_PROPCONTAINS,
NamespaceCache.SLIDE_NAMESPACE);
+ or.addContent(propcontains);
+ prop = new Element(E_PROP, NamespaceCache.DEFAULT_NAMESPACE);
+ propcontains.addContent(prop);
+ prop.addContent((Element)checkedOut.clone());
+ literal = new Element(DaslConstants.E_LITERAL,
NamespaceCache.DEFAULT_NAMESPACE);
+ propcontains.addContent(literal);
+ literal.setText(historyPath);
+
+ return resourcesWithVersionHistoryQueryElement;
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>