You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2002/05/08 09:23:21 UTC
cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method MoveMethod.java
juergen 02/05/08 00:23:21
Modified: src/webdav/server/org/apache/slide/webdav/method
MoveMethod.java
Log:
Implement pre- and postconditions of 'working resource' feature.
(ralf)
Revision Changes Path
1.36 +153 -8 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java
Index: MoveMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- MoveMethod.java 7 May 2002 13:00:52 -0000 1.35
+++ MoveMethod.java 8 May 2002 07:23:21 -0000 1.36
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v 1.35 2002/05/07 13:00:52 juergen Exp $
- * $Revision: 1.35 $
- * $Date: 2002/05/07 13:00:52 $
+ * $Header: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/MoveMethod.java,v 1.36 2002/05/08 07:23:21 juergen Exp $
+ * $Revision: 1.36 $
+ * $Date: 2002/05/08 07:23:21 $
*
* ====================================================================
*
@@ -75,8 +75,14 @@
import org.apache.slide.macro.*;
import org.apache.slide.lock.*;
import org.apache.slide.content.*;
+import org.apache.slide.search.SearchQuery;
+import org.apache.slide.search.SearchQueryResult;
+import org.apache.slide.search.Search;
+import org.apache.slide.search.RequestedResource;
+import org.apache.slide.search.BadQueryException;
import org.apache.slide.security.AccessDeniedException;
import org.apache.slide.structure.*;
+
import org.apache.slide.webdav.util.PreconditionViolationException;
import org.apache.slide.webdav.util.ViolatedPrecondition;
import org.apache.slide.webdav.util.UriHandler;
@@ -84,16 +90,20 @@
import org.apache.slide.webdav.util.XMLValue;
import org.apache.slide.webdav.util.VersioningHelper;
import org.apache.slide.webdav.util.PropertyHelper;
+import org.apache.slide.webdav.util.DaslConstants;
+import org.apache.slide.webdav.util.AbstractWebdavHelper;
import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
import org.apache.slide.webdav.util.resourcekind.ResourceKind;
import org.apache.slide.webdav.util.resourcekind.CheckedOutVersionControlled;
import org.apache.slide.webdav.util.resourcekind.DeltavCompliantUnmappedUrl;
import org.apache.slide.webdav.util.resourcekind.Workspace;
+import org.apache.slide.webdav.util.resourcekind.VersionControlled;
import org.apache.slide.util.Configuration;
import org.jdom.JDOMException;
+import org.jdom.Element;
import org.jdom.output.XMLOutputter;
@@ -117,10 +127,27 @@
protected PropertyHelper propertyHelper = null;
/**
- * Indicates if the source of the MOVE is a workspace.
+ * Indicates if the source of the MOVE request is a workspace.
+ */
+ protected boolean isRequestSourceWorkspace = false;
+
+ /**
+ * Indicates if the source of the current copy operation is a VCR.
+ * Used by {@link #beforeCopy beforeCopy()} and {@link #afterCopy afterCopy()}.
*/
- protected boolean isSourceWorkspace = false;
+ protected boolean isCopySourceVCR = false;
+ /**
+ * The Element returned by {@link #getWorkingResourceSearchElement
+ * getWorkingResourceSearchElement()}.
+ */
+ protected Element basicSearch = null;
+
+ /**
+ * The <literal> Element used in the basic search query returned by
+ * {@link #getWorkingResourceSearchElement getWorkingResourceSearchElement()}.
+ */
+ protected Element literal = null;
// ----------------------------------------------------------- Constructors
@@ -176,7 +203,7 @@
}
UriHandler sourceUriHandler = UriHandler.getUriHandler(token, sourceUri);
- isSourceWorkspace = sourceUriHandler.isWorkspaceUri();
+ isRequestSourceWorkspace = sourceUriHandler.isWorkspaceUri();
try {
// check preconditions
@@ -267,7 +294,7 @@
ViolatedPrecondition violatedPrecondition = null;
if( Configuration.useVersionControl() ) {
- if (isSourceWorkspace) {
+ if (isRequestSourceWorkspace) {
UriHandler destinationUriHandler = UriHandler.getUriHandler(token, destinationUri);
NodeRevisionDescriptors destinationRevisionDescriptors = null;
@@ -324,6 +351,20 @@
WebdavStatus.SC_FORBIDDEN),
sourceUri);
}
+ if (uriHandler.isWorkingresourceUri()) {
+ throw new PreconditionViolationException(new ViolatedPrecondition(DeltavConstants.C_CANNOT_RENAME_WORKING_RESOURCE,
+ WebdavStatus.SC_FORBIDDEN),
+ sourceUri);
+ }
+
+ NodeRevisionDescriptors sourceRevisionDescriptors =
+ versioningHelper.retrieveRevisionDescriptors(sourceUri);
+ NodeRevisionDescriptor sourceRevisionDescriptor =
+ versioningHelper.retrieveLatestRevisionDescriptor(sourceUri, sourceRevisionDescriptors);
+ ResourceKind resourceKind = AbstractResourceKind.determineResourceKind(token,
+ sourceRevisionDescriptors,
+ sourceRevisionDescriptor);
+ isCopySourceVCR = (resourceKind instanceof VersionControlled);
}
}
@@ -357,10 +398,114 @@
catch (SlideException e) {}
handleWorkspacePostconditions(destinationRevisionDescriptor, destinationUri);
+ handleWorkingResourcePostconditions(sourceUri, destinationUri);
}
}
/**
+ * Handles the working resource postconditions.
+ * <ul>
+ * <li>DAV:update-auto-update</li>
+ * </ul>
+ *
+ * @param sourceUri the Uri of the resource that has been copied.
+ * @param destinationUri the Uri of the copy.
+ *
+ * @throws SlideException
+ */
+ private void handleWorkingResourcePostconditions(String sourceUri, String destinationUri) throws SlideException {
+
+ if (isCopySourceVCR) {
+
+ Element basicSearch = getWorkingResourceSearchElement(sourceUri);
+ String grammarNamespace = basicSearch.getNamespaceURI();
+ Search searchHelper = token.getSearchHelper();
+ SearchQuery searchQuery = searchHelper.createSearchQuery(grammarNamespace,
+ basicSearch,
+ slideToken,
+ Integer.MAX_VALUE);
+ SearchQueryResult queryResult = searchHelper.search(slideToken, searchQuery);
+
+ Iterator queryResultIterator = queryResult.iterator();
+ RequestedResource requestedResource = null;
+ NodeRevisionDescriptors workingResourceRevisionDescriptors = null;
+ NodeRevisionDescriptor workingResourceRevisionDescriptor = null;
+ NodeProperty autoUpdateProperty = null;
+ String workingResourceUri = null;
+
+ while (queryResultIterator.hasNext()) {
+
+ requestedResource = (RequestedResource)queryResultIterator.next();
+ workingResourceUri = requestedResource.getInternalHref();
+ workingResourceRevisionDescriptors =
+ versioningHelper.retrieveRevisionDescriptors(workingResourceUri);
+ workingResourceRevisionDescriptor =
+ versioningHelper.retrieveLatestRevisionDescriptor(workingResourceUri,
+ workingResourceRevisionDescriptors);
+ autoUpdateProperty = new NodeProperty(P_AUTO_UPDATE,
+ propertyHelper.createHrefValue(destinationUri));
+ workingResourceRevisionDescriptor.setProperty(autoUpdateProperty);
+ content.store(slideToken,
+ workingResourceRevisionDescriptors.getUri(),
+ workingResourceRevisionDescriptor,
+ null);
+ }
+ }
+ }
+
+ /**
+ * Returns the query document used to search all resources that have
+ * a <auto-update> property with a <href> value containing
+ * the given <code>resourcePath</code>.
+ *
+ * @param resourcePath the Uri to search for.
+ *
+ * @return the query document.
+ */
+ private Element getWorkingResourceSearchElement(String resourcePath) {
+
+ if (basicSearch == null) {
+ basicSearch = new Element(DaslConstants.E_BASICSEARCH,
+ AbstractWebdavHelper.davNamespace);
+
+ Element select = new Element(DaslConstants.E_SELECT,
+ AbstractWebdavHelper.davNamespace);
+ basicSearch.addContent(select);
+ Element prop = new Element(E_PROP,
+ AbstractWebdavHelper.davNamespace);
+ select.addContent(prop);
+ Element autoUpdate = new Element(P_AUTO_UPDATE,
+ AbstractWebdavHelper.davNamespace);
+ prop.addContent(autoUpdate);
+
+ Element from = new Element(DaslConstants.E_FROM,
+ AbstractWebdavHelper.davNamespace);
+ basicSearch.addContent(from);
+ Element scope = new Element(DaslConstants.E_SCOPE,
+ AbstractWebdavHelper.davNamespace);
+ from.addContent(scope);
+ Element href = new Element(E_HREF,
+ AbstractWebdavHelper.davNamespace);
+ scope.addContent(href);
+ href.setText("/");
+
+ Element where = new Element(DaslConstants.E_WHERE,
+ AbstractWebdavHelper.davNamespace);
+ basicSearch.addContent(where);
+ Element propcontains = new Element(DaslConstants.E_PROPCONTAINS,
+ AbstractWebdavHelper.slideNamespace);
+ where.addContent(propcontains);
+ propcontains.addContent((Element)prop.clone());
+ literal = new Element(DaslConstants.E_LITERAL,
+ AbstractWebdavHelper.davNamespace);
+ propcontains.addContent(literal);
+ }
+ literal.setText(resourcePath);
+
+ return basicSearch;
+ }
+
+ /**
* Handles the workspace postconditions
* <ul>
* <li>DAV:workspace-moved</li>
@@ -376,7 +521,7 @@
if( Configuration.useVersionControl() ) {
- if (isSourceWorkspace) {
+ if (isRequestSourceWorkspace) {
// DAV:workspace-moved
revisionDescriptor.setProperty(new NodeProperty(P_WORKSPACE, propertyHelper.createHrefValue(this.destinationUri), true));
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>