Search in sources :

Example 1 with Node

use of org.suigeneris.jrcs.rcs.impl.Node in project xwiki-platform by xwiki.

the class ListAttachmentArchive method fromRCS.

/**
 * @param rcsArchive the RCS archive to import.
 * @throws Exception if getting a revision from the RCS archive or deserializing an attachment from XML fails
 */
private void fromRCS(final Archive rcsArchive) throws Exception {
    if (rcsArchive == null) {
        return;
    }
    final Node[] nodes = rcsArchive.changeLog();
    for (int i = nodes.length - 1; i > -1; i--) {
        final Object[] lines = rcsArchive.getRevision(nodes[i].getVersion());
        final StringBuilder content = new StringBuilder();
        for (int j = 0; j < lines.length; j++) {
            String line = lines[j].toString();
            content.append(line);
            if (j != lines.length - 1) {
                content.append("\n");
            }
        }
        final XWikiAttachment rev = new XWikiAttachment();
        rev.fromXML(content.toString());
        rev.setDoc(getAttachment().getDoc());
        rev.setAttachment_archive(this);
        // this should not be necessary, keeping to maintain behavior.
        rev.setVersion(nodes[i].getVersion().toString());
        revisions.add(rev);
    }
}
Also used : Node(org.suigeneris.jrcs.rcs.impl.Node) ToString(org.suigeneris.jrcs.util.ToString) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment)

Example 2 with Node

use of org.suigeneris.jrcs.rcs.impl.Node in project xwiki-platform by xwiki.

the class XWikiAttachmentArchive method getVersions.

/**
 * @return an array of versions which are available for this attachment, ordered by version number descending.
 */
public Version[] getVersions() {
    final Archive rcsArchive = getRCSArchive();
    Version[] versions;
    if (rcsArchive != null) {
        final Node[] nodes = rcsArchive.changeLog();
        versions = new Version[nodes.length];
        for (int i = 0; i < nodes.length; i++) {
            versions[i] = nodes[i].getVersion();
        }
    } else {
        // No archive means there is no history and only the current version
        versions = new Version[] { this.attachment.getRCSVersion() };
    }
    return versions;
}
Also used : Archive(org.suigeneris.jrcs.rcs.Archive) Version(org.suigeneris.jrcs.rcs.Version) Node(org.suigeneris.jrcs.rcs.impl.Node)

Aggregations

Node (org.suigeneris.jrcs.rcs.impl.Node)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 Archive (org.suigeneris.jrcs.rcs.Archive)1 Version (org.suigeneris.jrcs.rcs.Version)1 ToString (org.suigeneris.jrcs.util.ToString)1