Skip to content
Snippets Groups Projects
Commit 467d2470 authored by Goik Martin's avatar Goik Martin
Browse files

Providing qualified test failure message in case of invalid schema files

parent 35a294bb
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ import org.jdom2.input.SAXBuilder;
import org.jdom2.input.sax.XMLReaderSAX2Factory;
import org.jdom2.input.sax.XMLReaders;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/**
* Test and evaluate an individual XML instance.
......@@ -23,6 +24,7 @@ import org.xml.sax.SAXException;
*/
public class InstanceTest {
private static Logger log = LogManager.getLogger(InstanceTest.class);
final SAXBuilder parser = new SAXBuilder(XMLReaders.XSDVALIDATING);
final SAXBuilder b = new SAXBuilder(new XMLReaderSAX2Factory(false));
......@@ -56,8 +58,6 @@ public class InstanceTest {
*/
public final Optional<String> errMsg;
private static Logger log = LogManager.getLogger(InstanceTest.class);
@Override
public String toString() {
......@@ -89,11 +89,13 @@ public class InstanceTest {
try {
s = sf.newSchema (new File(xsdSchemaFilename));
validator = s.newValidator();
} catch (SAXException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} catch (final SAXParseException e) {
System.err.println(getErrorDescription(e));
System.exit(1);
} catch (SAXException e) {
System.err.println(getErrorDescription(e, xsdSchemaFilename));
System.exit(1);
}
this.instanceFilename = xmlInstance;
......@@ -161,4 +163,14 @@ public class InstanceTest {
}
}
static String getErrorDescription(final SAXParseException e) {
return "Your schema cannot be parsed:\n" +
e.getSystemId() + ", line " + e.getLineNumber() + ", column " + e.getLineNumber() + ": " + e.getLocalizedMessage() +
"\nThis may indicate your document is not well-formed\n\nAborting!\n\n\n";
}
static String getErrorDescription(final SAXException e, final String fileName) {
return "Your schema " + fileName + " cannot be parsed:\n" +
e.getLocalizedMessage() +
"\nAre you using non-standard features?\n\nAborting!\n\n\n";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment