From ae9bbd68b090e14c899e84418fe96b440d389c3c Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <andreas.romeyke@slub-dresden.de> Date: Fri, 21 Jul 2023 12:54:42 +0200 Subject: [PATCH] - use SchemaCatalogException if required attribute is empty or null --- .../plugin/XmlFormatValidationPlugin.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/java/org/slub/rosetta/dps/repository/plugin/XmlFormatValidationPlugin.java b/java/org/slub/rosetta/dps/repository/plugin/XmlFormatValidationPlugin.java index 60b7d11..5a1bfd0 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/XmlFormatValidationPlugin.java +++ b/java/org/slub/rosetta/dps/repository/plugin/XmlFormatValidationPlugin.java @@ -90,12 +90,12 @@ public class XmlFormatValidationPlugin implements FormatValidationPlugin { resultHandle.error("invalid entry(" + i + ") in namespace schema map file " + namespaceSchemaMapFile); } } - } catch (ParserConfigurationException | SAXException | IOException | URISyntaxException e) { + } catch (ParserConfigurationException | SAXException | IOException | URISyntaxException | SchemaCatalogException e) { resultHandle.error("parsing expection parsing namespace schema map file " + namespaceSchemaMapFile + " ," + e.getMessage()); } } - private void addtoNamespaceSchemaMap(String namespaceSchemaMapFile, String attr_type, String namespace, String sUri) throws URISyntaxException, SAXException { + private void addtoNamespaceSchemaMap(String namespaceSchemaMapFile, String attr_type, String namespace, String sUri) throws URISyntaxException, SAXException, SchemaCatalogException { ValidationSchemaType schematype = ValidationSchemaType.nothing; switch (attr_type) { case "schema" -> schematype = ValidationSchemaType.schema; @@ -116,12 +116,12 @@ public class XmlFormatValidationPlugin implements FormatValidationPlugin { } - private ValidationSchema getValidationSchemaIfPresent(String namespaceSchemaMapFile, String namespace, String sUri, ValidationSchemaType schematype) throws URISyntaxException, SAXException { - ValidationSchema v; - if ( - isWrongFileUri(sUri) - ) { - resultHandle.error("attribute schemauri should be start with: 'http://$server/path', 'https://$server/path' or 'file://localhost/path' to ensure coorect working, got: " + sUri); + private ValidationSchema getValidationSchemaIfPresent(String namespaceSchemaMapFile, String namespace, String sUri, ValidationSchemaType schematype) throws URISyntaxException, SAXException, SchemaCatalogException { + if ( null == sUri || sUri.isBlank()) { + throw new SchemaCatalogException("for namespace " + namespace + "attribute schemauri is empty or non-existent!"); + } + if ( isWrongFileUri(sUri) ) { + throw new SchemaCatalogException("for namespace " + namespace + "attribute schemauri should be start with: 'http://$server/path', 'https://$server/path' or 'file://localhost/path' to ensure coorect working, got: " + sUri); } URI uri; if ( @@ -132,10 +132,11 @@ public class XmlFormatValidationPlugin implements FormatValidationPlugin { uri = remapUri(namespaceSchemaMapFile, sUri); resultHandle.debug("SCHEMACATALOG, remap " + sUri + " to URI: " + uri); } - v = new ValidationSchema(namespace, schematype, uri); + ValidationSchema v = new ValidationSchema(namespace, schematype, uri); return v; } + private static boolean isNonRelativeUri(String sUri) { return (sUri.startsWith("http://")) || (sUri.startsWith("https://")) -- GitLab