You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/11/26 15:45:10 UTC

svn commit: r720892 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTasks/style.html src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java

Author: bodewig
Date: Wed Nov 26 06:45:10 2008
New Revision: 720892

URL: http://svn.apache.org/viewvc?rev=720892&view=rev
Log:
Add support for setting system properties in xslt.  PR 36653.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/style.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=720892&r1=720891&r2=720892&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Wed Nov 26 06:45:10 2008
@@ -570,6 +570,11 @@
    transform is empty.
    Bugzilla Report 46274.
 
+ * It is now possible to define system properties that should be set
+   during xslt's transformation.  This can be used to enable XInclude
+   processing in Xerces, for example.
+   Bugzilla Report 36653.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTasks/style.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/style.html?rev=720892&r1=720891&r2=720892&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/style.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/style.html Wed Nov 26 06:45:10 2008
@@ -419,6 +419,22 @@
 single-element collection.  Alternatively, use the <code>refid</code> to
 specify the resource or collection as a reference.</p>
 
+<h4>sysproperty</h4>
+<p>Use nested <code>&lt;sysproperty&gt;</code> elements to specify
+system properties required by the factory or transformation.  These
+properties will be made available to the VM during the execution of
+the class. The attributes for this element are the same as
+for <a href="exec.html#env">environment variables</a>.</p>
+
+<p><em>since Ant 1.8.0</em>.</p>
+
+<h4>syspropertyset</h4>
+
+<p>You can specify a set of properties to be used as system properties
+with <a href="../CoreTypes/propertyset.html">syspropertyset</a>s.</p>
+
+<p><em>since Ant 1.8.0</em>.</p>
+
 <h3>Examples</h3>
 <blockquote>
   <pre>
@@ -511,6 +527,15 @@
 &lt;/xsl:stylesheet&gt;
 </pre>
 
+<h4>Use an XInclude-aware version of Xerces while transforming</h4>
+
+<pre>
+&lt;xslt ...&gt;
+    &lt;sysproperty key="org.apache.xerces.xni.parser.XMLParserConfiguration"
+                 value="org.apache.xerces.parsers.XIncludeParserConfiguration"
+     /&gt;
+&lt;xslt&gt;
+</pre>
 </blockquote>
 
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java?rev=720892&r1=720891&r2=720892&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java Wed Nov 26 06:45:10 2008
@@ -26,8 +26,11 @@
 import org.apache.tools.ant.DirectoryScanner;
 import org.apache.tools.ant.DynamicConfigurator;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.CommandlineJava;
+import org.apache.tools.ant.types.Environment;
 import org.apache.tools.ant.types.Mapper;
 import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.PropertySet;
 import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
@@ -199,6 +202,14 @@
     private boolean failOnNoResources = true;
 
     /**
+     * System properties to set during transformation.
+     *
+     * @since Ant 1.8.0
+     */
+    private CommandlineJava.SysProperties sysProperties =
+        new CommandlineJava.SysProperties();
+
+    /**
      * Creates a new XSLTProcess Task.
      */
     public XSLTProcess() {
@@ -321,6 +332,10 @@
             return;
         }
         try {
+            if (sysProperties.size() > 0) {
+                sysProperties.setSystem();
+            }
+
             Resource styleResource;
             if (baseDir == null) {
                 baseDir = getProject().getBaseDir();
@@ -410,6 +425,9 @@
                 loader.cleanup();
                 loader = null;
             }
+            if (sysProperties.size() > 0) {
+                sysProperties.restoreSystem();
+            }
             liaison = null;
             stylesheetLoaded = false;
             baseDir = savedBaseDir;
@@ -596,6 +614,24 @@
     }
 
     /**
+     * A system property to set during transformation.
+     *
+     * @since Ant 1.8.0
+     */
+    public void addSysproperty(Environment.Variable sysp) {
+        sysProperties.addVariable(sysp);
+    }
+
+    /**
+     * A set of system properties to set during transformation.
+     *
+     * @since Ant 1.8.0
+     */
+    public void addSyspropertyset(PropertySet sysp) {
+        sysProperties.addSyspropertyset(sysp);
+    }
+
+    /**
      * Load processor here instead of in setProcessor - this will be
      * called from within execute, so we have access to the latest
      * classpath.