/** * Export {@link XWikiAttachment} to {@link DeletedAttachment}. * * @param attachment the deleted attachment * @param context the current context, used in the XML export * @throws XWikiException if an exception occurs during the XML export */ protected void setAttachment(XWikiAttachment attachment, XWikiContext context) throws XWikiException { setXml(attachment.toStringXML(true, true, context)); }
/** * Convert this attachment archive into JRCS format. * * @param context the XWikiContext for the request. * @return this archive in JRCS format. * @throws Exception if something goes wrong while serializing the attachment to XML or inserting it into the RCS * archive. */ private Archive toRCS(final XWikiContext context) throws Exception { final Version[] versions = this.getVersions(); Archive rcsArch = null; for (XWikiAttachment rev : this.revisions) { final String sdata = rev.toStringXML(true, false, context); final Object[] lines = ToString.stringToArray(sdata); if (rcsArch == null) { // First cycle. rcsArch = new Archive(lines, rev.getFilename(), rev.getVersion()); } else { rcsArch.addRevision(lines, ""); } } return rcsArch; }
/** * Convert this attachment archive into JRCS format. * * @param context the XWikiContext for the request. * @return this archive in JRCS format. * @throws Exception if something goes wrong while serializing the attachment to XML or inserting it into the RCS * archive. */ private Archive toRCS(final XWikiContext context) throws Exception { final Version[] versions = this.getVersions(); Archive rcsArch = null; for (XWikiAttachment rev : this.revisions) { final String sdata = rev.toStringXML(true, false, context); final Object[] lines = ToString.stringToArray(sdata); if (rcsArch == null) { // First cycle. rcsArch = new Archive(lines, rev.getFilename(), rev.getVersion()); } else { rcsArch.addRevision(lines, ""); } } return rcsArch; }
/** * 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); } }