Search in sources :

Example 1 with XWikiRCSNodeContent

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

the class XWikiDocumentArchive method setArchive.

/**
 * Deserialize class. Used in {@link com.xpn.xwiki.plugin.packaging.PackagePlugin}.
 *
 * @param text - archive in JRCS format
 * @throws XWikiException if parse error
 */
public void setArchive(String text) throws XWikiException {
    try {
        XWikiRCSArchive archive = new XWikiRCSArchive(text);
        resetArchive();
        Collection nodes = archive.getNodes(getId());
        for (Iterator it = nodes.iterator(); it.hasNext(); ) {
            XWikiRCSNodeInfo nodeInfo = (XWikiRCSNodeInfo) it.next();
            XWikiRCSNodeContent nodeContent = (XWikiRCSNodeContent) it.next();
            updateNode(nodeInfo);
            this.updatedNodeInfos.add(nodeInfo);
            this.updatedNodeContents.add(nodeContent);
        }
    } catch (Exception e) {
        Object[] args = { text, Long.valueOf(getId()) };
        throw new XWikiException(XWikiException.MODULE_XWIKI_DIFF, XWikiException.ERROR_XWIKI_DIFF_CONTENT_ERROR, "Exception while constructing archive for JRCS string [{0}] for document [{1}]", e, args);
    }
}
Also used : XWikiRCSArchive(com.xpn.xwiki.doc.rcs.XWikiRCSArchive) XWikiRCSNodeContent(com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) Iterator(java.util.Iterator) Collection(java.util.Collection) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with XWikiRCSNodeContent

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

the class XWikiDocumentArchive method updateArchive.

/**
 * Update history with new document version.
 *
 * @param doc - document for this version
 * @param author - author of version
 * @param date - date of version
 * @param comment - version comment
 * @param version - preferably document version in history
 * @param context - used for loading nodes content
 * @throws XWikiException in any error
 */
public void updateArchive(XWikiDocument doc, String author, Date date, String comment, Version version, XWikiContext context) throws XWikiException {
    Version oldLatestVer = getLatestVersion();
    Version newVer = version;
    if (newVer == null || oldLatestVer != null && newVer.compareVersions(oldLatestVer) <= 0) {
        newVer = createNextVersion(oldLatestVer, doc.isMinorEdit());
    }
    XWikiRCSNodeInfo newNode = new XWikiRCSNodeInfo(new XWikiRCSNodeId(getId(), newVer));
    newNode.setAuthor(author);
    newNode.setComment(comment);
    newNode.setDate(date);
    XWikiRCSNodeContent newContent = makePatch(newNode, doc, context);
    updateNode(newNode);
    this.updatedNodeInfos.add(newNode);
    this.updatedNodeContents.add(newContent);
}
Also used : XWikiRCSNodeContent(com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent) Version(org.suigeneris.jrcs.rcs.Version) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) XWikiRCSNodeId(com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)

Example 3 with XWikiRCSNodeContent

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent 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 4 with XWikiRCSNodeContent

use of com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent 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 5 with XWikiRCSNodeContent

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

the class XWikiDocumentArchive method getVersionXml.

/**
 * Return the XML corresponding to a version. If the version node contains just a diff, then restore the complete
 * XML by applying all patches from the nearest full version to the requested version.
 *
 * @param version The version to retrieve.
 * @param context The {@link com.xpn.xwiki.XWikiContext context}.
 * @return The XML corresponding to the version.
 * @throws XWikiException If any exception occured.
 */
public String getVersionXml(Version version, XWikiContext context) throws XWikiException {
    Version nearestFullVersion = getNearestFullVersion(version);
    List<XWikiRCSNodeContent> lstContent = loadRCSNodeContents(nearestFullVersion, version, context);
    List<String> origText = new ArrayList<String>();
    for (XWikiRCSNodeContent nodeContent : lstContent) {
        nodeContent.getPatch().patch(origText);
    }
    return ToString.arrayToString(origText.toArray());
}
Also used : XWikiRCSNodeContent(com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent) Version(org.suigeneris.jrcs.rcs.Version) ArrayList(java.util.ArrayList) 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