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 pn...@apache.org on 2003/08/25 17:51:08 UTC
cvs commit: jakarta-slide/src/webdav/server/org/apache/slide/webdav/method BindMethod.java CopyMethod.java MoveMethod.java RebindMethod.java UnbindMethod.java
pnever 2003/08/25 08:51:08
Modified: src/share/org/apache/slide/macro CopyListener.java
Macro.java MacroImpl.java
src/webdav/server/org/apache/slide/webdav/method
BindMethod.java CopyMethod.java MoveMethod.java
RebindMethod.java UnbindMethod.java
Log:
Fixed some problems WRT: COPY, MOVE and BIND
Revision Changes Path
1.3 +6 -6 jakarta-slide/src/share/org/apache/slide/macro/CopyListener.java
Index: CopyListener.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/macro/CopyListener.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CopyListener.java 25 Apr 2002 21:12:32 -0000 1.2
+++ CopyListener.java 25 Aug 2003 15:51:08 -0000 1.3
@@ -92,7 +92,7 @@
* of the Macro helper (contained in the
* MacroDeleteException.
*/
- public void beforeCopy(String sourceUri, String destinationUri) throws SlideException;
+ public void beforeCopy(String sourceUri, String destinationUri, boolean isRootOfCopy) throws SlideException;
/**
* This method is called after copying the resource to
@@ -105,7 +105,7 @@
* of the Macro helper (contained in the
* MacroDeleteException.
*/
- public void afterCopy(String sourceUri, String destinationUri) throws SlideException;
+ public void afterCopy(String sourceUri, String destinationUri, boolean isRootOfCopy) throws SlideException;
}
1.14 +5 -4 jakarta-slide/src/share/org/apache/slide/macro/Macro.java
Index: Macro.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/macro/Macro.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Macro.java 21 Aug 2003 14:48:22 -0000 1.13
+++ Macro.java 25 Aug 2003 15:51:08 -0000 1.14
@@ -80,6 +80,7 @@
new MacroParameters(true, true);
public final static String ALREADY_COPIED = "alreadyCopied";
+ public final static String PARENT_BINDINGS = "parentBindings";
// ------------------------------------------------------ Interface Methods
1.32 +60 -38 jakarta-slide/src/share/org/apache/slide/macro/MacroImpl.java
Index: MacroImpl.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/macro/MacroImpl.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- MacroImpl.java 21 Aug 2003 14:48:22 -0000 1.31
+++ MacroImpl.java 25 Aug 2003 15:51:08 -0000 1.32
@@ -239,34 +239,20 @@
}
// try to writeLock the complete destination tree
- synchronized( this ) {
- try {
- writeLock(token, destinationUri, true);
- }
- catch (SlideException x) {}; // ignore silently
+ try {
+ writeLock(token, destinationUri, true);
}
-
- if (parameters.isDeleteCreate()) {
- try {
- // We make sure the object we want to overwrite exists
- structureHelper.retrieve(token, destinationUri);
- delete(token, destinationUri, deleteRedirector, deleteListener);
- // TODO: remember parent-bindings, delete all mappings to the destination to really
- // delete, restore parent-bindings for new resource.
- } catch(ObjectNotFoundException onf) {
- // Silent catch, the target doesn't exist
- } catch(DeleteMacroException s) {
- throw s;
- } catch(SlideException s) {
- e.addException(s);
- throw e;
- }
+ catch( ServiceAccessException x ) {
+ e.addException(x);
+ throw e;
}
+ catch (SlideException x) {}; // ignore silently
Map alreadyCopied = new HashMap(); // maps source-UURI -> destination-URI
parameters.setParameter( ALREADY_COPIED, alreadyCopied );
- copyObject(token, sourceUri, destinationUri, parameters, e, copyRedirector, copyListener);
+ copyObject(token, sourceUri, destinationUri, parameters, true, e,
+ copyRedirector, copyListener, deleteRedirector, deleteListener);
// If there were errors, we throw the nested exception
if (!e.isEmpty()) {
@@ -290,7 +276,10 @@
ObjectNode onode = structureHelper.retrieve(token, uri);
if (onode != null && recursive) {
Iterator i = onode.getChildren().iterator();
- writeLock( token, (String)i.next(), true );
+ while (i.hasNext()) {
+ writeLock( token, (String)i.next(), true );
+ }
+
}
}
@@ -311,12 +300,14 @@
}
// try to writeLock the complete destination tree
- synchronized( this ) {
- try {
- writeLock(token, destinationUri, true);
- }
- catch (SlideException x) {}; // ignore silently
+ try {
+ writeLock(token, destinationUri, true);
}
+ catch( ServiceAccessException x ) {
+ e.addException(x);
+ throw e;
+ }
+ catch (SlideException x) {}; // ignore silently
if (parameters.isDeleteCreate()) {
try {
@@ -365,7 +356,7 @@
try {
// notify Listeners
if (copyListener != null) {
- copyListener.beforeCopy(sourceUri, destinationUri);
+ copyListener.beforeCopy(sourceUri, destinationUri, true);
}
structureHelper.addBinding( token, destinationParentNode, destinationSegment, sourceNode );
@@ -585,8 +576,10 @@
* @param CopyMacroException Exception occured during copy
*/
private void copyObject(SlideToken token, String sourceUri,
- String destinationUri, MacroParameters parameters, CopyMacroException e,
- CopyRouteRedirector copyRedirector, CopyListener copyListener) {
+ String destinationUri, MacroParameters parameters, boolean isRootOfCopy,
+ CopyMacroException e, CopyRouteRedirector copyRedirector, CopyListener copyListener,
+ DeleteTargetRedirector deleteRedirector, DeleteListener deleteListener
+ ) {
Domain.debug("Copy object : from " + sourceUri + " to "
+ destinationUri);
@@ -611,7 +604,34 @@
// notify CopyListener
if (copyListener != null) {
- copyListener.beforeCopy(sourceUri, destinationUri);
+ copyListener.beforeCopy(sourceUri, destinationUri, isRootOfCopy );
+ }
+
+ // delete target if it is the root of the copied tree
+ if (isRootOfCopy && parameters.isDeleteCreate()) {
+ try {
+ // We make sure the object we want to overwrite exists
+ structureHelper.retrieve(token, destinationUri);
+ if (parameters.getParameter(PARENT_BINDINGS) != null) {
+ Map parentBindings = (Map)parameters.getParameter(PARENT_BINDINGS);
+ Iterator i = parentBindings.entrySet().iterator();
+ while (i.hasNext()) {
+ Map.Entry me = (Map.Entry)i.next();
+ String uriToDelete = (String)me.getKey()+"/"+(String)me.getValue();
+ delete(token, uriToDelete, deleteRedirector, deleteListener);
+ }
+ }
+ else {
+ delete(token, destinationUri, deleteRedirector, deleteListener);
+ }
+ } catch(ObjectNotFoundException onf) {
+ // Silent catch, the target doesn't exist
+ } catch(DeleteMacroException s) {
+ throw s;
+ } catch(SlideException s) {
+ e.addException(s);
+ throw e;
+ }
}
boolean destinationExists = destinationExists(token, destinationUri);
@@ -698,7 +718,7 @@
// notify CopyListener
if (copyListener != null) {
- copyListener.afterCopy(sourceUri, destinationUri);
+ copyListener.afterCopy(sourceUri, destinationUri, isRootOfCopy);
}
// We copy each of this object's children
@@ -708,7 +728,9 @@
String childDestinationUri = destinationUri + childUri
.substring(sourceNode.getUri().length());
copyObject(token, childUri, childDestinationUri,
- parameters, e, copyRedirector, copyListener);
+ parameters, false, e, copyRedirector, copyListener,
+ deleteRedirector, deleteListener
+ );
}
} catch(SlideException ex) {
1.5 +17 -6 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/BindMethod.java
Index: BindMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/BindMethod.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BindMethod.java 18 Aug 2003 06:55:30 -0000 1.4
+++ BindMethod.java 25 Aug 2003 15:51:08 -0000 1.5
@@ -66,6 +66,8 @@
import java.io.IOException;
import java.util.List;
import org.apache.slide.common.NamespaceAccessToken;
+import org.apache.slide.common.ServiceAccessException;
+import org.apache.slide.common.SlideException;
import org.apache.slide.lock.ObjectLockedException;
import org.apache.slide.structure.CrossServerBindingException;
import org.apache.slide.structure.ObjectNode;
@@ -142,15 +144,24 @@
* @throws PreconditionViolationException
*
*/
- private void checkPreconditions() throws PreconditionViolationException {
+ private void checkPreconditions() throws PreconditionViolationException, ServiceAccessException {
resp.setStatus( WebdavStatus.SC_CREATED );
try {
collectionNode = structure.retrieve( slideToken, collectionUri );
- } catch (Exception e) {} // ignore silently
+ }
+ catch( ServiceAccessException e ) {
+ throw e;
+ }
+ catch (SlideException e) {} // ignore silently
+
try {
sourceNode = structure.retrieve( slideToken, sourceUri );
- } catch (Exception e) {} // ignore silently
+ }
+ catch( ServiceAccessException e ) {
+ throw e;
+ }
+ catch (Exception e) {} // ignore silently
if (collectionNode == null || !isCollection(collectionUri)) {
throw new PreconditionViolationException(
1.55 +70 -23 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java
Index: CopyMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/CopyMethod.java,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- CopyMethod.java 18 Aug 2003 06:57:37 -0000 1.54
+++ CopyMethod.java 25 Aug 2003 15:51:08 -0000 1.55
@@ -74,7 +74,6 @@
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.ServiceAccessException;
import org.apache.slide.common.SlideException;
-import org.apache.slide.common.Uri;
import org.apache.slide.content.BranchNotFoundException;
import org.apache.slide.content.NodeNotVersionedException;
import org.apache.slide.content.NodeProperty;
@@ -93,6 +92,7 @@
import org.apache.slide.macro.MacroParameters;
import org.apache.slide.security.AccessDeniedException;
import org.apache.slide.structure.LinkedObjectNotFoundException;
+import org.apache.slide.structure.ObjectNode;
import org.apache.slide.structure.ObjectNotFoundException;
import org.apache.slide.util.Configuration;
import org.apache.slide.webdav.WebdavException;
@@ -107,12 +107,15 @@
import org.apache.slide.webdav.util.VersioningHelper;
import org.apache.slide.webdav.util.ViolatedPrecondition;
import org.apache.slide.webdav.util.WebdavUtils;
+import org.apache.slide.webdav.util.XMLValue;
import org.apache.slide.webdav.util.resourcekind.AbstractResourceKind;
import org.apache.slide.webdav.util.resourcekind.CheckedInVersionControlled;
import org.apache.slide.webdav.util.resourcekind.ResourceKind;
import org.apache.slide.webdav.util.resourcekind.VersionableImpl;
import org.apache.util.WebdavStatus;
+import org.jdom.Element;
import org.jdom.JDOMException;
+import org.jdom.Namespace;
/**
* COPY Method.
@@ -211,7 +214,12 @@
content.retrieve(slideToken, destinationUri);
sendError = false;
}
- catch( Exception x ) {};
+ catch( ServiceAccessException x ) {
+ int statusCode = getErrorCode((SlideException)x);
+ sendError( statusCode, x );
+ throw new WebdavException( statusCode );
+ }
+ catch( SlideException x ) {};
}
if( sendError ) {
int statusCode = WebdavStatus.SC_FORBIDDEN;
@@ -220,20 +228,20 @@
}
}
- // compare resource types of source and destination
- boolean sameResourceType = isSameResourcetype();
-
- if (overwrite && sameResourceType) {
- macroParameters = new MacroParameters(true, true, false);
- }
- else if (overwrite && !sameResourceType) {
- macroParameters = new MacroParameters(true, true, true);
- }
- else {
- macroParameters = Macro.DEFAULT_PARAMETERS;
- }
-
try {
+ // compare resource types of source and destination
+ boolean sameResourceType = isSameResourcetype();
+
+ if (overwrite && sameResourceType) {
+ macroParameters = new MacroParameters(true, true, false);
+ }
+ else if (overwrite && !sameResourceType) {
+ macroParameters = new MacroParameters(true, true, true);
+ }
+ else {
+ macroParameters = Macro.DEFAULT_PARAMETERS;
+ }
+
boolean destinationExistsBefore = exists( destinationUri );
if (!overwrite && destinationExistsBefore) {
@@ -297,7 +305,7 @@
}
}
- private boolean isSameResourcetype() {
+ private boolean isSameResourcetype() throws ServiceAccessException {
boolean sameResourceType = false;
try {
NodeRevisionDescriptor sourceNrd =
@@ -307,7 +315,10 @@
sameResourceType =
sourceNrd.getResourceType().equals(destinationNrd.getResourceType());
}
- catch (Throwable e) {
+ catch (ServiceAccessException e) {
+ throw e;
+ }
+ catch (SlideException e) {
// ignore silently
}
return sameResourceType;
@@ -500,7 +511,7 @@
* of the Macro helper (contained in the
* MacroDeleteException.
*/
- public void beforeCopy(String sourceUri, String destinationUri) throws SlideException {
+ public void beforeCopy(String sourceUri, String destinationUri, boolean isRootOfCopy) throws SlideException {
if(Configuration.useVersionControl()) {
UriHandler sourceUh = UriHandler.getUriHandler(sourceUri);
@@ -513,6 +524,29 @@
beforeUpdateOrDelete( destinationUri );
}
}
+ if (isRootOfCopy && Configuration.useBinding(token.getUri(slideToken, destinationUri).getStore())) {
+ // collect the parent bindings of the destination node
+ Map parentBindings = new HashMap();
+ try {
+ NodeRevisionDescriptor destinationNrd =
+ content.retrieve( slideToken, content.retrieve(slideToken, destinationUri) );
+ XMLValue v = new XMLValue( (String)destinationNrd.getProperty( P_PARENT_SET ).getValue() );
+ Iterator i = v.iterator();
+ while (i.hasNext()) {
+ Namespace dnsp = Namespace.getNamespace(S_DAV);
+ Element parentElm = (Element)i.next();
+ String segment = parentElm.getChild(E_SEGMENT, dnsp).getTextTrim();
+ String href = parentElm.getChild(E_HREF, dnsp).getTextTrim();
+ parentBindings.put( href, segment );
+ }
+ }
+ catch( ServiceAccessException x ) {
+ throw x;
+ }
+ catch (SlideException e) {}
+ catch (JDOMException e) {}
+ macroParameters.setParameter( Macro.PARENT_BINDINGS, parentBindings );
+ }
}
/**
@@ -526,7 +560,7 @@
* of the Macro helper (contained in the
* MacroDeleteException.
*/
- public void afterCopy(String sourceUri, String destinationUri) throws SlideException {
+ public void afterCopy(String sourceUri, String destinationUri, boolean isRootOfCopy) throws SlideException {
if(Configuration.useVersionControl()) {
@@ -578,7 +612,20 @@
}
}
-
+ if (isRootOfCopy && Configuration.useBinding(token.getUri(slideToken, destinationUri).getStore())) {
+ // try to restore the parent bindings
+ if (macroParameters.getParameter(Macro.PARENT_BINDINGS) != null) {
+ Map parentBindings = (Map)macroParameters.getParameter(Macro.PARENT_BINDINGS);
+ Iterator i = parentBindings.entrySet().iterator();
+ while (i.hasNext()) {
+ Map.Entry me = (Map.Entry)i.next();
+ ObjectNode parentNode = structure.retrieve( slideToken, (String)me.getKey() );
+ ObjectNode destinationNode = structure.retrieve( slideToken, destinationUri );
+ String segment = (String)me.getValue();
+ structure.addBinding( slideToken, parentNode, segment, destinationNode );
+ }
+ }
+ }
}
1.59 +5 -5 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.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- MoveMethod.java 18 Aug 2003 06:57:37 -0000 1.58
+++ MoveMethod.java 25 Aug 2003 15:51:08 -0000 1.59
@@ -364,7 +364,7 @@
* of the Macro helper (contained in the
* MacroDeleteException.
*/
- public void beforeCopy(String sourceUri, String destinationUri) throws SlideException {
+ public void beforeCopy(String sourceUri, String destinationUri, boolean isRootOfCopy) throws SlideException {
if( Configuration.useVersionControl() ) {
@@ -425,7 +425,7 @@
* of the Macro helper (contained in the
* MacroDeleteException.
*/
- public void afterCopy(String sourceUri, String destinationUri) throws SlideException {
+ public void afterCopy(String sourceUri, String destinationUri, boolean isRootOfCopy) throws SlideException {
if( Configuration.useVersionControl() ) {
1.3 +23 -7 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/RebindMethod.java
Index: RebindMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/RebindMethod.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RebindMethod.java 18 Aug 2003 06:55:30 -0000 1.2
+++ RebindMethod.java 25 Aug 2003 15:51:08 -0000 1.3
@@ -66,6 +66,8 @@
import java.io.IOException;
import java.util.List;
import org.apache.slide.common.NamespaceAccessToken;
+import org.apache.slide.common.ServiceAccessException;
+import org.apache.slide.common.SlideException;
import org.apache.slide.lock.ObjectLockedException;
import org.apache.slide.structure.CrossServerBindingException;
import org.apache.slide.structure.ObjectNode;
@@ -145,7 +147,7 @@
overwrite = MethodUtil.getOverwriteHeader(req);
}
- private void checkPreconditions() throws PreconditionViolationException {
+ private void checkPreconditions() throws PreconditionViolationException, ServiceAccessException {
resp.setStatus( WebdavStatus.SC_CREATED );
UriHandler sourceUh = UriHandler.getUriHandler(sourceUri);
UriHandler sourceParentUh = sourceUh.getParentUriHandler();
@@ -156,13 +158,27 @@
try {
collectionNode = structure.retrieve( slideToken, collectionUri );
- } catch (Exception e) {} // ignore silently
+ }
+ catch( ServiceAccessException e ) {
+ throw e;
+ }
+ catch (SlideException e) {} // ignore silently
+
try {
sourceNode = structure.retrieve( slideToken, sourceUri );
- } catch (Exception e) {} // ignore silently
+ }
+ catch( ServiceAccessException e ) {
+ throw e;
+ }
+ catch (SlideException e) {} // ignore silently
+
try {
sourceParentNode = structure.retrieve( slideToken, sourceParentUri );
- } catch (Exception e) {} // ignore silently
+ }
+ catch( ServiceAccessException e ) {
+ throw e;
+ }
+ catch (SlideException e) {} // ignore silently
if (collectionNode == null || !isCollection(collectionUri)) {
throw new PreconditionViolationException(
1.4 +11 -5 jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UnbindMethod.java
Index: UnbindMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/method/UnbindMethod.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UnbindMethod.java 18 Aug 2003 06:55:30 -0000 1.3
+++ UnbindMethod.java 25 Aug 2003 15:51:08 -0000 1.4
@@ -66,6 +66,8 @@
import java.io.IOException;
import java.util.List;
import org.apache.slide.common.NamespaceAccessToken;
+import org.apache.slide.common.ServiceAccessException;
+import org.apache.slide.common.SlideException;
import org.apache.slide.lock.ObjectLockedException;
import org.apache.slide.structure.ObjectNode;
import org.apache.slide.webdav.WebdavException;
@@ -137,12 +139,16 @@
overwrite = MethodUtil.getOverwriteHeader(req);
}
- private void checkPreconditions() throws PreconditionViolationException {
+ private void checkPreconditions() throws PreconditionViolationException, ServiceAccessException {
resp.setStatus( WebdavStatus.SC_OK );
try {
collectionNode = structure.retrieve( slideToken, collectionUri );
- } catch (Exception e) {} // ignore silently
+ }
+ catch( ServiceAccessException e ) {
+ throw e;
+ }
+ catch (SlideException e) {} // ignore silently
if (collectionNode == null || !isCollection(collectionUri)) {
throw new PreconditionViolationException(