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

- bugfix, DTDs and Schemas uses URIs instead URLs, therefore some adaptions needed

parent 095d8f85
No related branches found
No related tags found
No related merge requests found
Pipeline #4213 passed
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<slubschemacatalog> <slubschemacatalog>
<entry schematype="schema" namespace="http://www.loc.gov/mods/v3" schemaurl="http://www.loc.gov/standards/mods/v3/mods-3-8.xsd" /> <entry schematype="schema" namespace="http://www.loc.gov/mods/v3" schemauri="http://www.loc.gov/standards/mods/v3/mods-3-8.xsd" />
<entry schematype="schema" namespace="http://www.lido-schema.org" schemaurl="http://www.lido-schema.org/schema/v1.1/lido-v1.1.xsd" /> <entry schematype="schema" namespace="http://www.lido-schema.org" schemauri="http://www.lido-schema.org/schema/v1.1/lido-v1.1.xsd" />
<entry schematype="schema" namespace="http://slubarchiv.slub-dresden.de/rights1" schemaurl="https://slubarchiv.slub-dresden.de/fileadmin/groups/slubsite/slubarchiv/standards/rights/rights1.xsd" /> <entry schematype="schema" namespace="http://slubarchiv.slub-dresden.de/rights1" schemauri="https://slubarchiv.slub-dresden.de/fileadmin/groups/slubsite/slubarchiv/standards/rights/rights1.xsd" />
<entry schematype="schema" namespace="http://www.loc.gov/standards/alto/ns-v2#" schemaurl="http://www.loc.gov/standards/alto/alto-v2.0.xsd" /> <entry schematype="schema" namespace="http://www.loc.gov/standards/alto/ns-v2#" schemauri="http://www.loc.gov/standards/alto/alto-v2.0.xsd" />
<entry schematype="relaxng" namespace="http://www.music-encoding.org/ns/mei" schemaurl="https://raw.githubusercontent.com/music-encoding/music-encoding/v3.0.0/schemata/mei-all.rng" /> <entry schematype="relaxng" namespace="http://www.music-encoding.org/ns/mei" schemauri="https://raw.githubusercontent.com/music-encoding/music-encoding/v3.0.0/schemata/mei-all.rng" />
</slubschemacatalog> </slubschemacatalog>
...@@ -18,11 +18,7 @@ package org.slub.rosetta.dps.repository.plugin; ...@@ -18,11 +18,7 @@ package org.slub.rosetta.dps.repository.plugin;
import com.exlibris.core.infra.common.exceptions.logging.ExLogger; import com.exlibris.core.infra.common.exceptions.logging.ExLogger;
import com.exlibris.dps.sdk.techmd.FormatValidationPlugin; import com.exlibris.dps.sdk.techmd.FormatValidationPlugin;
import org.w3c.dom.Document; import org.w3c.dom.*;
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.ErrorHandler;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
...@@ -35,14 +31,10 @@ import javax.xml.validation.SchemaFactory; ...@@ -35,14 +31,10 @@ import javax.xml.validation.SchemaFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.*;
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 * SLUBXmlFormatValidationPlugin
...@@ -71,7 +63,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -71,7 +63,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
for (int i = 0; i < nodesize; i++) { for (int i = 0; i < nodesize; i++) {
Node n = nodes.item(i); Node n = nodes.item(i);
NamedNodeMap attributes = n.getAttributes(); NamedNodeMap attributes = n.getAttributes();
List<String> attr_strings = List.of(new String[]{"schematype", "namespace", "schemaurl"}); List<String> attr_strings = List.of(new String[]{"schematype", "namespace", "schemauri"});
List<String> attr_list = attr_strings.stream().map(s -> attributes.getNamedItem(s).getTextContent()).toList(); List<String> attr_list = attr_strings.stream().map(s -> attributes.getNamedItem(s).getTextContent()).toList();
boolean allValid = attr_list.stream().allMatch(SLUBXmlFormatValidationPlugin::checkAttributesOfNamespaceSchemaMapFile); boolean allValid = attr_list.stream().allMatch(SLUBXmlFormatValidationPlugin::checkAttributesOfNamespaceSchemaMapFile);
if (allValid) { if (allValid) {
...@@ -85,16 +77,16 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -85,16 +77,16 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
default -> log.error("attribute schematype needs to be type of schema, schematron or relaxng, but is " + attr_type); default -> log.error("attribute schematype needs to be type of schema, schematron or relaxng, but is " + attr_type);
} }
assert (attr_strings.get(1).equals("namespace")); assert (attr_strings.get(1).equals("namespace"));
assert (attr_strings.get(2).equals("schemaurl")); assert (attr_strings.get(2).equals("schemauri"));
var namespace = attr_list.get(1); var namespace = attr_list.get(1);
String url = attr_list.get(2); String uri = attr_list.get(2);
ValidationSchema v = new ValidationSchema(namespace, schematype, new URL(url)); ValidationSchema v = new ValidationSchema(namespace, schematype, new URI(uri));
namespaceSchemaMap.add(v); namespaceSchemaMap.add(v);
} else { } else {
log.error("invalid entry(" + i + ") in namespace schema map file " + namespaceSchemaMapFile); log.error("invalid entry(" + i + ") in namespace schema map file " + namespaceSchemaMapFile);
} }
} }
} catch (ParserConfigurationException | SAXException | IOException e) { } catch (ParserConfigurationException | SAXException | IOException | URISyntaxException e) {
log.error("parsing expection parsing namespace schema map file " + namespaceSchemaMapFile + " ," + e.getMessage()); log.error("parsing expection parsing namespace schema map file " + namespaceSchemaMapFile + " ," + e.getMessage());
} }
} }
...@@ -199,8 +191,8 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -199,8 +191,8 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
} }
ValidationSchema validationSchema = null; ValidationSchema validationSchema = null;
try { try {
validationSchema = new ValidationSchema(null, type, new URL(info.systemID)); validationSchema = new ValidationSchema(null, type, new URI(info.systemID));
} catch (SAXException | MalformedURLException e) { } catch (SAXException | URISyntaxException e) {
if (debug) { if (debug) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
} }
...@@ -218,7 +210,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -218,7 +210,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
if (optEle.isPresent()) { if (optEle.isPresent()) {
System.out.println("found namespace " + optEle.get().nameSpace); System.out.println("found namespace " + optEle.get().nameSpace);
System.out.println("found schematype " + optEle.get().schemaType); System.out.println("found schematype " + optEle.get().schemaType);
System.out.println("found schemaURL " + optEle.get().schemaURL); System.out.println("found schemaURI " + optEle.get().schemaURI);
} else { } else {
System.out.println("no element found"); System.out.println("no element found");
} }
...@@ -231,7 +223,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -231,7 +223,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
System.out.println("map size=" + namespaceSchemaMap.size()); System.out.println("map size=" + namespaceSchemaMap.size());
while (it.hasNext()) { while (it.hasNext()) {
ValidationSchema v = it.next(); ValidationSchema v = it.next();
System.out.println(v.schemaURL); System.out.println(v.schemaURI);
System.out.println(v.nameSpace); System.out.println(v.nameSpace);
System.out.println(v.schemaType); System.out.println(v.schemaType);
} }
...@@ -252,10 +244,10 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -252,10 +244,10 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
valid = false; valid = false;
} else { } else {
reportDetail("assigned schema of type: " + schema.get().schemaType); reportDetail("assigned schema of type: " + schema.get().schemaType);
reportDetail("assigned schema url: " + schema.get().schemaURL); reportDetail("assigned schema uri: " + schema.get().schemaURI);
if (schema.get().schemaType == ValidationSchemaType.dtd) { if (schema.get().schemaType == ValidationSchemaType.dtd) {
useDtdValidation(); useDtdValidation();
} else if (!schema.get().schemaURL.toString().isBlank()) { } else if (!schema.get().schemaURI.toString().isBlank()) {
useOtherSchemataValidation(schema); useOtherSchemataValidation(schema);
} }
valid = validateAgainstSchema(filePath); valid = validateAgainstSchema(filePath);
...@@ -283,21 +275,31 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { ...@@ -283,21 +275,31 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin {
return valid; return valid;
} }
private void useOtherSchemataValidation(Optional<ValidationSchema> optSchema) throws SAXException { private void useOtherSchemataValidation(Optional<ValidationSchema> optSchema) throws SAXException, MalformedURLException {
if (optSchema.isPresent()) { if (optSchema.isPresent()) {
ValidationSchema schema = optSchema.get(); ValidationSchema schema = optSchema.get();
if (debug) { if (debug) {
System.out.println("-> set schema to " + schema.schemaURL); System.out.println("-> set schema to " + schema.schemaURI);
} }
URL schemaURL;
try {
schemaURL = schema.schemaURI.toURL();
} catch (
MalformedURLException e
) {
reportError(e.getMessage());
throw e;
}
if (schema.schemaType.equals(ValidationSchemaType.schema)) { if (schema.schemaType.equals(ValidationSchemaType.schema)) {
var schemaInst = SchemaFactory.newDefaultInstance().newSchema(schema.schemaURL); var schemaInst = SchemaFactory.newDefaultInstance().newSchema(schemaURL);
dbf.setSchema(schemaInst); dbf.setSchema(schemaInst);
} else if (schema.schemaType.equals(ValidationSchemaType.relaxng)) { } 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.CompactSyntaxSchemaFactory");
var schemaInst = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI).newSchema(schema.schemaURL); var schemaInst = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI).newSchema(schemaURL);
dbf.setSchema(schemaInst); dbf.setSchema(schemaInst);
} else if (schema.schemaType.equals(ValidationSchemaType.schematron)) { } else if (schema.schemaType.equals(ValidationSchemaType.schematron)) {
var schemaInst = SchemaFactory.newInstance("http://purl.oclc.org/dsdl/schematron").newSchema(schema.schemaURL); var schemaInst = SchemaFactory.newInstance("http://purl.oclc.org/dsdl/schematron").newSchema(schemaURL);
dbf.setSchema(schemaInst); dbf.setSchema(schemaInst);
} }
assert (dbf.getSchema() != null); assert (dbf.getSchema() != null);
......
...@@ -2,16 +2,16 @@ package org.slub.rosetta.dps.repository.plugin; ...@@ -2,16 +2,16 @@ package org.slub.rosetta.dps.repository.plugin;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import java.net.URL; import java.net.URI;
class ValidationSchema { class ValidationSchema {
public final String nameSpace; public final String nameSpace;
public final ValidationSchemaType schemaType; public final ValidationSchemaType schemaType;
public final URL schemaURL; public final URI schemaURI;
public ValidationSchema(String nameSpace, ValidationSchemaType schemaType, URL schemaURL) throws SAXException { public ValidationSchema(String nameSpace, ValidationSchemaType schemaType, URI schemaURI) throws SAXException {
this.nameSpace = nameSpace; this.nameSpace = nameSpace;
this.schemaURL = schemaURL; this.schemaURI = schemaURI;
this.schemaType = schemaType; this.schemaType = schemaType;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment