From 197f9ee4ec7343a06970c466ceb29fe51678521b Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 26 Nov 2008 14:45:10 +0000 Subject: [PATCH] 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 --- WHATSNEW | 5 +++ docs/manual/CoreTasks/style.html | 25 +++++++++++++ .../tools/ant/taskdefs/XSLTProcess.java | 36 +++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/WHATSNEW b/WHATSNEW index d528bbd33..19024bda9 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -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 ============================================= diff --git a/docs/manual/CoreTasks/style.html b/docs/manual/CoreTasks/style.html index 04ee7db3b..bf6b9193e 100644 --- a/docs/manual/CoreTasks/style.html +++ b/docs/manual/CoreTasks/style.html @@ -419,6 +419,22 @@ this element, the stylesheet should be specified as a nested resource or single-element collection. Alternatively, use the refid to specify the resource or collection as a reference.

+

sysproperty

+

Use nested <sysproperty> 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 environment variables.

+ +

since Ant 1.8.0.

+ +

syspropertyset

+ +

You can specify a set of properties to be used as system properties +with syspropertysets.

+ +

since Ant 1.8.0.

+

Examples

@@ -511,6 +527,15 @@ specify the resource or collection as a reference.

</xsl:stylesheet>
+

Use an XInclude-aware version of Xerces while transforming

+ +
+<xslt ...>
+    <sysproperty key="org.apache.xerces.xni.parser.XMLParserConfiguration"
+                 value="org.apache.xerces.parsers.XIncludeParserConfiguration"
+     />
+<xslt>
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java index f2d6b2372..fac6608ab 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java @@ -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