conor 01/02/18 05:05:04
Modified: src/main/org/apache/tools/ant Tag: ANT_13_BRANCH
ProjectHelper.java
Log:
Handle include files. This patch is based on input from David Li
but I have made a number of changes. This code handles all the
testcases I have created.
Submitted by: David Li <[EMAIL PROTECTED]>
Revision Changes Path
No revision
No revision
1.47.2.1 +27 -4
jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
Index: ProjectHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
retrieving revision 1.47
retrieving revision 1.47.2.1
diff -u -r1.47 -r1.47.2.1
--- ProjectHelper.java 2001/01/18 02:50:32 1.47
+++ ProjectHelper.java 2001/02/18 13:05:04 1.47.2.1
@@ -99,13 +99,17 @@
*/
private void parse() throws BuildException {
FileInputStream inputStream = null;
+ InputSource inputSource = null;
try {
SAXParser saxParser = getParserFactory().newSAXParser();
parser = saxParser.getParser();
- inputStream = new FileInputStream(buildFile);
- saxParser.parse(inputStream, new RootHandler());
+ String uri = "file:" + buildFile.getAbsolutePath().replace('\\',
'/');
+ for (int index = uri.indexOf('#'); index != -1; index =
uri.indexOf('#')) {
+ uri = uri.substring(0, index) + "%23" +
uri.substring(index+1);
+ }
+ saxParser.parse(uri, new RootHandler());
}
catch(ParserConfigurationException exc) {
throw new BuildException("Parser has not been configured
correctly", exc);
@@ -208,16 +212,35 @@
*/
public InputSource resolveEntity(String publicId,
String systemId) {
-
+
if (systemId.startsWith("file:")) {
String path = systemId.substring(5);
+ int index = path.indexOf("file:");
+
+ // we only have to handle these for backward compatibility
+ // since they are in the FAQ.
+ while (index != -1) {
+ path = path.substring(0, index) + path.substring(index +
5);
+ index = path.indexOf("file:");
+ }
+
+ String entitySystemId = path;
+ index = path.indexOf("%23");
+ // convert these to #
+ while (index != -1) {
+ path = path.substring(0, index) + "#" +
path.substring(index + 3);
+ index = path.indexOf("%23");
+ }
+
File file = new File(path);
if (!file.isAbsolute()) {
file = new File(buildFileParent, path);
}
try {
- return new InputSource(new FileInputStream(file));
+ InputSource inputSource = new InputSource(new
FileInputStream(file));
+ inputSource.setSystemId("file:" + entitySystemId);
+ return inputSource;
} catch (FileNotFoundException fne) {
project.log(file.getAbsolutePath()+" could not be
found",
Project.MSG_WARN);