diff --git a/java/org/slub/rosetta/dps/repository/plugin/SLUBXmlFormatValidationPlugin.java b/java/org/slub/rosetta/dps/repository/plugin/SLUBXmlFormatValidationPlugin.java index 13ce3b958dd648fdf083b566e1b99cac7fb27f0a..fedae34c99e8395db3b31c7d886ed32fec11bbda 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/SLUBXmlFormatValidationPlugin.java +++ b/java/org/slub/rosetta/dps/repository/plugin/SLUBXmlFormatValidationPlugin.java @@ -75,6 +75,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { private boolean wellformed = false; private final DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance(); private List<String> errors = new ArrayList<>(); + private List<String> detail = new ArrayList<>(); private static final HashSet<validationSchema> namespaceSchemaMap = new HashSet<>() { { add(new validationSchema("http://www.loc.gov/standards/alto/ns-v2#", schema, "http://www.loc.gov/standards/alto/alto-v2.0.xsd")); @@ -167,6 +168,8 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new File(filePath)); xmlInfoRecord info = getXMLinfo(doc); + detail.add("detect XML type via NS:" + info.nameSpaceUri); + printXMLinfo(doc); if (!info.xmlVersion.equals("1.0")) { reportError("not an expected XML 1.0 document, found " + info.xmlVersion, filePath); @@ -175,6 +178,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { return false; } wellformed=true; + detail.add("checked XML is wellformed"); /* TODO: align corresponding Schema based on systemID */ var schema = assignSchema(doc); if (schema.isEmpty()) { @@ -182,6 +186,9 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { valid = false; return false; } + detail.add("assigned schema of type: " + schema.get().schemaType); + detail.add("assigned schema url: " + schema.get().schemaURL); + // TODO: SAXParser parser = spf.newSAXParser(); // parser.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), "catalog.xml"); @@ -227,6 +234,11 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { return null; } + @Override + public String getValidationDetails() { + return detail.stream().reduce("", (all, res) -> all.concat("\n") .concat(res) ); + } + /** stand-alone check, main file to call local installed clamd * @param args list of files which should be scanned */ diff --git a/java/org/slub/rosetta/dps/repository/plugin/TestSLUBXmlFormatValidationPlugin.java b/java/org/slub/rosetta/dps/repository/plugin/TestSLUBXmlFormatValidationPlugin.java index 35fc96f34332c72e513706e757ac039cd78e6c3f..9e49193e1967948fa2470875aaac598536cbcda5 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/TestSLUBXmlFormatValidationPlugin.java +++ b/java/org/slub/rosetta/dps/repository/plugin/TestSLUBXmlFormatValidationPlugin.java @@ -9,8 +9,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.stream.Stream; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; + /** * Tests for {@link SLUBXmlFormatValidationPlugin}. * @@ -20,9 +20,7 @@ import static org.junit.Assert.assertTrue; @RunWith(JUnit4.class) public class TestSLUBXmlFormatValidationPlugin { private static SLUBXmlFormatValidationPlugin mock; - - - + private Path[] testPaths; @Before public void setUp() { @@ -43,6 +41,7 @@ public class TestSLUBXmlFormatValidationPlugin { assertFalse("validateFormat(" + path + "), returns valid?", mock.validateFormat(path.toString())); assertFalse("validateFormat(" + path + "), is valid?", mock.validateFormat(path.toString())); assertTrue( "validateFormat(" + path + "), is wellformed?", mock.isWellFormed()); + assertNotNull("getValidationDetails(), " + path + ", not null", mock.getValidationDetails()); } } }