Search in sources :

Example 6 with XWikiRCSNodeContent

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();
    }
}
Also used : XWikiRCSNodeContent(com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent) Version(org.suigeneris.jrcs.rcs.Version) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) ToString(org.suigeneris.jrcs.util.ToString)

Aggregations

XWikiRCSNodeContent (com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent)6 XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)5 Version (org.suigeneris.jrcs.rcs.Version)3 ArrayList (java.util.ArrayList)2 ToString (org.suigeneris.jrcs.util.ToString)2 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiPatch (com.xpn.xwiki.doc.rcs.XWikiPatch)1 XWikiRCSArchive (com.xpn.xwiki.doc.rcs.XWikiRCSArchive)1 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1