Hello,

Attached is a patch with a number of enhancements to the Ant DVSLTask
class and related files including examples.

Overview of modifications:
DVSL.java:
* New setClassLoader method allows setting the ClassLoader to be used to
load toolbox classes.
* New setStylesheet method with a File object (more Ant task friendly).

DVSLTask.java:
* Refactored XSLTProgress.java removing all the liaison support.  Starting
with this class brings the following functionality:
  - Consistency with the <style> task in most respects.
  - Dependency support.  Files will only be processed if a respective
source file is newer than the target file or the stylesheet is newer.
  - Nested <classpath> element, classpath and classpathref attributes.
* Renamed toolbox attribute to toolboxfile for better consistency with Ant
conventions.  Using the toolbox attribute instead of toolboxfile will
cause a deprecation warning.
* New attribute outputencoding.  Defaults to UTF-8.  I suspect this is
just a short term solution until DVSL can handle this in a similar manner
to XSLT.
* New nested elements:
  - <classpath>
  - <tool>
  - <velconfig>

Updates to build.xml's in examples:
* Added a compile target to compile the helper Java class.
* Updated to demonstrate new features.

Classpath support
    If any of the classpath, classpathref attributes or <classpath> nested
element are specified in the <dvsl> task, that classpath is used to load
the velocity config class and any toolbox classes rather than the one
specified in the <taskdef> for the <dvsl> task or system classloader.
    The build.xml's in the examples have been modified so the <taskdef> no
longer specifies in the classpath the location of the toolbox classes.

Toolbox support
    The new nested <tool> element can be used to set the toolbox directly
from the build.xml.  For instance:
    <tool name="toolbox.mystring.greeting" value="Good morning" />
Properties specified in the <tool> element take precedence over those in
the toolbox file.  The toolbox example has been updated to demonstrate
this.

Velocity Config support
    The new nested <velconfig> element can be used to set the Velocity
configuration properties directly from the build.xml.  For instance:
    <velconfig name="runtime.log" value="${basedir}/dvsl.log" />

The documentation for these modifications needs to be updated.  I started
to modify the style.html file which documents the <style> task.  One
problem is this is an HTML file, not XML.  I suppose the build.xml could
be modified to copy this file from xdocs to docs allowing it to be
maintained in HTML for now.  You can see the original version at
http://jakarta.apache.org/ant/manual/CoreTasks/style.html.

It would be nice to come up with DVSL stylesheet that could be used to
format Ant task documentation in HTML.  

-Bill
Index: jakarta-velocity-dvsl/build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-velocity-dvsl/build.xml,v
retrieving revision 1.9
diff -u -w -u -r1.9 build.xml
--- jakarta-velocity-dvsl/build.xml     29 Jan 2002 00:32:36 -0000      1.9
+++ jakarta-velocity-dvsl/build.xml     9 Feb 2002 07:25:17 -0000
@@ -232,7 +232,7 @@
       <dvsl
            basedir="${docs.src}"
            destdir="${docs.dest}/"
-          toolbox="${docs.src}/toolbox.props"
+           toolboxfile="${docs.src}/toolbox.props"
            extension=".html"
            style="${source.home}/stylesheets/site.dvsl"
            excludes="**/project.xml"
Index: jakarta-velocity-dvsl/docs/users-guide.html
===================================================================
RCS file: /home/cvspublic/jakarta-velocity-dvsl/docs/users-guide.html,v
retrieving revision 1.2
diff -u -w -u -r1.2 users-guide.html
Index: jakarta-velocity-dvsl/examples/simple/build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-velocity-dvsl/examples/simple/build.xml,v
retrieving revision 1.3
diff -u -w -u -r1.3 build.xml
--- jakarta-velocity-dvsl/examples/simple/build.xml     6 Feb 2002 04:45:16 -0000      
 1.3
+++ jakarta-velocity-dvsl/examples/simple/build.xml     9 Feb 2002 07:25:17 -0000
@@ -1,12 +1,26 @@
 <project name="dvsl-simple" default="doall" basedir=".">
 
+<!-- ========== External Dependencies ===================================== -->
+
+ <!-- the local JJAR repository -->
+ <property name="local.repository"       value="../../lib" />
+
+<!-- ========== Component Declarations ==================================== -->
+
+  <!-- The name of this component -->
+  <property name="project.name"          value="velocity-dvsl" />
+
+  <!-- The current version number of this component -->
+  <property name="project.version"       value="0.32"/>
+
   <!-- The docs source directory -->
   <property name="docs.src"             value="xdocs"/>
 
   <!-- The docs destination directory  -->
   <property name="docs.dest"             value="docs"/>
 
-  <property name="local.repository"   value="../../lib/" />
+  <!-- The compile debug setting -->
+  <property name="compile.debug"         value="true" />
 
   <!-- Construct compile classpath -->
   <path id="classpath">
@@ -17,13 +31,22 @@
 
 <!-- ========== Executable Targets ======================================== -->
 
-  <target name="doall">
+  <target name="compile">
+
+    <javac  srcdir="${basedir}"
+            destdir="${basedir}"
+            includes="*.java"
+            debug="${compile.debug}"
+            classpathref="classpath" />
+
+  </target>
+
+  <target name="doall" depends="compile">
   
       <taskdef name="dvsl" classname="org.apache.tools.dvsl.DVSLTask">
                         
           <classpath>
-             <pathelement location="../../velocity-dvsl-0.32.jar"/>
-             <pathelement location="."/>
+             <pathelement location="../../${project.name}-${project.version}.jar"/>
              <path refid="classpath"/>
           </classpath>
 
@@ -35,13 +58,12 @@
            extension=".html" 
            style="${docs.src}/example1.dvsl"
            includes="example1.xml" 
+           classpath="."
           velocityConfigClass="ConfigVel"           
       />
+
   </target>
 
 </project>
-
-
-
 
 
Index: jakarta-velocity-dvsl/examples/toolbox/build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-velocity-dvsl/examples/toolbox/build.xml,v
retrieving revision 1.1
diff -u -w -u -r1.1 build.xml
--- jakarta-velocity-dvsl/examples/toolbox/build.xml    18 Dec 2001 20:53:06 -0000     
 1.1
+++ jakarta-velocity-dvsl/examples/toolbox/build.xml    9 Feb 2002 07:25:17 -0000
@@ -9,10 +9,10 @@
 
 
   <!-- The name of this component -->
-  <property name="project.name"          value="dvsl" />
+  <property name="project.name"          value="velocity-dvsl" />
 
   <!-- The current version number of this component -->
-  <property name="project.version"       value="0.2"/>
+  <property name="project.version"       value="0.32"/>
 
   <!-- The docs source directory -->
   <property name="docs.src"             value="xdocs"/>
@@ -20,6 +20,9 @@
   <!-- The docs destination directory  -->
   <property name="docs.dest"             value="docs"/>
 
+  <!-- The compile debug setting -->
+  <property name="compile.debug"         value="true" />
+
   <!-- Construct compile classpath -->
   <path id="classpath">
     <fileset dir="${local.repository}">
@@ -30,13 +33,23 @@
 <!-- ========== Executable Targets ======================================== -->
 
 
-  <target name="tooltest">
+  <target name="compile">
+
+    <javac  srcdir="${basedir}"
+            destdir="${basedir}"
+            includes="*.java"
+            debug="${compile.debug}"
+            classpathref="classpath" />
+
+  </target>
+
+
+  <target name="tooltest" depends="compile">
   
       <taskdef name="dvsl" classname="org.apache.tools.dvsl.DVSLTask">
                         
           <classpath>
              <pathelement location="../../${project.name}-${project.version}.jar"/>
-             <pathelement location="."/>
              <path refid="classpath"/>
           </classpath>
 
@@ -48,14 +61,25 @@
            extension=".html" 
            style="${docs.src}/site.dvsl"
            excludes="**/project.xml"
-           toolbox="toolbox.props"
+           toolboxfile="toolbox.props"
            includes="**/*.xml" 
-      />
-  </target>
+      >
+           <!-- Or, could specify this as an attribute -->
+           <classpath>
+             <pathelement location="." />
+           </classpath>
 
-</project>
+           <!-- This overrides the same property in toolbox.props -->
+           <tool name="toolbox.string.mystring" value="Howdy partner!" />
 
+           <!-- Specify name and location of velocity log file -->
+           <velconfig name="runtime.log" value="${basedir}/dvsl.log" />
 
+     </dvsl>
+
+  </target>
+
+</project>
 
 
 
Index: jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSL.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSL.java,v
retrieving revision 1.5
diff -u -w -u -r1.5 DVSL.java
--- jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSL.java      6 Feb 2002 
04:47:12 -0000       1.5
+++ jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSL.java      9 Feb 2002 
+07:25:17 -0000
@@ -1,7 +1,7 @@
 /*
  * The Apache Software License, Version 1.1
  *
- * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -102,6 +102,7 @@
     private Context styleContext;
     private DVSLContext baseContext = new DVSLContext();
     private Transformer transformer;
+    private ClassLoader classLoader;
     private boolean ready = false;
 
     private Map velConfig = null;
@@ -110,6 +111,7 @@
 
     public DVSL()
     {
+        classLoader = DVSL.class.getClassLoader();
     }
 
     /**
@@ -142,6 +144,22 @@
 
     /**
      *  <p>
+     *  Specify a classloader for loading the Toolbox classes.  Setting to null
+     *  resets to the default ClassLoader.
+     *  </p>
+     *
+     *  @param classLoader ClassLoader or null for default ClassLoader
+     */
+    public void setClassLoader( ClassLoader classLoader )
+    {
+        if ( classLoader == null )
+            this.classLoader = this.getClass().getClassLoader();
+        else
+            this.classLoader = classLoader;
+    }
+
+    /**
+     *  <p>
      *  Loads the toolbox from the input Properties.
      *  </p>
      *
@@ -193,7 +211,7 @@
             {
                 String toolname = key.substring( TOOL_PROP_PREFIX.length());
 
-                Object o = Class.forName( value ).newInstance();
+                Object o = Class.forName( value, true, classLoader ).newInstance();
                 
                 toolbox.put( toolname, o );
             }
@@ -235,6 +253,15 @@
     public void setStylesheet( String stylesheet )
         throws Exception
     {
+        setStylesheet(new File(stylesheet));
+    }
+
+    /**
+     *  Convenience function.  See...
+     */
+    public void setStylesheet( File stylesheet )
+        throws Exception
+    {
         FileReader fr = null;
         
         try
@@ -265,7 +292,7 @@
      *  to transform.  Just do it once, and transform away...
      *  </p>
      *
-     *  @param stylesheet Reader with stylesheet char stream
+     *  @param styleReader Reader with stylesheet char stream
      */
     public void setStylesheet( Reader styleReader )
         throws Exception
@@ -448,7 +475,6 @@
 
         return transformer.transform( dom4jdoc, writer );
     }
-
 
     public long transform( File f, Writer writer )
         throws Exception
Index: jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSLTask.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSLTask.java,v
retrieving revision 1.2
diff -u -w -u -r1.2 DVSLTask.java
--- jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSLTask.java  6 Feb 2002 
04:47:12 -0000       1.2
+++ jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSLTask.java  9 Feb 2002 
+07:25:17 -0000
@@ -1,7 +1,7 @@
 /*
  * The Apache Software License, Version 1.1
  *
- * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -51,239 +51,518 @@
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */
+
 package org.apache.tools.dvsl;
 
-import java.util.Properties;
-import java.util.Map;
 
-import java.io.Writer;
-import java.io.FileWriter;
-import java.io.File;
-import java.io.BufferedWriter;
-import java.io.FileInputStream;
+import java.io.*;
+import java.util.*;
 
+import org.apache.tools.ant.AntClassLoader;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.MatchingTask;
-
-import org.apache.velocity.VelocityContext;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.util.FileUtils;
 
 
 /**
- *  Simple Ant task to mimic the behavior of the
- *  included Ant Style XSL task.
+ * A Task to process via DVSL a set of XML documents. This is
+ * useful for building views of XML based documentation.
+ * arguments:  (XXX: NEEDS UPDATING)
+ * <ul>
+ * <li>basedir
+ * <li>destdir
+ * <li>style
+ * <li>in
+ * <li>out
+ * <li>includes
+ * <li>excludes
+ * <li>force
+ * <li>extension
+ * <li>outputencoding
+ * <li>classpath
+ * <li>classpathref
+ * <li>toolboxfile
+ * <li>velocityconfigclass
+ * <li>
+ * </ul>
+ * <p>Of these arguments, the <b>sourcedir</b> and <b>destdir</b> are required.</p>
+ * <p>Following are the supported nested elements:</p>
+ * <ul>
+ * <li>&lt;include&gt;
+ * <li>&lt;exclude&gt;
+ * <li>&lt;classpath&gt;
+ * <li>&lt;tool name="toolbox-property" value="value-or-object" /&gt;
+ * <li>&lt;velconfig name="velocity-config-name" value="config-value" /&gt;
+ * </ul>
+ * <p>This task will recursively scan the sourcedir and destdir
+ * looking for XML documents to process via DVSL. Any other files,
+ * such as images, or html files in the source directory will be
+ * copied into the destination directory.  XXX: is that true???</p>
  *
- *  Still needs :
- *      <style> only-on-change (also like Anakia)
- *      auto-output directory creation 
+ * <p>This task was adapted from Ant's <style> task (XSLTProcess class).</p>
  *
+ * @author <a href="mailto:[EMAIL PROTECTED]";>Keith Visco</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]";>Sam Ruby</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]";>Russell Gold</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]";>Stefan Bodewig</a>
  *  @author <a href="mailto:[EMAIL PROTECTED]";>Geir Magnusson Jr.</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burton.</a>
  */
-public class DVSLTask extends MatchingTask
-{
-    protected File basedir;
-    protected File destdir;
-    protected String stylesheet;
-    protected String toolboxProps;
-    protected String extension = ".html";
-    protected String velPropClass = null;
 
-    /*
-     * I wish they called this sourcedir in Style.  grrr...
+public class DVSLTask extends MatchingTask {
+
+    private DVSL dvsl;
+
+    private File destDir = null;
+    private File baseDir = null;
+    private File stylesheet = null;
+    private File inFile = null;
+    private File outFile = null;
+
+    private String targetExtension = ".html";
+    private String outputEncoding = "UTF-8";
+
+    private Path classpath = null;
+    private ClassLoader classLoader = null;
+
+    private boolean force = false;
+
+    private Vector toolAttr = new Vector();
+    private File toolboxFile = null;
+    private Properties toolboxProps = null;
+
+    private String velConfigClass = null;
+    private Vector velConfigAttr = new Vector();
+
+    //private String outputtype = null;  // later when output type is supported
+
+    /**
+     * Creates a new DVSLTask2 Task.
+     **/
+    public DVSLTask() {
+        classLoader = DVSLTask.class.getClassLoader();
+    } //-- DVSLTask2
+
+    /**
+     * Executes the task.
      */
-    public void setBasedir( File bd )
-    {
-        basedir = bd;
-    }
 
-    public void setDestdir( File dd )
-    {
-        destdir = dd;
-    }
+    public void execute() throws BuildException {
+        DirectoryScanner scanner;
+        String[]         list;
+        String[]         dirs;
 
-    public void setStyle( String style )
-    {
-        stylesheet = style;
+        if (stylesheet == null) {
+            throw new BuildException("no stylesheet specified", location);
     }
 
-    public void setExtension( String ext )
-    {
-        extension = ext;
+        if (baseDir == null) {
+            baseDir = project.resolveFile(".");
     }
 
-    public void setToolbox( String toolbox )
-    {
-        toolboxProps = toolbox;
-    }
+        /*
+         * make a DVSL
+         */
+        dvsl = new DVSL();
 
-    /**
-     *  <p>
-     *  Allows the user to specify a class that implements
-     *  java.util.Properties that will have user properties
-     *  to be used when setting up DVSL
-     *  </p>
+        /*
+         * Create a new Classloader for loading the Toolbox and the Velocity 
+properties class.
      */
-    public void setVelocityConfigClass( String classname )
-    {
-        velPropClass = classname;
+        if ( classpath != null ) {
+            classLoader = new AntClassLoader( project, classpath );
+            dvsl.setClassLoader( classLoader );
     }
 
-    public void execute () throws BuildException
-    {
         /*
-         *  use the current project directory if no source dir set
+         * If the user gave us a velPropClass, we create an instance
+         * of that to use to config the VelocityEngine inside te DVSL
          */
-        if (basedir == null)
-        {
-            basedir = project.resolveFile(".");
+        Object velConfigObj = null;
+        if ( velConfigClass != null ) {
+            try {
+                velConfigObj = Class.forName( velConfigClass, true, classLoader 
+).newInstance();
+            }
+            catch( Exception ex ) {
+                throw new BuildException("Error instantiating VelocityPropClass : " + 
+ex );
+            }
         }
 
         /*
-         *  use the current directory as well.  Will check to prevent that we don't
-         *  overwrite the source
+         * If any nested Velocity Config elements have been specified, overlay any 
+settings
+         * in the Velocity Config object.
          */
-        if (destdir == null )
-        {
-            destdir = project.resolveFile(".");
+        if ( !velConfigAttr.isEmpty() ) {
+            // If vel config object is valid, use that, else use an empty HashMap.
+            if ( velConfigObj != null && velConfigObj instanceof Map )
+                ;
+            else
+                velConfigObj = new HashMap();
+            // Now copy velocity config attributes into the Map
+            for ( Enumeration e = velConfigAttr.elements(); e.hasMoreElements(); ) {
+                VelocityConfig p = (VelocityConfig)e.nextElement();
+                ((Map) velConfigObj).put( p.getName(), p.getValue() );
+            }
         }
 
         /*
-         *  must have a stylesheet
+         * Finally, set the Velocity Config object in DVSL if it's valid.
          */
-        if (stylesheet == null) 
-        {
-            throw new BuildException("You must specify a stylesheet (.vsl file) with 
the style parameter");
+        if ( velConfigObj != null && velConfigObj instanceof Map ) {
+            dvsl.setVelocityConfig( (Map) velConfigObj );
         }
 
         /*
-         *  now just do it
+         * now the stylesheet
          */
-        process();
+        try {
+            log( "Loading stylesheet " + stylesheet, Project.MSG_INFO);
+            dvsl.setStylesheet( stylesheet );
+        } catch (Exception ex) {
+            log("Failed to read stylesheet " + stylesheet, Project.MSG_INFO);
+            throw new BuildException(ex);
     }
 
-
-    /**
-     *  does the real work.  Gets the list of files to work on,
-     *  and transforms each one
-     */
-    protected void process()
-        throws BuildException
-    {
         /*
-         *  make a DVSL
+         *  now, if we were given a toolbox, set that up too
          */
+        toolboxProps = new Properties();
+        try {
+            if ( toolboxFile != null)
+                toolboxProps.load( new FileInputStream( toolboxFile ) );
+            // Overlay any parameters
+            for ( Enumeration e = toolAttr.elements(); e.hasMoreElements(); ) {
+                Tool p = (Tool)e.nextElement();
+                toolboxProps.setProperty( p.getName(), p.getValue() );
+            }
+            dvsl.setToolbox( toolboxProps );
+        }
+        catch( Exception ee ) {
+            throw new BuildException( "Error loading the toolbox : " + ee );
+        }
      
-        DVSL dvsl = new DVSL();
+        // if we have an in file and out then process them
+        if (inFile != null && outFile != null) {
+            process(inFile, outFile, stylesheet);
+            return;
+        }
 
         /*
-         *  now, if the user gave us a velPropClass, we create an instance
-         *  of that to use to config the VelocityEngine inside te DVSL
+         * if we get here, in and out have not been specified, we are
+         * in batch processing mode.
          */
 
-        if( velPropClass != null )
-        {
-            Object ob = null;
+        //-- make sure Source directory exists...
+        if (destDir == null ) {
+            String msg = "destdir attributes must be set!";
+            throw new BuildException(msg);
+        }
+        scanner = getDirectoryScanner(baseDir);
+        log("Transforming into "+destDir, Project.MSG_INFO);
 
-            try
-            {
-                 ob = Class.forName( velPropClass).newInstance();
+        // Process all the files marked for styling
+        list = scanner.getIncludedFiles();
+        for (int i = 0;i < list.length; ++i) {
+            process( baseDir, list[i], destDir, stylesheet );
+        }
+
+        // Process all the directoried marked for styling
+        dirs = scanner.getIncludedDirectories();
+        for (int j = 0;j < dirs.length;++j){
+            list=new File(baseDir,dirs[j]).list();
+            for (int i = 0;i < list.length;++i) {
+                process( baseDir, list[i], destDir, stylesheet );
             }
-            catch( Exception ex )
-            {
-                throw new BuildException("Error instantiating VelocityPropClass : " + 
ex );
             }
+    } //-- execute
 
-            if ( ob instanceof Map )
-            {
-                dvsl.setVelocityConfig( (Map) ob );
+    /**
+     * Set whether to check dependencies, or always generate.
+     **/
+    public void setForce(boolean force) {
+        this.force = force;
+    } //-- setForce
+
+    /**
+     * Set the base directory.
+     **/
+    public void setBasedir(File dir) {
+        baseDir = dir;
+    } //-- setSourceDir
+
+    /**
+     * Set the destination directory into which the XSL result
+     * files should be copied to
+     * @param dir name of the destination directory
+     **/
+    public void setDestdir(File dir) {
+        destDir = dir;
+    } //-- setDestDir
+
+    /**
+     * Set the desired file extension to be used for the target
+     * @param name the extension to use
+     **/
+    public void setExtension(String name) {
+        targetExtension = name;
+    } //-- setDestDir
+
+    /**
+     * Sets the file to use for styling relative to the base directory
+     * of this task.
+     */
+    //public void setStyle(String dvslFile) {  // XXX:
+    public void setStyle(File dvslFile) {
+        this.stylesheet = dvslFile;
             }
+
+    /**
+     * Sets the Toolbox properties file to use.
+     * @param toolboxFile properties file of tools
+     * @deprecated use setToolboxFile instead
+     */
+    public void setToolbox(String toolboxFile) {
+        log("DEPRECATED - use the toolboxfile attribute instead");
+        this.toolboxFile = new File(toolboxFile);
         }
 
-        /*
-         * now the stylesheet
+    /**
+     * Sets the Toolbox properties file to use.
+     * @param toolboxFile properties file of tools
          */
-        try
-        {
-            dvsl.setStylesheet( stylesheet );
+    public void setToolboxFile(File toolboxFile) {
+        this.toolboxFile = toolboxFile;
         }
-        catch( Exception e )
-        {
-            throw new BuildException("Problem setting stylesheet : " + e );
+
+    /**
+     * Allows the user to specify a class that implements
+     * {@link java.util.Properties} that will have user properties
+     * to be used when setting up DVSL.
+     * @param classname Velocity configuration class to load
+     */
+    public void setVelocityConfigClass(String classname) {
+        velConfigClass = classname;
         }
 
-        /*
-         *  now, if we were given a toolbox, set that up too
+    /**
+     * Sets an output file
+     * @param outFile output file
          */
+    public void setOut(File outFile){
+        this.outFile = outFile;
+    }
 
-        if ( toolboxProps != null)
-        {   
-            try
-            {
-                Properties p = new Properties();
+    /**
+     * Sets an input xml file to be styled
+     * @param inFile input file
+     */
+    public void setIn(File inFile){
+        this.inFile = inFile;
+    }
                 
-                p.load( new FileInputStream( project.resolveFile( toolboxProps ) ) );
+    /**
+     * Sets the character encoding for the output file.
+     * @param encoding Output encoding
+     */
+    public void setOutputEncoding( String encoding ) {
+        if ( encoding != null )
+            this.outputEncoding = encoding;
+    }
                 
-                dvsl.setToolbox( p );
+    /**
+     * Set the classpath to load the Processor through (attribute).
+     * @param classpath classpath to set
+     */
+    public void setClasspath(Path classpath) {
+        createClasspath().append(classpath);
             }
-            catch( Exception ee )
-            {
-                throw new BuildException( "Error loading the toolbox : " + ee );
+
+    /**
+     * Set the classpath to load the Processor through (nested element).
+     */
+    public Path createClasspath() {
+        if (classpath == null) {
+            classpath = new Path(project);
             }
+        return classpath.createPath();
         }
 
-        /*
-         *  get a list of the input files and process each one
+    /**
+     * Set the classpath to load the Processor through via reference
+     * (attribute).
+     * @param r reference to classpath
          */
+    public void setClasspathRef(Reference r) {
+        createClasspath().setRefid(r);
+    }
         
-        String[] infiles = getDirectoryScanner( basedir ).getIncludedFiles();
+    /**
+     * Processes the given input XML file and stores the result
+     * in the given resultFile.
+     **/
+    private void process(File baseDir, String xmlFile, File destDir,
+                         File stylesheet)
+        throws BuildException {
+
+        String fileExt=targetExtension;
+        File   outFile=null;
+        File   inFile=null;
+
+        try {
+            long styleSheetLastModified = stylesheet.lastModified();
+            inFile = new File(baseDir,xmlFile);
+            int dotPos = xmlFile.lastIndexOf('.');
+            if(dotPos>0){
+                outFile = new 
+File(destDir,xmlFile.substring(0,xmlFile.lastIndexOf('.'))+fileExt);
+            }else{
+                outFile = new File(destDir,xmlFile+fileExt);
+            }
+            if (force ||
+                inFile.lastModified() > outFile.lastModified() ||
+                styleSheetLastModified > outFile.lastModified()) {
+                ensureDirectoryFor( outFile );
+                log("Processing "+inFile+" to "+outFile);
+                transform(inFile, outFile);
+            }
+        }
+        catch (Exception ex) {
+            // If failed to process document, must delete target document,
+            // or it will not attempt to process it the second time
+            log("Failed to process " + inFile, Project.MSG_INFO);
+            if (outFile != null) {
+                outFile.delete();
+            }
+
+            throw new BuildException(ex);
+        }
+
+    } //-- processXML
+
+    private void process(File inFile, File outFile, File stylesheet) throws 
+BuildException {
+        try{
+            long styleSheetLastModified = stylesheet.lastModified();
+            log("In file "+inFile+" time: " + inFile.lastModified() , 
+Project.MSG_DEBUG);
+            log("Out file "+outFile+" time: " + outFile.lastModified() , 
+Project.MSG_DEBUG);
+            log("Style file "+stylesheet+" time: " + styleSheetLastModified , 
+Project.MSG_DEBUG);
+            if (force ||
+                inFile.lastModified() > outFile.lastModified() ||
+                styleSheetLastModified > outFile.lastModified()) {
+                ensureDirectoryFor( outFile );
+                log("Processing " + inFile + " to " + outFile, Project.MSG_INFO);
+                transform(inFile, outFile);
+            }
+        }catch (Exception ex) {
+            log("Failed to process " + inFile, Project.MSG_INFO);
+            if(outFile!=null) {
+             outFile.delete();
+            }
+            throw new BuildException(ex);
+        }
+    }
+
+    private void transform( File inFile, File outFile )
+        throws Exception
+    {
+        BufferedWriter writer =
+                new BufferedWriter(new OutputStreamWriter(
+                                       new FileOutputStream(outFile),
+                                           outputEncoding));
+        dvsl.transform( inFile, writer );
+        writer.close();
+    }
 
-        for (int i = 0;i < infiles.length; ++i)
-        {
-            /*
-             *  get the infile and create the outfilename
-             */
-            String infilename = infiles[i];
-            String root = infilename.substring( 0, infilename.lastIndexOf('.'));
-            String outfilename = root + extension;
+    private void ensureDirectoryFor( File targetFile ) throws BuildException {
+        File directory = new File( targetFile.getParent() );
+        if (!directory.exists()) {
+            if (!directory.mkdirs()) {
+                throw new BuildException("Unable to create directory: "
+                                         + directory.getAbsolutePath() );
+            }
+        }
+    }
 
-            Writer writer = null;
+    // support for <tool> nested element
+    public Tool createTool() {
+        Tool p = new Tool();
+        toolAttr.addElement(p);
+        return p;
+    }
 
-            try
-            {
-                File infile = new File( basedir, infilename);
-                File outfile = new File( destdir, outfilename);
+    public class Tool {
+        private String name = null;
+        private String value = null;
                 
-                writer = new BufferedWriter( new FileWriter( outfile ) );
+        public void setName(String name) {
+            this.name = name;
+        }
 
-                /*
-                 *  do the transformation
-                 */
+        public String getName() throws BuildException {
+            if (name == null) {
+                throw new BuildException("Name attribute is missing.");
+            }
+            return name;
+        }
                 
-                long time = dvsl.transform( infile, writer );
+        public void setValue(String value) {
+            this.value = value;
+        }
 
-                log("Processed " + infilename + " to " + outfilename + " in " + time 
+ " msec.");
+        public String getValue() throws BuildException {
+            if (value == null) {
+                throw new BuildException("value attribute is missing.");
             }
-            catch( Exception e )
-            {
-                throw new BuildException( "Exception while procesing " + infilename + 
" : " + e );
+            return value;
             }
-            finally
-            {
-                if (writer != null)
-                {
-                    try
-                    {
-                        writer.flush();
-                        writer.close();
                     }
-                    catch( Exception ee )
-                    {
+
+    // support for <velconfig> nested element
+    public VelocityConfig createVelConfig() {
+        VelocityConfig p = new VelocityConfig();
+        velConfigAttr.addElement(p);
+        return p;
                     }
+
+    public class VelocityConfig {
+        private String name = null;
+        private String value = null;
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public String getName() throws BuildException {
+            if (name == null) {
+                throw new BuildException("Name attribute is missing.");
                 }
+            return name;
             }   
+
+        public void setValue(String value) {
+            this.value = value;
         }
 
-        log("Processing complete.");
+        public String getValue() throws BuildException {
+            if (value == null) {
+                throw new BuildException("Value attribute is missing.");
     }
+            return value;
 }
+    }
+
+    /**
+     * Set the output type to use for the transformation.  Only "xml" (the
+     * default) is guaranteed to work for all parsers.  Xalan2 also
+     * supports "html" and "text".<br>
+     * <i>Not currently implemented.</i>
+     * @param type the output method to use
+     */
+    /*
+    public void setOutputtype(String type) {
+        this.outputtype = type;
+    }
+    */
+
+} //-- DVSLTask2

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to