X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Ftest%2Fsrc%2Ftest%2Futil%2FXMLValidator.java;fp=dol%2Ftest%2Fsrc%2Ftest%2Futil%2FXMLValidator.java;h=eba16cd4cd0c7119e64ba6a076aa7177c20560df;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/test/src/test/util/XMLValidator.java b/dol/test/src/test/util/XMLValidator.java new file mode 100644 index 0000000..eba16cd --- /dev/null +++ b/dol/test/src/test/util/XMLValidator.java @@ -0,0 +1,56 @@ +package test.util; + +import java.util.ResourceBundle; +import java.io.IOException; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; + +/** + * Class to check well-formedness and validity of XML documents. + */ +public class XMLValidator { + + /** + * Check the well-formedness and validity of an XML document. + * The file is checked against the schema which is referenced from + * within the file. When the document is an XML schema, it is checked + * against http://www.w3.org/2001/XMLSchema.xsd. + * + * @param filename filename of the file to be checked + */ + public static boolean isValid(String filename) { + ResourceBundle resourceBundle = ResourceBundle.getBundle("test"); + + SAXBuilder builder = new SAXBuilder(true); + builder.setFeature("http://xml.org/sax/features/validation", + true); + builder.setFeature("http://apache.org/xml/features/validation/" + + "schema", true); + builder.setFeature("http://apache.org/xml/features/validation/" + + "schema-full-checking", true); + builder.setProperty("http://apache.org/xml/properties/schema/" + + "external-schemaLocation", + "http://www.w3.org/2001/XMLSchema " + + "http://www.w3.org/2001/XMLSchema.xsd " + + resourceBundle.getString("LOCAL_SCHEMAS")); + + try { + builder.build(filename); + } + catch (JDOMException e) { + System.out.println("Found an error in " + filename + "."); + System.out.println(e.getMessage()); + System.out.println(""); + return false; + } + catch (IOException e) { + System.out.println("Found an error in " + filename + "."); + System.out.println(e.getMessage()); + System.out.println(""); + return false; + } + + return true; + } +}