Browse Source

Improve error reporting in <xmlvalidate> and tell the XML where the

document is located.

Removed tabs, this makes this patch look a lot bigger than it is.

Submitted by:	Jesse Glick <Jesse.Glick@netbeans.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269019 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
86bed70a9b
1 changed files with 23 additions and 3 deletions
  1. +23
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java

+ 23
- 3
src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java View File

@@ -56,6 +56,8 @@ package org.apache.tools.ant.taskdefs.optional;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
@@ -346,7 +348,14 @@ public class XMLValidateTask extends Task {
try { try {
log("Validating " + afile.getName() + "... ", Project.MSG_VERBOSE); log("Validating " + afile.getName() + "... ", Project.MSG_VERBOSE);
errorHandler.init(afile); errorHandler.init(afile);
xmlReader.parse(new InputSource(new FileReader(afile)));
InputSource is = new InputSource(new FileReader(afile));
String uri = "file:" + afile.getAbsolutePath().replace('\\', '/');
for (int index = uri.indexOf('#'); index != -1;
index = uri.indexOf('#')) {
uri = uri.substring(0, index) + "%23" + uri.substring(index+1);
}
is.setSystemId(uri);
xmlReader.parse(is);
} catch (SAXException ex) { } catch (SAXException ex) {
if (failOnError) if (failOnError)
throw new BuildException("Could'nt validate document " + afile); throw new BuildException("Could'nt validate document " + afile);
@@ -411,8 +420,19 @@ public class XMLValidateTask extends Task {
} }


private String getMessage(SAXParseException e) { private String getMessage(SAXParseException e) {

return currentFile + ":" + e.getLineNumber() + ": " + e.getMessage();
String sysID = e.getSystemId();
if (sysID != null) {
try {
int line = e.getLineNumber();
int col = e.getColumnNumber();
return new URL(sysID).getFile() +
(line == -1 ? "" : (":" + line +
(col == -1 ? "" : (":" + col)))) +
": " + e.getMessage();
} catch (MalformedURLException mfue) {
}
}
return e.getMessage();
} }
} }
} }

Loading…
Cancel
Save