Search in sources :

Example 6 with XWikiRCSNodeInfo

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.

the class XWikiDocumentArchive method loadRCSNodeContents.

/**
 * @return List of {@link XWikiRCSNodeContent} where vfrom<=version<=vto order by version
 * @param vfrom - start version
 * @param vto - end version
 * @param context - used everywhere
 * @throws XWikiException if any error
 */
private List<XWikiRCSNodeContent> loadRCSNodeContents(Version vfrom, Version vto, XWikiContext context) throws XWikiException {
    List<XWikiRCSNodeContent> result = new ArrayList<XWikiRCSNodeContent>();
    for (XWikiRCSNodeInfo nodeInfo : getNodes(vfrom, vto)) {
        XWikiRCSNodeContent nodeContent = nodeInfo.getContent(context);
        result.add(nodeContent);
    }
    return result;
}
Also used : XWikiRCSNodeContent(com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) ArrayList(java.util.ArrayList)

Example 7 with XWikiRCSNodeInfo

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.

the class XWikiDocumentArchive method makePatch.

/**
 * Make a patch. It is store only modified nodes(latest). New nodes need be saved after.
 *
 * @param newnode - new node information
 * @param doc - document for that patch created
 * @param context - used for loading node contents and generating xml
 * @return node content for newnode
 * @throws XWikiException if exception while loading content
 */
protected XWikiRCSNodeContent makePatch(XWikiRCSNodeInfo newnode, XWikiDocument doc, XWikiContext context) throws XWikiException {
    XWikiRCSNodeContent result = new XWikiRCSNodeContent();
    result.setPatch(new XWikiPatch().setFullVersion(doc, context));
    newnode.setContent(result);
    XWikiRCSNodeInfo latestNode = getLatestNode();
    if (latestNode != null) {
        int nodesCount = getNodes().size();
        int nodesPerFull = context.getWiki() == null ? 5 : Integer.parseInt(context.getWiki().getConfig().getProperty("xwiki.store.rcs.nodesPerFull", "5"));
        if (nodesPerFull <= 0 || (nodesCount % nodesPerFull) != 0) {
            XWikiRCSNodeContent latestContent = latestNode.getContent(context);
            latestContent.getPatch().setDiffVersion(latestContent.getPatch().getContent(), doc, context);
            latestNode.setContent(latestContent);
            updateNode(latestNode);
            getUpdatedNodeContents().add(latestContent);
        }
    }
    return result;
}
Also used : XWikiRCSNodeContent(com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) XWikiPatch(com.xpn.xwiki.doc.rcs.XWikiPatch)

Example 8 with XWikiRCSNodeInfo

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo 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)

Example 9 with XWikiRCSNodeInfo

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.

the class XWikiDocumentArchive method loadDocument.

/**
 * @return selected version of document, null if version is not found.
 * @param version - which version to load
 * @param context - used for loading
 * @throws XWikiException if any error
 */
public XWikiDocument loadDocument(Version version, XWikiContext context) throws XWikiException {
    XWikiRCSNodeInfo nodeInfo = getNode(version);
    if (nodeInfo == null) {
        return null;
    }
    try {
        String content = getVersionXml(version, context);
        XWikiDocument doc = new XWikiDocument();
        doc.fromXML(content);
        doc.setRCSVersion(version);
        doc.setComment(nodeInfo.getComment());
        doc.setAuthor(nodeInfo.getAuthor());
        doc.setMinorEdit(nodeInfo.isMinorEdit());
        doc.setMostRecent(version.equals(getLatestVersion()));
        // A document coming from the archive should never be considered new.
        doc.setNew(false);
        return doc;
    } catch (Exception e) {
        Object[] args = { version.toString(), Long.valueOf(getId()) };
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_RCS_READING_REVISIONS, "Exception while reading version [{0}] for document id [{1,number}]", e, args);
    }
}
Also used : XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) ToString(org.suigeneris.jrcs.util.ToString) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException)

Example 10 with XWikiRCSNodeInfo

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo in project xwiki-platform by xwiki.

the class XWikiDocumentArchive method setNodes.

/**
 * @param versions - collection of XWikiRCSNodeInfo
 */
public void setNodes(Collection<XWikiRCSNodeInfo> versions) {
    resetArchive();
    for (XWikiRCSNodeInfo node : versions) {
        updateNode(node);
    }
    if (getNodes().size() > 0) {
        // ensure latest version is full
        getLatestNode().setDiff(false);
        updateNode(getLatestNode());
    }
}
Also used : XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)

Aggregations

XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)10 XWikiRCSNodeContent (com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent)5 XWikiException (com.xpn.xwiki.XWikiException)4 Version (org.suigeneris.jrcs.rcs.Version)4 ToString (org.suigeneris.jrcs.util.ToString)3 ArrayList (java.util.ArrayList)2 HibernateException (org.hibernate.HibernateException)2 XWikiDocumentArchive (com.xpn.xwiki.doc.XWikiDocumentArchive)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 Date (java.util.Date)1 Iterator (java.util.Iterator)1