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; }
attachment.setComment(getString(WikiAttachmentFilter.PARAMETER_REVISION_COMMENT, parameters, "")); attachment.setDate(getDate(WikiAttachmentFilter.PARAMETER_REVISION_DATE, parameters, new Date()));
attachment.setComment(getComment()); attachment.setDate(getDate()); attachment.setDoc(getDoc());