/** * Get a TransactionRunnable for deleting an attachment archive. * this runnable can be run with any transaction including a VoidTransaction. * * @param archive The attachment archive to delete. * @return a StartableTransactionRunnable for deleting the attachment archive. */ public StartableTransactionRunnable getArchiveDeleteRunnable(final XWikiAttachmentArchive archive) { if (archive == null) { throw new NullPointerException("The archive to delete cannot be null."); } if (archive.getAttachment() == null) { throw new IllegalArgumentException( "Cannot delete an archive unless it is associated with an attachment."); } return new AttachmentArchiveDeleteRunnable( archive, this.fileTools, this.fileTools.getAttachmentFileProvider(archive.getAttachment())); } }
/** * Get a TransactionRunnable for deleting an attachment archive. this runnable can be run with any transaction * including a VoidTransaction. * * @param archive The attachment archive to delete. * @return a StartableTransactionRunnable for deleting the attachment archive. */ public StartableTransactionRunnable getArchiveDeleteRunnable(final XWikiAttachmentArchive archive) { if (archive == null) { throw new NullPointerException("The archive to delete cannot be null."); } if (archive.getAttachment() == null) { throw new IllegalArgumentException("Cannot delete an archive unless it is associated with an attachment."); } return new AttachmentArchiveDeleteRunnable(archive, this.fileTools, this.fileTools.getAttachmentFileProvider(archive.getAttachment().getReference())); } }
/** * {@inheritDoc} * * @see java.lang.Object#clone() */ @Override public Object clone() { XWikiAttachmentArchive attachmentarchive = null; try { attachmentarchive = (XWikiAttachmentArchive) getClass().newInstance(); } catch (Exception e) { // This should not happen LOG.error("Error while attachmentArchive.clone()", e); } attachmentarchive.setAttachment(getAttachment()); attachmentarchive.setRCSArchive(getRCSArchive()); return attachmentarchive; }
/** * Get a TransactionRunnable for saving or updating the current attachment. * this runnable can be run with any transaction including a VoidTransaction. * * @param archive The attachment archive to save. * @param context An XWikiContext used for getting the attachments from the archive with getRevision() * and for getting the content from the attachments with getContentInputStream(). * @return a new StartableTransactionRunnable for saving this attachment archive. * @throws XWikiException if versions of the arrachment cannot be loaded form the archive. */ public StartableTransactionRunnable getArchiveSaveRunnable(final XWikiAttachmentArchive archive, final XWikiContext context) throws XWikiException { return new AttachmentArchiveSaveRunnable( archive, this.fileTools, this.fileTools.getAttachmentFileProvider(archive.getAttachment()), this.metaSerializer, context); }
/** * Set the archive from a byte array representation of a JRCS archive. * * @param data a byte array representation of a JRCS archive. * @throws XWikiException if anything goes wrong. */ public void setArchive(final byte[] data) throws XWikiException { if ((data == null) || (data.length == 0)) { this.archive = null; } else { try { // attachment.fromXML(data.toString()); final ByteArrayInputStream is = new ByteArrayInputStream(data); this.archive = new Archive(getAttachment().getFilename(), is); } catch (Exception e) { Object[] args = {getAttachment().getFilename()}; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT, GENERIC_EXCEPTION_MESSAGE, e, args); } } }
/** * {@inheritDoc} * <p> * bTransaction cannot be used in this case, in order to have transaction atomicity, please use * getArchiveSaveRunnable() instead. * </p> * * @see AttachmentVersioningStore#saveArchive(XWikiAttachmentArchive, XWikiContext, boolean) */ @Override public void saveArchive(final XWikiAttachmentArchive archive, final XWikiContext context, final boolean bTransaction) throws XWikiException { try { this.getArchiveSaveRunnable(archive, context).start(); } catch (Exception e) { if (e instanceof XWikiException) { throw (XWikiException) e; } final Object[] args = { UNKNOWN_NAME, UNKNOWN_NAME }; if (archive.getAttachment() != null) { args[0] = archive.getAttachment().getFilename(); if (archive.getAttachment().getDoc() != null) { args[1] = archive.getAttachment().getDoc().getFullName(); } } throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_UNKNOWN, "Exception while saving attachment archive {0} of document {1}", e, args); } }
if (archive.getAttachment() != null) { args[0] = archive.getAttachment().getFilename(); if (archive.getAttachment().getDoc() != null) { args[1] = archive.getAttachment().getDoc().getFullName();
/** * Get a TransactionRunnable for saving or updating the current attachment. this runnable can be run with any * transaction including a VoidTransaction. * * @param archive The attachment archive to save. * @param context An XWikiContext used for getting the attachments from the archive with getRevision() and for * getting the content from the attachments with getContentInputStream(). * @return a new StartableTransactionRunnable for saving this attachment archive. * @throws XWikiException if versions of the attachment cannot be loaded form the archive. */ public StartableTransactionRunnable getArchiveSaveRunnable(final XWikiAttachmentArchive archive, final XWikiContext context) throws XWikiException { return new AttachmentArchiveSaveRunnable(archive, this.fileTools, this.fileTools.getAttachmentFileProvider(archive.getAttachment().getReference()), this.metaSerializer, context); }
/** * Update the archive. * * @param data not used for anything, the data is loaded from the attachment included * with this archive. * @param context the XWikiContext for the request used to load the correct attachment * content from the database. * @throws XWikiException if anything goes wrong. */ public void updateArchive(final byte[] data, final XWikiContext context) throws XWikiException { try { this.attachment.incrementVersion(); this.attachment.setDate(new Date()); final String sdata = this.attachment.toStringXML(true, false, context); final Object[] lines = ToString.stringToArray(sdata); if (this.archive != null) { this.archive.addRevision(lines, ""); } else { this.archive = new Archive(lines, getAttachment().getFilename(), getAttachment().getVersion()); } } catch (Exception e) { Object[] args = {getAttachment().getFilename()}; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_ATTACHMENT_ARCHIVEFORMAT, GENERIC_EXCEPTION_MESSAGE, e, args); } }
return; if (archive.getVersions().length == 0 && archive.getAttachment() != null) { archive.updateArchive(context); final String versionName = versions[i].toString(); final XWikiAttachment attachVer = archive.getRevision(archive.getAttachment(), versionName, context); attachmentVersions.add(attachVer);
return; if (archive.getVersions().length == 0 && archive.getAttachment() != null) { archive.updateArchive(context); final String versionName = versions[i].toString(); final XWikiAttachment attachVer = archive.getRevision(archive.getAttachment(), versionName, context); attachmentVersions.add(attachVer);