From 5fa2b3cd6484967339e8bd85e3b180117cf4cff3 Mon Sep 17 00:00:00 2001
From: Stephane Bailliez
Date: Fri, 12 Jul 2002 21:25:29 +0000
Subject: [PATCH] trax factory settings are now configured within a
element.
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273104 13f79535-47bb-0310-9956-ffa450edef68
---
docs/manual/CoreTasks/style.html | 47 ++--
src/etc/testcases/taskdefs/optional/xslt.xml | 12 +-
.../tools/ant/taskdefs/XSLTProcess.java | 224 ++++++++++--------
3 files changed, 167 insertions(+), 116 deletions(-)
diff --git a/docs/manual/CoreTasks/style.html b/docs/manual/CoreTasks/style.html
index 37fda2296..ed502c803 100644
--- a/docs/manual/CoreTasks/style.html
+++ b/docs/manual/CoreTasks/style.html
@@ -102,18 +102,6 @@ element which is used to perform Entity and URI resolution
No |
-
- factory |
-
- fully qualified class name of the transformer
- factory to use. For example
- org.apache.xalan.processor.TransformerFactoryImpl
- or org.apache.xalan.xsltc.trax.TransformerFactoryImpl
- or net.sf.saxon.TransformerFactoryImpl...
- |
- No. Works only with 'trax'/default processor
- and defaults to JAXP lookup mechanism. |
-
includes |
comma- or space-separated list of patterns of files that must be included.
@@ -219,8 +207,29 @@ XSLT specifications.
|
-attribute ('trax' processors only)
-Used to specify settings of the processor.
+
factory ('trax' processors only)
+Used to specify factory settings.
+Parameters
+
+
+ Attribute |
+ Description |
+ Required |
+
+
+ name |
+ fully qualified classname of the
+ transformer factory to use. For example
+ org.apache.xalan.processor.TransformerFactoryImpl
+ or org.apache.xalan.xsltc.trax.TransformerFactoryImpl
+ or net.sf.saxon.TransformerFactoryImpl...
+ |
+ No. Defaults to the JAXP lookup mechanism. |
+
+
+
+attribute
+Used to specify settings of the processor factory.
The attribute names and values are entirely processor specific
so you must be aware of the implementation to figure them out.
Read the documentation of your processor.
@@ -257,7 +266,7 @@ And in Saxon 7.x:
Yes |
-
+
Examples
@@ -298,7 +307,13 @@ And in Saxon 7.x:
<outputproperty name="indent" value="yes"/>
</xslt>
-
+ Using factory settings
+<xslt in="doc.xml" out="build/doc/output.xml"
+ style="style/apache.xsl">
+ <factory name="org.apache.xalan.processor.TransformerFactoryImpl">
+ <attribute name="http://xml.apache.org/xalan/features/optimize" value="true"/>
+ </factory>
+</xslt>
Copyright © 2000-2002 Apache Software Foundation. All rights
diff --git a/src/etc/testcases/taskdefs/optional/xslt.xml b/src/etc/testcases/taskdefs/optional/xslt.xml
index 03900453c..cb4567455 100644
--- a/src/etc/testcases/taskdefs/optional/xslt.xml
+++ b/src/etc/testcases/taskdefs/optional/xslt.xml
@@ -46,16 +46,18 @@
+ style="xml/test.xsl">
+
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
index 4d10a288f..b470b3426 100644
--- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
+++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
@@ -146,22 +146,15 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
/**
* Whether to style all files in the included directories as well.
- *
* @since Ant 1.5
*/
private boolean performDirectoryScan = true;
/**
- * the factory class name to use for TraXLiaison
+ * factory element for TraX processors only
* @since Ant 1.6
*/
- private String factory = null;
-
- /**
- * the list of factory attributes to use for TraXLiaison
- * @since Ant 1.6
- */
- private Vector attributes = new Vector();
+ private Factory factory = null;
/**
* Creates a new XSLTProcess Task.
@@ -181,14 +174,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
performDirectoryScan = b;
}
- /**
- * Set the factory to use for the TraXLiaison.
- * @param value the name of the factory
- */
- public void setFactory(String value){
- factory = value;
- }
-
/**
* Executes the task.
*
@@ -712,76 +697,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
}
- /**
- * Create an instance of a factory attribute.
- * @return the newly created factory attribute
- * @since Ant 1.6
- */
- public Attribute createAttribute() {
- Attribute attr = new Attribute();
- attributes.addElement(attr);
- return attr;
- }
-
- /**
- * A JAXP factory attribute. This is mostly processor specific, for
- * example for Xalan 2.3+, the following attributes could be set:
- *
- * - http://xml.apache.org/xalan/features/optimize (true|false)
- * - http://xml.apache.org/xalan/features/incremental (true|false)
- *
- * @since Ant 1.6
- */
- public static class Attribute implements DynamicConfigurator {
-
- /** attribute name, mostly processor specific */
- private String name;
-
- /** attribute value, often a boolean string */
- private Object value;
-
- /**
- * @return the attribute name.
- */
- public String getName() {
- return name;
- }
-
- /**
- * @return the output property value.
- */
- public Object getValue() {
- return value;
- }
-
- public Object createDynamicElement(String name) throws BuildException {
- return null;
- }
-
- public void setDynamicAttribute(String name, String value)
- throws BuildException {
- // only 'name' and 'value' exist.
- if ("name".equalsIgnoreCase(name)) {
- this.name = value;
- } else if ("value".equalsIgnoreCase(name)) {
- // a value must be of a given type
- // say boolean|integer|string that are mostly used.
- if ("true".equalsIgnoreCase(value)
- || "false".equalsIgnoreCase(value) ){
- this.value = new Boolean(value);
- } else {
- try {
- this.value = new Integer(value);
- } catch (NumberFormatException e) {
- this.value = value;
- }
- }
- } else {
- throw new BuildException("Unsupported attribute: " + name);
- }
- }
- }
-
/**
* Initialize internal instance of XMLCatalog
*/
@@ -826,7 +741,15 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*/
protected void configureTraXLiaison(TraXLiaison liaison){
if (factory != null) {
- liaison.setFactory(factory);
+ liaison.setFactory(factory.getName());
+
+ // configure factory attributes
+ for (Enumeration attrs = factory.getAttributes();
+ attrs.hasMoreElements();) {
+ Factory.Attribute attr =
+ (Factory.Attribute)attrs.nextElement();
+ liaison.setAttribute(attr.getName(), attr.getValue());
+ }
}
// use XMLCatalog as the entity resolver and URI resolver
@@ -835,13 +758,6 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
liaison.setURIResolver(xmlCatalog);
}
- // configure factory attributes
- for (Enumeration attrs = attributes.elements();
- attrs.hasMoreElements();) {
- Attribute attr = (Attribute)attrs.nextElement();
- liaison.setAttribute(attr.getName(), attr.getValue());
- }
-
// configure output properties
for (Enumeration props = outputProperties.elements();
props.hasMoreElements();) {
@@ -850,4 +766,122 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
}
}
+ /**
+ * Create the factory element to configure a trax liaison.
+ * @return the newly created factory element.
+ * @throws BuildException if the element is created more than one time.
+ */
+ public Factory createFactory() throws BuildException {
+ if (factory != null) {
+ throw new BuildException("'factory' element must be unique");
+ }
+ factory = new Factory();
+ return factory;
+ }
+
+ /**
+ * The factory element to configure a transformer factory
+ * @since Ant 1.6
+ */
+ public static class Factory {
+
+ /** the factory class name to use for TraXLiaison */
+ private String name;
+
+ /**
+ * the list of factory attributes to use for TraXLiaison
+ */
+ private Vector attributes = new Vector();
+
+ /**
+ * @return the name of the factory.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Set the name of the factory
+ * @param name the name of the factory.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Create an instance of a factory attribute.
+ * @return the newly created factory attribute
+ */
+ public void addAttribute(Attribute attr) {
+ attributes.addElement(attr);
+ }
+
+ /**
+ * return the attribute elements.
+ * @return the enumeration of attributes
+ */
+ public Enumeration getAttributes() {
+ return attributes.elements();
+ }
+
+ /**
+ * A JAXP factory attribute. This is mostly processor specific, for
+ * example for Xalan 2.3+, the following attributes could be set:
+ *
+ * - http://xml.apache.org/xalan/features/optimize (true|false)
+ * - http://xml.apache.org/xalan/features/incremental (true|false)
+ *
+ */
+ public static class Attribute implements DynamicConfigurator {
+
+ /** attribute name, mostly processor specific */
+ private String name;
+
+ /** attribute value, often a boolean string */
+ private Object value;
+
+ /**
+ * @return the attribute name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the output property value.
+ */
+ public Object getValue() {
+ return value;
+ }
+
+ public Object createDynamicElement(String name) throws BuildException {
+ return null;
+ }
+
+ public void setDynamicAttribute(String name, String value)
+ throws BuildException {
+ // only 'name' and 'value' exist.
+ if ("name".equalsIgnoreCase(name)) {
+ this.name = value;
+ } else if ("value".equalsIgnoreCase(name)) {
+ // a value must be of a given type
+ // say boolean|integer|string that are mostly used.
+ if ("true".equalsIgnoreCase(value)
+ || "false".equalsIgnoreCase(value) ){
+ this.value = new Boolean(value);
+ } else {
+ try {
+ this.value = new Integer(value);
+ } catch (NumberFormatException e) {
+ this.value = value;
+ }
+ }
+ } else {
+ throw new BuildException("Unsupported attribute: " + name);
+ }
+ }
+ } // -- class Attribute
+
+ } // -- class Factory
+
} //-- XSLTProcess