Browse Source

Fix for SystemId of stylesheet

Bugzilla 39407.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@412369 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 19 years ago
parent
commit
731eadf2ee
6 changed files with 77 additions and 1 deletions
  1. +12
    -0
      src/etc/testcases/taskdefs/optional/xml/books.xml
  2. +12
    -0
      src/etc/testcases/taskdefs/optional/xml/stylesheet_include.xsl
  3. +12
    -0
      src/etc/testcases/taskdefs/optional/xml/stylesheet_with_include.xsl
  4. +6
    -0
      src/etc/testcases/taskdefs/optional/xslt.xml
  5. +24
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
  6. +11
    -0
      src/testcases/org/apache/tools/ant/taskdefs/optional/XsltTest.java

+ 12
- 0
src/etc/testcases/taskdefs/optional/xml/books.xml View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<books>
<book name="hamlet">
<author name="shakespeare"/>
</book>
<book name="the lord of rings">
<author name="tolkien"/>
</book>
<book name="le malade imaginaire">
<author name="moliere"/>
</book>
</books>

+ 12
- 0
src/etc/testcases/taskdefs/optional/xml/stylesheet_include.xsl View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="author">
<author>
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
</author>
</xsl:template>
</xsl:stylesheet>

+ 12
- 0
src/etc/testcases/taskdefs/optional/xml/stylesheet_with_include.xsl View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml"/>
<xsl:include href="stylesheet_include.xsl"/>
<xsl:template match="/">
<authors>
<xsl:apply-templates/>
</authors>
</xsl:template>
</xsl:stylesheet>

+ 6
- 0
src/etc/testcases/taskdefs/optional/xslt.xml View File

@@ -79,4 +79,10 @@
style="xml/apache.xsl"> style="xml/apache.xsl">
</xslt> </xslt>
</target> </target>
<target name="testStyleSheetWithInclude" depends="init">
<xslt in="xml/books.xml"
out="xml/out/test-out.xml"
style="xml/stylesheet_with_include.xsl">
</xslt>
</target>
</project> </project>

+ 24
- 1
src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java View File

@@ -27,6 +27,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Vector; import java.util.Vector;
import java.util.Enumeration; import java.util.Enumeration;
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.ErrorListener; import javax.xml.transform.ErrorListener;
@@ -50,6 +51,7 @@ import org.apache.tools.ant.taskdefs.XSLTProcess;
import org.apache.tools.ant.types.XMLCatalog; import org.apache.tools.ant.types.XMLCatalog;
import org.apache.tools.ant.types.Resource; import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.resources.FileResource; import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.resources.URLResource;
import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JAXPUtils; import org.apache.tools.ant.util.JAXPUtils;
import org.xml.sax.EntityResolver; import org.xml.sax.EntityResolver;
@@ -64,6 +66,13 @@ import org.xml.sax.XMLReader;
*/ */
public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware { public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware {


/**
* Helper for transforming filenames to URIs.
*
* @since Ant 1.7
*/
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();

/** /**
* The current <code>Project</code> * The current <code>Project</code>
*/ */
@@ -126,6 +135,7 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware
FileResource fr = new FileResource(); FileResource fr = new FileResource();
fr.setProject(project); fr.setProject(project);
fr.setFile(stylesheet); fr.setFile(stylesheet);
setStylesheet(fr);
} }


/** /**
@@ -249,10 +259,23 @@ public class TraXLiaison implements XSLTLiaison3, ErrorListener, XSLTLoggerAware
// The line below is a hack: the system id must an URI, but it is not // The line below is a hack: the system id must an URI, but it is not
// cleat to get the URI of an resource, so just set the name of the // cleat to get the URI of an resource, so just set the name of the
// resource as a system id // resource as a system id
src.setSystemId(resource.getName());
src.setSystemId(resourceToURI(resource));
return src; return src;
} }


private String resourceToURI(Resource resource) {
if (resource instanceof FileResource) {
File f = ((FileResource) resource).getFile();
return FILE_UTILS.toURI(f.getAbsolutePath());
}
if (resource instanceof URLResource) {
URL u = ((URLResource) resource).getURL();
return String.valueOf(u);
} else {
return resource.getName();
}
}

/** /**
* Read in templates from the stylesheet * Read in templates from the stylesheet
*/ */


+ 11
- 0
src/testcases/org/apache/tools/ant/taskdefs/optional/XsltTest.java View File

@@ -88,5 +88,16 @@ public class XsltTest extends BuildFileTest {
public void testXMLWithEntitiesInNonAsciiPath() throws Exception { public void testXMLWithEntitiesInNonAsciiPath() throws Exception {
executeTarget("testXMLWithEntitiesInNonAsciiPath"); executeTarget("testXMLWithEntitiesInNonAsciiPath");
} }

/**
* check that the system id gets set properly on stylesheets.
* @throws Exception if something goes wrong.
*/
public void testStyleSheetWithInclude() throws Exception {
executeTarget("testStyleSheetWithInclude");
if (getLog().indexOf("java.io.FileNotFoundException") != -1) {
fail("xsl:include was not found");
}
}
} }



Loading…
Cancel
Save