Browse Source

trax factory settings are now configured within a <factory> element.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273104 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 23 years ago
parent
commit
5fa2b3cd64
3 changed files with 167 additions and 116 deletions
  1. +31
    -16
      docs/manual/CoreTasks/style.html
  2. +7
    -5
      src/etc/testcases/taskdefs/optional/xslt.xml
  3. +129
    -95
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java

+ 31
- 16
docs/manual/CoreTasks/style.html View File

@@ -102,18 +102,6 @@ element which is used to perform Entity and URI resolution</p>
</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">factory</td>

<td valign="top">fully qualified class name of the transformer
factory to use. For example
<tt>org.apache.xalan.processor.TransformerFactoryImpl</tt>
or <tt>org.apache.xalan.xsltc.trax.TransformerFactoryImpl</tt>
or <tt>net.sf.saxon.TransformerFactoryImpl</tt>...
</td>
<td align="center" valign="top">No. Works only with 'trax'/default processor
and defaults to JAXP lookup mechanism.</td>
</tr>
<tr>
<td valign="top">includes</td>
<td valign="top">comma- or space-separated list of patterns of files that must be included.
@@ -219,8 +207,29 @@ XSLT specifications</a>.
</tr>
</table>

<h4>attribute ('trax' processors only)</h4>
<p>Used to specify settings of the processor.
<h4>factory ('trax' processors only)</h4>
Used to specify factory settings.
<h4>Parameters</h4>
<table width="60%" border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">name</td>
<td valign="top">fully qualified classname of the
transformer factory to use. For example
<tt>org.apache.xalan.processor.TransformerFactoryImpl</tt>
or <tt>org.apache.xalan.xsltc.trax.TransformerFactoryImpl</tt>
or <tt>net.sf.saxon.TransformerFactoryImpl</tt>...
</td>
<td align="center" valign="top">No. Defaults to the JAXP lookup mechanism.</td>
</tr>
</table>
<blockquote>
<h4>attribute </h4>
<p>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:
<td align="center" valign="top">Yes</td>
</tr>
</table>
</blockquote>

<h3>Examples</h3>
<blockquote>
@@ -298,7 +307,13 @@ And in Saxon 7.x:
&lt;outputproperty name=&quot;indent&quot; value=&quot;yes&quot;/&gt;
&lt;/xslt&gt;</pre>


<h4>Using factory settings</h4>
<pre>&lt;xslt in=&quot;doc.xml&quot; out=&quot;build/doc/output.xml&quot;
style=&quot;style/apache.xsl&quot;&gt;
&lt;factory name=&quot;org.apache.xalan.processor.TransformerFactoryImpl&quot;&gt;
&lt;attribute name=&quot;http://xml.apache.org/xalan/features/optimize&quot; value=&quot;true&quot;/&gt;
&lt;/factory&gt;
&lt;/xslt&gt;</pre>
</blockquote>
<hr>
<p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights


+ 7
- 5
src/etc/testcases/taskdefs/optional/xslt.xml View File

@@ -46,16 +46,18 @@
<target name="testFactory" depends="init">
<style in="xml/test.xml"
out="xml/out/test-out.xml"
style="xml/test.xsl"
factory="org.apache.xalan.processor.TransformerFactoryImpl"/>
style="xml/test.xsl">
<factory name="org.apache.xalan.processor.TransformerFactoryImpl"/>
</style>
</target>

<target name="testAttribute" depends="init">
<style in="xml/test.xml"
out="xml/out/test-out.xml"
style="xml/test.xsl"
factory="org.apache.xalan.processor.TransformerFactoryImpl">
<attribute name="http://xml.apache.org/xalan/features/optimize" value="true"/>
style="xml/test.xsl">
<factory name="org.apache.xalan.processor.TransformerFactoryImpl">
<attribute name="http://xml.apache.org/xalan/features/optimize" value="true"/>
</factory>
</style>
</target>



+ 129
- 95
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -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:
* <ul>
* <li>http://xml.apache.org/xalan/features/optimize (true|false) </li>
* <li>http://xml.apache.org/xalan/features/incremental (true|false) </li>
* </ul>
* @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:
* <ul>
* <li>http://xml.apache.org/xalan/features/optimize (true|false) </li>
* <li>http://xml.apache.org/xalan/features/incremental (true|false) </li>
* </ul>
*/
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

Loading…
Cancel
Save