@@ -83,6 +83,9 @@ Other changes: | |||||
nativeheaderdir attribute. | nativeheaderdir attribute. | ||||
Bugzilla Report 59905 | Bugzilla Report 59905 | ||||
* it is now possible to set features of the TraX factory used by <xslt> | |||||
and <junitreport>. | |||||
Changes from Ant 1.9.6 TO Ant 1.9.7 | Changes from Ant 1.9.6 TO Ant 1.9.7 | ||||
=================================== | =================================== | ||||
@@ -395,7 +395,7 @@ Used to specify factory settings. | |||||
</tr> | </tr> | ||||
</table> | </table> | ||||
<h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
<h4>attribute </h4> | |||||
<h4>attribute</h4> | |||||
<p>Used to specify settings of the processor factory. | <p>Used to specify settings of the processor factory. | ||||
The attribute names and values are entirely processor specific | The attribute names and values are entirely processor specific | ||||
so you must be aware of the implementation to figure them out. | so you must be aware of the implementation to figure them out. | ||||
@@ -435,6 +435,35 @@ And in Saxon 7.x: | |||||
</tr> | </tr> | ||||
</table> | </table> | ||||
</blockquote> | </blockquote> | ||||
<h4>feature</h4> | |||||
<p><em>since Ant 1.9.8</em></p> | |||||
<p>Used to specify settings of the processor factory. The feature | |||||
names are mostly processor specific so you must be aware of the | |||||
implementation to figure them out. Read the documentation of your | |||||
processor. The only feature all implementations are required to | |||||
support | |||||
is <code>http://javax.xml.XMLConstants/feature/secure-processing</code>. | |||||
<blockquote> | |||||
<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">Name of the feature</td> | |||||
<td align="center" valign="top">Yes</td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">value</td> | |||||
<td valign="top">value of the feature. A boolean value | |||||
(i.e. permitted values are true,false,yes,no,on,off).</td> | |||||
<td align="center" valign="top">No, defaults to false</td> | |||||
</tr> | |||||
</table> | |||||
</blockquote> | |||||
</blockquote> | </blockquote> | ||||
<h4>mapper</h4> | <h4>mapper</h4> | ||||
@@ -1462,7 +1462,12 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
/** | /** | ||||
* the list of factory attributes to use for TraXLiaison | * the list of factory attributes to use for TraXLiaison | ||||
*/ | */ | ||||
private final Vector attributes = new Vector(); | |||||
private final List<Attribute> attributes = new ArrayList<Attribute>(); | |||||
/** | |||||
* the list of factory features to use for TraXLiaison | |||||
*/ | |||||
private final List<Feature> features = new ArrayList<Feature>(); | |||||
/** | /** | ||||
* @return the name of the factory. | * @return the name of the factory. | ||||
@@ -1484,7 +1489,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
* @param attr the newly created factory attribute | * @param attr the newly created factory attribute | ||||
*/ | */ | ||||
public void addAttribute(final Attribute attr) { | public void addAttribute(final Attribute attr) { | ||||
attributes.addElement(attr); | |||||
attributes.add(attr); | |||||
} | } | ||||
/** | /** | ||||
@@ -1492,7 +1497,24 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
* @return the enumeration of attributes | * @return the enumeration of attributes | ||||
*/ | */ | ||||
public Enumeration getAttributes() { | public Enumeration getAttributes() { | ||||
return attributes.elements(); | |||||
return Collections.enumeration(attributes); | |||||
} | |||||
/** | |||||
* Create an instance of a factory feature. | |||||
* @param feature the newly created feature | |||||
* @since Ant 1.9.8 | |||||
*/ | |||||
public void addFeature(final Feature feature) { | |||||
features.add(feature); | |||||
} | |||||
/** | |||||
* The configured features. | |||||
* @since Ant 1.9.8 | |||||
*/ | |||||
public Iterable<Feature> getFeatures() { | |||||
return features; | |||||
} | } | ||||
/** | /** | ||||
@@ -1519,7 +1541,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
} | } | ||||
/** | /** | ||||
* @return the output property value. | |||||
* @return the attribute value. | |||||
*/ | */ | ||||
public Object getValue() { | public Object getValue() { | ||||
return value; | return value; | ||||
@@ -1565,6 +1587,49 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { | |||||
} | } | ||||
} | } | ||||
} // -- class Attribute | } // -- class Attribute | ||||
/** | |||||
* A feature for the TraX factory. | |||||
* @since Ant 1.9.8 | |||||
*/ | |||||
public static class Feature { | |||||
private String name; | |||||
private boolean value; | |||||
public Feature() { } | |||||
public Feature(String name, boolean value) { | |||||
this.name = name; | |||||
this.value = value; | |||||
} | |||||
/** | |||||
* @param name the feature name. | |||||
*/ | |||||
public void setName(String name) { | |||||
this.name = name; | |||||
} | |||||
/** | |||||
* @param value the feature value. | |||||
*/ | |||||
public void setValue(boolean value) { | |||||
this.value = value; | |||||
} | |||||
/** | |||||
* @return the feature name. | |||||
*/ | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
/** | |||||
* @return the feature value. | |||||
*/ | |||||
public boolean getValue() { | |||||
return value; | |||||
} | |||||
} | |||||
} // -- class Factory | } // -- class Factory | ||||
/** | /** | ||||
@@ -28,8 +28,12 @@ import java.io.InputStream; | |||||
import java.io.OutputStream; | import java.io.OutputStream; | ||||
import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||
import java.net.URL; | import java.net.URL; | ||||
import java.util.ArrayList; | |||||
import java.util.Enumeration; | import java.util.Enumeration; | ||||
import java.util.HashMap; | |||||
import java.util.Hashtable; | import java.util.Hashtable; | ||||
import java.util.List; | |||||
import java.util.Map; | |||||
import java.util.Vector; | import java.util.Vector; | ||||
import javax.xml.parsers.ParserConfigurationException; | import javax.xml.parsers.ParserConfigurationException; | ||||
@@ -123,7 +127,10 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware | |||||
private final Hashtable<String, Object> params = new Hashtable<String, Object>(); | private final Hashtable<String, Object> params = new Hashtable<String, Object>(); | ||||
/** factory attributes */ | /** factory attributes */ | ||||
private final Vector attributes = new Vector(); | |||||
private final List<Object[]> attributes = new ArrayList<Object[]>(); | |||||
/** factory features */ | |||||
private final Map<String, Boolean> features = new HashMap<String, Boolean>(); | |||||
/** whether to suppress warnings */ | /** whether to suppress warnings */ | ||||
private boolean suppressWarnings = false; | private boolean suppressWarnings = false; | ||||
@@ -436,10 +443,18 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware | |||||
// specific attributes for the transformer | // specific attributes for the transformer | ||||
final int size = attributes.size(); | final int size = attributes.size(); | ||||
for (int i = 0; i < size; i++) { | for (int i = 0; i < size; i++) { | ||||
final Object[] pair = (Object[]) attributes.elementAt(i); | |||||
final Object[] pair = attributes.get(i); | |||||
tfactory.setAttribute((String) pair[0], pair[1]); | tfactory.setAttribute((String) pair[0], pair[1]); | ||||
} | } | ||||
for (Map.Entry<String, Boolean> feature : features.entrySet()) { | |||||
try { | |||||
tfactory.setFeature(feature.getKey(), feature.getValue()); | |||||
} catch (TransformerConfigurationException ex) { | |||||
throw new BuildException(ex); | |||||
} | |||||
} | |||||
if (uriResolver != null) { | if (uriResolver != null) { | ||||
tfactory.setURIResolver(uriResolver); | tfactory.setURIResolver(uriResolver); | ||||
} | } | ||||
@@ -466,7 +481,17 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware | |||||
*/ | */ | ||||
public void setAttribute(final String name, final Object value) { | public void setAttribute(final String name, final Object value) { | ||||
final Object[] pair = new Object[]{name, value}; | final Object[] pair = new Object[]{name, value}; | ||||
attributes.addElement(pair); | |||||
attributes.add(pair); | |||||
} | |||||
/** | |||||
* Set a custom feature for the JAXP factory implementation. | |||||
* @param name the feature name. | |||||
* @param value the value of the feature | |||||
* @since Ant 1.9.8 | |||||
*/ | |||||
public void setFeature(final String name, final boolean value) { | |||||
features.put(name, value); | |||||
} | } | ||||
/** | /** | ||||
@@ -625,6 +650,10 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware | |||||
(XSLTProcess.Factory.Attribute) attrs.nextElement(); | (XSLTProcess.Factory.Attribute) attrs.nextElement(); | ||||
setAttribute(attr.getName(), attr.getValue()); | setAttribute(attr.getName(), attr.getValue()); | ||||
} | } | ||||
for (final XSLTProcess.Factory.Feature feature | |||||
: factory.getFeatures()) { | |||||
setFeature(feature.getName(), feature.getValue()); | |||||
} | |||||
} | } | ||||
final XMLCatalog xmlCatalog = xsltTask.getXMLCatalog(); | final XMLCatalog xmlCatalog = xsltTask.getXMLCatalog(); | ||||