if( rRk instanceof CheckedOutVersionControlled || rRk instanceof Working ) {
boolean isWorkingResource = (rRk instanceof Working);
NodeProperty coutProp = rNrd.getProperty( P_CHECKED_OUT );
NodeProperty predSetProp = rNrd.getProperty( P_PREDECESSOR_SET );
NodeProperty autoUpdProp = rNrd.getProperty( P_AUTO_UPDATE );
// prepare auto-update
NodeRevisionDescriptors autoUpdNrds = null;
NodeRevisionDescriptor autoUpdNrd = null;
if( autoUpdProp != null ) {
Element autoUpdElm = pHelp.parsePropertyValue( (String)autoUpdProp.getValue() );
String autoUpdUri = autoUpdElm.getTextTrim();
autoUpdNrds = content.retrieve( sToken, autoUpdUri );
autoUpdNrd = content.retrieve( sToken, autoUpdNrds );
}
// Retrieve VHR
Element coutElm = pHelp.parsePropertyValue( (String)coutProp.getValue() );
String vrUriOld = coutElm.getTextTrim();
UriHandler vrUhOld = UriHandler.getUriHandler( vrUriOld );
NodeRevisionNumber vrNrnOld = new NodeRevisionNumber( vrUhOld.getVersionName() );
String vhrUri = vrUhOld.getAssociatedHistoryUri();
NodeRevisionDescriptors vhrNrds = content.retrieve( sToken, vhrUri );
NodeRevisionDescriptor vhrNrd = content.retrieve( sToken, vhrNrds ); //vhrUri
NodeProperty vSetProp = vhrNrd.getProperty( P_VERSION_SET );
// Retrieve old VR
NodeRevisionDescriptor vrNrdOld =
content.retrieve( sToken, vhrNrds, vrNrnOld ); // vrUriOld
// update the old VR's DAV:checkout-set property
if (!PropertyHelper.removeHrefFromProperty(vrNrdOld, P_CHECKOUT_SET, rUri)) {
StringBuffer b = new StringBuffer("Invalid path");
PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(sToken, nsaToken, sConf);
NodeProperty checkoutSetProp = propertyHelper.getProperty(P_CHECKOUT_SET, vhrNrds, vrNrdOld, req.getContextPath(), null);
if( checkoutSetProp != null && checkoutSetProp.getValue() != null ) {
XMLValue checkoutSetValue = new XMLValue( checkoutSetProp.getValue().toString() );
if (checkoutSetValue.iterator().hasNext()) {
b.append(" - please use "+checkoutSetValue.getTextValue()+" instead");
}
}
throw new ConflictException(
rUri, new SlideException(b.toString()));
}
content.store(sToken, vhrNrds.getUri(), vrNrdOld, null);
// check preconditions
ViolatedPrecondition violatedPrecondition =
getCheckinPreconditionViolation( predSetProp, vhrNrds, forkOk, autoUpdNrd );
if (violatedPrecondition != null) {
throw new PreconditionViolationException(violatedPrecondition, rUri);
}
// check forking
String forkBranch = getForkBranch(predSetProp, vhrNrds, forkOk);
NodeRevisionDescriptor vrNrdNew = null;
if (forkBranch != null) {
// Create a new branch
NodeRevisionNumber branchedRevisionNumber =
content.fork(sToken, vhrNrds.getUri(), forkBranch, vrNrdOld);
vhrNrds = content.retrieve( sToken, vhrUri );
vrNrdNew = content.retrieve(sToken, vhrNrds, branchedRevisionNumber);
vrNrdNew.setContentLength(rNrd.getContentLength());
}
else {
// Create new VR in the MAIN branch
vrNrdNew = new NodeRevisionDescriptor( rNrd.getContentLength() );
}
i = pHelp.createInitialProperties(VersionImpl.getInstance()).iterator();
while( i.hasNext() )
vrNrdNew.setProperty( (NodeProperty)i.next() );
// Copy dead properties VCR --> VR-new
j = rNrd.enumerateProperties();
while( j.hasMoreElements() ) {
NodeProperty p = (NodeProperty)j.nextElement();
if( p.isLiveProperty() )
continue;
if( !vrNrdNew.exists(p.getName()) )
vrNrdNew.setProperty( p );
}
// Copy specific live properties VCR/WR -> VR
vrNrdNew.setContentType(rNrd.getContentType()); // P_GETCONTENTTYPE
vrNrdNew.setContentLength(rNrd.getContentLength()); // P_GETCONTENTLENGTH
vrNrdNew.setContentLanguage( rNrd.getContentLanguage() ); // P_GETCONTENTLANGUAGE
String comment = (autoVersion ? "CREATED BY AUTO-VERSIONING. " : "");
if( rNrd.exists(P_COMMENT) )
comment += (String)rNrd.getProperty(P_COMMENT).getValue();
vrNrdNew.setProperty(
new NodeProperty(P_COMMENT, comment) );
vrNrdNew.setProperty( rNrd.getProperty(P_CHECKOUT_FORK) );
vrNrdNew.setProperty( rNrd.getProperty(P_CHECKIN_FORK) );
NodeRevisionContent rNrc = content.retrieve( sToken, rNrds, rNrd );
if (forkBranch != null) {
content.store(sToken, vhrUri, vrNrdNew, rNrc);
}
else {
String branch = vrNrdOld.getBranchName();
content.create( sToken, vhrUri, branch, vrNrdNew, rNrc );
}
// create new VR node
String vrUriNew = vhrUri+"/"+vrNrdNew.getRevisionNumber().toString();
UriHandler vrUhNew = UriHandler.getUriHandler( vrUriNew );
SubjectNode vrNodeNew = new SubjectNode();
structure.create( sToken, vrNodeNew, vrUriNew );
// set specific properties
if( keepCheckedOut ) {
rNrd.setProperty(
new NodeProperty(P_CHECKED_OUT, pHelp.createHrefValue(vrUriNew)) );
rNrd.setProperty(
new NodeProperty(P_PREDECESSOR_SET, "") );
PropertyHelper.addHrefToProperty(rNrd, P_PREDECESSOR_SET, vrUriNew);
PropertyHelper.addHrefToProperty(vrNrdNew, P_CHECKOUT_SET, rUri);
}
else {
if( !isWorkingResource ) {
rNrd.removeProperty( coutProp );
rNrd.setProperty(
new NodeProperty(P_CHECKED_IN, pHelp.createHrefValue(vrUriNew)) );
rNrd.removeProperty( I_CHECKIN_LOCKTOKEN , NamespaceCache.SLIDE_URI);
// retry with default (DAV:) namespace which was the
// former namespace of this property
rNrd.removeProperty( I_CHECKIN_LOCKTOKEN );
rNrd.removeProperty(P_PREDECESSOR_SET);
rNrd.removeProperty(P_CHECKOUT_FORK);
rNrd.removeProperty(P_CHECKIN_FORK);
}
}
vhrNrd.setLastModified( new Date() ); // P_GETLASTMODIFIED
vhrNrd.setProperty( new NodeProperty(
P_VERSION_SET, ((String)vSetProp.getValue())+pHelp.createHrefValue(vrUriNew)) );
vrNrdNew.setName( rNrd.getName() ); // P_DISPLAYNAME
vrNrdNew.setCreationDate( new Date() ); // P_CREATIONDATE
vrNrdNew.setLastModified( new Date() ); // P_GETLASTMODIFIED
vrNrdNew.setETag( PropertyHelper.computeEtag(vrUriNew, vrNrdNew) ); // P_GETETAG
vrNrdNew.setProperty(
new NodeProperty(P_VERSION_NAME, vrUhNew.getVersionName()) );
vrNrdNew.setProperty(
new NodeProperty(P_PREDECESSOR_SET, predSetProp.getValue()) );
// Store changes
if( keepCheckedOut || !isWorkingResource ) {
content.store( sToken, rUri, rNrd, null ); //revisionContent=null
try {