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

- added getValidationDetails()

parent 2883b2ba
No related branches found
No related tags found
No related merge requests found
Pipeline #3579 passed
......@@ -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
*/
......
......@@ -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}.
*
......@@ -21,8 +21,6 @@ import static org.junit.Assert.assertTrue;
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());
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment