Browse Source

Fix URIs for DTDs entered with a full path location under Windows

PR: 23913


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275759 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 21 years ago
parent
commit
299a7d5929
2 changed files with 42 additions and 2 deletions
  1. +19
    -2
      src/main/org/apache/tools/ant/types/XMLCatalog.java
  2. +23
    -0
      src/testcases/org/apache/tools/ant/types/XMLCatalogTest.java

+ 19
- 2
src/main/org/apache/tools/ant/types/XMLCatalog.java View File

@@ -74,6 +74,7 @@ import javax.xml.transform.sax.SAXSource;
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 @@ public class XMLCatalog extends DataType
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 @@ public class XMLCatalog extends DataType

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) {


+ 23
- 0
src/testcases/org/apache/tools/ant/types/XMLCatalogTest.java View File

@@ -238,6 +238,29 @@ public class XMLCatalogTest extends TestCase {
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() {



Loading…
Cancel
Save