Search in sources :

Example 6 with Archive

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

the class ListAttachmentArchive method setArchive.

@Override
public void setArchive(final byte[] data) throws XWikiException {
    this.revisions.clear();
    if ((data != null) && (data.length == 0)) {
        try {
            final ByteArrayInputStream is = new ByteArrayInputStream(data);
            final Archive rcsArchive = new Archive(getAttachment().getFilename(), is);
            this.setRCSArchive(rcsArchive);
        } catch (Exception e) {
            if (e instanceof XWikiException) {
                throw (XWikiException) e;
            }
            Object[] args = { getAttachment().getFilename() };
            throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT, GENERIC_EXCEPTION_MESSAGE, e, args);
        }
    }
}
Also used : XWikiAttachmentArchive(com.xpn.xwiki.doc.XWikiAttachmentArchive) Archive(org.suigeneris.jrcs.rcs.Archive) ByteArrayInputStream(java.io.ByteArrayInputStream) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException)

Example 7 with Archive

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

the class ListAttachmentArchive method toRCS.

/**
 * Convert this attachment archive into JRCS format.
 *
 * @param context the XWikiContext for the request.
 * @return this archive in JRCS format.
 * @throws Exception if something goes wrong while serializing the attachment to XML or inserting it into the RCS
 * archive.
 */
private Archive toRCS(final XWikiContext context) throws Exception {
    final Version[] versions = this.getVersions();
    Archive rcsArch = null;
    for (XWikiAttachment rev : this.revisions) {
        final String sdata = rev.toStringXML(true, false, context);
        final Object[] lines = ToString.stringToArray(sdata);
        if (rcsArch == null) {
            // First cycle.
            rcsArch = new Archive(lines, rev.getFilename(), rev.getVersion());
        } else {
            rcsArch.addRevision(lines, "");
        }
    }
    return rcsArch;
}
Also used : XWikiAttachmentArchive(com.xpn.xwiki.doc.XWikiAttachmentArchive) Archive(org.suigeneris.jrcs.rcs.Archive) Version(org.suigeneris.jrcs.rcs.Version) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) ToString(org.suigeneris.jrcs.util.ToString)

Aggregations

Archive (org.suigeneris.jrcs.rcs.Archive)7 Version (org.suigeneris.jrcs.rcs.Version)4 XWikiException (com.xpn.xwiki.XWikiException)3 XWikiAttachmentArchive (com.xpn.xwiki.doc.XWikiAttachmentArchive)2 Test (org.junit.Test)2 ToString (org.suigeneris.jrcs.util.ToString)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Date (java.util.Date)1 Node (org.suigeneris.jrcs.rcs.impl.Node)1