public void fromXML(Element docel) throws XWikiException { setFilename(docel.element("filename").getText()); setFilesize(Integer.parseInt(docel.element("filesize").getText())); setAuthor(docel.element("author").getText()); setVersion(docel.element("version").getText()); setComment(docel.element("comment").getText()); String sdate = docel.element("date").getText(); Date date = new Date(Long.parseLong(sdate)); setDate(date); Element contentel = docel.element("content"); if (contentel != null) { String base64content = contentel.getText(); byte[] content = Base64.decodeBase64(base64content.getBytes()); setContent(content); } Element archiveel = docel.element("versions"); if (archiveel != null) { String archive = archiveel.getText(); setArchive(archive); } }
@Override public XWikiAttachment parse(final Element docel) throws IOException { if (!ROOT_ELEMENT_NAME.equals(docel.getName())) { throw new IOException("XML not recognizable as attachment metadata, expecting <attachment> tag"); } if (docel.attribute(SERIALIZER_PARAM) == null || !THIS_SERIALIZER.equals(docel.attribute(SERIALIZER_PARAM).getValue())) { throw new IOException("Cannot parse this attachment metadata, it was saved with a different " + "serializer."); } final XWikiAttachment out = new XWikiAttachment(); out.setFilename(docel.element(FILENAME).getText()); out.setFilesize(Integer.parseInt(docel.element(FILESIZE).getText())); out.setAuthor(docel.element(AUTHOR).getText()); out.setVersion(docel.element(VERSION).getText()); out.setComment(docel.element(COMMENT).getText()); final String sdate = docel.element(DATE).getText(); final Date date = new Date(Long.parseLong(sdate)); out.setDate(date); return out; }
@Override public XWikiAttachment parse(final Element docel) throws IOException { if (!ROOT_ELEMENT_NAME.equals(docel.getName())) { throw new IOException("XML not recognizable as attachment metadata, expecting <attachment> tag"); } if (docel.attribute(SERIALIZER_PARAM) == null || !THIS_SERIALIZER.equals(docel.attribute(SERIALIZER_PARAM).getValue())) { throw new IOException("Cannot parse this attachment metadata, it was saved with a different " + "serializer."); } final XWikiAttachment out = new XWikiAttachment(); out.setFilename(docel.element(FILENAME).getText()); out.setLongSize(Long.parseLong(docel.element(FILESIZE).getText())); out.setAuthor(docel.element(AUTHOR).getText()); out.setVersion(docel.element(VERSION).getText()); out.setComment(docel.element(COMMENT).getText()); final String sdate = docel.element(DATE).getText(); final Date date = new Date(Long.parseLong(sdate)); out.setDate(date); return out; }
/** * @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); } }
/** * @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); } }
revattach.fromXML(scontent); revattach.setDoc(attachment.getDoc()); revattach.setVersion(rev); return revattach; } catch (Exception e) {
if (version != null) { if (VALID_VERSION.matcher(version).matches()) { attachment.setVersion(version); } else if (NumberUtils.isDigits(version)) { attachment.setVersion(version + ".1"); } else {
oldAttachmentRevision.setVersion(attachmentToRevert.getVersion()); oldAttachmentRevision.setMetaDataDirty(true); oldAttachmentRevision.getAttachment_content().setContentDirty(true); restoredAttachmentRevision.setAttachment_archive(restoredAttachment.getAttachment_archive()); restoredAttachmentRevision.getAttachment_archive().setAttachment(restoredAttachmentRevision); restoredAttachmentRevision.setVersion(restoredAttachment.getVersion()); restoredAttachmentRevision.setMetaDataDirty(true); restoredAttachmentRevision.getAttachment_content().setContentDirty(true);