Search in sources :

Example 16 with Version

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

the class VoidAttachmentVersioningStoreTest method testHistory.

public void testHistory() throws XWikiException {
    XWikiDocument doc = new XWikiDocument(new DocumentReference("Wiki", "Main", "Test"));
    XWikiAttachment attachment = new XWikiAttachment(doc, "filename");
    // 1.1
    attachment.setContent(new byte[] { 1 });
    attachment.updateContentArchive(this.getContext());
    assertEquals(attachment, attachment.getAttachmentRevision("1.1", this.getContext()));
    // 1.2
    attachment.setContent(new byte[] { 2 });
    attachment.updateContentArchive(this.getContext());
    assertEquals(attachment, attachment.getAttachmentRevision("1.2", this.getContext()));
    // there should be only 1.2 version.
    assertNull(attachment.getAttachmentRevision("1.1", this.getContext()));
    assertNull(attachment.getAttachmentRevision("1.3", this.getContext()));
    assertEquals(1, attachment.getVersions().length);
    assertEquals(new Version(1, 2), attachment.getVersions()[0]);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Version(org.suigeneris.jrcs.rcs.Version) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 17 with Version

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

the class XWikiDocumentLocaleEventGenerator method write.

@Override
public void write(XWikiDocument document, Object filter, XWikiDocumentFilter documentFilter, DocumentInstanceInputProperties properties) throws FilterException {
    XWikiContext xcontext = this.xcontextProvider.get();
    // > WikiDocumentLocale
    FilterEventParameters localeParameters = new FilterEventParameters();
    if (properties.isWithJRCSRevisions()) {
        try {
            localeParameters.put(XWikiWikiDocumentFilter.PARAMETER_JRCSREVISIONS, document.getDocumentArchive(xcontext).getArchive(xcontext));
        } catch (XWikiException e) {
            this.logger.error("Document [{}] has malformed history", document.getDocumentReference(), e);
        }
    }
    localeParameters.put(WikiDocumentFilter.PARAMETER_CREATION_AUTHOR, document.getCreator());
    localeParameters.put(WikiDocumentFilter.PARAMETER_CREATION_DATE, document.getCreationDate());
    localeParameters.put(WikiDocumentFilter.PARAMETER_LASTREVISION, document.getVersion());
    documentFilter.beginWikiDocumentLocale(document.getLocale(), localeParameters);
    if (properties.isWithRevisions()) {
        try {
            for (Version version : document.getRevisions(xcontext)) {
                XWikiDocument revisionDocument = xcontext.getWiki().getDocument(document, version.toString(), xcontext);
                writeRevision(revisionDocument, filter, documentFilter, properties);
            }
        } catch (XWikiException e) {
            this.logger.error("Failed to get document [{}] history", document.getDocumentReference(), e);
        }
    }
    writeRevision(document, filter, documentFilter, properties);
    // < WikiDocumentLocale
    documentFilter.endWikiDocumentLocale(document.getLocale(), FilterEventParameters.EMPTY);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) FilterEventParameters(org.xwiki.filter.FilterEventParameters) Version(org.suigeneris.jrcs.rcs.Version) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 18 with Version

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

the class AttachmentHistoryResourceImpl method getAttachmentHistory.

@Override
public Attachments getAttachmentHistory(String wikiName, String spaceName, String pageName, String attachmentName, Integer start, Integer number) throws XWikiRestException {
    try {
        DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
        Document doc = documentInfo.getDocument();
        final com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName);
        if (xwikiAttachment == null) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        Attachments attachments = new Attachments();
        Version[] versions = xwikiAttachment.getVersions();
        List<Version> versionList = new ArrayList<Version>();
        for (Version version : versions) {
            versionList.add(version);
        }
        RangeIterable<Version> ri = new RangeIterable<Version>(versionList, start, number);
        for (Version version : ri) {
            com.xpn.xwiki.api.Attachment xwikiAttachmentAtVersion = xwikiAttachment.getAttachmentRevision(version.toString());
            URL url = Utils.getXWikiContext(componentManager).getURLFactory().createAttachmentRevisionURL(attachmentName, spaceName, doc.getName(), version.toString(), null, wikiName, Utils.getXWikiContext(componentManager));
            String attachmentXWikiAbsoluteUrl = url.toString();
            String attachmentXWikiRelativeUrl = Utils.getXWikiContext(componentManager).getURLFactory().getURL(url, Utils.getXWikiContext(componentManager));
            attachments.getAttachments().add(DomainObjectFactory.createAttachmentAtVersion(objectFactory, uriInfo.getBaseUri(), xwikiAttachmentAtVersion, attachmentXWikiRelativeUrl, attachmentXWikiAbsoluteUrl, Utils.getXWikiApi(componentManager), false));
        }
        return attachments;
    } catch (XWikiException e) {
        throw new XWikiRestException(e);
    }
}
Also used : RangeIterable(org.xwiki.rest.internal.RangeIterable) WebApplicationException(javax.ws.rs.WebApplicationException) XWikiRestException(org.xwiki.rest.XWikiRestException) ArrayList(java.util.ArrayList) Document(com.xpn.xwiki.api.Document) Attachments(org.xwiki.rest.model.jaxb.Attachments) URL(java.net.URL) Version(org.suigeneris.jrcs.rcs.Version) XWikiException(com.xpn.xwiki.XWikiException)

Example 19 with Version

use of org.suigeneris.jrcs.rcs.Version 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)

Example 20 with Version

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

the class XWikiDocumentArchive method updateNode.

/**
 * @param node - node added to versionToNode and fullNodes
 */
protected void updateNode(XWikiRCSNodeInfo node) {
    Version ver = node.getId().getVersion();
    this.versionToNode.put(ver, node);
    if (!node.isDiff()) {
        this.fullVersions.add(ver);
    } else {
        this.fullVersions.remove(ver);
    }
}
Also used : Version(org.suigeneris.jrcs.rcs.Version)

Aggregations

Version (org.suigeneris.jrcs.rcs.Version)24 XWikiException (com.xpn.xwiki.XWikiException)7 ToString (org.suigeneris.jrcs.util.ToString)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 ArrayList (java.util.ArrayList)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)4 Date (java.util.Date)4 Archive (org.suigeneris.jrcs.rcs.Archive)4 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)3 XWikiDocumentArchive (com.xpn.xwiki.doc.XWikiDocumentArchive)3 XWikiRCSNodeContent (com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 Test (org.junit.Test)2 Document (com.xpn.xwiki.api.Document)1 XWikiAttachmentArchive (com.xpn.xwiki.doc.XWikiAttachmentArchive)1 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)1 IOException (java.io.IOException)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1