@Test public void test1() { try { Document document = EpubProcessorSupport.createDocumentBuilder().parse(PackageDocumentMetadataReader.class.getResourceAsStream("/opf/test2.opf")); Metadata metadata = PackageDocumentMetadataReader.readMetadata(document); assertEquals(1, metadata.getAuthors().size()); } catch (Exception e) { e.printStackTrace(); assertTrue(false); } }
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);  }