DublinCoreXmlFormat extends DefaultHandler { @Nonnull public static DublinCoreCatalog read(InputStream xml) throws IOException, SAXException, ParserConfigurationException { return new DublinCoreXmlFormat().readImpl(new InputSource(xml)); } private  DublinCoreXmlFormat(); private  DublinCoreXmlFormat(boolean includeEmpty); @Nonnull static DublinCoreCatalog read(InputStream xml); @Nonnull static DublinCoreCatalog read(File xml); @Nonnull static DublinCoreCatalog read(String xml); static Opt<DublinCoreCatalog> readOpt(String xml); @Nonnull static DublinCoreCatalog read(Node xml); @Nonnull static DublinCoreCatalog read(File xml, boolean includeEmptiedElements); static DublinCoreCatalog merge(DublinCoreCatalog fromCatalog, DublinCoreCatalog intoCatalog); static Document writeDocument(DublinCoreCatalog dc); @Override void characters(char[] ch, int start, int length); @Override void startPrefixMapping(String prefix, String uri); @Override void startElement(String uri, String localName, String name, Attributes attributes); @Override void endElement(String uri, String localName, String name); @Override void error(SAXParseException e); @Override void fatalError(SAXParseException e); @Override void warning(SAXParseException e);  }
@Test public void readFromFile() throws Exception { assertEquals( "Land and Vegetation: Key players on the Climate Scene", DublinCoreXmlFormat .read(IoSupport.classPathResourceAsFile("/dublincore.xml").get()) .getFirst(DublinCore.PROPERTY_TITLE)); }
@Test public void readFromStringWithXmlHeader() throws Exception { final String xml = "<?xml version=\"1.0\"?>\n" + "<dublincore xmlns=\"http: + " xmlns:xsi=\"http: + " xmlns:dcterms=\"http: + " <dcterms:title>Land and Vegetation: Key players on the Climate Scene</dcterms:title>\n" + " <dcterms:subject>climate, land, vegetation</dcterms:subject>\n" + "</dublincore>"; assertEquals( "Land and Vegetation: Key players on the Climate Scene", DublinCoreXmlFormat.read(xml).getFirst(DublinCore.PROPERTY_TITLE)); }
@Test public void readFromStringWithoutXmlHeader() throws Exception { final String xml = "<dublincore xmlns=\"http: + " xmlns:xsi=\"http: + " xmlns:dcterms=\"http: + " <dcterms:title>Land and Vegetation: Key players on the Climate Scene</dcterms:title>\n" + " <dcterms:subject>climate, land, vegetation</dcterms:subject>\n" + "</dublincore>"; assertEquals( "Land and Vegetation: Key players on the Climate Scene", DublinCoreXmlFormat.read(xml).getFirst(DublinCore.PROPERTY_TITLE)); }
@Test public void readFromNode() throws Exception { final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); final Document doc = dbf.newDocumentBuilder().parse( IoSupport.classPathResourceAsFile("/matterhorn-inlined-list-records-response.xml").get()); final NamespaceContext ctx = XmlNamespaceContext.mk( XmlNamespaceBinding.mk("inlined", "http: XmlNamespaceBinding.mk("mp", "http: XmlNamespaceBinding.mk("dc", DublinCores.OC_DC_CATALOG_NS_URI)); final Node mpNode = Xpath.mk(doc, ctx).node(" final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpNode); assertNotNull(mp); assertEquals("10.0000/5820", mp.getIdentifier().toString()); final Node dcNode = Xpath.mk(doc, ctx).node(" final DublinCoreCatalog dc = DublinCoreXmlFormat.read(dcNode); assertNotNull(dc); assertEquals("10.0000/5820", DublinCores.mkOpencastEpisode(dc).getDcIdentifier().get()); }