Skip to content

Commit

Permalink
Update validator to use new schema namespace.
Browse files Browse the repository at this point in the history
Also, fix the validator build, and add a utility shell script showing how to run the validator.
  • Loading branch information
mbjones committed Aug 17, 2019
1 parent 0720f11 commit 9f77365
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
6 changes: 6 additions & 0 deletions bin/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# echo "usage: runEMLParser <emlfile>"
# echo "where <emlfile> is the file you want to parse."
NAMESPACES="eml://ecoinformatics.org/eml-2.0.0 https://knb.ecoinformatics.org/emlparser/schema/eml-2.0.0/eml.xsd eml://ecoinformatics.org/eml-2.0.1 https://knb.ecoinformatics.org/emlparser/schema/eml-2.0.1/eml.xsd eml://ecoinformatics.org/eml-2.1.0 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.0/eml.xsd eml://ecoinformatics.org/eml-2.1.1 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.1/eml.xsd https://eml.ecoinformatics.org/eml-2.2.0 xsd/eml.xsd eml://ecoinformatics.org/literature-2.1.0 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.0/eml-literature.xsd eml://ecoinformatics.org/project-2.1.0 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.0/eml-project.xsd eml://ecoinformatics.org/literature-2.1.1 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.1/eml-literature.xsd eml://ecoinformatics.org/project-2.1.1 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.1/eml-project.xsd http://www.xml-cml.org/schema/stmml-1.1 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.0/stmml.xsd http://www.xml-cml.org/schema/stmml https://knb.ecoinformatics.org/emlparser/schema/eml-2.0.1/stmml.xsd"
CLASSPATH="./lib/eml.jar:./lib/xercesImpl-2.12.0.jar:./lib/xml-apis-1.4.01.jar:./lib/xalan-2.7.2.jar:./lib/apache/servlet.jar"
java -cp "$CLASSPATH" org.ecoinformatics.eml.EMLValidator $1
java -cp "$CLASSPATH" org.ecoinformatics.eml.SAXValidate $1 "$NAMESPACES"
1 change: 0 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,6 @@

<target name="clean" depends="init">
<delete dir="./build"/>
<delete dir="./dist"/>
<delete file="${eml-version}.zip"/>
<delete file="${eml-version}.tar.gz"/>
<delete file="${datamanager.name}.zip"/>
Expand Down
Binary file modified lib/eml.jar
Binary file not shown.
4 changes: 0 additions & 4 deletions lib/runEMLParser

This file was deleted.

29 changes: 17 additions & 12 deletions src/main/java/org/ecoinformatics/eml/EMLValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Validate an EML document by executing additional validation checks that are
* not already encoded in XML Schema. These are described in the EML
* specification.
* specification.
*
* Typical usage is to instantiate EMLValidator against an EML filename, and
* then execute the validate() method.
Expand Down Expand Up @@ -74,6 +74,11 @@ public static void main(String[] args) {
EMLValidator validator = new EMLValidator(file);
boolean isValid = validator.validate();
System.err.println("isValid: " + (new Boolean(isValid)).toString());
if (!isValid) {
for (String e : validator.getErrors()) {
System.err.println(e);
}
}
}

/**
Expand Down Expand Up @@ -107,11 +112,11 @@ public boolean validate() {
isValid = false;
}

// If an element references another using a child `references` element
// or references attribute, another element with that value in its `id`
// If an element references another using a child `references` element
// or references attribute, another element with that value in its `id`
// attribute MUST exist in the document
// If an `additionalMetadata` element references another using a child
// `describes` element, another element with that value in its `id`
// If an `additionalMetadata` element references another using a child
// `describes` element, another element with that value in its `id`
// attribute MUST exist in the document
ArrayList<String> refs = getXPathValues("//annotation[@references]/@references|//references|//describes");
for (String s : refs) {
Expand All @@ -122,8 +127,8 @@ public boolean validate() {
}


// Elements which contain an `annotation` child element MUST contain an
// `id` attribute, unless the containing `annotation` element contains a
// Elements which contain an `annotation` child element MUST contain an
// `id` attribute, unless the containing `annotation` element contains a
// `references` attribute
NodeList missing_id_ref = getXPathNodeList("//*[annotation and not(@id) and not(annotation[@references]) and not(parent::*/describes)]");
length = missing_id_ref.getLength();
Expand All @@ -136,7 +141,7 @@ public boolean validate() {
//}
}

// If an element references another using a child `references` element,
// If an element references another using a child `references` element,
// it MUST not have an `id` attribute itself
NodeList both_id_ref = getXPathNodeList("//*[references and @id]");
length = both_id_ref.getLength();
Expand All @@ -149,9 +154,9 @@ public boolean validate() {
//}
}

// TODO: When `references` is used, the `system` attribute MUST have the
// same value in both the target and source elements, or it must be
// absent in both. For now, we have decided to not enforce this
// TODO: When `references` is used, the `system` attribute MUST have the
// same value in both the target and source elements, or it must be
// absent in both. For now, we have decided to not enforce this
// constraint, as snobody seems to use it.

return isValid;
Expand Down Expand Up @@ -202,7 +207,7 @@ private ArrayList getXPathValues(String xpath) {
}

/**
* Extract a NodeList using an XPath on the provided Node n.
* Extract a NodeList using an XPath on the provided Node n.
* @param xpath an XPath expression to be executed
* @param n the XML DOM Node on which to execute the XPath
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
eml://ecoinformatics.org/eml-2.0.1 https://knb.ecoinformatics.org/emlparser/schema/eml-2.0.1/eml.xsd
eml://ecoinformatics.org/eml-2.1.0 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.0/eml.xsd
eml://ecoinformatics.org/eml-2.1.1 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.1/eml.xsd
eml://ecoinformatics.org/eml-2.2.0 https://knb.ecoinformatics.org/emlparser/schema/eml-2.2.0/eml.xsd
https://eml.ecoinformatics.org/eml-2.2.0 https://knb.ecoinformatics.org/emlparser/schema/eml-2.2.0/eml.xsd
eml://ecoinformatics.org/literature-2.1.0 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.0/eml-literature.xsd
eml://ecoinformatics.org/project-2.1.0 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.0/eml-project.xsd
eml://ecoinformatics.org/literature-2.1.1 https://knb.ecoinformatics.org/emlparser/schema/eml-2.1.1/eml-literature.xsd
Expand Down

0 comments on commit 9f77365

Please sign in to comment.