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

- added getValidationDetails()

parent 2883b2ba
Branches
Tags
No related merge requests found
Pipeline #3579 passed
...@@ -75,6 +75,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -75,6 +75,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
private boolean wellformed = false; private boolean wellformed = false;
private final DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance(); private final DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance();
private List<String> errors = new ArrayList<>(); private List<String> errors = new ArrayList<>();
private List<String> detail = new ArrayList<>();
private static final HashSet<validationSchema> namespaceSchemaMap = new HashSet<>() { 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")); 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 { ...@@ -167,6 +168,8 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
DocumentBuilder db = dbf.newDocumentBuilder(); DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File(filePath)); Document doc = db.parse(new File(filePath));
xmlInfoRecord info = getXMLinfo(doc); xmlInfoRecord info = getXMLinfo(doc);
detail.add("detect XML type via NS:" + info.nameSpaceUri);
printXMLinfo(doc); printXMLinfo(doc);
if (!info.xmlVersion.equals("1.0")) { if (!info.xmlVersion.equals("1.0")) {
reportError("not an expected XML 1.0 document, found " + info.xmlVersion, filePath); reportError("not an expected XML 1.0 document, found " + info.xmlVersion, filePath);
...@@ -175,6 +178,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -175,6 +178,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
return false; return false;
} }
wellformed=true; wellformed=true;
detail.add("checked XML is wellformed");
/* TODO: align corresponding Schema based on systemID */ /* TODO: align corresponding Schema based on systemID */
var schema = assignSchema(doc); var schema = assignSchema(doc);
if (schema.isEmpty()) { if (schema.isEmpty()) {
...@@ -182,6 +186,9 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -182,6 +186,9 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
valid = false; valid = false;
return 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(); // TODO: SAXParser parser = spf.newSAXParser();
// parser.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), "catalog.xml"); // parser.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), "catalog.xml");
...@@ -227,6 +234,11 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -227,6 +234,11 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
return null; 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 /** 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
*/ */
......
...@@ -9,8 +9,8 @@ import java.nio.file.Files; ...@@ -9,8 +9,8 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link SLUBXmlFormatValidationPlugin}. * Tests for {@link SLUBXmlFormatValidationPlugin}.
* *
...@@ -20,9 +20,7 @@ import static org.junit.Assert.assertTrue; ...@@ -20,9 +20,7 @@ import static org.junit.Assert.assertTrue;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class TestSLUBXmlFormatValidationPlugin { public class TestSLUBXmlFormatValidationPlugin {
private static SLUBXmlFormatValidationPlugin mock; private static SLUBXmlFormatValidationPlugin mock;
private Path[] testPaths; private Path[] testPaths;
@Before @Before
public void setUp() { public void setUp() {
...@@ -43,6 +41,7 @@ public class TestSLUBXmlFormatValidationPlugin { ...@@ -43,6 +41,7 @@ public class TestSLUBXmlFormatValidationPlugin {
assertFalse("validateFormat(" + path + "), returns valid?", mock.validateFormat(path.toString())); assertFalse("validateFormat(" + path + "), returns valid?", mock.validateFormat(path.toString()));
assertFalse("validateFormat(" + path + "), is valid?", mock.validateFormat(path.toString())); assertFalse("validateFormat(" + path + "), is valid?", mock.validateFormat(path.toString()));
assertTrue( "validateFormat(" + path + "), is wellformed?", mock.isWellFormed()); assertTrue( "validateFormat(" + path + "), is wellformed?", mock.isWellFormed());
assertNotNull("getValidationDetails(), " + path + ", not null", mock.getValidationDetails());
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment