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]);
}
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);
}
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);
}
}
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());
}
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);
}
}
Aggregations