Browse Source

Add support for setting system properties in xslt. PR 36653.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@720892 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
197f9ee4ec
3 changed files with 66 additions and 0 deletions
  1. +5
    -0
      WHATSNEW
  2. +25
    -0
      docs/manual/CoreTasks/style.html
  3. +36
    -0
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java

+ 5
- 0
WHATSNEW View File

@@ -570,6 +570,11 @@ Other changes:
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
=============================================



+ 25
- 0
docs/manual/CoreTasks/style.html View File

@@ -419,6 +419,22 @@ this element, the stylesheet should be specified as a nested resource or
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 @@ specify the resource or collection as a reference.</p>
&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>




+ 36
- 0
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -26,8 +26,11 @@ import org.apache.tools.ant.BuildException;
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;
@@ -198,6 +201,14 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*/
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.
*/
@@ -321,6 +332,10 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
return;
}
try {
if (sysProperties.size() > 0) {
sysProperties.setSystem();
}

Resource styleResource;
if (baseDir == null) {
baseDir = getProject().getBaseDir();
@@ -410,6 +425,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
loader.cleanup();
loader = null;
}
if (sysProperties.size() > 0) {
sysProperties.restoreSystem();
}
liaison = null;
stylesheetLoaded = false;
baseDir = savedBaseDir;
@@ -595,6 +613,24 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
failOnNoResources = b;
}

/**
* 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


Loading…
Cancel
Save