diff --git a/java/org/slub/rosetta/dps/repository/plugin/SLUBXmlFormatValidationPlugin.java b/java/org/slub/rosetta/dps/repository/plugin/SLUBXmlFormatValidationPlugin.java index 02b1f4f6672564a753c9ad0af39fb43969745bd4..0044f92ba1321ab18207fd20021118b018d7f927 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/SLUBXmlFormatValidationPlugin.java +++ b/java/org/slub/rosetta/dps/repository/plugin/SLUBXmlFormatValidationPlugin.java @@ -170,7 +170,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { private XmlInfoRecord getXMLinfo(Document doc) { String namespaceURI = doc.getNamespaceURI(); - String documentURI = doc.getDocumentURI(); + //String documentURI = doc.getDocumentURI(); String xmlVersion = doc.getXmlVersion(); var docType = doc.getDoctype(); String publicId = ""; @@ -182,7 +182,8 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { if (null == namespaceURI) { /* ugly hack but works */ namespaceURI = doc.getDocumentElement().getNamespaceURI(); } - return new XmlInfoRecord(namespaceURI, documentURI, xmlVersion, systemId, publicId); + // return new XmlInfoRecord(namespaceURI, documentURI, xmlVersion, systemId, publicId); + return new XmlInfoRecord(namespaceURI, xmlVersion, systemId, publicId); } private Optional<ValidationSchema> assignSchema(Document doc) { XmlInfoRecord info = getXMLinfo(doc); @@ -301,6 +302,33 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { return valid; } + private void check_ns_of_childs(Node root) { + String root_ns = root.getNamespaceURI(); + NodeList childNodes = root.getChildNodes(); + for (int i=0; i<childNodes.getLength(); i++) { + var child_ns = childNodes.item(i).getNamespaceURI(); + if (child_ns != null && child_ns != root_ns) { + System.out.println( "root ns = " + root_ns + " child ns = " + child_ns); + var res = validationResourceResolver.find_by_ns( child_ns); + if (res.isEmpty()) { + System.out.println( "no entry for child ns: " + child_ns + " found!"); + } else { + assert(res.get().schemaType.equals("schema")); + var schema = res.get().schemaURI; + SLUBValidateSchema validator = new SLUBValidateSchema( validationResourceResolver ); + try { + valid = validator.validateAgainst(childNodes.item(i), schema); + } catch (IOException e) { + System.out.println( e.getMessage() ); + } + } + } + } + for (int i=0; i<childNodes.getLength(); i++) { + check_ns_of_childs( childNodes.item(i) ); + } + } + private void validateFormatAgainstAnySchema(String filePath, Document doc, ValidationSchema validationSchema) throws IOException, ParserConfigurationException, SAXException { reportDetail("assigned schema of type: " + validationSchema.schemaType); reportDetail("assigned schema uri: " + validationSchema.schemaURI); @@ -311,7 +339,14 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { errors.addAll( validator.get_errors() ); } else if (schemaType == ValidationSchemaType.schema) { SLUBValidateSchema validator = new SLUBValidateSchema( validationResourceResolver ); + // Slect validation roots from DOM + Element root = doc.getDocumentElement(); + check_ns_of_childs(root); + valid = validator.validateAgainst(doc, validationSchema.schemaURI); + /* + valid = validator.validateAgainst(doc, validationSchema.schemaURI); + */ errors.addAll( validator.get_errors() ); } else if (schemaType == ValidationSchemaType.relaxng) { SLUBValidateRelaxNG validator = new SLUBValidateRelaxNG( ); @@ -369,6 +404,7 @@ public class SLUBXmlFormatValidationPlugin implements FormatValidationPlugin { dbf.setSchema(null); //dbf.setXIncludeAware(true); dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); //db.setEntityResolver(validationCatalogResolver); //db.setErrorHandler(validationErrorHandler); diff --git a/java/org/slub/rosetta/dps/repository/plugin/XmlInfoRecord.java b/java/org/slub/rosetta/dps/repository/plugin/XmlInfoRecord.java index 72d91ce37f0a0755d15913fd37d884761e6e8310..1ed413b117deb365332bfab7854e8074c14a4264 100644 --- a/java/org/slub/rosetta/dps/repository/plugin/XmlInfoRecord.java +++ b/java/org/slub/rosetta/dps/repository/plugin/XmlInfoRecord.java @@ -2,13 +2,16 @@ package org.slub.rosetta.dps.repository.plugin; class XmlInfoRecord { public final String nameSpaceUri; - public final String documentUri; + //public final String documentUri; public final String xmlVersion; public final String systemID; public final String publicID; - public XmlInfoRecord(String nameSpaceUri, String documentUri, String xmlVersion, String systemID, String publicID) { - this.documentUri = documentUri; + public XmlInfoRecord( + String nameSpaceUri, + //String documentUri, + String xmlVersion, String systemID, String publicID) { + //this.documentUri = documentUri; this.nameSpaceUri = nameSpaceUri; this.xmlVersion = xmlVersion; this.systemID = systemID; @@ -18,7 +21,7 @@ class XmlInfoRecord { System.out.println( "\n-------------------------------------------" + "\n namespaceuri= " + this.nameSpaceUri - + "\n documenturi = " + this.documentUri + // + "\n documenturi = " + this.documentUri + "\n xmlVersion = " + this.xmlVersion + "\n systemID = " + this.systemID + "\n publicID = " + this.publicID