/** * Clone attachments from another document. This implementation expects that this document is the same as the other * document and thus attachments will be saved in the database in the same place as the ones which they are cloning. * * @param sourceDocument an XWikiDocument to copy attachments from */ private void cloneAttachments(final XWikiDocument sourceDocument) { this.getAttachmentList().clear(); for (XWikiAttachment attach : sourceDocument.getAttachmentList()) { XWikiAttachment newAttach = (XWikiAttachment) attach.clone(); // Document is set to this because if this document is renamed then the attachment will have a new id // and be saved somewhere different. newAttach.setDoc(this); this.getAttachmentList().add(newAttach); } }
/** * Clone an attachment but not it's archive.{@link ListAttachmentArchive#clone()} calls {@link * XWikiAttachment#clone()} and if the attachment is associated with an archive it call clone the archive. This * function prevents an infinite loop. * * @param original an attachment to clone. * @return a clone of original which has no XWikiAttachmentArchive attached. */ private static XWikiAttachment cloneAttachment(final XWikiAttachment original) { final XWikiAttachmentArchive arch = original.getAttachment_archive(); try { original.setAttachment_archive(null); return (XWikiAttachment) original.clone(); } finally { original.setAttachment_archive(arch); } }
/** * Clone an attachment but not it's archive.{@link ListAttachmentArchive#clone()} calls {@link * XWikiAttachment#clone()} and if the attachment is associated with an archive it call clone the archive. This * function prevents an infinite loop. * * @param original an attachment to clone. * @return a clone of original which has no XWikiAttachmentArchive attached. */ private static XWikiAttachment cloneAttachment(final XWikiAttachment original) { final XWikiAttachmentArchive arch = original.getAttachment_archive(); try { original.setAttachment_archive(null); return (XWikiAttachment) original.clone(); } finally { original.setAttachment_archive(arch); } }
/** * Copy attachments from one document to another. This implementation expects that you are copying the attachment * from one document to another and thus it should be saved seperately from the original in the database. * * @param sourceDocument an XWikiDocument to copy attachments from */ public void copyAttachments(XWikiDocument sourceDocument) { getAttachmentList().clear(); Iterator<XWikiAttachment> attit = sourceDocument.getAttachmentList().iterator(); while (attit.hasNext()) { XWikiAttachment attachment = attit.next(); XWikiAttachment newattachment = (XWikiAttachment) attachment.clone(); newattachment.setDoc(this); // TODO: Why must attachment content must be set dirty --cjdelisle if (newattachment.getAttachment_content() != null) { newattachment.getAttachment_content().setContentDirty(true); } getAttachmentList().add(newattachment); } setContentDirty(true); }
/** * {@inheritDoc} * <p> * The XWiki context is unused and may safely be null. * </p> * * @see com.xpn.xwiki.doc.DeletedAttachment#setAttachment(XWikiAttachment, XWikiContext) */ @Override protected void setAttachment(final XWikiAttachment attachment, final XWikiContext context) { this.attachment = (XWikiAttachment) attachment.clone(); if (this.getDate() != null) { this.setId(generateId(this.attachment, this.getDate())); } }
XWikiAttachment thumbnail = (XWikiAttachment) attachment.clone(); thumbnail.setContent(new ByteArrayInputStream(bout.toByteArray()), bout.size());
XWikiAttachment thumbnail; if (data != null) { thumbnail = (XWikiAttachment) image.clone(); thumbnail.setContent(new ByteArrayInputStream(data), data.length); } else {
fakeAvatarAttachment = (XWikiAttachment) realAvatarAttachment.clone(); sourceImageInputStream = realAvatarAttachment.getContentInputStream(context);
@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; }