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

- debugging output enabled

parent 16252e59
No related branches found
No related tags found
No related merge requests found
...@@ -22,20 +22,19 @@ import com.exlibris.dps.sdk.techmd.MDExtractorPlugin; ...@@ -22,20 +22,19 @@ import com.exlibris.dps.sdk.techmd.MDExtractorPlugin;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer; import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamSource;
import javax.xml.xpath.XPath; import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFactory;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
...@@ -87,12 +86,18 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -87,12 +86,18 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
this.mediaconch_binary_path = initp.get("mediaconch_binary_path").trim(); this.mediaconch_binary_path = initp.get("mediaconch_binary_path").trim();
this.mediaconch_profile_path = initp.get("mediaconch_profile_path").trim(); this.mediaconch_profile_path = initp.get("mediaconch_profile_path").trim();
this.mediainfo_binary_path = initp.get("mediainfo_binary_path").trim(); this.mediainfo_binary_path = initp.get("mediainfo_binary_path").trim();
try {
checkFileExists(this.mediainfo_binary_path);
checkFileExists(this.mediaconch_binary_path);
checkFileExists(this.mediaconch_profile_path);
System.out.println("SLUBTechnicalMetadataExtractorMediaConchPlugin instantiated with " System.out.println("SLUBTechnicalMetadataExtractorMediaConchPlugin instantiated with "
+ " mediaconch_binary_path=" + mediaconch_binary_path + " mediaconch_binary_path=" + mediaconch_binary_path
+ " mediaconch_profile_path=" + mediaconch_profile_path + " mediaconch_profile_path=" + mediaconch_profile_path
+ " mediainfo_binary_path=" + mediainfo_binary_path + " mediainfo_binary_path=" + mediainfo_binary_path
); );
} catch (Exception e) {
e.printStackTrace();
}
} }
@Override @Override
...@@ -109,15 +114,18 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -109,15 +114,18 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
@Override @Override
public void extract(String filePath) throws Exception { public void extract(String filePath) throws Exception {
if (StringUtils.isEmptyString(mediaconch_binary_path)) { if (StringUtils.isEmptyString(this.mediaconch_binary_path)) {
throw new Exception("mediaconch_binary_path not found"); throw new Exception("mediaconch_binary_path not found");
} }
if (StringUtils.isEmptyString(mediaconch_profile_path)) { if (StringUtils.isEmptyString(this.mediaconch_profile_path)) {
throw new Exception("mediaconch_profile_path not found"); throw new Exception("mediaconch_profile_path not found");
} }
if (StringUtils.isEmptyString(mediainfo_binary_path)) { if (StringUtils.isEmptyString(this.mediainfo_binary_path)) {
throw new Exception("mediainfo_binary_path not found"); throw new Exception("mediainfo_binary_path not found");
} }
checkFileExists(this.mediaconch_binary_path);
checkFileExists(this.mediaconch_profile_path);
checkFileExists(this.mediainfo_binary_path);
// mediaconch validation // mediaconch validation
call_mediaconch(filePath); call_mediaconch(filePath);
// mediainfo metadata extraction // mediainfo metadata extraction
...@@ -127,6 +135,7 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -127,6 +135,7 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
private void call_mediainfo_and_result_processing(String filePath) throws Exception { private void call_mediainfo_and_result_processing(String filePath) throws Exception {
String execstring = this.mediainfo_binary_path + " -f --Output=XML " + filePath; String execstring = this.mediainfo_binary_path + " -f --Output=XML " + filePath;
System.out.println("executing: " + execstring); System.out.println("executing: " + execstring);
checkFileExists(this.mediainfo_binary_path);
InputStreamReader process_out; InputStreamReader process_out;
try { try {
Process p = Runtime.getRuntime().exec(execstring); Process p = Runtime.getRuntime().exec(execstring);
...@@ -135,7 +144,7 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -135,7 +144,7 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
} catch (IOException e) { } catch (IOException e) {
//log.error("exception creation socket, clamd not available at host=" + host + "port=" + port, e); //log.error("exception creation socket, clamd not available at host=" + host + "port=" + port, e);
System.out.println("ERROR: (actual) mediainfo not available, path=" + this.mediainfo_binary_path + ", " + e.getMessage()); System.out.println("ERROR: (actual) mediainfo not available, path=" + this.mediainfo_binary_path + ", " + e.getMessage());
throw new Exception("ERROR: (actual) mediaconch not available, path=" + this.mediainfo_binary_path + ", " + e.getMessage()); throw new Exception("ERROR: (actual) mediainfo not available, path=" + this.mediainfo_binary_path + ", " + e.getMessage());
} }
BufferedReader reader = new BufferedReader(process_out); BufferedReader reader = new BufferedReader(process_out);
String line = reader.readLine(); String line = reader.readLine();
...@@ -162,12 +171,10 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -162,12 +171,10 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
temp_media_streamwriter.close(); temp_media_streamwriter.close();
/* xslt transform */ /* xslt transform */
InputStream stylestream = getClass().getResourceAsStream(MEDIAINFO_XSD); InputStream stylestream = getClass().getResourceAsStream(MEDIAINFO_XSD);
File tmp = new File(
String.valueOf(getClass().getResource(MEDIAINFO_XSD))
);
System.out.println("Resource=" + tmp.getPath());
StreamSource stylesource = new StreamSource(stylestream); StreamSource stylesource = new StreamSource(stylestream);
stylesource.setSystemId("./resources" + MEDIAINFO_XSD); stylesource.setSystemId("./resources" + MEDIAINFO_XSD);
System.out.println("stylesource, tempfile_raw=" + temp_media_outputfile.getAbsolutePath());
System.out.println("stylesource, tempfile_transformed=" + temp_media_transformed_outputfile.getAbsolutePath());
System.out.println("stylesource, systemID=" + stylesource.getSystemId()); System.out.println("stylesource, systemID=" + stylesource.getSystemId());
System.out.println("stylesource, publicID=" + stylesource.getPublicId()); System.out.println("stylesource, publicID=" + stylesource.getPublicId());
/* media info xml */ /* media info xml */
...@@ -177,21 +184,40 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -177,21 +184,40 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
System.out.println("mediainfo_source, systemID=" + mediainfo_source.getSystemId()); System.out.println("mediainfo_source, systemID=" + mediainfo_source.getSystemId());
System.out.println("mediainfo_source, publicID=" + mediainfo_source.getPublicId()); System.out.println("mediainfo_source, publicID=" + mediainfo_source.getPublicId());
// Use a Transformer for output // Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance(); TransformerFactory tFactory;
try {
tFactory = TransformerFactory.newInstance();
System.out.println("Factory module name:" + tFactory.getClass().getModule().getName());
tFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); tFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
tFactory.setFeature(XMLConstants.USE_CATALOG, false); tFactory.setFeature(XMLConstants.USE_CATALOG, false);
try {
System.out.println("stylesource=" + stylesource);
assert (!stylesource.isEmpty());
Transformer transformer = tFactory.newTransformer(stylesource); Transformer transformer = tFactory.newTransformer(stylesource);
assert (transformer != null);
System.out.println("transformer=" + transformer);
/* ok, mediainfo is loaded correctly, and xslt loaded too */ /* ok, mediainfo is loaded correctly, and xslt loaded too */
/* debug output: */ /* debug output: */
StreamResult result = new StreamResult(temp_media_transformed_outputstream); StreamResult result = new StreamResult(temp_media_transformed_outputstream);
System.out.println("result=" + result.getClass());
transformer.transform(mediainfo_source, result); transformer.transform(mediainfo_source, result);
} catch (TransformerConfigurationException e) {
System.err.println("TransformerConfigurationException" + e);
e.printStackTrace();
}
}catch (TransformerFactoryConfigurationError e) {
System.err.println("TransformerConfigurationError" + e);
e.printStackTrace();
}
temp_media_transformed_outputstream.close(); temp_media_transformed_outputstream.close();
mediastream.close(); mediastream.close();
/* TODO: read transformed outputfile and return attributes */ /* TODO: read transformed outputfile and return attributes */
extract_attributes_of_transformed_result(temp_media_transformed_outputfile); 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 { private void extract_attributes_of_transformed_result(File temp_media_transformed_outputfile) throws Exception {
checkFileExists(String.valueOf(temp_media_transformed_outputfile));
XPathFactory xPathfactory = XPathFactory.newInstance(); XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath(); XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("/mdExtractor/attributes/key"); XPathExpression expr = xpath.compile("/mdExtractor/attributes/key");
...@@ -251,6 +277,7 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -251,6 +277,7 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
public String getAgent() { public String getAgent() {
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();
response.append("mediaconch:\n"); response.append("mediaconch:\n");
String[] executables = { String[] executables = {
this.mediaconch_binary_path, this.mediaconch_binary_path,
this.mediainfo_binary_path this.mediainfo_binary_path
...@@ -259,6 +286,7 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -259,6 +286,7 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
String execstring = executable + " --Version"; String execstring = executable + " --Version";
InputStreamReader process_out = null; InputStreamReader process_out = null;
try { try {
checkFileExists( executable);
Process p = Runtime.getRuntime().exec(execstring); Process p = Runtime.getRuntime().exec(execstring);
p.waitFor(); p.waitFor();
process_out = new InputStreamReader(p.getInputStream()); process_out = new InputStreamReader(p.getInputStream());
...@@ -267,10 +295,12 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -267,10 +295,12 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} }
if (process_out != null) { if (process_out != null) {
BufferedReader reader = new BufferedReader(process_out); BufferedReader reader = new BufferedReader(process_out);
String line = null; String line;
try { try {
line = reader.readLine(); line = reader.readLine();
while (line != null) { while (line != null) {
...@@ -448,6 +478,13 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -448,6 +478,13 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
return "video/x-matroska"; return "video/x-matroska";
} }
private void checkFileExists (String filename) throws Exception {
File f = new File(filename);
if (! f.exists() ) {
System.out.println("ERROR: path=" + filename + "not available");
throw new Exception("ERROR: path=" + filename + "not available");
}
}
/** stand alone check, main file to call local installed clamd /** stand alone check, main file to call local installed clamd
* @param args list of files which should be scanned * @param args list of files which should be scanned
*/ */
...@@ -463,8 +500,10 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract ...@@ -463,8 +500,10 @@ public class SLUBTechnicalMetadataExtractorMediaConchPlugin implements MDExtract
System.out.println(); System.out.println();
for (String file : args) { for (String file : args) {
try { try {
System.out.println("extracting from " + file);
plugin.extract(file); plugin.extract(file);
} catch (Exception e) { } catch (Exception e) {
System.out.println("CALLERROR:");
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("RESULT: " + plugin.isValid()); System.out.println("RESULT: " + plugin.isValid());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment