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

- add support for relaxng

parent 801fa8d0
Branches
Tags
No related merge requests found
Pipeline #4216 failed
......@@ -20,7 +20,7 @@ JAR:=SLUBXmlFormatValidationPlugin.jar
# classpath
JUNITCLASSPATH:=./java/:/usr/share/java/junit4.jar:$(shell find ${ROSETTASDKDEPOSIT} -name "*.jar" -print |xargs echo |sed -e "s/ /:/g"):$(JAR)
#SOURCESCLASSPATH=org/slub/rosetta/dps/repository/plugin/storage/nfs
CLASSPATH:=${ROSETTASDKDEPOSIT}/dps-sdk-${ROSETTAVERSION}.jar:${LOCALJARS}
CLASSPATH:=/usr/share/java/jing.jar:${ROSETTASDKDEPOSIT}/dps-sdk-${ROSETTAVERSION}.jar:${LOCALJARS}
#BUILDPATH=$(CLASSPATH)
# sources
......
......@@ -18,7 +18,11 @@ package org.slub.rosetta.dps.repository.plugin;
import com.exlibris.core.infra.common.exceptions.logging.ExLogger;
import com.exlibris.dps.sdk.techmd.FormatValidationPlugin;
import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
......@@ -34,8 +38,13 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* SLUBXmlFormatValidationPlugin
*
......@@ -238,19 +247,21 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
if (checkIfWellformed(doc)) {
wellformed = true;
errors.clear();
Optional<ValidationSchema> schema = assignSchema(doc);
if (schema.isEmpty()) {
Optional<ValidationSchema> optSchema = assignSchema(doc);
if (optSchema.isEmpty()) {
System.out.println("-- empty");
reportError("there is no related schema found in *our* catalog of allowed XML types.", filePath);
valid = false;
} else {
reportDetail("assigned schema of type: " + schema.get().schemaType);
reportDetail("assigned schema uri: " + schema.get().schemaURI);
if (schema.get().schemaType == ValidationSchemaType.dtd) {
reportDetail("assigned schema of type: " + optSchema.get().schemaType);
reportDetail("assigned schema uri: " + optSchema.get().schemaURI);
if (optSchema.get().schemaType == ValidationSchemaType.dtd) {
useDtdValidation();
} else if (!schema.get().schemaURI.toString().isBlank()) {
useOtherSchemataValidation(schema);
}
valid = validateAgainstSchema(filePath);
} else if (!optSchema.get().schemaURI.toString().isBlank()) {
useOtherSchemataValidation(optSchema);
valid = validateAgainstSchema(filePath);
}
}
}
} catch (ParserConfigurationException e) {
......@@ -295,7 +306,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
var schemaInst = SchemaFactory.newDefaultInstance().newSchema(schemaURL);
dbf.setSchema(schemaInst);
} else if (schema.schemaType.equals(ValidationSchemaType.relaxng)) {
System.setProperty(SchemaFactory.class.getName() + ":" + XMLConstants.RELAXNG_NS_URI, "com.thaiopensource.relaxng.jaxp.CompactSyntaxSchemaFactory");
System.setProperty(SchemaFactory.class.getName() + ":" + XMLConstants.RELAXNG_NS_URI, "com.thaiopensource.relaxng.jaxp.XMLSyntaxSchemaFactory");
var schemaInst = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI).newSchema(schemaURL);
dbf.setSchema(schemaInst);
} else if (schema.schemaType.equals(ValidationSchemaType.schematron)) {
......
......@@ -56,12 +56,7 @@ public class TestSLUBXmlFormatValidationPlugin {
assertTrue ("validateFormat (pass), check if "+path+" exist", Files.exists(path));
assertTrue ("validateFormat(" + path + "), returns valid?", mock.validateFormat(path.toString()));
assertTrue ( "validateFormat(" + path + "), is wellformed?", mock.isWellFormed());
if (path.toString().endsWith(".mei")) {
System.out.println("Hint: RelaxNG not fully supported yet!");
assertFalse("validateFormat(" + path + "), reports no errors?", mock.getErrors().isEmpty());
} else {
assertTrue ("validateFormat(" + path + "), reports no errors?", mock.getErrors().isEmpty());
}
assertNotNull("getValidationDetails(), " + path + ", not null", mock.getValidationDetails());
assertTrue ("validateFormat(" + path + "), is valid?", mock.isValid());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment