Skip to content

Commit

Permalink
Resolving delta between what the XML parser does under Eclipse and wh…
Browse files Browse the repository at this point in the history
…at it does outside of Eclipse.
  • Loading branch information
johncurrier committed Aug 28, 2008
1 parent 3e56cbc commit 7407cc9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/net/sourceforge/schemaspy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void main(String[] argv) throws Exception {
try {
rc = analyzer.analyze(new Config(argv));
} catch (Exception exc) {
System.err.println(exc);
System.err.println(exc.getClass().getSimpleName() + ": " + exc.getMessage());
}

System.exit(rc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public InvalidConfigurationException(Throwable cause) {
}

public InvalidConfigurationException(String msg, Throwable cause) {
super(msg, cause);
super(msg + " " + cause.getMessage(), cause);
}
}
18 changes: 6 additions & 12 deletions src/net/sourceforge/schemaspy/model/xml/SchemaMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public SchemaMeta(String xmlMeta, String dbName, String schema) throws InvalidCo
metaFile = meta;

Document doc = parse(metaFile);
if (doc == null) {
throw new InvalidConfigurationException();
}

NodeList commentsNodes = doc.getElementsByTagName("comments");
if (commentsNodes != null && commentsNodes.getLength() > 0)
Expand Down Expand Up @@ -97,7 +94,7 @@ private void validate(Document document) throws SAXException, IOException {

// load a WXS schema, represented by a Schema instance
InputStream xsl = getClass().getResourceAsStream("/schemaspy.meta.xsd");

Schema schema = factory.newSchema(new StreamSource(xsl));

// create a Validator instance, which can be used to validate an instance document
Expand All @@ -107,30 +104,27 @@ private void validate(Document document) throws SAXException, IOException {
validator.validate(new DOMSource(document));
}

private Document parse(File file) {
private Document parse(File file) throws InvalidConfigurationException {
DocumentBuilder docBuilder;
Document doc = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setIgnoringElementContentWhitespace(true);
factory.setIgnoringComments(true);

try {
docBuilder = factory.newDocumentBuilder();
} catch (ParserConfigurationException exc) {
System.err.println("Invalid parser configuration: " + exc.getMessage());
return null;
throw new InvalidConfigurationException("Invalid XML parser configuration", exc);
}

try {
doc = docBuilder.parse(file);
validate(doc);
} catch (SAXException exc) {
// exception already reported to stderr by error handler
System.err.println(file + " failed XML validation");
return null;
throw new InvalidConfigurationException(file + " failed XML validation:", exc);
} catch (IOException exc) {
System.err.println("Could not read file: " + exc.getMessage());
return null;
throw new InvalidConfigurationException("Could not read " + file + ":", exc);
}

return doc;
Expand Down

0 comments on commit 7407cc9

Please sign in to comment.