/** * {@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; }
public XWikiAttachment getAttachmentRevision(String rev, XWikiContext context) throws XWikiException { if (StringUtils.equals(rev, this.getVersion())) { return this; } return loadArchive(context).getRevision(this, rev, context); }
public void updateContentArchive(XWikiContext context) throws XWikiException { if (this.attachment_content == null) { return; } // XWikiAttachmentArchive no longer uses the byte array passed as it's first parameter making it redundant. loadArchive(context).updateArchive(null, context); }
/** * @deprecated since 2.6M1 please do not use this, it is bound to a jrcs based implementation. */ @Deprecated public void setArchive(Archive archive) { if (this.attachment_archive == null) { this.attachment_archive = new XWikiAttachmentArchive(); this.attachment_archive.setAttachment(this); } this.attachment_archive.setRCSArchive(archive); }
public void setArchive(String data) throws XWikiException { if (this.attachment_archive == null) { this.attachment_archive = new XWikiAttachmentArchive(); this.attachment_archive.setAttachment(this); } this.attachment_archive.setArchive(data.getBytes()); }
public Object doInHibernate(Session session) throws HibernateException, XWikiException { XWikiAttachmentArchive archive = new XWikiAttachmentArchive(); archive.setAttachment(attachment); session.delete(archive); return null; } });
return; if (archive.getVersions().length == 0 && archive.getAttachment() != null) { archive.updateArchive(context); final Version[] versions = archive.getVersions(); final List<XWikiAttachment> attachmentVersions = new ArrayList<>(versions.length); final String versionName = versions[i].toString(); final XWikiAttachment attachVer = archive.getRevision(archive.getAttachment(), versionName, context); attachmentVersions.add(attachVer);
/** * 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())); } }
attachment.setAttachment_archive((XWikiAttachmentArchive) getAttachment_archive().clone()); attachment.getAttachment_archive().setAttachment(attachment);
public synchronized Version[] getVersions() { try { return getAttachment_archive().getVersions(); } catch (Exception ex) { LOG.warn(String.format("Cannot retrieve versions of attachment [%s@%s]: %s", getFilename(), getDoc() .getFullName(), ex.getMessage())); return new Version[] {new Version(this.getVersion())}; } }
/** * Get the archive if it is currently stored in RAM. * * @return a byte array representation of a JRCS archive or an empty array if the archive is not * available on the heap. * @throws XWikiException if anything goes wrong. */ public byte[] getArchive() throws XWikiException { return getArchive(null); }
/** * {@inheritDoc} */ @Override public Object clone() { // super.clone() is needed for checkstyle super.clone(); return new VoidAttachmentArchive(getAttachment()); } }
restoredAttachmentRevision.getAttachment_archive().setAttachment(restoredAttachmentRevision); restoredAttachmentRevision.setVersion(restoredAttachment.getVersion()); restoredAttachmentRevision.setMetaDataDirty(true);
public Object doInHibernate(Session session) throws HibernateException { try { session.load(archive, archive.getId()); } catch (ObjectNotFoundException e) { // if none found then return empty created archive } return null; } });
/** * {@inheritDoc} */ public void deleteArchive(final XWikiAttachment attachment, final XWikiContext context, boolean bTransaction) throws XWikiException { try { executeWrite(context, bTransaction, new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException, XWikiException { XWikiAttachmentArchive archive = new XWikiAttachmentArchive(); archive.setAttachment(attachment); session.delete(archive); return null; } }); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn(String.format("Error deleting attachment archive [%s] of doc [%s]", attachment.getFilename(), attachment.getDoc().getFullName()), e); } } } }
return; if (archive.getVersions().length == 0 && archive.getAttachment() != null) { archive.updateArchive(context); final Version[] versions = archive.getVersions(); final List<XWikiAttachment> attachmentVersions = new ArrayList<XWikiAttachment>(versions.length); final String versionName = versions[i].toString(); final XWikiAttachment attachVer = archive.getRevision(archive.getAttachment(), versionName, context); attachmentVersions.add(attachVer);
/** * 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())); } }
@Override public XWikiAttachment restoreAttachment(final XWikiAttachment attachment, final XWikiContext context) throws XWikiException { XWikiAttachment result = attachment; if (result != null) { // TODO Add XWikiAttachment#clone(XWikiAttachment) // this toXML does not copy content. result.fromXML(this.attachment.toXML(context)); if (this.attachment.getAttachment_content() != null) { attachment.setAttachment_content((XWikiAttachmentContent) this.attachment.getAttachment_content() .clone()); attachment.getAttachment_content().setAttachment(attachment); } if (this.attachment.getAttachment_archive() != null) { result.setAttachment_archive((XWikiAttachmentArchive) this.attachment.getAttachment_archive().clone()); result.getAttachment_archive().setAttachment(result); } } else { result = (XWikiAttachment) this.attachment.clone(); } result.setDoc(context.getWiki().getDocument(this.attachment.getReference().getDocumentReference(), context)); return result; }
/** * @param archive the attachment archive to delete. * @param fileTools tools for getting the metadata and versions of the attachment and locks. * @param provider the file provider for gettign the files to delete. */ public AttachmentArchiveDeleteRunnable(final XWikiAttachmentArchive archive, final FilesystemStoreTools fileTools, final AttachmentFileProvider provider) { final List<File> toDelete = new ArrayList<>(); toDelete.add(provider.getAttachmentVersioningMetaFile()); final Version[] versions = archive.getVersions(); for (int i = 0; i < versions.length; i++) { toDelete.add(provider.getAttachmentVersionContentFile(versions[i].toString())); } for (File file : toDelete) { new FileDeleteTransactionRunnable(file, fileTools.getBackupFile(file), fileTools.getLockForFile(file)) .runIn(this); } } }
/** * {@inheritDoc} */ public XWikiAttachmentArchive loadArchive(final XWikiAttachment attachment, XWikiContext context, boolean bTransaction) throws XWikiException { try { final XWikiAttachmentArchive archive = new XWikiAttachmentArchive(); archive.setAttachment(attachment); executeRead(context, bTransaction, new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { try { session.load(archive, archive.getId()); } catch (ObjectNotFoundException e) { // if none found then return empty created archive } return null; } }); attachment.setAttachment_archive(archive); return archive; } catch (Exception e) { Object[] args = {attachment.getFilename(), attachment.getDoc().getFullName()}; throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_LOADING_ATTACHMENT, "Exception while loading attachment archive {0} of document {1}", e, args); } }