diff --git a/README.md b/README.md index 8dedb7fe075b38f75319141d76b17858b6b63f3b..a88d85b9c50d1d5be972ac67f5cd05fa72e3b886 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Schemas <entry schematype="schema" namespace="http://www.loc.gov/standards/alto/ns-v2#" schemaurl="http://www.loc.gov/standards/alto/alto-v2.0.xsd" /> </slubschemacatalog> ``` +* please ensure, that the 'schemaurl' starts either with 'http://$server/', 'https://$server/' or 'file://localhost/'! For testing purposes relative URLs also supported. For a (german) introduction how to use it, check https://www.data2type.de/xml-xslt-xslfo/docbook/xml-kataloge diff --git a/java/org/slub/rosetta/dps/repository/plugin/XmlFormatValidationPlugin.java b/java/org/slub/rosetta/dps/repository/plugin/XmlFormatValidationPlugin.java index c2b2578754277100c30cbb2dbaad881ab82f94ec..6ce4580bc21dbc7dc818939e02db7a7436959eb3 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/XmlFormatValidationPlugin.java +++ b/java/org/slub/rosetta/dps/repository/plugin/XmlFormatValidationPlugin.java @@ -92,35 +92,42 @@ public class XmlFormatValidationPlugin implements FormatValidationPlugin { } } - private void addtoNamespaceSchemaMap(String namespaceSchemaMapFile, String attr_type, String namespace, String sUri) throws URISyntaxException, SAXException { - var schematype = ValidationSchemaType.nothing; - switch (attr_type) { - case "schema" -> schematype = ValidationSchemaType.schema; - case "schematron" -> schematype = ValidationSchemaType.schematron; - case "relaxng" -> schematype = ValidationSchemaType.relaxng; - case "nonvalidating" -> schematype = ValidationSchemaType.nonvalidating; - default -> validationLogger.error("attribute schematype needs to be type of schema, schematron or relaxng, but is " + attr_type); - } - URI uri; + private void addtoNamespaceSchemaMap(String namespaceSchemaMapFile, String attr_type, String namespace, String sUrl) throws URISyntaxException, SAXException { + ValidationSchemaType schematype = ValidationSchemaType.nothing; + switch (attr_type) { + case "schema" -> schematype = ValidationSchemaType.schema; + case "schematron" -> schematype = ValidationSchemaType.schematron; + case "relaxng" -> schematype = ValidationSchemaType.relaxng; + case "nonvalidating" -> schematype = ValidationSchemaType.nonvalidating; + default -> + validationLogger.error("attribute schematype needs to be type of schema, schematron or relaxng, but is " + attr_type); + } + if ( + sUrl.startsWith("file:") + && !sUrl.startsWith("file://localhost/") + ) { + validationLogger.error("attribute schemaurl should be start with: 'http://$server/path', 'https://$server/path' or 'file://localhost/path' to ensure coorect working, got: " + sUrl); + } + URI uri; if ( - (sUri.startsWith("http://")) - || (sUri.startsWith("https://")) - || (sUri.startsWith("file://")) - || (sUri.contains("://")) + (sUrl.startsWith("http://")) + || (sUrl.startsWith("https://")) + || (sUrl.startsWith("file://")) + || (sUrl.contains("://")) ) { - uri = new URI(sUri); + uri = new URI(sUrl); } else { - uri = remapUri(namespaceSchemaMapFile, sUri); - validationLogger.debug( "SCHEMACATALOG, remap to URI: " + uri); + uri = remapUri(namespaceSchemaMapFile, sUrl); + validationLogger.debug("SCHEMACATALOG, remap to URI: " + uri); } ValidationSchema v = new ValidationSchema(namespace, schematype, uri); - namespaceSchemaMap.add(v); + namespaceSchemaMap.add(v); } //@NotNull - private URI remapUri(String namespaceSchemaMapFile, String sUri) throws URISyntaxException { - URI partUri = new URI(sUri); - String baseStr = "file://" + new File(namespaceSchemaMapFile).getAbsoluteFile().getParent() + "/"; + private URI remapUri(String namespaceSchemaMapFile, String sUrl) throws URISyntaxException { + URI partUri = new URI(sUrl); + String baseStr = "file://localhost/" + new File(namespaceSchemaMapFile).getAbsoluteFile().getParent() + "/"; URI baseUri = new URI( baseStr); return baseUri.resolve(partUri); }