diff --git a/java/org/slub/rosetta/dps/repository/plugin/SLUBTechnicalMetadataExtractorMediaConchPlugin.java b/java/org/slub/rosetta/dps/repository/plugin/SLUBTechnicalMetadataExtractorMediaConchPlugin.java index 31cd0fbdf0a72d9a56b0f4f5a1e39dd2babf9a4c..99740b05a1608b9d9113033bd97a99486d0c8edb 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/SLUBTechnicalMetadataExtractorMediaConchPlugin.java +++ b/java/org/slub/rosetta/dps/repository/plugin/SLUBTechnicalMetadataExtractorMediaConchPlugin.java @@ -19,12 +19,24 @@ package org.slub.rosetta.dps.repository.plugin; import com.exlibris.core.sdk.strings.StringUtils; import com.exlibris.dps.sdk.techmd.MDExtractorPlugin; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -173,11 +185,27 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract /* debug output: */ StreamResult result = new StreamResult(temp_media_transformed_outputstream); transformer.transform(mediainfo_source, result); - /* TODO: read debugFile and return attributes */ - attributes.put("key", "value"); - /* */ temp_media_transformed_outputstream.close(); mediastream.close(); + /* TODO: read transformed outputfile and return attributes */ + extract_attributes_of_transformed_result(temp_media_transformed_outputfile); + } + + private void extract_attributes_of_transformed_result(File temp_media_transformed_outputfile) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + XPathFactory xPathfactory = XPathFactory.newInstance(); + XPath xpath = xPathfactory.newXPath(); + XPathExpression expr = xpath.compile("/mdExtractor/attributes/key"); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document temp_media_transformed_source = db.parse(temp_media_transformed_outputfile); + NodeList nl = (NodeList) expr.evaluate(temp_media_transformed_source, XPathConstants.NODESET); + int len = nl.getLength(); + for ( int i = 0; i < len; i++ ) { + Node node = nl.item(i); + String id = String.valueOf(node.getAttributes().getNamedItem("id")); + String value = node.getTextContent(); + attributes.put(id, value); + } } private void call_mediaconch(String filePath) throws Exception { @@ -395,7 +423,7 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract @Override public boolean isValid() { - System.out.println("DEBUG: is valid=" + this.isvalid); + //System.out.println("DEBUG: is valid=" + this.isvalid); return this.isvalid; } @Override @@ -461,8 +489,11 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract System.out.println("----------------------------------"); System.out.println("getProfile:"); System.out.println( plugin.getProfile()); - - + System.out.println("----------------------------------"); + System.out.println("getAttributeByName (summarized):"); + for (Map.Entry m: plugin.attributes.entrySet()) { + System.out.println( m.getKey() + " -> " + m.getValue()); + } } }