ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/types XMLCatalogTest.java
Date Tue, 09 Dec 2003 01:14:31 GMT
antoine     2003/12/08 17:14:31

  Modified:    src/main/org/apache/tools/ant/types XMLCatalog.java
               src/testcases/org/apache/tools/ant/types XMLCatalogTest.java
  Log:
  Fix URIs for DTDs entered with a full path location under Windows
  PR: 23913
  
  Revision  Changes    Path
  1.34      +20 -3     ant/src/main/org/apache/tools/ant/types/XMLCatalog.java
  
  Index: XMLCatalog.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/XMLCatalog.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- XMLCatalog.java	23 Sep 2003 14:33:43 -0000	1.33
  +++ XMLCatalog.java	9 Dec 2003 01:14:31 -0000	1.34
  @@ -74,6 +74,7 @@
   import org.apache.tools.ant.AntClassLoader;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
  +import org.apache.tools.ant.taskdefs.condition.Os;
   import org.apache.tools.ant.util.FileUtils;
   import org.apache.tools.ant.util.JAXPUtils;
   import org.xml.sax.EntityResolver;
  @@ -678,6 +679,8 @@
       private InputSource filesystemLookup(ResourceLocation matchingEntry) {
   
           String uri = matchingEntry.getLocation();
  +        // the following line seems to be necessary on Windows under JDK 1.2
  +        uri = uri.replace(File.separatorChar, '/');
           URL baseURL = null;
   
           //
  @@ -697,11 +700,25 @@
   
           InputSource source = null;
           URL url = null;
  -
           try {
               url = new URL(baseURL, uri);
           } catch (MalformedURLException ex) {
  -            // ignore
  +            // this processing is useful under Windows when the location of the DTD has
been given as an absolute path
  +            // see Bugzilla Report 23913
  +            File testFile = new File(uri);
  +            if (testFile.exists() && testFile.canRead()) {
  +                log("uri : '"
  +                    + uri + "' matches a readable file", Project.MSG_DEBUG);
  +                try {
  +                    url = fileUtils.getFileURL(testFile);
  +                } catch (MalformedURLException ex1) {
  +                    throw new BuildException("could not find an URL for :" + testFile.getAbsolutePath());
  +                }
  +            } else {
  +                log("uri : '"
  +                    + uri + "' does not match a readable file", Project.MSG_DEBUG);
  +
  +            }
           }
   
           if (url != null) {
  
  
  
  1.7       +24 -1     ant/src/testcases/org/apache/tools/ant/types/XMLCatalogTest.java
  
  Index: XMLCatalogTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/types/XMLCatalogTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XMLCatalogTest.java	25 Sep 2003 07:44:13 -0000	1.6
  +++ XMLCatalogTest.java	9 Dec 2003 01:14:31 -0000	1.7
  @@ -238,6 +238,29 @@
               fail("resolveEntity() failed!" + e.toString());
           }
       }
  +    // inspired by Bugzilla Report 23913
  +    // a problem used to happen under Windows when the location of the DTD was given as
an absolute path
  +    // possibly with a mixture of file separators
  +    public void testAbsolutePath() {
  +        ResourceLocation dtd = new ResourceLocation();
  +        dtd.setPublicId("-//stevo//DTD doc 1.0//EN");
  +
  +        String sysid = System.getProperty("user.dir") + File.separator + "src/etc/testcases/taskdefs/optional/xml/doc.dtd";
  +        dtd.setLocation(sysid);
  +        catalog.addDTD(dtd);
  +        File dtdFile = project.resolveFile(sysid);
  +
  +        try {
  +            InputSource result = catalog.resolveEntity("-//stevo//DTD doc 1.0//EN",
  +                                                       "nap:chemical+brothers");
  +            assertNotNull(result);
  +            assertEquals(toURLString(dtdFile),
  +                         result.getSystemId());
  +        } catch (Exception e) {
  +            fail("resolveEntity() failed!" + e.toString());
  +        }
  +
  +    }
   
       public void testSimpleEntry() {
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message