@Test public void getRevisionWhenThereIsNoHistory() throws Exception { when(attachment.getVersion()).thenReturn("1.1"); assertNull(archive.getRevision(null, "2.7", null)); }
public XWikiAttachment getRevision(final XWikiAttachment attachment, final String rev, final XWikiContext context) throws XWikiException { try { final Archive rcsArchive = getRCSArchive(); if (rcsArchive == null) { return this.attachment.getVersion().equals(rev) ? this.attachment : null; } final Version version = rcsArchive.getRevisionVersion(rev); if (version == null) { return null; } final Object[] lines = rcsArchive.getRevision(version); final StringBuilder content = new StringBuilder(); for (int i = 0; i < lines.length; i++) { String line = lines[i].toString(); content.append(line); if (i != lines.length - 1) { content.append("\n"); } } final String scontent = content.toString(); final XWikiAttachment revattach = new XWikiAttachment(); revattach.fromXML(scontent); revattach.setDoc(attachment.getDoc(), false); revattach.setVersion(rev); return revattach; } catch (Exception e) { final Object[] args = { attachment.getFilename() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT, GENERIC_EXCEPTION_MESSAGE, e, args); } }
XWikiAttachmentArchive implements Cloneable { public XWikiAttachment getRevision(final XWikiAttachment attachment, final String rev, final XWikiContext context) throws XWikiException { try { final Archive rcsArchive = getRCSArchive(); if (rcsArchive == null) { return this.attachment.getVersion().equals(rev) ? this.attachment : null; } final Version version = rcsArchive.getRevisionVersion(rev); if (version == null) { return null; } final Object[] lines = rcsArchive.getRevision(version); final StringBuilder content = new StringBuilder(); for (int i = 0; i < lines.length; i++) { String line = lines[i].toString(); content.append(line); if (i != lines.length - 1) { content.append("\n"); } } final String scontent = content.toString(); final XWikiAttachment revattach = new XWikiAttachment(); revattach.fromXML(scontent); revattach.setDoc(attachment.getDoc(), false); revattach.setVersion(rev); return revattach; } catch (Exception e) { final Object[] args = { attachment.getFilename() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT, GENERIC_EXCEPTION_MESSAGE, e, args); } } }
XWikiAttachmentArchive implements Cloneable { public XWikiAttachment getRevision(final XWikiAttachment attachment, final String rev, final XWikiContext context) throws XWikiException { try { final Archive rcsArchive = getRCSArchive(); if (rcsArchive == null) { return this.attachment.getVersion().equals(rev) ? this.attachment : null; } final Version version = rcsArchive.getRevisionVersion(rev); if (version == null) { return null; } final Object[] lines = rcsArchive.getRevision(version); final StringBuilder content = new StringBuilder(); for (int i = 0; i < lines.length; i++) { String line = lines[i].toString(); content.append(line); if (i != lines.length - 1) { content.append("\n"); } } final String scontent = content.toString(); final XWikiAttachment revattach = new XWikiAttachment(); revattach.fromXML(scontent); revattach.setDoc(attachment.getDoc(), false); revattach.setVersion(rev); return revattach; } catch (Exception e) { final Object[] args = { attachment.getFilename() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT, GENERIC_EXCEPTION_MESSAGE, e, args); } }  }
XWikiAttachmentArchive implements Cloneable { public XWikiAttachment getRevision(final XWikiAttachment attachment, final String rev, final XWikiContext context) throws XWikiException { try { final Archive rcsArchive = getRCSArchive(); if (rcsArchive == null) { return this.attachment.getVersion().equals(rev) ? this.attachment : null; } final Version version = rcsArchive.getRevisionVersion(rev); if (version == null) { return null; } final Object[] lines = rcsArchive.getRevision(version); final StringBuilder content = new StringBuilder(); for (int i = 0; i < lines.length; i++) { String line = lines[i].toString(); content.append(line); if (i != lines.length - 1) { content.append("\n"); } } final String scontent = content.toString(); final XWikiAttachment revattach = new XWikiAttachment(); revattach.fromXML(scontent); revattach.setDoc(attachment.getDoc(), false); revattach.setVersion(rev); return revattach; } catch (Exception e) { final Object[] args = { attachment.getFilename() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT, GENERIC_EXCEPTION_MESSAGE, e, args); } }  long getId(); void setId(final long id); @Override Object clone(); @Deprecated Archive getRCSArchive(); @Deprecated void setRCSArchive(final Archive archive); String getArchiveAsString(); String getArchiveAsString(final XWikiContext context); byte[] getArchive(); byte[] getArchive(final XWikiContext context); void setArchive(final byte[] data); void setArchive(final String data); @Deprecated void updateArchive(final byte[] data, final XWikiContext context); void updateArchive(final XWikiContext context); XWikiAttachment getAttachment(); void setAttachment(final XWikiAttachment attachment); Version[] getVersions(); XWikiAttachment getRevision(final XWikiAttachment attachment, final String rev, final XWikiContext context); }
XWikiAttachmentArchive implements Cloneable { public XWikiAttachment getRevision(final XWikiAttachment attachment, final String rev, final XWikiContext context) throws XWikiException { try { final Archive rcsArchive = getRCSArchive(); if (rcsArchive == null) { return this.attachment.getVersion().equals(rev) ? this.attachment : null; } final Version version = rcsArchive.getRevisionVersion(rev); if (version == null) { return null; } final Object[] lines = rcsArchive.getRevision(version); final StringBuilder content = new StringBuilder(); for (int i = 0; i < lines.length; i++) { String line = lines[i].toString(); content.append(line); if (i != lines.length - 1) { content.append("\n"); } } final String scontent = content.toString(); final XWikiAttachment revattach = new XWikiAttachment(); revattach.fromXML(scontent); revattach.setDoc(attachment.getDoc(), false); revattach.setVersion(rev); return revattach; } catch (Exception e) { final Object[] args = { attachment.getFilename() }; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT, GENERIC_EXCEPTION_MESSAGE, e, args); } }  long getId(); void setId(final long id); @Override Object clone(); @Deprecated Archive getRCSArchive(); @Deprecated void setRCSArchive(final Archive archive); String getArchiveAsString(); String getArchiveAsString(final XWikiContext context); byte[] getArchive(); byte[] getArchive(final XWikiContext context); void setArchive(final byte[] data); void setArchive(final String data); @Deprecated void updateArchive(final byte[] data, final XWikiContext context); void updateArchive(final XWikiContext context); XWikiAttachment getAttachment(); void setAttachment(final XWikiAttachment attachment); Version[] getVersions(); XWikiAttachment getRevision(final XWikiAttachment attachment, final String rev, final XWikiContext context);  }