Conor,

  Thanks for the response. 

I attached another patch that solves both of our problems. Basically,
the patch create a InputSource from a FileInputStream so your problem
with filename with # being used as URI fregment won't exist. The
systemId set on the InputSource so the parser can read the System Entity
correctly.

I believe this compilant toh the External Entity (4.2.2) in the XML
spec.

http://www.w3.org/TR/REC-xml#sec-entity-decl

Right the sentence you quoted below refering to the System Entity.

"meant to be dereferenced to obtain input for the XML processor to
construct the entity's replacement text.] ... relative URIs are relative
to the location of the resource within which the entity declaration
occurs."

According to the above, if a system entity build.inc is define in
file:/foo/bar/build.xml. It should be dereference to
file:/foo/bar/build.inc. I believe patch implements this semantics.

Regarding to the build.inc in the Log4J distribution. I think the
development team has forgotten to include it in the tar/zip
distribution. I got it from the CVS.

David Li
DigitalSesame

Conor MacNeill wrote:
> 
> David,
> 
> Sorry, I saw your earlier post on this subject but didn't get around to
> addressing it. I am not an expert on XML entity declarations but I did some
> background research on this.
> 
> Firstly, let me point you to this patch, applied about a month ago which is
> the reverse of the first part of your patch
> http://jakarta.apache.org/cvsweb/index.cgi/jakarta-ant/src/main/org/apache/
> tools/ant/ProjectHelper.java.diff?r1=1.44&r2=1.45&diff_format=h
> 
> Now I believe that patch was to prevent a # in a directory name being
> interpreted as a URL fragment separator. This used to fail and I can only
> assume that JAXP is converting the File object in this call
> 
> public void parse(File file, HandlerBase base)
> 
> into a file: URL and then invoking
> 
> public void parse(String uri, HandlerBase base)
> 
> Maybe, that is not a good approach.
> 
> According to the XML spec, the SystemLiteral is a URI as defined in
> RFC2396/RFC2732. I am not sure how the XML parser will interpret the
> build.inc in
>     <!ENTITY build.inc SYSTEM "build.inc">
> 
> as a URI.
> 
> The second part of your patch is in an if block
>             if (systemId.startsWith("file:")) {
> 
> so it is unlikely that "build.inc" will trigger the changed code. I would
> be inclined to change your "build.inc" to "file:build.inc" as presented in
> the FAQ. Otherwise, we would have to exclude directories which include the
> # character from being used with Ant. To quote the original bug report
> 
> "This bug is particularly nasty for us since we use the Continuus
> configuration management system which likes to place projects under a
> directory named projectName#userName. This bug renders ANT unusable in our
> environment. "
> 
> Also, to test this I checked out log4j and did not find the exact
> construction you mention. I did find a lot of references to build.inc but
> no build.inc itself.
> 
> I'd be interested in comments on this. My inclination is to say this is not
> a bug.
> 
> Conor
>
Index: src/main/org/apache/tools/ant/ProjectHelper.java
===================================================================
RCS file: 
/home/topware/cvsroot/Enhydra/modules/Ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
retrieving revision 1.1.1.3
diff -c -r1.1.1.3 ProjectHelper.java
*** src/main/org/apache/tools/ant/ProjectHelper.java    2001/02/05 15:21:55     
1.1.1.3
--- src/main/org/apache/tools/ant/ProjectHelper.java    2001/02/17 07:35:26
***************
*** 99,111 ****
       */
      private void parse() throws BuildException {
          FileInputStream inputStream = null;
          
          try {
              SAXParser saxParser = getParserFactory().newSAXParser();
              parser = saxParser.getParser();
!             
!             inputStream = new FileInputStream(buildFile);
!             saxParser.parse(inputStream, new RootHandler());
          }
          catch(ParserConfigurationException exc) {
              throw new BuildException("Parser has not been configured 
correctly", exc);
--- 99,115 ----
       */
      private void parse() throws BuildException {
          FileInputStream inputStream = null;
+       InputSource inputSource = null;
          
          try {
              SAXParser saxParser = getParserFactory().newSAXParser();
              parser = saxParser.getParser();
! 
!           inputStream = new FileInputStream(buildFile);
!           inputSource = new InputSource(inputStream);
!           inputSource.setSystemId("file:" +  buildFile.getAbsolutePath());
!           System.out.println ("parse: " + inputSource.getSystemId());
!           saxParser.parse(inputSource, new RootHandler());
          }
          catch(ParserConfigurationException exc) {
              throw new BuildException("Parser has not been configured 
correctly", exc);
***************
*** 217,223 ****
                  }
                  
                  try {
!                     return new InputSource(new FileInputStream(file));
                  } catch (FileNotFoundException fne) {
                      project.log(file.getAbsolutePath()+" could not be found", 
                                  Project.MSG_WARN);
--- 221,229 ----
                  }
                  
                  try {
!                   InputSource inputSource = new InputSource(new 
FileInputStream(file));
!                   inputSource.setSystemId("file:" + file.getAbsolutePath());
!                     return inputSource;
                  } catch (FileNotFoundException fne) {
                      project.log(file.getAbsolutePath()+" could not be found", 
                                  Project.MSG_WARN);

Reply via email to