use of org.xml.sax.HandlerBase in project ant by apache.
the class ProjectHelperImpl method parse.
/**
* Parses the project file, configuring the project as it goes.
*
* @param project project instance to be configured.
* @param source the source from which the project is read.
* @exception BuildException if the configuration is invalid or cannot
* be read.
*/
public void parse(Project project, Object source) throws BuildException {
if (!(source instanceof File)) {
throw new BuildException("Only File source supported by " + "default plugin");
}
File bFile = (File) source;
InputStream inputStream = null;
InputSource inputSource = null;
this.project = project;
this.buildFile = new File(bFile.getAbsolutePath());
buildFileParent = new File(this.buildFile.getParent());
try {
try {
parser = JAXPUtils.getParser();
} catch (BuildException e) {
parser = new XMLReaderAdapter(JAXPUtils.getXMLReader());
}
String uri = FILE_UTILS.toURI(bFile.getAbsolutePath());
inputStream = Files.newInputStream(bFile.toPath());
inputSource = new InputSource(inputStream);
inputSource.setSystemId(uri);
project.log("parsing buildfile " + bFile + " with URI = " + uri, Project.MSG_VERBOSE);
HandlerBase hb = new RootHandler(this);
parser.setDocumentHandler(hb);
parser.setEntityResolver(hb);
parser.setErrorHandler(hb);
parser.setDTDHandler(hb);
parser.parse(inputSource);
} catch (SAXParseException exc) {
Location location = new Location(exc.getSystemId(), exc.getLineNumber(), exc.getColumnNumber());
Throwable t = exc.getException();
if (t instanceof BuildException) {
BuildException be = (BuildException) t;
if (be.getLocation() == Location.UNKNOWN_LOCATION) {
be.setLocation(location);
}
throw be;
}
throw new BuildException(exc.getMessage(), t, location);
} catch (SAXException exc) {
Throwable t = exc.getException();
if (t instanceof BuildException) {
throw (BuildException) t;
}
throw new BuildException(exc.getMessage(), t);
} catch (FileNotFoundException exc) {
throw new BuildException(exc);
} catch (UnsupportedEncodingException exc) {
throw new BuildException("Encoding of project file is invalid.", exc);
} catch (IOException exc) {
throw new BuildException("Error reading project file: " + exc.getMessage(), exc);
} finally {
FileUtils.close(inputStream);
}
}
Aggregations