Browse Source

Make XmlValidateTest pass.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278312 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
873ae06ded
1 changed files with 7 additions and 11 deletions
  1. +7
    -11
      src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java

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

@@ -332,7 +332,7 @@ public class XMLValidateTask extends Task {
*/ */
protected void initValidator() { protected void initValidator() {


xmlReader=createXmlReader();
xmlReader = createXmlReader();


xmlReader.setEntityResolver(getEntityResolver()); xmlReader.setEntityResolver(getEntityResolver());
xmlReader.setErrorHandler(errorHandler); xmlReader.setErrorHandler(errorHandler);
@@ -348,7 +348,6 @@ public class XMLValidateTask extends Task {
setFeature(feature.getName(), feature.getValue()); setFeature(feature.getName(), feature.getValue());


} }

// Sets properties // Sets properties
for (int i = 0; i < propertyList.size(); i++) { for (int i = 0; i < propertyList.size(); i++) {
final Property prop = (Property) propertyList.elementAt(i); final Property prop = (Property) propertyList.elementAt(i);
@@ -521,7 +520,7 @@ public class XMLValidateTask extends Task {
protected boolean doValidate(File afile) { protected boolean doValidate(File afile) {
//for every file, we have a new instance of the validator //for every file, we have a new instance of the validator
initValidator(); initValidator();
boolean result = true;
try { try {
log("Validating " + afile.getName() + "... ", Project.MSG_VERBOSE); log("Validating " + afile.getName() + "... ", Project.MSG_VERBOSE);
errorHandler.init(afile); errorHandler.init(afile);
@@ -529,31 +528,28 @@ public class XMLValidateTask extends Task {
String uri = FILE_UTILS.toURI(afile.getAbsolutePath()); String uri = FILE_UTILS.toURI(afile.getAbsolutePath());
is.setSystemId(uri); is.setSystemId(uri);
xmlReader.parse(is); xmlReader.parse(is);
return true;
} catch (SAXException ex) { } catch (SAXException ex) {
log("Caught when validating: " + ex.toString(), Project.MSG_DEBUG); log("Caught when validating: " + ex.toString(), Project.MSG_DEBUG);
if (failOnError) { if (failOnError) {
throw new BuildException( throw new BuildException(
"Could not validate document " + afile); "Could not validate document " + afile);
} else {
log("Could not validate document " + afile + ": " + ex.toString());
} }
log("Could not validate document " + afile + ": " + ex.toString());
result = false;
} catch (IOException ex) { } catch (IOException ex) {
throw new BuildException( throw new BuildException(
"Could not validate document " + afile, "Could not validate document " + afile,
ex); ex);
} }

if (errorHandler.getFailure()) { if (errorHandler.getFailure()) {
if (failOnError) { if (failOnError) {
throw new BuildException( throw new BuildException(
afile + " is not a valid XML document."); afile + " is not a valid XML document.");
} else {
log(afile + " is not a valid XML document", Project.MSG_ERR);
} }
result = false;
log(afile + " is not a valid XML document", Project.MSG_ERR);
} }
//if we got here. it was as a result of a caught and logged exception.
return false;
return result;
} }


/** /**


Loading…
Cancel
Save