ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [5/7] ant git commit: add support for TraX factory features
Date Sun, 04 Sep 2016 14:25:02 GMT
add support for TraX factory features


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/cac55fbf
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/cac55fbf
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/cac55fbf

Branch: refs/heads/1.9.x
Commit: cac55fbfc097a36a2b6af3dc7a08c8418a9c02a5
Parents: 9b6f926
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Sun Sep 4 13:32:01 2016 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Sun Sep 4 13:32:01 2016 +0200

----------------------------------------------------------------------
 WHATSNEW                                        |  3 +
 manual/Tasks/style.html                         | 31 ++++++++-
 .../apache/tools/ant/taskdefs/XSLTProcess.java  | 73 ++++++++++++++++++--
 .../ant/taskdefs/optional/TraXLiaison.java      | 35 +++++++++-
 4 files changed, 134 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/cac55fbf/WHATSNEW
----------------------------------------------------------------------
diff --git a/WHATSNEW b/WHATSNEW
index cc199c2..3a23c1f 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 <xslt>
+   and <junitreport>.
+
 Changes from Ant 1.9.6 TO Ant 1.9.7
 ===================================
 

http://git-wip-us.apache.org/repos/asf/ant/blob/cac55fbf/manual/Tasks/style.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/style.html b/manual/Tasks/style.html
index a1b9f2d..32fa621 100644
--- a/manual/Tasks/style.html
+++ b/manual/Tasks/style.html
@@ -395,7 +395,7 @@ Used to specify factory settings.
   </tr>
 </table>
 <h3>Parameters specified as nested elements</h3>
-<h4>attribute </h4>
+<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.
@@ -435,6 +435,35 @@ And in Saxon 7.x:
   </tr>
 </table>
 </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>
 <h4>mapper</h4>
 

http://git-wip-us.apache.org/repos/asf/ant/blob/cac55fbf/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
index 4fe3126..6f54d1d 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<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.
@@ -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<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() {
                 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
 
     /**

http://git-wip-us.apache.org/repos/asf/ant/blob/cac55fbf/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
----------------------------------------------------------------------
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 8d9a44a..fea97d2 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<String, Object> params = new Hashtable<String, Object>();
 
     /** 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 */
     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<String, Boolean> 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();


Mime
View raw message