use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent in project xwiki-platform by xwiki.
the class XWikiDocumentArchive method removeVersions.
/**
* Remove document versions from vfrom to vto, inclusive.
*
* @param newerVersion - start version
* @param olderVersion - end version
* @param context - used for loading nodes content
* @throws XWikiException if any error
*/
public void removeVersions(Version newerVersion, Version olderVersion, XWikiContext context) throws XWikiException {
Version upperBound = newerVersion;
Version lowerBound = olderVersion;
if (upperBound.compareVersions(lowerBound) < 0) {
Version tmp = upperBound;
upperBound = lowerBound;
lowerBound = tmp;
}
Version firstVersionAfter = getNextVersion(upperBound);
Version firstVersionBefore = getPrevVersion(lowerBound);
if (firstVersionAfter == null && firstVersionBefore == null) {
resetArchive();
return;
}
if (firstVersionAfter == null) {
// Deleting the most recent version.
// Store full version in firstVersionBefore
String xmlBefore = getVersionXml(firstVersionBefore, context);
XWikiRCSNodeInfo niBefore = getNode(firstVersionBefore);
XWikiRCSNodeContent ncBefore = niBefore.getContent(context);
ncBefore.getPatch().setFullVersion(xmlBefore);
niBefore.setContent(ncBefore);
updateNode(niBefore);
getUpdatedNodeContents().add(ncBefore);
} else if (firstVersionBefore != null) {
// We're not deleting from the first version, so we must make a new diff jumping over
// the deleted versions.
String xmlAfter = getVersionXml(firstVersionAfter, context);
String xmlBefore = getVersionXml(firstVersionBefore, context);
XWikiRCSNodeInfo niBefore = getNode(firstVersionBefore);
XWikiRCSNodeContent ncBefore = niBefore.getContent(context);
ncBefore.getPatch().setDiffVersion(xmlBefore, xmlAfter, "");
niBefore.setContent(ncBefore);
updateNode(niBefore);
getUpdatedNodeContents().add(ncBefore);
}
// if (firstVersionBefore == null) => nothing else to do, except delete
for (Iterator<XWikiRCSNodeInfo> it = getNodes(upperBound, lowerBound).iterator(); it.hasNext(); ) {
XWikiRCSNodeInfo ni = it.next();
this.fullVersions.remove(ni.getId().getVersion());
this.deletedNodes.add(ni);
it.remove();
}
}
Aggregations