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

- simplified XMLInfoRecord

parent 9186e035
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment