@Test public void testParse() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(TEST_CONTENT.getBytes("US-ASCII")); final XWikiAttachment attach = this.serializer.parse(bais); bais.close(); Assert.assertEquals("Attachment1 had wrong name", "file1", attach.getFilename()); Assert.assertEquals("Attachment1 had wrong author", "me", attach.getAuthor()); Assert.assertEquals("Attachment1 had wrong version", "1.1", attach.getVersion()); Assert.assertEquals("Attachment1 had wrong comment", attach.getComment(), "something whitty"); Assert.assertEquals("Attachment1 had wrong date.", attach.getDate().getTime() + "", "1293045632000"); }
@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; }
AttachmentMetadataSerializer extends AbstractXMLSerializer<XWikiAttachment, XWikiAttachment> { @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; } }
AttachmentMetadataSerializer extends AbstractXMLSerializer<XWikiAttachment, XWikiAttachment> { @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; }  }
AttachmentMetadataSerializer extends AbstractXMLSerializer<XWikiAttachment, XWikiAttachment> { @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; }  @Override XWikiAttachment parse(final Element docel); @Override void serialize(final XWikiAttachment attach, final XMLWriter writer); }
AttachmentMetadataSerializer extends AbstractXMLSerializer<XWikiAttachment, XWikiAttachment> { @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; }  @Override XWikiAttachment parse(final Element docel); @Override void serialize(final XWikiAttachment attach, final XMLWriter writer);  }