net.sf.fikin.ant
Class XsltTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by net.sf.fikin.ant.XsltTask
All Implemented Interfaces:
javax.xml.transform.ErrorListener
Direct Known Subclasses:
StxTask

public class XsltTask
extends org.apache.tools.ant.Task
implements javax.xml.transform.ErrorListener

Reworked version of Ant's STYLE/XSLT task

Main differences are:

created on Aug 9, 2005

Since:
Version:
$Revision: 1.5 $
Author:
niki
Ant Task Name:
xslt2

Nested Class Summary
 class XsltTask.Factory
          The factory element to configure a transformer factory
 
Field Summary
protected  java.util.Vector depends
          extra files this transfrmation is dependent to
protected  XsltTask.Factory factory
          factory element for TraX processors only
protected  boolean failOnError
          fail on error during transformation, by default true
protected  org.apache.tools.ant.util.FileUtils fileUtils
          Utilities used for file operations
protected  boolean force
          force output of target files even if they already exist
protected  java.util.Vector inFilesets
          input xml documents
protected  org.apache.tools.ant.types.Mapper mapperElement
          Mapper to use when a set of files gets processed
protected  java.util.Vector params
          transformation parameters
protected  java.util.Hashtable paramsHT
          internal member, used to represent parmas in hashtable format
protected  boolean reuseLoadedStylesheet
          whether to reuse Transformer if transforming multiple files
protected  java.io.File xslFile
          xslt to be used for the transformation
protected  Xslt xslt
          internal member used to refernence reusable Xslt object
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
XsltTask()
           
 
Method Summary
 void add(org.apache.tools.ant.util.FileNameMapper fileNameMapper)
          A nested filenamemapper
 void addFileset(org.apache.tools.ant.types.FileSet set)
          Adds a set of files to copy.
protected  void check()
          do a checking on the set parameters
 Depends createDepends()
          Create an instance of an XSL parameter type "depends" for configuration by Ant.
 XsltTask.Factory createFactory()
          Create the factory element to configure a trax liaison.
 org.apache.tools.ant.types.Mapper createMapper()
          Defines the mapper to map source to destination files.
 XsltParam createParam()
          Create an instance of an XSL parameter for configuration by Ant.
 void error(javax.xml.transform.TransformerException exception)
          callback from XSLT when some error
 void execute()
          execute the transformation
 void fatalError(javax.xml.transform.TransformerException exception)
          callback from XSLT when some fatal error
protected  java.io.File getOutFile(java.io.File inFile)
          determine output file name for the given inout name
protected  java.util.Hashtable getParams()
          return hashtable with all transformation params (convert them from Vector)
protected  java.util.Hashtable getParams(java.util.Enumeration e)
          create a new hashtable with all elements
protected  Xslt getXslt()
          instantiate (if needed) an xslt object and return it it would be one an same object if xslt is to be reused
protected  boolean isUpToDate(java.io.File in, java.io.File out)
          check if timestamp is up to date for input, output and depends and param-locations
protected  javax.xml.transform.TransformerFactory newStyleFactory()
          instantiate a new factory and set the attributes
protected  Xslt newXslt()
          instantiate a new xslt object
protected  void scan(org.apache.tools.ant.types.FileSet fs)
          scan a fileset and process each individual file
 void setFailOnError(boolean flg)
          Set whether to abort the execution in case of error during xslt, by default is true
 void setForce(boolean force)
          Set whether to check dependencies, or always generate; optional, default is false.
 void setIn(java.io.File inFile)
          specifies a single XML document to be styled.
 void setOut(java.io.File outFile)
          Specifies the output name for the styled result from the in attribute; required if in is set
 void setReloadStylesheet(boolean b)
          Controls whether the stylesheet is reloaded for every transform.
 void setStyle(java.io.File xslFile)
          Name of the stylesheet to use - given either relative to the project's basedir or as an absolute path
protected  void transform(java.io.File inFile)
          transform an input file
protected  void transform(java.io.File in, java.io.File out)
          transform input into output
 void warning(javax.xml.transform.TransformerException exception)
          callback from XSLT when some warning
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inFilesets

protected java.util.Vector inFilesets
input xml documents


mapperElement

protected org.apache.tools.ant.types.Mapper mapperElement
Mapper to use when a set of files gets processed


xslFile

protected java.io.File xslFile
xslt to be used for the transformation


failOnError

protected boolean failOnError
fail on error during transformation, by default true


force

protected boolean force
force output of target files even if they already exist


reuseLoadedStylesheet

protected boolean reuseLoadedStylesheet
whether to reuse Transformer if transforming multiple files


fileUtils

protected org.apache.tools.ant.util.FileUtils fileUtils
Utilities used for file operations


factory

protected XsltTask.Factory factory
factory element for TraX processors only


params

protected java.util.Vector params
transformation parameters


depends

protected java.util.Vector depends
extra files this transfrmation is dependent to


paramsHT

protected java.util.Hashtable paramsHT
internal member, used to represent parmas in hashtable format


xslt

protected Xslt xslt
internal member used to refernence reusable Xslt object

Constructor Detail

XsltTask

public XsltTask()
Method Detail

setOut

public void setOut(java.io.File outFile)
Specifies the output name for the styled result from the in attribute; required if in is set

Parameters:
outFile - the output File instance.
Ant Task Param Required:
required if in is set, otherwise a nested is expected

setIn

public void setIn(java.io.File inFile)
specifies a single XML document to be styled. Should be used with the out attribute

Parameters:
inFile - the input file
Ant Task Param Required:
required if out is set, otherwise one or more nested are expected

setStyle

public void setStyle(java.io.File xslFile)
Name of the stylesheet to use - given either relative to the project's basedir or as an absolute path

Parameters:
xslFile - the stylesheet to use
Ant Task Param Required:
this or styleSystemId="mySystemId"

addFileset

public void addFileset(org.apache.tools.ant.types.FileSet set)
Adds a set of files to copy.

Parameters:
set - a set of files to copy
Ant Task Param Required:
required if is set too, otherwise in and out is expected

createMapper

public org.apache.tools.ant.types.Mapper createMapper()
                                               throws org.apache.tools.ant.BuildException
Defines the mapper to map source to destination files.

Returns:
a mapper to be configured
Throws:
org.apache.tools.ant.BuildException - if more than one mapper is defined
Ant Task Param Required:
required if is used

add

public void add(org.apache.tools.ant.util.FileNameMapper fileNameMapper)
A nested filenamemapper

Parameters:
fileNameMapper - the mapper to add
Ant Task Param Required:
required if is used

setFailOnError

public void setFailOnError(boolean flg)
Set whether to abort the execution in case of error during xslt, by default is true

Parameters:
flg - abort execution if true
Ant Task Param Required:
false

setForce

public void setForce(boolean force)
Set whether to check dependencies, or always generate; optional, default is false.

Parameters:
force - true if always generate.
Ant Task Param Required:
false

setReloadStylesheet

public void setReloadStylesheet(boolean b)
Controls whether the stylesheet is reloaded for every transform.

Setting this to true may get around a bug in certain Xalan-J versions, default is false.

Ant Task Param Required:
false

createParam

public XsltParam createParam()
Create an instance of an XSL parameter for configuration by Ant.

Returns:
an instance of the Param class to be configured.
Ant Task Param Required:
false

createDepends

public Depends createDepends()
Create an instance of an XSL parameter type "depends" for configuration by Ant.

Returns:
an instance of the Depends class to be configured.
Ant Task Param Required:
false

createFactory

public XsltTask.Factory createFactory()
                               throws org.apache.tools.ant.BuildException
Create the factory element to configure a trax liaison.

Returns:
the newly created factory element.
Throws:
org.apache.tools.ant.BuildException - if the element is created more than one time.

execute

public void execute()
             throws org.apache.tools.ant.BuildException
execute the transformation

Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - in case of error

check

protected void check()
              throws org.apache.tools.ant.BuildException
do a checking on the set parameters

Throws:
org.apache.tools.ant.BuildException

scan

protected void scan(org.apache.tools.ant.types.FileSet fs)
scan a fileset and process each individual file

Parameters:
fs -

transform

protected void transform(java.io.File inFile)
transform an input file

Parameters:
inFile -

getOutFile

protected java.io.File getOutFile(java.io.File inFile)
determine output file name for the given inout name

Parameters:
inFile -
Returns:
output name, null if mapping was not possible to map it to any mapping rule

isUpToDate

protected boolean isUpToDate(java.io.File in,
                             java.io.File out)
check if timestamp is up to date for input, output and depends and param-locations

Parameters:
in -
out -
Returns:
true if outfile is newer, otherwise false

transform

protected void transform(java.io.File in,
                         java.io.File out)
                  throws org.apache.tools.ant.BuildException
transform input into output

Parameters:
in -
out -
Throws:
org.apache.tools.ant.BuildException

getXslt

protected Xslt getXslt()
                throws java.io.FileNotFoundException,
                       javax.xml.transform.TransformerConfigurationException,
                       java.lang.ClassNotFoundException,
                       java.lang.NoSuchMethodException,
                       java.lang.InstantiationException,
                       java.lang.reflect.InvocationTargetException,
                       java.lang.IllegalAccessException
instantiate (if needed) an xslt object and return it it would be one an same object if xslt is to be reused

Returns:
xslt
Throws:
java.io.FileNotFoundException
javax.xml.transform.TransformerConfigurationException
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException

getParams

protected java.util.Hashtable getParams()
return hashtable with all transformation params (convert them from Vector)

Returns:
vector with params in hashtable format where name is the key and value is the value

getParams

protected java.util.Hashtable getParams(java.util.Enumeration e)
create a new hashtable with all elements

Parameters:
e - is a list of Parameter objects
Returns:
hashtable where key=param.name and object=param.value

newXslt

protected Xslt newXslt()
                throws java.io.FileNotFoundException,
                       javax.xml.transform.TransformerConfigurationException,
                       java.lang.ClassNotFoundException,
                       java.lang.NoSuchMethodException,
                       java.lang.InstantiationException,
                       java.lang.reflect.InvocationTargetException,
                       java.lang.IllegalAccessException
instantiate a new xslt object

Returns:
Xslt object
Throws:
java.io.FileNotFoundException
javax.xml.transform.TransformerConfigurationException
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException

newStyleFactory

protected javax.xml.transform.TransformerFactory newStyleFactory()
                                                          throws java.lang.ClassNotFoundException,
                                                                 java.lang.NoSuchMethodException,
                                                                 java.lang.InstantiationException,
                                                                 java.lang.reflect.InvocationTargetException,
                                                                 java.lang.IllegalAccessException
instantiate a new factory and set the attributes

Returns:
new factory
Throws:
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.InstantiationException
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException

warning

public void warning(javax.xml.transform.TransformerException exception)
             throws javax.xml.transform.TransformerException
callback from XSLT when some warning

Specified by:
warning in interface javax.xml.transform.ErrorListener
Throws:
javax.xml.transform.TransformerException

error

public void error(javax.xml.transform.TransformerException exception)
           throws javax.xml.transform.TransformerException
callback from XSLT when some error

Specified by:
error in interface javax.xml.transform.ErrorListener
Throws:
javax.xml.transform.TransformerException

fatalError

public void fatalError(javax.xml.transform.TransformerException exception)
                throws javax.xml.transform.TransformerException
callback from XSLT when some fatal error

Specified by:
fatalError in interface javax.xml.transform.ErrorListener
Throws:
javax.xml.transform.TransformerException


Copyright © 2003-2007 Nikolay Fiykov. All Rights Reserved.