diff --git a/WHATSNEW b/WHATSNEW index cc199c207..3a23c1f13 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -83,6 +83,9 @@ Other changes: nativeheaderdir attribute. Bugzilla Report 59905 + * it is now possible to set features of the TraX factory used by + and . + Changes from Ant 1.9.6 TO Ant 1.9.7 =================================== diff --git a/manual/Tasks/style.html b/manual/Tasks/style.html index a1b9f2db2..32fa6214a 100644 --- a/manual/Tasks/style.html +++ b/manual/Tasks/style.html @@ -395,7 +395,7 @@ Used to specify factory settings.

Parameters specified as nested elements

-

attribute

+

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. @@ -435,6 +435,35 @@ And in Saxon 7.x: +

feature

+

since Ant 1.9.8

+

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 http://javax.xml.XMLConstants/feature/secure-processing. +

+

Parameters

+ + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
nameName of the featureYes
valuevalue of the feature. A boolean value + (i.e. permitted values are true,false,yes,no,on,off).No, defaults to false
+

mapper

diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java index 4fe31260b..6f54d1d4c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java @@ -1462,7 +1462,12 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { /** * the list of factory attributes to use for TraXLiaison */ - private final Vector attributes = new Vector(); + private final List attributes = new ArrayList(); + + /** + * the list of factory features to use for TraXLiaison + */ + private final List features = new ArrayList(); /** * @return the name of the factory. @@ -1484,7 +1489,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { * @param attr the newly created factory attribute */ 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 */ 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 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() { return value; @@ -1565,6 +1587,49 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { } } } // -- 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 /** diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java index 8d9a44a65..fea97d2aa 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java @@ -28,8 +28,12 @@ import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Field; import java.net.URL; +import java.util.ArrayList; import java.util.Enumeration; +import java.util.HashMap; import java.util.Hashtable; +import java.util.List; +import java.util.Map; import java.util.Vector; import javax.xml.parsers.ParserConfigurationException; @@ -123,7 +127,10 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware private final Hashtable params = new Hashtable(); /** factory attributes */ - private final Vector attributes = new Vector(); + private final List attributes = new ArrayList(); + + /** factory features */ + private final Map features = new HashMap(); /** whether to suppress warnings */ private boolean suppressWarnings = false; @@ -436,10 +443,18 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware // specific attributes for the transformer final int size = attributes.size(); 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]); } + for (Map.Entry feature : features.entrySet()) { + try { + tfactory.setFeature(feature.getKey(), feature.getValue()); + } catch (TransformerConfigurationException ex) { + throw new BuildException(ex); + } + } + if (uriResolver != null) { tfactory.setURIResolver(uriResolver); } @@ -466,7 +481,17 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware */ public void setAttribute(final String name, final Object 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(); setAttribute(attr.getName(), attr.getValue()); } + for (final XSLTProcess.Factory.Feature feature + : factory.getFeatures()) { + setFeature(feature.getName(), feature.getValue()); + } } final XMLCatalog xmlCatalog = xsltTask.getXMLCatalog();