freemarker.ext.ant
Class FreeMarkerXmlTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.apache.tools.ant.taskdefs.MatchingTask
              extended by freemarker.ext.ant.FreeMarkerXmlTask
All Implemented Interfaces:
TemplateExceptionListener, java.lang.Cloneable, java.util.EventListener, org.apache.tools.ant.types.selectors.SelectorContainer

public class FreeMarkerXmlTask
extends org.apache.tools.ant.taskdefs.MatchingTask
implements TemplateExceptionListener

This is an Ant task for transforming XML documents using FM-Classic templates. It uses the JDOM adapter class, the NodeListModel. It will read a set of XML documents, and pass them to the template for processing, building the corresponding output files in the destination directory.

It makes the following variables available to the template in the data model:

It supports the following attributes:

Attribute Description Required
basedir location of the XML files. Defaults to the project's basedir. No
destdir location to store the generated files. Yes
includes comma-separated list of patterns of files that must be included; all files are included when omitted. No
includesfile the name of a file that contains include patterns. No
excludes comma-separated list of patterns of files that must be excluded; no files (except default excludes) are excluded when omitted. No
excludesfile the name of a file that contains exclude patterns. No
defaultexcludes indicates whether default excludes should be used (yes | no); default excludes are used when omitted. No
extension extension of generated files. Defaults to .html. No
template location of the FreeMarker template file that will be applied to XML files Yes
projectfile path to the project file. If omitted, it will not be available to templates No
incremental indicates whether all files should be regenerated (no), or only those that are older than the XML file, the template file, or the project file (yes). Defaults to yes. No
encoding The encoding of the output files. Default to platform default encoding. No

Version:
$Id: FreeMarkerXmlTask.java 1152 2013-04-15 10:34:50Z run2000 $
Author:
Attila Szegedi, szegedia@freemail.hu, Jonathan Revusky, jon@revusky.com

Field Summary
 
Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
fileset
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
FreeMarkerXmlTask()
          Constructor creates the SAXBuilder.
 
Method Summary
 void exceptionThrown(TemplateExceptionEvent e)
          This method is called whenever a TemplateExceptionEvent is generated by a FM-Classic template.
 void execute()
          Execute this task as an Ant task.
 void setBasedir(java.io.File dir)
          Set the base directory.
 void setDestdir(java.io.File dir)
          Set the destination directory into which the generated files should be copied to
 void setEncoding(java.lang.String encoding)
          Set encoding for generated files.
 void setExtension(java.lang.String extension)
          Set the output file extension.
 void setIncremental(java.lang.String incremental)
          Turn on/off incremental processing.
 void setProjectfile(java.lang.String projectAttribute)
          Set the path to the project XML file
 void setTemplate(java.lang.String template)
          Set the path to the template file
 
Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask
add, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject, XsetIgnore, XsetItems
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FreeMarkerXmlTask

public FreeMarkerXmlTask()
Constructor creates the SAXBuilder.

Method Detail

setBasedir

public void setBasedir(java.io.File dir)
Set the base directory. Defaults to .

Parameters:
dir - the name of the base input directory

setDestdir

public void setDestdir(java.io.File dir)
Set the destination directory into which the generated files should be copied to

Parameters:
dir - the name of the destination directory

setExtension

public void setExtension(java.lang.String extension)
Set the output file extension. .html by default.

Parameters:
extension - the file extension for the output files

setTemplate

public void setTemplate(java.lang.String template)
Set the path to the template file

Parameters:
template - the template to be used when transforming the XML

setProjectfile

public void setProjectfile(java.lang.String projectAttribute)
Set the path to the project XML file

Parameters:
projectAttribute - the project attribute from the Ant task

setIncremental

public void setIncremental(java.lang.String incremental)
Turn on/off incremental processing. On by default


setEncoding

public void setEncoding(java.lang.String encoding)
Set encoding for generated files. Defaults to platform default encoding.

Parameters:
encoding - the encoding to be used

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Execute this task as an Ant task.

Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException

exceptionThrown

public void exceptionThrown(TemplateExceptionEvent e)
                     throws TemplateException
This method is called whenever a TemplateExceptionEvent is generated by a FM-Classic template. Implement this method to decide how to respond to such events.

Specified by:
exceptionThrown in interface TemplateExceptionListener
Throws:
TemplateException