geirm 02/02/21 22:07:01
Modified: src/java/org/apache/tools/dvsl DVSL.java DVSLTask.java
Added: src/java/org/apache/tools/dvsl AntLogSystem.java
Log:
Cool patch from Bill Burton <[EMAIL PROTECTED]> to put all logging through
the ant logger.
The only downside is that some of the message from velocity are appear to
be a lot scarier than they really are... good to see though
Revision Changes Path
1.8 +50 -17 jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSL.java
Index: DVSL.java
===================================================================
RCS file: /home/cvs/jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSL.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DVSL.java 20 Feb 2002 05:25:21 -0000 1.7
+++ DVSL.java 22 Feb 2002 06:07:01 -0000 1.8
@@ -54,33 +54,29 @@
package org.apache.tools.dvsl;
-import java.util.List;
-import java.util.Properties;
-import java.util.Enumeration;
-import java.util.Map;
-import java.util.HashMap;
-
-import java.io.Writer;
-import java.io.StringWriter;
+import java.io.File;
import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.File;
import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
-import org.apache.velocity.context.Context;
import org.apache.velocity.Template;
-import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.runtime.log.LogSystem;
import org.dom4j.Document;
-import org.dom4j.Element;
-import org.dom4j.Node;
-import org.dom4j.DocumentException;
-import org.dom4j.io.SAXReader;
/**
* Main DVSL class - use this as the helper class for apps
@@ -106,6 +102,8 @@
private boolean ready = false;
private Map velConfig = null;
+ private File logFile;
+ private LogSystem logger;
private TemplateHandler templateHandler = new TemplateHandler();
@@ -119,6 +117,36 @@
/**
* <p>
+ * lets the user specify a filename for logging.
+ * </p>
+ */
+ public void setLogFile( File logFile )
+ {
+ this.logFile = logFile;
+ if ( velConfig == null )
+ {
+ velConfig = new HashMap();
+ }
+ velConfig.put( VelocityEngine.RUNTIME_LOG, logFile.getAbsolutePath() );
+ }
+
+ /**
+ * <p>
+ * lets the user specify a class instance for logging.
+ * </p>
+ */
+ public void setLogSystem( LogSystem logger )
+ {
+ this.logger = logger;
+ if ( velConfig == null )
+ {
+ velConfig = new HashMap();
+ }
+ velConfig.put( VelocityEngine.RUNTIME_LOG_LOGSYSTEM, logger );
+ }
+
+ /**
+ * <p>
* lets the user pass a java.util.Properties containing
* properties for the configuration of the VelocityEngine
* used by DVSL
@@ -126,6 +154,10 @@
*/
public void setVelocityConfig( Map map )
{
+ if ( velConfig != null )
+ {
+ map.putAll(velConfig);
+ }
velConfig = map;
}
@@ -634,3 +666,4 @@
}
}
+
1.6 +563 -531
jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSLTask.java
Index: DVSLTask.java
===================================================================
RCS file:
/home/cvs/jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/DVSLTask.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DVSLTask.java 20 Feb 2002 05:25:22 -0000 1.5
+++ DVSLTask.java 22 Feb 2002 06:07:01 -0000 1.6
@@ -1,62 +1,62 @@
-/*
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
- * Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowlegement may appear in the software itself,
- * if and wherever such third-party acknowlegements normally appear.
- *
- * 4. The names "The Jakarta Project", "Velocity", "DVSL" and "Apache Software
- * Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
- * permission, please contact [EMAIL PROTECTED]
- *
- * 5. Products derived from this software may not be called "Apache"
- * nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-package org.apache.tools.dvsl;
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Velocity", "DVSL" and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.tools.dvsl;
import java.util.Map;
import java.util.Properties;
-import java.util.Vector;
+import java.util.Vector;
import java.util.HashMap;
import java.util.Enumeration;
@@ -66,84 +66,87 @@
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
-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.tools.ant.types.Path;
-import org.apache.tools.ant.types.Reference;
+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.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.util.FileUtils;
-import org.apache.velocity.VelocityContext;
-
-
-/**
- * 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><include>
- * <li><exclude>
- * <li><classpath>
- * <li><tool name="toolbox-property" value="value-or-object" />
- * <li><velconfig name="velocity-config-name" value="config-value" />
- * </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>
- *
- * <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>
- */
-
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.runtime.RuntimeConstants;
+
+
+/**
+ * A Task to process via DVSL a set of XML documents. This is
+ * useful for building views of XML based documentation.
+ * arguments:
+ * <ul>
+ * <li>basedir
+ * <li>destdir
+ * <li>style
+ * <li>in
+ * <li>out
+ * <li>logfile
+ * <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, or,
+ * <b>in</b> and <b>out</b> are required.</p>
+ * <p>Following are the supported nested elements:</p>
+ * <ul>
+ * <li><include>
+ * <li><exclude>
+ * <li><classpath>
+ * <li><tool name="toolbox-property" value="value-or-object" />
+ * <li><velconfig name="velocity-config-name" value="config-value" />
+ * </ul>
+ * <p>This task will recursively scan the sourcedir and destdir
+ * looking for XML documents to process via DVSL. </p>
+ *
+ * <p>This task was adapted from Ant's <style> task (XSLTProcess class) from
the
+ * 1.4.1 release.</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
-{
- 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 DVSL dvsl;
+
+ private File destDir = null;
+ private File baseDir = null;
+ private File stylesheet = null;
+ private File inFile = null;
+ private File outFile = null;
+ private File logFile = 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 Map velConfigMap = null;
private Vector velConfigAttr = new Vector();
@@ -153,28 +156,28 @@
//private String outputtype = null; // later when output type is supported
/**
- * Creates a new DVSLTask2 Task.
+ * Creates a new DVSLTask Task.
**/
public DVSLTask()
- {
- classLoader = DVSLTask.class.getClassLoader();
+ {
+ classLoader = DVSLTask.class.getClassLoader();
}
-
- /**
- * Executes the task.
- */
+
+ /**
+ * Executes the task.
+ */
public void execute()
throws BuildException
- {
- DirectoryScanner scanner;
- String[] list;
- String[] dirs;
-
+ {
+ DirectoryScanner scanner;
+ String[] list;
+ String[] dirs;
+
if (stylesheet == null)
- {
- throw new BuildException("no stylesheet specified", location);
- }
-
+ {
+ throw new BuildException("no stylesheet specified", location);
+ }
+
if (baseDir == null)
{
baseDir = project.resolveFile(".");
@@ -189,24 +192,24 @@
/*
* Create a new Classloader for loading the Toolbox and the Velocity
- * properties class.
- */
+ * properties class.
+ */
if ( classpath != null )
- {
- classLoader = new AntClassLoader( project, classpath );
- dvsl.setClassLoader( classLoader );
- }
-
- /*
- * If the user gave us a velPropClass, we create an instance
- * of that to use to config the VelocityEngine inside te DVSL
- */
- Object velConfigObj = null;
+ {
+ classLoader = new AntClassLoader( project, classpath );
+ dvsl.setClassLoader( classLoader );
+ }
+
+ /*
+ * If the user gave us a velPropClass, we create an instance
+ * of that to use to config the VelocityEngine inside te DVSL
+ */
+ Object velConfigObj = null;
if ( velConfigClass != null )
- {
+ {
try
- {
+ {
velConfigObj = Class.forName( velConfigClass, true, classLoader
).newInstance();
if ( velConfigObj instanceof Map )
@@ -216,269 +219,295 @@
else
{
throw new BuildException("VelocityPropClass is not instanceof
java.util.Map" );
- }
- }
+ }
+ }
catch( Exception ex )
- {
+ {
throw new BuildException("Error instantiating VelocityPropClass : "
- + ex );
- }
- }
-
- /*
- * If any nested Velocity Config elements have been specified, overlay any
settings
- * in the Velocity Config object.
- */
+ + ex );
+ }
+ }
+
+ /*
+ * If any nested Velocity Config elements have been specified, overlay any
settings
+ * in the Velocity Config object.
+ */
if ( !velConfigAttr.isEmpty() )
{
if ( velConfigMap == null )
{
velConfigMap = new HashMap();
}
-
+
/*
* Now copy velocity config attributes into the Map
- */
+ */
for ( Enumeration e = velConfigAttr.elements(); e.hasMoreElements(); )
- {
- VelocityConfig p = (VelocityConfig)e.nextElement();
- velConfigMap.put( p.getName(), p.getValue() );
- }
- }
-
- /*
- * Finally, set the Velocity Config object in DVSL if it's valid.
- */
+ {
+ VelocityConfig p = (VelocityConfig)e.nextElement();
+ velConfigMap.put( p.getName(), p.getValue() );
+ }
+ }
+
+ /*
+ * Finally, set the Velocity Config object in DVSL if it's valid.
+ */
if ( velConfigMap != null)
- {
- dvsl.setVelocityConfig( velConfigMap );
- }
-
- /*
- * now the stylesheet
- */
+ {
+ dvsl.setVelocityConfig( velConfigMap );
+ }
+
+ /*
+ * If a logfile attribute was specified, use that for the log file name,
+ * otherwise use a Velocity to Ant logging adapter.
+ */
+ if ( logFile != null )
+ {
+ dvsl.setLogFile( logFile );
+ }
+ else
+ {
+ dvsl.setLogSystem( new AntLogSystem( this ) );
+ }
+
+ /*
+ * now the stylesheet
+ */
try
- {
- log( "Loading stylesheet " + stylesheet, Project.MSG_INFO);
- dvsl.setStylesheet( stylesheet );
+ {
+ 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);
- }
-
- /*
- * now, if we were given a toolbox, set that up too
- */
- toolboxProps = new Properties();
+ {
+ log("Failed to read stylesheet " + stylesheet, Project.MSG_INFO);
+ throw new BuildException(ex);
+ }
+
+ /*
+ * 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() );
+ {
+ Tool p = (Tool)e.nextElement();
+ toolboxProps.setProperty( p.getName(), p.getValue() );
}
-
- dvsl.setToolbox( toolboxProps );
- }
+
+ dvsl.setToolbox( toolboxProps );
+ }
catch( Exception ee )
- {
- throw new BuildException( "Error loading the toolbox : " + ee );
- }
-
+ {
+ throw new BuildException( "Error loading the toolbox : " + ee );
+ }
+
/*
* if we have an in file and out then process them
*/
-
+
if (inFile != null && outFile != null)
- {
- process(inFile, outFile, stylesheet);
- return;
- }
-
- /*
- * if we get here, in and out have not been specified, we are
- * in batch processing mode.
- */
-
+ {
+ process(inFile, outFile, stylesheet);
+ return;
+ }
+
+ /*
+ * if we get here, in and out have not been specified, we are
+ * in batch processing mode.
+ */
+
/*
* make sure Source directory exists...
- */
+ */
if (destDir == null )
- {
- String msg = "destdir attributes must be set!";
- throw new BuildException(msg);
- }
+ {
+ String msg = "destdir attributes must be set!";
+ throw new BuildException(msg);
+ }
+
+ scanner = getDirectoryScanner(baseDir);
+ log("Transforming into "+destDir, Project.MSG_INFO);
- scanner = getDirectoryScanner(baseDir);
- log("Transforming into "+destDir, Project.MSG_INFO);
-
/*
* Process all the files marked for styling
- */
- list = scanner.getIncludedFiles();
+ */
+ list = scanner.getIncludedFiles();
for (int i = 0;i < list.length; ++i)
- {
- process( baseDir, list[i], destDir, stylesheet );
- }
-
+ {
+ 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();
+ {
+ list=new File(baseDir,dirs[j]).list();
for (int i = 0;i < list.length;++i)
- {
- process( baseDir, list[i], destDir, stylesheet );
- }
- }
- } //-- execute
-
- /**
- * Set whether to check dependencies, or always generate.
- **/
+ {
+ process( baseDir, list[i], destDir, stylesheet );
+ }
+ }
+ } //-- execute
+
+ /**
+ * Set whether to check dependencies, or always generate.
+ * @param force false to check dependencies, true to always generate
+ */
public void setForce(boolean force)
- {
- this.force = force;
- } //-- setForce
-
- /**
- * Set the base directory.
- **/
+ {
+ this.force = force;
+ }
+
+ /**
+ * Set the base directory.
+ * @param dir name of 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
- **/
+ {
+ baseDir = dir;
+ }
+
+ /**
+ * Set the destination directory where the generated
+ * files should be directed.
+ * @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
- **/
+ {
+ destDir = dir;
+ }
+
+ /**
+ * Set the desired file extension to be used for the target files.
+ * If not specified, "<code>.html</code>" is used.
+ * @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:
+ {
+ targetExtension = name;
+ }
+
+ /**
+ * Sets the file to use for stylesheet.
+ * @param dvslFile stylesheet filename
+ */
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
- */
+ {
+ this.stylesheet = dvslFile;
+ }
+
+ /**
+ * Sets the file to use for logging. If not specified, all logging
+ * is directed through Ant's logging system.
+ * @param logFile logging filename
+ */
+ public void setLogFile(File logFile)
+ {
+ this.logFile = logFile;
+ }
+
+ /**
+ * 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);
- }
-
- /**
- * Sets the Toolbox properties file to use.
- * @param toolboxFile properties file of tools
- */
+ {
+ log("DEPRECATED - use the toolboxfile attribute instead");
+ this.toolboxFile = new File(toolboxFile);
+ }
+
+ /**
+ * Sets the Toolbox properties file to use.
+ * @param toolboxFile properties file of tools
+ */
public void setToolboxFile(File toolboxFile)
- {
- this.toolboxFile = toolboxFile;
- }
-
- /**
- * 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
- */
+ {
+ this.toolboxFile = toolboxFile;
+ }
+
+ /**
+ * 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;
- }
-
- /**
- * Sets an output file
- * @param outFile output file
- */
+ {
+ velConfigClass = classname;
+ }
+
+ /**
+ * Sets an output file
+ * @param outFile output file
+ */
public void setOut(File outFile)
- {
- this.outFile = outFile;
- }
-
- /**
- * Sets an input xml file to be styled
- * @param inFile input file
- */
+ {
+ this.outFile = outFile;
+ }
+
+ /**
+ * Sets an input xml file to be styled
+ * @param inFile input file
+ */
public void setIn(File inFile)
- {
- this.inFile = inFile;
- }
-
- /**
- * Sets the character encoding for the output file.
- * @param encoding Output encoding
- */
+ {
+ this.inFile = inFile;
+ }
+
+ /**
+ * Sets the character encoding for output files. If not specified,
+ * output is written with UTF-8 encoding.
+ * @param encoding Output encoding
+ */
public void setOutputEncoding( String encoding )
- {
- if ( encoding != null )
- this.outputEncoding = encoding;
- }
-
- /**
- * Set the classpath to load the Processor through (attribute).
- * @param classpath classpath to set
- */
+ {
+ if ( encoding != null )
+ this.outputEncoding = encoding;
+ }
+
+ /**
+ * Set the classpath to load the Processor through (attribute).
+ * @param classpath classpath to set
+ */
public void setClasspath(Path classpath)
- {
- createClasspath().append(classpath);
- }
-
- /**
- * Set the classpath to load the Processor through (nested element).
- */
+ {
+ createClasspath().append(classpath);
+ }
+
+ /**
+ * Set the classpath to load the Processor through (nested element).
+ */
public Path createClasspath()
- {
+ {
if (classpath == null)
- {
- classpath = new Path(project);
- }
- return classpath.createPath();
- }
-
- /**
- * Set the classpath to load the Processor through via reference
- * (attribute).
- * @param r reference to classpath
- */
+ {
+ classpath = new Path(project);
+ }
+ return classpath.createPath();
+ }
+
+ /**
+ * Set the classpath to load the Processor through via reference
+ * (attribute).
+ * @param r reference to classpath
+ */
public void setClasspathRef(Reference r)
{
createClasspath().setRefid(r);
@@ -505,84 +534,86 @@
private void process(File baseDir, String xmlFile, File destDir,
File stylesheet)
throws BuildException
- {
-
- String fileExt=targetExtension;
- File outFile=null;
- File inFile=null;
-
+ {
+
+ 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);
+ {
+ 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);
- }
+ {
+ outFile = new File(destDir,xmlFile+fileExt);
+ }
- if (force ||
- inFile.lastModified() > outFile.lastModified() ||
+ if (force ||
+ inFile.lastModified() > outFile.lastModified() ||
styleSheetLastModified > outFile.lastModified())
- {
- ensureDirectoryFor( outFile );
- log("Processing "+inFile+" to "+outFile);
- transform(inFile, outFile);
- }
- }
+ {
+ ensureDirectoryFor( outFile );
+ log("Processing "+inFile+" to "+outFile, Project.MSG_INFO);
+ long time = transform(inFile, outFile);
+ log("Processed "+inFile+" in "+time+" ms.", Project.MSG_VERBOSE);
+ }
+ }
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);
+
+ log("Failed to process " + inFile, Project.MSG_INFO);
if (outFile != null)
- {
- outFile.delete();
- }
-
- throw new BuildException(ex);
- }
- } //-- processXML
-
+ {
+ outFile.delete();
+ }
+
+ throw new BuildException(ex);
+ }
+ }
+
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);
+ {
+ 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() ||
+ if (force ||
+ inFile.lastModified() > outFile.lastModified() ||
styleSheetLastModified > outFile.lastModified())
- {
- ensureDirectoryFor( outFile );
- log("Processing " + inFile + " to " + outFile, Project.MSG_INFO);
- transform(inFile, outFile);
- }
+ {
+ ensureDirectoryFor( outFile );
+ log("Processing " + inFile + " to " + outFile, Project.MSG_INFO);
+ long time = transform(inFile, outFile);
+ log("Processed "+inFile+" in "+time+" ms.", Project.MSG_VERBOSE);
+ }
}
catch (Exception ex)
- {
- log("Failed to process " + inFile, Project.MSG_INFO);
+ {
+ log("Failed to process " + inFile, Project.MSG_INFO);
if(outFile!=null)
- {
- outFile.delete();
- }
- throw new BuildException(ex);
- }
- }
+ {
+ outFile.delete();
+ }
+ throw new BuildException(ex);
+ }
+ }
/**
* <p>
@@ -591,133 +622,134 @@
*
* @param inFile XML document source
* @param outFile File for transformed input
- *
- */
- private void transform( File inFile, File outFile )
- throws Exception
- {
- BufferedWriter writer =
- new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(outFile),
+ * @return elapsed time in ms. for transformation
+ */
+ private long transform( File inFile, File outFile )
+ throws Exception
+ {
+ BufferedWriter writer =
+ new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(outFile),
outputEncoding));
-
- dvsl.transform( inFile, writer );
- writer.close();
- }
-
+
+ long time = dvsl.transform( inFile, writer );
+ writer.close();
+ return time;
+ }
+
private void ensureDirectoryFor( File targetFile ) throws BuildException
- {
- File directory = new File( targetFile.getParent() );
+ {
+ File directory = new File( targetFile.getParent() );
if (!directory.exists())
- {
+ {
if (!directory.mkdirs())
- {
- throw new BuildException("Unable to create directory: "
- + directory.getAbsolutePath() );
- }
- }
- }
-
+ {
+ throw new BuildException("Unable to create directory: "
+ + directory.getAbsolutePath() );
+ }
+ }
+ }
+
/**
- * support for <tool> nested element
- */
+ * support for <tool> nested element
+ */
public Tool createTool()
- {
- Tool p = new Tool();
- toolAttr.addElement(p);
- return p;
- }
-
+ {
+ Tool p = new Tool();
+ toolAttr.addElement(p);
+ return p;
+ }
+
public class Tool
- {
- private String name = null;
- private String value = null;
-
+ {
+ private String name = null;
+ private String value = null;
+
public void setName(String name)
- {
- this.name = name;
- }
-
+ {
+ this.name = name;
+ }
+
public String getName() throws BuildException
- {
+ {
if (name == null)
- {
- throw new BuildException("Name attribute is missing.");
- }
- return name;
- }
-
+ {
+ throw new BuildException("Name attribute is missing.");
+ }
+ return name;
+ }
+
public void setValue(String value)
- {
- this.value = value;
- }
-
+ {
+ this.value = value;
+ }
+
public String getValue() throws BuildException
- {
+ {
if (value == null)
- {
- throw new BuildException("value attribute is missing.");
- }
- return value;
- }
- }
-
+ {
+ throw new BuildException("value attribute is missing.");
+ }
+ return value;
+ }
+ }
+
/**
- * support for <velconfig> nested element
- */
+ * support for <velconfig> nested element
+ */
public VelocityConfig createVelConfig()
- {
- VelocityConfig p = new VelocityConfig();
- velConfigAttr.addElement(p);
- return p;
- }
-
+ {
+ VelocityConfig p = new VelocityConfig();
+ velConfigAttr.addElement(p);
+ return p;
+ }
+
public class VelocityConfig
- {
- private String name = null;
- private String value = null;
-
+ {
+ private String name = null;
+ private String value = null;
+
public void setName(String name)
- {
- this.name = name;
- }
-
+ {
+ this.name = name;
+ }
+
public String getName() throws BuildException
- {
+ {
if (name == null)
- {
- throw new BuildException("Name attribute is missing.");
- }
- return name;
- }
-
+ {
+ throw new BuildException("Name attribute is missing.");
+ }
+ return name;
+ }
+
public void setValue(String value)
- {
- this.value = value;
- }
-
+ {
+ this.value = value;
+ }
+
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;
- }
- */
-
+ {
+ 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;
+ }
+ */
+
}
1.1
jakarta-velocity-dvsl/src/java/org/apache/tools/dvsl/AntLogSystem.java
Index: AntLogSystem.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity","DVSL", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.dvsl;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.log.LogSystem;
/**
* Implementation of a logger to output messages via an Ant Task's log
* method. Velocity log levels are mapped to corresponding log levels
* defined in Ant's logging API. The end result is messages will only
* be output if Ant log level is high enough.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Bill Burton</a>
* @version $Id: AntLogSystem.java,v 1.1 2002/02/22 06:07:01 geirm Exp $
*/
public class AntLogSystem implements LogSystem
{
// Reference to the Ant Task object that initialized the Velocity Engine.
Task task;
/**
* Initialize this logger with a reference to the calling Ant Task
*
* @param task Ant Task to use for logging. This must not be null.
*/
public AntLogSystem(Task task)
{
this.task = task;
}
/**
* Initialize the logger.
*
* @throws Exception if null was passed into the constructor
*/
public void init( RuntimeServices rs ) throws Exception
{
if ( task == null )
{
throw new Exception( "PANIC: " + this.getClass().getName() +
" was instantiated with a null Ant Task reference");
}
}
/**
* <p>
* Log Velocity messages through the Ant Task log method. The mapping of logging
* levels from Velocity to Ant is as follows:
* </p>
*
* <blockquote><pre>
* Velocity Level --> Ant Level
* LogSystem.DEBUG_ID --> Project.MSG_DEBUG
* LogSystem.INFO_ID --> Project.MSG_VERBOSE
* LogSystem.WARN_ID --> Project.MSG_WARN
* LogSystem.ERROR_ID --> Project.MSG_ERR
* </pre></blockquote>
*
* @param level severity level
* @param message complete error message
* @see org.apache.velocity.runtime.log.LogSystem
* @see org.apache.tools.ant.Task#log(String, int)
*/
public void logVelocityMessage( int level, String message )
{
switch ( level )
{
case LogSystem.WARN_ID:
task.log( RuntimeConstants.WARN_PREFIX + message, Project.MSG_WARN );
break;
case LogSystem.INFO_ID:
task.log( RuntimeConstants.INFO_PREFIX + message,
Project.MSG_VERBOSE );
break;
case LogSystem.DEBUG_ID:
task.log( RuntimeConstants.DEBUG_PREFIX + message, Project.MSG_DEBUG
);
break;
case LogSystem.ERROR_ID:
task.log( RuntimeConstants.ERROR_PREFIX + message, Project.MSG_ERR );
break;
default:
task.log( message );
break;
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>