@Test public void loadArchiveTest() throws Exception { this.versionStore.saveArchive(this.archive, null, false); final XWikiAttachmentArchive newArch = this.versionStore.loadArchive(archive.getAttachment(), null, false); Assert.assertTrue(newArch.getVersions().length == 3); final XWikiAttachment version1 = newArch.getRevision(archive.getAttachment(), "1.1", null); final XWikiAttachment version2 = newArch.getRevision(archive.getAttachment(), "1.2", null); final XWikiAttachment version3 = newArch.getRevision(archive.getAttachment(), "1.3", null); Assert.assertTrue(version1.getVersion().equals("1.1")); Assert.assertTrue(version1.getFilename().equals("attachment.txt")); Assert.assertEquals("I am version 1.1", IOUtils.toString(version1.getContentInputStream(null))); Assert.assertSame(version1.getDoc(), this.archive.getAttachment().getDoc()); Assert.assertTrue(version2.getVersion().equals("1.2")); Assert.assertTrue(version2.getFilename().equals("attachment.txt")); Assert.assertEquals("I am version 1.2", IOUtils.toString(version2.getContentInputStream(null))); Assert.assertSame(version2.getDoc(), this.archive.getAttachment().getDoc()); Assert.assertTrue(version3.getVersion().equals("1.3")); Assert.assertTrue(version3.getFilename().equals("attachment.txt")); Assert.assertEquals("I am version 1.3", IOUtils.toString(version3.getContentInputStream(null))); Assert.assertSame(version3.getDoc(), this.archive.getAttachment().getDoc()); }
@Override public XWikiAttachmentArchive loadArchive(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException { try { return this.loadArchive(attachment, this.fileTools.getAttachmentFileProvider(attachment.getReference())); } catch (Exception e) { if (e instanceof XWikiException) { throw (XWikiException) e; } final Object[] args = { attachment.getFilename(), UNKNOWN_NAME }; if (attachment.getDoc() != null) { args[1] = attachment.getDoc().getFullName(); } throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Exception while loading attachment archive {0} for document {1}", e, args); } }
FilesystemAttachmentVersioningStore implements AttachmentVersioningStore { @Override public XWikiAttachmentArchive loadArchive(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException { try { return this.loadArchive(attachment, this.fileTools.getAttachmentFileProvider(attachment.getReference())); } catch (Exception e) { if (e instanceof XWikiException) { throw (XWikiException) e; } final Object[] args = { attachment.getFilename(), UNKNOWN_NAME }; if (attachment.getDoc() != null) { args[1] = attachment.getDoc().getFullName(); } throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Exception while loading attachment archive {0} for document {1}", e, args); } } }
FilesystemAttachmentVersioningStore implements AttachmentVersioningStore { @Override public XWikiAttachmentArchive loadArchive(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException { try { return this.loadArchive(attachment, this.fileTools.getAttachmentFileProvider(attachment.getReference())); } catch (Exception e) { if (e instanceof XWikiException) { throw (XWikiException) e; } final Object[] args = { attachment.getFilename(), UNKNOWN_NAME }; if (attachment.getDoc() != null) { args[1] = attachment.getDoc().getFullName(); } throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Exception while loading attachment archive {0} for document {1}", e, args); } }  }
FilesystemAttachmentVersioningStore implements AttachmentVersioningStore { @Override public XWikiAttachmentArchive loadArchive(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException { try { return this.loadArchive(attachment, this.fileTools.getAttachmentFileProvider(attachment.getReference())); } catch (Exception e) { if (e instanceof XWikiException) { throw (XWikiException) e; } final Object[] args = { attachment.getFilename(), UNKNOWN_NAME }; if (attachment.getDoc() != null) { args[1] = attachment.getDoc().getFullName(); } throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Exception while loading attachment archive {0} for document {1}", e, args); } }  @Override String getHint(); @Override XWikiAttachmentArchive loadArchive(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void saveArchive(final XWikiAttachmentArchive archive, final XWikiContext context,
        final boolean bTransaction); StartableTransactionRunnable getArchiveSaveRunnable(final XWikiAttachmentArchive archive,
        final XWikiContext context); @Override void deleteArchive(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction); StartableTransactionRunnable getArchiveDeleteRunnable(final XWikiAttachmentArchive archive); }
FilesystemAttachmentVersioningStore implements AttachmentVersioningStore { @Override public XWikiAttachmentArchive loadArchive(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction) throws XWikiException { try { return this.loadArchive(attachment, this.fileTools.getAttachmentFileProvider(attachment.getReference())); } catch (Exception e) { if (e instanceof XWikiException) { throw (XWikiException) e; } final Object[] args = { attachment.getFilename(), UNKNOWN_NAME }; if (attachment.getDoc() != null) { args[1] = attachment.getDoc().getFullName(); } throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Exception while loading attachment archive {0} for document {1}", e, args); } }  @Override String getHint(); @Override XWikiAttachmentArchive loadArchive(final XWikiAttachment attachment, final XWikiContext context,
        final boolean bTransaction); @Override void saveArchive(final XWikiAttachmentArchive archive, final XWikiContext context,
        final boolean bTransaction); StartableTransactionRunnable getArchiveSaveRunnable(final XWikiAttachmentArchive archive,
        final XWikiContext context); @Override void deleteArchive(final XWikiAttachment attachment, final XWikiContext context, final boolean bTransaction); StartableTransactionRunnable getArchiveDeleteRunnable(final XWikiAttachmentArchive archive);  }