public void fromXML(String data) throws XWikiException { SAXReader reader = new SAXReader(); Document domdoc = null; try { StringReader in = new StringReader(data); domdoc = reader.read(in); } catch (DocumentException e) { throw new XWikiException(XWikiException.MODULE_XWIKI_DOC, XWikiException.ERROR_DOC_XML_PARSING, "Error parsing xml", e, null); } Element docel = domdoc.getRootElement(); fromXML(docel); }
/** * @param rcsArchive the RCS archive to import. * @throws Exception if getting a revision from the RCS archive or deserializing an attachment from XML fails */ private void fromRCS(final Archive rcsArchive) throws Exception { if (rcsArchive == null) { return; } final Node[] nodes = rcsArchive.changeLog(); for (int i = nodes.length - 1; i > -1; i--) { final Object[] lines = rcsArchive.getRevision(nodes[i].getVersion()); final StringBuilder content = new StringBuilder(); for (int j = 0; j < lines.length; j++) { String line = lines[j].toString(); content.append(line); if (j != lines.length - 1) { content.append("\n"); } } final XWikiAttachment rev = new XWikiAttachment(); rev.fromXML(content.toString()); rev.setDoc(getAttachment().getDoc()); rev.setAttachment_archive(this); // this should not be necessary, keeping to maintain behavior. rev.setVersion(nodes[i].getVersion().toString()); revisions.add(rev); } }
/** * @param rcsArchive the RCS archive to import. * @throws Exception if getting a revision from the RCS archive or deserializing an attachment from XML fails */ private void fromRCS(final Archive rcsArchive) throws Exception { if (rcsArchive == null) { return; } final Node[] nodes = rcsArchive.changeLog(); for (int i = nodes.length - 1; i > -1; i--) { final Object[] lines = rcsArchive.getRevision(nodes[i].getVersion()); final StringBuilder content = new StringBuilder(); for (int j = 0; j < lines.length; j++) { String line = lines[j].toString(); content.append(line); if (j != lines.length - 1) { content.append("\n"); } } final XWikiAttachment rev = new XWikiAttachment(); rev.fromXML(content.toString()); rev.setDoc(this.getAttachment().getDoc()); rev.setAttachment_archive(this); // this should not be necessary, keeping to maintain behavior. rev.setVersion(nodes[i].getVersion().toString()); revisions.add(rev); } }
revattach.fromXML(scontent); revattach.setDoc(attachment.getDoc()); revattach.setVersion(rev);
/** * Restore a {@link XWikiAttachment} from a {@link DeletedAttachment}. Note that this method does not actually * restore the attachment to its owner document, it simply recomposes an {@link XWikiAttachment} object from the * saved data. * * @return restored attachment * @param attachment optional object where to put the attachment data, if not <code>null</code> * @param context the current {@link XWikiContext context} * @throws XWikiException If an exception occurs while the Attachment is restored from the XML. See * {@link XWikiAttachment#fromXML(String)}. */ public XWikiAttachment restoreAttachment(XWikiAttachment attachment, XWikiContext context) throws XWikiException { XWikiAttachment result = attachment; if (result == null) { result = new XWikiAttachment(); } result.fromXML(getXml()); if (result.getDoc() == null || !(this.getDocName().equals(result.getDoc().getFullName()))) { result.setDoc(context.getWiki().getDocument(this.getDocName(), context)); } return result; } }
XWikiAttachment attach = new XWikiAttachment(); attach.setDoc(this); attach.fromXML(atel); getAttachmentList().add(attach);
@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; }