ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject svn commit: r412369 - in /ant/core/trunk/src: etc/testcases/taskdefs/optional/ etc/testcases/taskdefs/optional/xml/ main/org/apache/tools/ant/taskdefs/optional/ testcases/org/apache/tools/ant/taskdefs/optional/
Date Wed, 07 Jun 2006 11:28:23 GMT
Author: antoine
Date: Wed Jun  7 04:28:22 2006
New Revision: 412369

URL: http://svn.apache.org/viewvc?rev=412369&view=rev
Log:
Fix for SystemId of stylesheet
Bugzilla 39407.

Added:
    ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/books.xml
    ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/stylesheet_include.xsl
    ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/stylesheet_with_include.xsl
Modified:
    ant/core/trunk/src/etc/testcases/taskdefs/optional/xslt.xml
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
    ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/optional/XsltTest.java

Added: ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/books.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/books.xml?rev=412369&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/books.xml (added)
+++ ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/books.xml Wed Jun  7 04:28:22 2006
@@ -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>
\ No newline at end of file

Added: ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/stylesheet_include.xsl
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/stylesheet_include.xsl?rev=412369&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/stylesheet_include.xsl (added)
+++ ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/stylesheet_include.xsl Wed Jun
 7 04:28:22 2006
@@ -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>

Added: ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/stylesheet_with_include.xsl
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/stylesheet_with_include.xsl?rev=412369&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/stylesheet_with_include.xsl (added)
+++ ant/core/trunk/src/etc/testcases/taskdefs/optional/xml/stylesheet_with_include.xsl Wed
Jun  7 04:28:22 2006
@@ -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>

Modified: ant/core/trunk/src/etc/testcases/taskdefs/optional/xslt.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/optional/xslt.xml?rev=412369&r1=412368&r2=412369&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/optional/xslt.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/optional/xslt.xml Wed Jun  7 04:28:22 2006
@@ -79,4 +79,10 @@
            style="xml/apache.xsl">
     </xslt>
   </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>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java?rev=412369&r1=412368&r2=412369&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java Wed Jun
 7 04:28:22 2006
@@ -27,6 +27,7 @@
 import java.io.OutputStream;
 import java.util.Vector;
 import java.util.Enumeration;
+import java.net.URL;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.transform.ErrorListener;
@@ -50,6 +51,7 @@
 import org.apache.tools.ant.types.XMLCatalog;
 import org.apache.tools.ant.types.Resource;
 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.JAXPUtils;
 import org.xml.sax.EntityResolver;
@@ -65,6 +67,13 @@
 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>
      */
     private Project project;
@@ -126,6 +135,7 @@
         FileResource fr = new FileResource();
         fr.setProject(project);
         fr.setFile(stylesheet);
+        setStylesheet(fr);
     }
 
     /**
@@ -249,8 +259,21 @@
         // 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
         // resource as a system id
-        src.setSystemId(resource.getName());
+        src.setSystemId(resourceToURI(resource));
         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();
+        }
     }
 
     /**

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/optional/XsltTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/optional/XsltTest.java?rev=412369&r1=412368&r2=412369&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/optional/XsltTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/optional/XsltTest.java Wed
Jun  7 04:28:22 2006
@@ -88,5 +88,16 @@
     public void testXMLWithEntitiesInNonAsciiPath() throws Exception {
         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");
+        }
+    }
 }
 



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


Mime
View raw message