@Test public void test2() throws SAXException, IOException { String input = "<package version=\"2.0\" xmlns=\"http: + "<metadata xmlns=\"http: + "<dc:title>Three Men in a Boat</dc:title>" + "<dc:creator opf:role=\"aut\" opf:file-as=\"Jerome, Jerome K.\">Jerome K. Jerome</dc:creator>" + "<dc:creator opf:role=\"ill\" opf:file-as=\"Frederics, A.\">A. Frederics</dc:creator>" + "<dc:language>en</dc:language>" + "<dc:date opf:event=\"publication\">1889</dc:date>" + "<dc:date opf:event=\"creation\">2009-05-17</dc:date>" + "<dc:identifier opf:scheme=\"URI\" id=\"BookId\">zelda@mobileread.com:2010040720</dc:identifier>" + "<dc:contributor opf:role=\"bkp\">zelda pinwheel</dc:contributor>" + "<dc:publisher>zelda pinwheel</dc:publisher>" + "<dc:rights>Public Domain</dc:rights>" + "<dc:type>Text</dc:type>" + "<dc:type>Image</dc:type>" + "<dc:subject>Travel</dc:subject>" + "<dc:subject>Humour</dc:subject>" + "<dc:description>Three Men in a Boat (To Say Nothing of the Dog), published in 1889, is a humorous account by Jerome K. Jerome of a boating holiday on the Thames between Kingston and Oxford. The book was initially intended to be a serious travel guide, with accounts of local history along the route, but the humorous elements took over to the point where the serious and somewhat sentimental passages seem a distraction to the comic novel. One of the most praised things about Three Men in a Boat is how undated it appears to modern readers, the jokes seem fresh and witty even today.</dc:description>" + "<meta name=\"cover\" content=\"cover_pic\" />" + "<meta name=\"calibre:rating\" content=\"8\"/>" + "</metadata>" + "</package>"; Document metadataDocument = EpubProcessorSupport.createDocumentBuilder().parse(new InputSource(new StringReader(input))); Metadata metadata = PackageDocumentMetadataReader.readMetadata(metadataDocument); Assert.assertEquals("Three Men in a Boat", metadata.getFirstTitle()); Assert.assertNotNull(metadata.getIdentifiers()); Assert.assertEquals(1, metadata.getIdentifiers().size()); Identifier identifier = metadata.getIdentifiers().get(0); Assert.assertEquals("URI", identifier.getScheme()); Assert.assertEquals("zelda@mobileread.com:2010040720", identifier.getValue()); Assert.assertEquals("8", metadata.getMetaAttribute("calibre:rating")); Assert.assertEquals("cover_pic", metadata.getMetaAttribute("cover")); }
public static Metadata readMetadata(Document packageDocument) { Metadata result = new Metadata(); Element metadataElement = DOMUtil.getFirstElementByTagNameNS(packageDocument.getDocumentElement(), NAMESPACE_OPF, OPFTags.metadata); if(metadataElement == null) { log.error("Package does not contain element " + OPFTags.metadata); return result; } result.setTitles(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.title)); result.setPublishers(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.publisher)); result.setDescriptions(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.description)); result.setRights(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.rights)); result.setTypes(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.type)); result.setSubjects(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.subject)); result.setIdentifiers(readIdentifiers(metadataElement)); result.setAuthors(readCreators(metadataElement)); result.setContributors(readContributors(metadataElement)); result.setDates(readDates(metadataElement)); result.setOtherProperties(readOtherProperties(metadataElement)); result.setMetaAttributes(readMetaProperties(metadataElement)); Element languageTag = DOMUtil.getFirstElementByTagNameNS(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.language); if (languageTag != null) { result.setLanguage(DOMUtil.getTextChildrenContent(languageTag)); } return result; }
PackageDocumentMetadataReader extends PackageDocumentBase { public static Metadata readMetadata(Document packageDocument) { Metadata result = new Metadata(); Element metadataElement = DOMUtil.getFirstElementByTagNameNS(packageDocument.getDocumentElement(), NAMESPACE_OPF, OPFTags.metadata); if(metadataElement == null) { log.error("Package does not contain element " + OPFTags.metadata); return result; } result.setTitles(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.title)); result.setPublishers(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.publisher)); result.setDescriptions(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.description)); result.setRights(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.rights)); result.setTypes(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.type)); result.setSubjects(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.subject)); result.setIdentifiers(readIdentifiers(metadataElement)); result.setAuthors(readCreators(metadataElement)); result.setContributors(readContributors(metadataElement)); result.setDates(readDates(metadataElement)); result.setOtherProperties(readOtherProperties(metadataElement)); result.setMetaAttributes(readMetaProperties(metadataElement)); Element languageTag = DOMUtil.getFirstElementByTagNameNS(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.language); if (languageTag != null) { result.setLanguage(DOMUtil.getTextChildrenContent(languageTag)); } return result; } }
PackageDocumentMetadataReader extends PackageDocumentBase { public static Metadata readMetadata(Document packageDocument) { Metadata result = new Metadata(); Element metadataElement = DOMUtil.getFirstElementByTagNameNS(packageDocument.getDocumentElement(), NAMESPACE_OPF, OPFTags.metadata); if(metadataElement == null) { log.error("Package does not contain element " + OPFTags.metadata); return result; } result.setTitles(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.title)); result.setPublishers(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.publisher)); result.setDescriptions(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.description)); result.setRights(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.rights)); result.setTypes(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.type)); result.setSubjects(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.subject)); result.setIdentifiers(readIdentifiers(metadataElement)); result.setAuthors(readCreators(metadataElement)); result.setContributors(readContributors(metadataElement)); result.setDates(readDates(metadataElement)); result.setOtherProperties(readOtherProperties(metadataElement)); result.setMetaAttributes(readMetaProperties(metadataElement)); Element languageTag = DOMUtil.getFirstElementByTagNameNS(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.language); if (languageTag != null) { result.setLanguage(DOMUtil.getTextChildrenContent(languageTag)); } return result; }  }
PackageDocumentMetadataReader extends PackageDocumentBase { public static Metadata readMetadata(Document packageDocument) { Metadata result = new Metadata(); Element metadataElement = DOMUtil.getFirstElementByTagNameNS(packageDocument.getDocumentElement(), NAMESPACE_OPF, OPFTags.metadata); if(metadataElement == null) { log.error("Package does not contain element " + OPFTags.metadata); return result; } result.setTitles(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.title)); result.setPublishers(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.publisher)); result.setDescriptions(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.description)); result.setRights(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.rights)); result.setTypes(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.type)); result.setSubjects(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.subject)); result.setIdentifiers(readIdentifiers(metadataElement)); result.setAuthors(readCreators(metadataElement)); result.setContributors(readContributors(metadataElement)); result.setDates(readDates(metadataElement)); result.setOtherProperties(readOtherProperties(metadataElement)); result.setMetaAttributes(readMetaProperties(metadataElement)); Element languageTag = DOMUtil.getFirstElementByTagNameNS(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.language); if (languageTag != null) { result.setLanguage(DOMUtil.getTextChildrenContent(languageTag)); } return result; }  static Metadata readMetadata(Document packageDocument); }
PackageDocumentMetadataReader extends PackageDocumentBase { public static Metadata readMetadata(Document packageDocument) { Metadata result = new Metadata(); Element metadataElement = DOMUtil.getFirstElementByTagNameNS(packageDocument.getDocumentElement(), NAMESPACE_OPF, OPFTags.metadata); if(metadataElement == null) { log.error("Package does not contain element " + OPFTags.metadata); return result; } result.setTitles(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.title)); result.setPublishers(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.publisher)); result.setDescriptions(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.description)); result.setRights(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.rights)); result.setTypes(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.type)); result.setSubjects(DOMUtil.getElementsTextChild(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.subject)); result.setIdentifiers(readIdentifiers(metadataElement)); result.setAuthors(readCreators(metadataElement)); result.setContributors(readContributors(metadataElement)); result.setDates(readDates(metadataElement)); result.setOtherProperties(readOtherProperties(metadataElement)); result.setMetaAttributes(readMetaProperties(metadataElement)); Element languageTag = DOMUtil.getFirstElementByTagNameNS(metadataElement, NAMESPACE_DUBLIN_CORE, DCTags.language); if (languageTag != null) { result.setLanguage(DOMUtil.getTextChildrenContent(languageTag)); } return result; }  static Metadata readMetadata(Document packageDocument);  }