Skip to content
Snippets Groups Projects
Commit 41d96a4b authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- added code to extract the attributes of transfomed results

parent bda17832
No related branches found
No related tags found
No related merge requests found
......@@ -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());
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment