pnever 02/04/29 09:51:08
Modified: src/webdav/server/org/apache/slide/webdav/util
VersioningHelper.java
Log:
- Adapted to changes determineResourceKind() method
- Modified checkout / checkin to return URI of created resource
Revision Changes Path
1.39 +145 -70
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.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- VersioningHelper.java 29 Apr 2002 13:22:19 -0000 1.38
+++ VersioningHelper.java 29 Apr 2002 16:51:08 -0000 1.39
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
1.38 2002/04/29 13:22:19 pnever Exp $
- * $Revision: 1.38 $
- * $Date: 2002/04/29 13:22:19 $
+ * $Header:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/util/VersioningHelper.java,v
1.39 2002/04/29 16:51:08 pnever Exp $
+ * $Revision: 1.39 $
+ * $Date: 2002/04/29 16:51:08 $
*
* ====================================================================
*
@@ -126,7 +126,7 @@
*/
public class VersioningHelper extends AbstractWebdavHelper {
-
+
/**
* The NodeRevisionNumber of the VCR backup needed for checkout-uncheckout.
*/
@@ -144,9 +144,9 @@
* Factory method.
*/
public static VersioningHelper
- getVersioningHelper( SlideToken sToken, NamespaceAccessToken nsaToken,
+ getVersioningHelper( SlideToken sToken, NamespaceAccessToken nsaToken,
HttpServletRequest req, HttpServletResponse resp,
WebdavServletConfig sConf ) {
-
+
return new VersioningHelper( sToken, nsaToken, req, resp, sConf );
}
@@ -173,7 +173,7 @@
*/
protected final String modifyContentUri;
-
+
/**
* Protected contructor
*/
@@ -207,7 +207,7 @@
* Retrieve the DeltaV-compliant NRDS instance for the specified resource path.
*/
public NodeRevisionDescriptors
- retrieveRevisionDescriptors( String resourcePath ) throws SlideException {
+ retrieveRevisionDescriptors( String resourcePath ) throws SlideException {
return retrieveRevisionDescriptors(nsaToken, sToken, content, resourcePath);
}
@@ -224,7 +224,7 @@
* resource path and associated to the specified NRDS instance.
*/
public NodeRevisionDescriptor
- retrieveLatestRevisionDescriptor( String resourcePath, NodeRevisionDescriptors
rNrds ) throws SlideException {
+ retrieveLatestRevisionDescriptor( String resourcePath,
NodeRevisionDescriptors rNrds ) throws SlideException {
return retrieveLatestRevisionDescriptor(nsaToken, sToken, content,
resourcePath, rNrds);
}
@@ -267,7 +267,7 @@
public NodeRevisionDescriptor retrieveLabeledRevision(String resourcePath,
String label) throws SlideException, LabeledRevisionNotFoundException {
return retrieveLabeledRevision(nsaToken, sToken, content, resourcePath,
label);
}
-
+
/**
* Set the specified resource under version control
*
@@ -282,7 +282,7 @@
NodeRevisionDescriptors rNrds = retrieveRevisionDescriptors( resourcePath );
NodeRevisionDescriptor rNrd = retrieveLatestRevisionDescriptor(
resourcePath, rNrds );
NodeRevisionContent rNrc = content.retrieve( sToken, rNrds, rNrd );
- ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
+ ResourceKind rRk = AbstractResourceKind.determineResourceKind(
resourcePath, rNrd );
if( !rRk.isSupportedMethod(req.getMethod()) ) {
resp.setStatus(WebdavStatus.SC_BAD_REQUEST);
@@ -405,8 +405,8 @@
}
catch( ObjectNotFoundException e ) {}; // can be ignored here!
- ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
- ResourceKind evRk = AbstractResourceKind.determineResourceKind( evNrd );
+ ResourceKind rRk = AbstractResourceKind.determineResourceKind(
resourcePath, rNrd );
+ ResourceKind evRk = AbstractResourceKind.determineResourceKind(
existingVersionPath, evNrd );
if( !(rRk instanceof DeltavCompliantUnmappedUrl) ) {
throw new PreconditionViolationException(
@@ -485,8 +485,8 @@
rNrd = retrieveLatestRevisionDescriptor( resourcePath, rNrds );
}
catch( ObjectNotFoundException e ) {}; // can be ignored here!
-
- ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
+
+ ResourceKind rRk = AbstractResourceKind.determineResourceKind(
resourcePath, rNrd );
if( !(rRk instanceof DeltavCompliantUnmappedUrl) ) {
throw new PreconditionViolationException(
@@ -500,7 +500,7 @@
resp.setStatus( WebdavStatus.SC_BAD_REQUEST );
throw new WebdavException( WebdavStatus.SC_BAD_REQUEST );
}
-
+
// Set initial ws properties
String wsUri = String.valueOf(rUh);
NodeRevisionDescriptor wsNrd =
@@ -528,17 +528,34 @@
}
/**
- * Checkout the specified resource
+ * Checkout a resource (for both: checkout-in-place and working-resource
features).
+ * @param resourcePath the request URI
+ * @param forkOk true, if the request body contained a DAV:fork-ok element
+ * @param applyToVersion true, if the request body contained a
DAV:apply-to-version element
+ * @return the URI of the created working resource, null if no resource was
created
+ * @throws SlideException
+ * @throws JDOMException
+ * @throws IOException
+ * @throws PreconditionViolatedException
*/
- public void checkout( String resourcePath, boolean forkOk, boolean
applyToVersion )
+ public String checkout( String resourcePath, boolean forkOk, boolean
applyToVersion )
throws SlideException, JDOMException, IOException,
PreconditionViolationException {
- checkout(resourcePath, forkOk, applyToVersion, false);
+ return checkout(resourcePath, forkOk, applyToVersion, false);
}
/**
- * Checkout the specified resource
+ * Checkout a resource (for both: checkout-in-place and working-resource
features).
+ * @param resourcePath the request URI
+ * @param forkOk true, if the request body contained a DAV:fork-ok element
+ * @param applyToVersion true, if the request body contained a
DAV:apply-to-version element
+ * @param isAutoVersionCheckout true, if this is an implicit request due to
auto-versioning
+ * @return the URI of the created working resource, null if no resource was
created
+ * @throws SlideException
+ * @throws JDOMException
+ * @throws IOException
+ * @throws PreconditionViolatedException
*/
- public void checkout( String resourcePath, boolean forkOk, boolean
applyToVersion, boolean isAutoVersionCheckout )
+ public String checkout( String resourcePath, boolean forkOk, boolean
applyToVersion, boolean isAutoVersionCheckout )
throws SlideException, JDOMException, IOException,
PreconditionViolationException {
UriHandler rUh = new UriHandler( nsaToken.getName(), resourcePath );
@@ -547,31 +564,52 @@
if( rUh.isVersionUri() ) {
NodeRevisionContent rNrc = content.retrieve( sToken, rNrds, rNrd );
- checkout( rNrds, rNrd, rNrc, forkOk, null ); // autoUpdateUri=null
+ return checkout( rNrds, rNrd, rNrc, forkOk, null ); //
autoUpdateUri=null
}
else {
- checkout( rNrds, rNrd, forkOk, applyToVersion, isAutoVersionCheckout);
- }
+ return checkout( rNrds, rNrd, forkOk, applyToVersion,
isAutoVersionCheckout);
+ }
}
/**
- * Checkout the specified resource
+ * Checkout a resource (for both: checkout-in-place and working-resource
features).
+ * @param rNrds the revision descriptors instance
+ * @param rNrd the revision descriptor instance
+ * @param forkOk true, if the request body contained a DAV:fork-ok element
+ * @param applyToVersion true, if the request body contained a
DAV:apply-to-version element
+ * @return the URI of the created working resource, null if no resource was
created
+ * @throws SlideException
+ * @throws JDOMException
+ * @throws IOException
+ * @throws PreconditionViolatedException
*/
- public void checkout( NodeRevisionDescriptors rNrds,
- NodeRevisionDescriptor rNrd, boolean forkOk, boolean applyToVersion )
+ public String checkout( NodeRevisionDescriptors rNrds,
+ NodeRevisionDescriptor rNrd, boolean forkOk, boolean
applyToVersion )
throws SlideException, JDOMException, IOException,
PreconditionViolationException {
- checkout(rNrds, rNrd, forkOk, applyToVersion, false);
+ return checkout(rNrds, rNrd, forkOk, applyToVersion, false);
}
/**
- * Checkout the specified resource
+ * Checkout a resource (for both: checkout-in-place and working-resource
features).
+ * Checkout a resource (for both: checkout-in-place and working-resource
features).
+ * @param rNrds the revision descriptors instance
+ * @param rNrd the revision descriptor instance
+ * @param forkOk true, if the request body contained a DAV:fork-ok element
+ * @param applyToVersion true, if the request body contained a
DAV:apply-to-version element
+ * @param isAutoVersionCheckout true, if this is an implicit request due to
auto-versioning
+ * @return the URI of the created working resource, null if no resource was
created
+ * @throws SlideException
+ * @throws JDOMException
+ * @throws IOException
+ * @throws PreconditionViolatedException
*/
- public void checkout( NodeRevisionDescriptors rNrds,
+ public String checkout( NodeRevisionDescriptors rNrds,
NodeRevisionDescriptor rNrd, boolean forkOk, boolean
applyToVersion, boolean isAutoVersionCheckout )
throws SlideException, JDOMException, IOException,
PreconditionViolationException {
Iterator i;
- ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
+ String rUri = getUri( rNrds, rNrd );
+ ResourceKind rRk = AbstractResourceKind.determineResourceKind( rUri, rNrd );
if( !rRk.isSupportedMethod(req.getMethod()) ) {
// check precondition C_MUST_BE_CHECKED_IN
@@ -596,9 +634,7 @@
// working resource feature
if( applyToVersion ) {
NodeRevisionContent cinNrc = content.retrieve( sToken, cinNrds,
cinNrd );
- String rUri = getUri( rNrds, rNrd );
- checkout( cinNrds, cinNrd, cinNrc, forkOk, rUri ); //
autoUpdateUri=rUri
- return;
+ return checkout( cinNrds, cinNrd, cinNrc, forkOk, rUri ); //
autoUpdateUri=rUri
}
ViolatedPrecondition violatedPrecondition =
getCheckoutPreconditionViolation(cinNrds, cinNrd, forkOk);
@@ -635,6 +671,7 @@
// Store changes
content.store( sToken, rNrds.getUri(), rNrd, null );
//revisionContent=null
+ return null;
}
else {
Domain.warn(
@@ -645,15 +682,26 @@
}
/**
- * Checkout the specified version (workingresource feature)
+ * Checkout a resource (working-resource features only).
+ * @param rNrds the revision descriptors instance associated to the version
being checked-out
+ * @param rNrd the revision descriptor instance associated to the version being
checked-out
+ * @param rNrc the revision content instance associated to the version being
checked-out
+ * @param forkOk true, if the request body contained a DAV:fork-ok element
+ * @param autoUpdateUri the URI of the VCR that will be updated when the WR
will be checked-in
+ * @return the URI of the created working resource
+ * @throws SlideException
+ * @throws JDOMException
+ * @throws IOException
+ * @throws PreconditionViolatedException
*/
- public void checkout( NodeRevisionDescriptors rNrds, NodeRevisionDescriptor
rNrd, NodeRevisionContent rNrc,
+ public String checkout( NodeRevisionDescriptors rNrds, NodeRevisionDescriptor
rNrd, NodeRevisionContent rNrc,
boolean forkOk, String autoUpdateUri )
- throws SlideException, JDOMException, IOException,
PreconditionViolationException {
+ throws SlideException, JDOMException, IOException,
PreconditionViolationException {
Iterator i;
Enumeration j;
- ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
+ String rUri = getUri( rNrds, rNrd );
+ ResourceKind rRk = AbstractResourceKind.determineResourceKind( rUri, rNrd );
if( !rRk.isSupportedMethod(req.getMethod()) ) {
// check precondition C_MUST_BE_CHECKED_IN
@@ -666,7 +714,6 @@
if( rRk instanceof Version ) {
- String rUri = getUri( rNrds, rNrd );
UriHandler rUh = new UriHandler( nsaToken.getName(), rUri );
String vhUri = rUh.getAssociatedHistoryUri();
@@ -682,13 +729,13 @@
String wrUri = String.valueOf( wrUh );
SubjectNode wrNode = new SubjectNode();
structure.create( sToken, wrNode, String.valueOf(wrUh) );
-
+
// set WR props
NodeRevisionDescriptor wrNrd = new NodeRevisionDescriptor();
i = pHelp.createInitialProperties(WorkingImpl.getInstance()).iterator();
while( i.hasNext() )
wrNrd.setProperty( (NodeProperty)i.next() );
-
+
// set specific live props
wrNrd.setProperty(
new NodeProperty(P_CHECKED_OUT, pHelp.createHrefValue(rUri)) );
@@ -715,7 +762,7 @@
else {
wrNrd.removeProperty( P_AUTO_UPDATE );
}
-
+
// Copy dead properties VR -> WR
j = rNrd.enumerateProperties();
while( j.hasMoreElements() ) {
@@ -726,6 +773,10 @@
}
content.create( sToken, wrUri, wrNrd, rNrc );
+
+ // Set status created
+ resp.setStatus( WebdavStatus.SC_CREATED );
+ return wrUri;
}
else {
Domain.warn(
@@ -764,8 +815,8 @@
if (E_FORBIDDEN.equals(checkoutForkElement.getName())) {
return new
ViolatedPrecondition(C_CHECKOUT_OF_VERSION_WITH_DESCENDANT_IS_FORBIDDEN,
WebdavStatus.SC_FORBIDDEN);
}
-
- // check precondition
C_CHECKOUT_OF_VERSION_WITH_DESCENDANT_IS_DISCOURAGED
+
+ // check precondition
C_CHECKOUT_OF_VERSION_WITH_DESCENDANT_IS_DISCOURAGED
else if (E_DISCOURAGED.equals(checkoutForkElement.getName()) &&
!isForkOk) {
return new
ViolatedPrecondition(C_CHECKOUT_OF_VERSION_WITH_DESCENDANT_IS_DISCOURAGED,
WebdavStatus.SC_CONFLICT);
}
@@ -774,15 +825,15 @@
// check if the version is already checked out
PropertyHelper propertyHelper = new PropertyHelper(sToken,
nsaToken);
XMLValue checkoutSetValue =
propertyHelper.computeCheckoutSet(cinNrds, cinNrd);
- if (checkoutSetValue.iterator().hasNext()) {
-
- // check precondition
C_CHECKOUT_OF_CHECKED_OUT_VERSION_IS_FORBIDDEN
- if (E_FORBIDDEN.equals(checkoutForkElement.getName())) {
+ if (checkoutSetValue.iterator().hasNext()) {
+
+ // check precondition
C_CHECKOUT_OF_CHECKED_OUT_VERSION_IS_FORBIDDEN
+ if (E_FORBIDDEN.equals(checkoutForkElement.getName())) {
return new
ViolatedPrecondition(C_CHECKOUT_OF_CHECKED_OUT_VERSION_IS_FORBIDDEN,
WebdavStatus.SC_FORBIDDEN);
- }
+ }
// check precondition
C_CHECKOUT_OF_CHECKED_OUT_VERSION_IS_DISCOURAGED
- else if
(E_DISCOURAGED.equals(checkoutForkElement.getName()) && !isForkOk) {
+ else if (E_DISCOURAGED.equals(checkoutForkElement.getName()) &&
!isForkOk) {
return new
ViolatedPrecondition(C_CHECKOUT_OF_CHECKED_OUT_VERSION_IS_DISCOURAGED,
WebdavStatus.SC_CONFLICT);
}
}
@@ -814,7 +865,8 @@
throws SlideException, JDOMException, IOException,
PreconditionViolationException {
Iterator i;
- ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
+ String rUri = getUri( rNrds, rNrd );
+ ResourceKind rRk = AbstractResourceKind.determineResourceKind( rUri, rNrd );
// check precondition C_MUST_BE_CHECKED_OUT_VERSION_CONTROLLED_RESOURCE
if ( ! (rRk instanceof CheckedOutVersionControlled) ) {
@@ -852,27 +904,45 @@
}
/**
- * Checkin the specified resource
+ * Checkin the specified resource (for both: checkout-in-place and
working-resource features).
+ * @param resourcePath the request URI
+ * @param forkOk true, if the request body contained a DAV:fork-ok element
+ * @param keepCheckedOut true, if the request body contained a
DAV:keep-checked-out element
+ * @return the URI of the created version resource
+ * @throws SlideException
+ * @throws JDOMException
+ * @throws IOException
+ * @throws PreconditionViolatedException
*/
- public void checkin( String resourcePath, boolean forkOk, boolean
keepCheckedOut )
+ public String checkin( String resourcePath, boolean forkOk, boolean
keepCheckedOut )
throws SlideException, JDOMException, IOException,
PreconditionViolationException {
NodeRevisionDescriptors rNrds = retrieveRevisionDescriptors( resourcePath );
NodeRevisionDescriptor rNrd = retrieveLatestRevisionDescriptor(
resourcePath, rNrds );
- checkin( rNrds, rNrd, forkOk, keepCheckedOut );
+ return checkin( rNrds, rNrd, forkOk, keepCheckedOut );
}
/**
- * Checkin the specified resource
+ * Checkin the specified resource (for both: checkout-in-place and
working-resource features).
+ * @param rNrds the revision descriptors instance
+ * @param rNrd the revision descriptor instance
+ * @param forkOk true, if the request body contained a DAV:fork-ok element
+ * @param keepCheckedOut true, if the request body contained a
DAV:keep-checked-out element
+ * @return the URI of the created version resource
+ * @throws SlideException
+ * @throws JDOMException
+ * @throws IOException
+ * @throws PreconditionViolatedException
*/
- public void checkin( NodeRevisionDescriptors rNrds,
- NodeRevisionDescriptor rNrd, boolean forkOk, boolean keepCheckedOut )
+ public String checkin( NodeRevisionDescriptors rNrds,
+ NodeRevisionDescriptor rNrd, boolean forkOk, boolean
keepCheckedOut )
throws SlideException, JDOMException, IOException,
PreconditionViolationException {
Iterator i;
Enumeration j;
NodeRevisionContent rNrc = content.retrieve( sToken, rNrds, rNrd );
- ResourceKind rRk = AbstractResourceKind.determineResourceKind( rNrd );
+ String rUri = getUri( rNrds, rNrd );
+ ResourceKind rRk = AbstractResourceKind.determineResourceKind( rUri, rNrd );
if( !rRk.isSupportedMethod(req.getMethod()) ) {
// check precondition C_MUST_BE_CHECKED_OUT
@@ -925,7 +995,7 @@
}
// Copy content-type VCR->VR
vrNrdNew.setContentType(rNrd.getContentType()); // P_GETCONTENTTYPE
-
+
content.create( sToken, vhrUri, vrNrdNew, rNrc );
String vrUriNew = vhrUri+"/"+vrNrdNew.getRevisionNumber().toString();
UriHandler vrUhNew = new UriHandler( nsaToken.getName(), vrUriNew );
@@ -943,7 +1013,7 @@
vhrNrd.setLastModified( new Date() ); // P_GETLASTMODIFIED
vhrNrd.setProperty( new NodeProperty(
- P_VERSION_SET,
((String)vSetProp.getValue())+pHelp.createHrefValue(vrUriNew)) );
+ P_VERSION_SET,
((String)vSetProp.getValue())+pHelp.createHrefValue(vrUriNew)) );
/* Content Type --end-- */
vrNrdNew.setName(vrUhNew.getVersionName() ); // P_DISPLAYNAME
vrNrdNew.setETag( vrUriNew.hashCode()+"_"+req.getContentLength() ); //
P_GETETAG
@@ -957,16 +1027,21 @@
content.store( sToken, rNrds.getUri(), rNrd, null );
//revisionContent=null
content.store( sToken, vhrUri, vhrNrd, null ); //revisionContent=null
content.store( sToken, vhrUri, vrNrdNew, null ); //revisionContent=null
+
+ // Set status created
+ resp.setStatus( WebdavStatus.SC_CREATED );
+ return vrUriNew;
}
else if( rRk instanceof Working ) {
Domain.info(
"Working resource feature NOT YET IMPLEMENTED" );
+ return null;
}
else {
Domain.warn(
"Do not know how to checkout a '"+rRk+"' resource" );
resp.setStatus(WebdavStatus.SC_CONFLICT);
- return;
+ return null;
}
}
@@ -1020,8 +1095,8 @@
if (E_FORBIDDEN.equals(checkinFork)) {
return new
ViolatedPrecondition(C_CHECKIN_FORK_FORBIDDEN, WebdavStatus.SC_FORBIDDEN);
}
-
- // check precondition C_CHECKIN_FORK_DISCOURAGED
+
+ // check precondition C_CHECKIN_FORK_DISCOURAGED
else if (E_DISCOURAGED.equals(checkinFork) && !isForkOk
) {
return new
ViolatedPrecondition(C_CHECKIN_FORK_DISCOURAGED, WebdavStatus.SC_CONFLICT);
}
@@ -1059,7 +1134,7 @@
* @throws SlideException
*/
public String getUri(NodeRevisionDescriptors revisionDescriptors,
- NodeRevisionDescriptor revisionDescriptor) throws
SlideException {
+ NodeRevisionDescriptor revisionDescriptor) throws
SlideException {
return getUri(nsaToken, sToken, content, revisionDescriptors,
revisionDescriptor);
}
@@ -1262,7 +1337,7 @@
destination.setProperty((NodeProperty)propertiesEnum.nextElement());
}
}
-
+
/**
* Returns the name of the element that represents the value of the
* <code><auto-version></code> property of the given
@@ -1301,7 +1376,7 @@
NodeRevisionDescriptor vcrRevisionDescriptor =
retrieveLatestRevisionDescriptor(resourceUri, vcrRevisionDescriptors);
return mustCheckoutAutoVersionedVCR(vcrRevisionDescriptors,
vcrRevisionDescriptor);
}
-
+
/**
* Indicates if the (VCR) reource be checked out prior to modifying it
* depending on its <code><auto-version></code> property.
@@ -1339,7 +1414,7 @@
NodeRevisionDescriptor vcrRevisionDescriptor =
retrieveLatestRevisionDescriptor(resourceUri, vcrRevisionDescriptors);
return mustCheckinAutoVersionedVCR(slideToken, vcrRevisionDescriptors,
vcrRevisionDescriptor);
}
-
+
/**
* Indicates if the (VCR) reource be checked in after modifying it
* depending on its <code><auto-version></code> property.
@@ -1729,18 +1804,18 @@
Content content,
NodeRevisionDescriptors revisionDescriptors,
NodeRevisionDescriptor revisionDescriptor) throws
SlideException {
-
+
StringBuffer uri = new StringBuffer();
UriHandler uriHandler = UriHandler.getUriHandler(nsaToken,
revisionDescriptors.getUri());
if ( ! uriHandler.isHistoryUri() ) {
// any resource
uri.append(revisionDescriptors.getUri());
- }
+ }
else {
if (revisionDescriptor.getRevisionNumber().equals(new
NodeRevisionNumber(0, 0))) {
// history resource
uri.append(revisionDescriptors.getUri());
- }
+ }
else {
// version resource
uri.append(revisionDescriptors.getUri());
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>