ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbaill...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs XSLTProcess.java
Date Fri, 12 Jul 2002 21:25:29 GMT
sbailliez    2002/07/12 14:25:29

  Modified:    docs/manual/CoreTasks style.html
               src/etc/testcases/taskdefs/optional xslt.xml
               src/main/org/apache/tools/ant/taskdefs XSLTProcess.java
  Log:
  trax factory settings are now configured within a <factory> element.
  
  Revision  Changes    Path
  1.23      +31 -16    jakarta-ant/docs/manual/CoreTasks/style.html
  
  Index: style.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/style.html,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- style.html	11 Jul 2002 22:52:55 -0000	1.22
  +++ style.html	12 Jul 2002 21:25:29 -0000	1.23
  @@ -103,18 +103,6 @@
       <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.
         All files are included when omitted.</td>
  @@ -219,8 +207,29 @@
     </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 @@
       <td align="center" valign="top">Yes</td>
     </tr>
   </table>
  -
  +</blockquote>
   
   <h3>Examples</h3>
   <blockquote>
  @@ -298,7 +307,13 @@
     &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
  
  
  
  1.4       +7 -5      jakarta-ant/src/etc/testcases/taskdefs/optional/xslt.xml
  
  Index: xslt.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/optional/xslt.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- xslt.xml	11 Jul 2002 22:52:55 -0000	1.3
  +++ xslt.xml	12 Jul 2002 21:25:29 -0000	1.4
  @@ -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>
   
  
  
  
  1.48      +130 -96   jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  
  Index: XSLTProcess.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- XSLTProcess.java	11 Jul 2002 22:52:55 -0000	1.47
  +++ XSLTProcess.java	12 Jul 2002 21:25:29 -0000	1.48
  @@ -146,22 +146,15 @@
   
       /**
        * 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.
  @@ -182,14 +175,6 @@
       }
   
       /**
  -     * 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.
        *
        * @exception BuildException if there is an execution problem.
  @@ -713,76 +698,6 @@
   
   
       /**
  -     * 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
        */
       public void init() throws BuildException {
  @@ -826,7 +741,15 @@
        */
       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 @@
               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();) {
  @@ -849,5 +765,123 @@
               liaison.setOutputProperty(prop.getName(), prop.getValue());
           }
       }
  +
  +    /**
  +     * 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
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message