Package org.osjava.jardiff.ant
Class JDXSLTProcess
- java.lang.Object
-
- org.apache.tools.ant.ProjectComponent
-
- org.apache.tools.ant.Task
-
- org.apache.tools.ant.taskdefs.MatchingTask
-
- org.osjava.jardiff.ant.JDXSLTProcess
-
- All Implemented Interfaces:
java.lang.Cloneable,org.apache.tools.ant.taskdefs.XSLTLogger,org.apache.tools.ant.types.selectors.SelectorContainer
public class JDXSLTProcess extends org.apache.tools.ant.taskdefs.MatchingTask implements org.apache.tools.ant.taskdefs.XSLTLogger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJDXSLTProcess.FactoryThe factory element to configure a transformer factorystatic classJDXSLTProcess.OutputPropertySpecify how the result tree should be output as specified in the specification.static classJDXSLTProcess.ParamThe Param inner class used to store XSL parametersprivate classJDXSLTProcess.StyleMapperMapper implementation of the "traditional" way <xslt> mapped filenames.
-
Field Summary
Fields Modifier and Type Field Description private java.io.FilebaseDirwhere to find the source XML file, default is the project's basedirprivate org.apache.tools.ant.types.PathclasspathClasspath to use when trying to load the XSL processorprivate java.io.FiledestDirdestination directoryprivate JDXSLTProcess.Factoryfactoryfactory element for TraX processors onlyprivate org.apache.tools.ant.util.FileUtilsfileUtilsUtilities used for file operationsprivate booleanforceforce output of target files even if they already existprivate java.io.FileinFileInput XML document to be usedprivate org.apache.tools.ant.taskdefs.XSLTLiaisonliaisonThe Liason implementation to use to communicate with the XSL processorprivate org.apache.tools.ant.AntClassLoaderloaderAntClassLoader for the nested <classpath> - if set.private org.apache.tools.ant.types.MappermapperElementMapper to use when a set of files gets processed.private java.io.FileoutFileOutput fileprivate java.util.VectoroutputPropertiesXSL output properties to be usedprivate java.util.Vectorparamsadditional parameters to be passed to the stylesheetsprivate booleanperformDirectoryScanWhether to style all files in the included directories as well.private java.lang.StringprocessorThe name of the XSL processor to useprivate booleanreuseLoadedStylesheetwhether to reuse Transformer if transforming multiple files.private booleanstylesheetLoadedFlag which indicates if the stylesheet has been loaded into the processorprivate java.lang.StringstyleurlSystemid of stylesheet (url).private java.lang.StringtargetExtensionextension of the files produced by XSL processingprivate static java.lang.StringTRAX_LIAISON_CLASSName of the TRAX Liaison classprivate static java.lang.StringXALAN_LIAISON_CLASSName of the now-deprecated Xalan liaison classprivate org.apache.tools.ant.types.XMLCatalogxmlCatalogfor resolving entities such as dtdsprivate java.lang.StringxslFileXSL stylesheetprivate static java.lang.StringXSLP_LIAISON_CLASSName of the now-deprecated XSLP Liaison class
-
Constructor Summary
Constructors Constructor Description JDXSLTProcess()Creates a new JDXSLTProcess Task.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConfiguredXMLCatalog(org.apache.tools.ant.types.XMLCatalog xmlCatalog)Add the catalog to our internal catalogvoidaddMapper(org.apache.tools.ant.types.Mapper mapper)Defines the mapper to map source to destination files.protected voidconfigureLiaison(java.lang.Object stylesheet)Loads the stylesheet and set xsl:param parameters.org.apache.tools.ant.types.PathcreateClasspath()Set the optional classpath to the XSL processorJDXSLTProcess.FactorycreateFactory()Create the factory element to configure a trax liaison.JDXSLTProcess.OutputPropertycreateOutputProperty()Create an instance of an output property to be configured.JDXSLTProcess.ParamcreateParam()Create an instance of an XSL parameter for configuration by Ant.private voidensureDirectoryFor(java.io.File targetFile)Ensure the directory exists for a given filevoidexecute()Executes the task.JDXSLTProcess.FactorygetFactory()Get the factory instance configured for this processorprotected org.apache.tools.ant.taskdefs.XSLTLiaisongetLiaison()Get the Liason implementation to use in processing.java.util.EnumerationgetOutputProperties()org.apache.tools.ant.types.XMLCataloggetXMLCatalog()Get the XML catalog containing entity definitionsvoidinit()Initialize internal instance of XMLCatalogprivate java.lang.ClassloadClass(java.lang.String classname)Load named class either via the system classloader or a given custom classloader.private voidprocess(java.io.File inFile, java.io.File outFile, java.lang.Object stylesheet)Process the input file to the output file with the given stylesheet.private voidprocess(java.io.File baseDir, java.lang.String xmlFile, java.io.File destDir, java.lang.Object stylesheet)Processes the given input XML file and stores the result in the given resultFile.private voidresolveProcessor(java.lang.String proc)Load processor here instead of in setProcessor - this will be called from within execute, so we have access to the latest classpath.voidsetBasedir(java.io.File dir)Set the base directory; optional, default is the project's basedir.voidsetClasspath(org.apache.tools.ant.types.Path classpath)Set the optional classpath to the XSL processorvoidsetClasspathRef(org.apache.tools.ant.types.Reference r)Set the reference to an optional classpath to the XSL processorvoidsetDestdir(java.io.File dir)Set the destination directory into which the XSL result files should be copied to; required, unless in and out are specified.voidsetExtension(java.lang.String name)Set the desired file extension to be used for the target; optional, default is html.voidsetForce(boolean force)Set whether to check dependencies, or always generate; optional, default is false.voidsetIn(java.io.File inFile)specifies a single XML document to be styled.voidsetOut(java.io.File outFile)Specifies the output name for the styled result from the in attribute; required if in is setvoidsetProcessor(java.lang.String processor)Set the name of the XSL processor to use; optional, default trax.voidsetReloadStylesheet(boolean b)Controls whether the stylesheet is reloaded for every transform.voidsetScanIncludedDirectories(boolean b)Whether to style all files in the included directories as well; optional, default is true.voidsetStyle(java.lang.String xslFile)Name of the stylesheet to use - given either relative to the project's basedir or as an absolute path; required.voidsetStyleurl(java.lang.String styleurl)Set the stylesheet url.-
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, 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
-
-
-
-
Field Detail
-
destDir
private java.io.File destDir
destination directory
-
baseDir
private java.io.File baseDir
where to find the source XML file, default is the project's basedir
-
xslFile
private java.lang.String xslFile
XSL stylesheet
-
targetExtension
private java.lang.String targetExtension
extension of the files produced by XSL processing
-
params
private java.util.Vector params
additional parameters to be passed to the stylesheets
-
inFile
private java.io.File inFile
Input XML document to be used
-
outFile
private java.io.File outFile
Output file
-
processor
private java.lang.String processor
The name of the XSL processor to use
-
classpath
private org.apache.tools.ant.types.Path classpath
Classpath to use when trying to load the XSL processor
-
styleurl
private java.lang.String styleurl
Systemid of stylesheet (url).
-
liaison
private org.apache.tools.ant.taskdefs.XSLTLiaison liaison
The Liason implementation to use to communicate with the XSL processor
-
stylesheetLoaded
private boolean stylesheetLoaded
Flag which indicates if the stylesheet has been loaded into the processor
-
force
private boolean force
force output of target files even if they already exist
-
fileUtils
private org.apache.tools.ant.util.FileUtils fileUtils
Utilities used for file operations
-
outputProperties
private java.util.Vector outputProperties
XSL output properties to be used
-
xmlCatalog
private org.apache.tools.ant.types.XMLCatalog xmlCatalog
for resolving entities such as dtds
-
TRAX_LIAISON_CLASS
private static final java.lang.String TRAX_LIAISON_CLASS
Name of the TRAX Liaison class- See Also:
- Constant Field Values
-
XSLP_LIAISON_CLASS
private static final java.lang.String XSLP_LIAISON_CLASS
Name of the now-deprecated XSLP Liaison class- See Also:
- Constant Field Values
-
XALAN_LIAISON_CLASS
private static final java.lang.String XALAN_LIAISON_CLASS
Name of the now-deprecated Xalan liaison class- See Also:
- Constant Field Values
-
performDirectoryScan
private boolean performDirectoryScan
Whether to style all files in the included directories as well.- Since:
- Ant 1.5
-
factory
private JDXSLTProcess.Factory factory
factory element for TraX processors only- Since:
- Ant 1.6
-
reuseLoadedStylesheet
private boolean reuseLoadedStylesheet
whether to reuse Transformer if transforming multiple files.- Since:
- 1.5.2
-
loader
private org.apache.tools.ant.AntClassLoader loader
AntClassLoader for the nested <classpath> - if set.We keep this here in order to reset the context classloader in execute. We can't use liaison.getClass().getClassLoader() since the actual liaison class may have been loaded by a loader higher up (system classloader, for example).
- Since:
- Ant 1.6.2
-
mapperElement
private org.apache.tools.ant.types.Mapper mapperElement
Mapper to use when a set of files gets processed.- Since:
- Ant 1.6.2
-
-
Method Detail
-
setScanIncludedDirectories
public void setScanIncludedDirectories(boolean b)
Whether to style all files in the included directories as well; optional, default is true.- Parameters:
b- true if files in included directories are processed.- Since:
- Ant 1.5
-
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.
- Since:
- Ant 1.5.2
-
addMapper
public void addMapper(org.apache.tools.ant.types.Mapper mapper)
Defines the mapper to map source to destination files.- Throws:
org.apache.tools.ant.BuildException- if more than one mapper is defined- Since:
- Ant 1.6.2
-
execute
public void execute() throws org.apache.tools.ant.BuildExceptionExecutes the task.- Overrides:
executein classorg.apache.tools.ant.Task- Throws:
org.apache.tools.ant.BuildException- if there is an execution problem.
-
setForce
public void setForce(boolean force)
Set whether to check dependencies, or always generate; optional, default is false.- Parameters:
force- true if always generate.
-
setBasedir
public void setBasedir(java.io.File dir)
Set the base directory; optional, default is the project's basedir.- Parameters:
dir- the base directory
-
setDestdir
public void setDestdir(java.io.File dir)
Set the destination directory into which the XSL result files should be copied to; required, unless in and out are specified.- Parameters:
dir- the name of the destination directory
-
setExtension
public void setExtension(java.lang.String name)
Set the desired file extension to be used for the target; optional, default is html.- Parameters:
name- the extension to use
-
setStyle
public void setStyle(java.lang.String xslFile)
Name of the stylesheet to use - given either relative to the project's basedir or as an absolute path; required.- Parameters:
xslFile- the stylesheet to use
-
setClasspath
public void setClasspath(org.apache.tools.ant.types.Path classpath)
Set the optional classpath to the XSL processor- Parameters:
classpath- the classpath to use when loading the XSL processor
-
createClasspath
public org.apache.tools.ant.types.Path createClasspath()
Set the optional classpath to the XSL processor- Returns:
- a path instance to be configured by the Ant core.
-
setClasspathRef
public void setClasspathRef(org.apache.tools.ant.types.Reference r)
Set the reference to an optional classpath to the XSL processor- Parameters:
r- the id of the Ant path instance to act as the classpath for loading the XSL processor
-
setProcessor
public void setProcessor(java.lang.String processor)
Set the name of the XSL processor to use; optional, default trax. Other values are "xalan" for Xalan1 and "xslp" for XSL:P, though the later is strongly deprecated.- Parameters:
processor- the name of the XSL processor
-
setStyleurl
public void setStyleurl(java.lang.String styleurl)
Set the stylesheet url.- Since:
- JarDiff 0.2
-
addConfiguredXMLCatalog
public void addConfiguredXMLCatalog(org.apache.tools.ant.types.XMLCatalog xmlCatalog)
Add the catalog to our internal catalog- Parameters:
xmlCatalog- the XMLCatalog instance to use to look up DTDs
-
resolveProcessor
private void resolveProcessor(java.lang.String proc) throws java.lang.ExceptionLoad processor here instead of in setProcessor - this will be called from within execute, so we have access to the latest classpath.- Parameters:
proc- the name of the processor to load.- Throws:
java.lang.Exception- if the processor cannot be loaded.
-
loadClass
private java.lang.Class loadClass(java.lang.String classname) throws java.lang.ExceptionLoad named class either via the system classloader or a given custom classloader.- Parameters:
classname- the name of the class to load.- Returns:
- the requested class.
- Throws:
java.lang.Exception- if the class could not be loaded.
-
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.
-
setIn
public void setIn(java.io.File inFile)
specifies a single XML document to be styled. Should be used with the out attribute; ; required if out is set- Parameters:
inFile- the input file
-
process
private void process(java.io.File baseDir, java.lang.String xmlFile, java.io.File destDir, java.lang.Object stylesheet) throws org.apache.tools.ant.BuildExceptionProcesses the given input XML file and stores the result in the given resultFile.- Parameters:
baseDir- the base directory for resolving files.xmlFile- the input filedestDir- the destination directorystylesheet- the stylesheet to use.- Throws:
org.apache.tools.ant.BuildException- if the processing fails.
-
process
private void process(java.io.File inFile, java.io.File outFile, java.lang.Object stylesheet) throws org.apache.tools.ant.BuildExceptionProcess the input file to the output file with the given stylesheet.- Parameters:
inFile- the input file to process.outFile- the destination file.stylesheet- the stylesheet to use.- Throws:
org.apache.tools.ant.BuildException- if the processing fails.
-
ensureDirectoryFor
private void ensureDirectoryFor(java.io.File targetFile) throws org.apache.tools.ant.BuildExceptionEnsure the directory exists for a given file- Parameters:
targetFile- the file for which the directories are required.- Throws:
org.apache.tools.ant.BuildException- if the directories cannot be created.
-
getFactory
public JDXSLTProcess.Factory getFactory()
Get the factory instance configured for this processor- Returns:
- the factory instance in use
-
getXMLCatalog
public org.apache.tools.ant.types.XMLCatalog getXMLCatalog()
Get the XML catalog containing entity definitions- Returns:
- the XML catalog for the task.
-
getOutputProperties
public java.util.Enumeration getOutputProperties()
-
getLiaison
protected org.apache.tools.ant.taskdefs.XSLTLiaison getLiaison()
Get the Liason implementation to use in processing.- Returns:
- an instance of the XSLTLiason interface.
-
createParam
public JDXSLTProcess.Param createParam()
Create an instance of an XSL parameter for configuration by Ant.- Returns:
- an instance of the Param class to be configured.
-
createOutputProperty
public JDXSLTProcess.OutputProperty createOutputProperty()
Create an instance of an output property to be configured.- Returns:
- the newly created output property.
- Since:
- Ant 1.5
-
init
public void init() throws org.apache.tools.ant.BuildExceptionInitialize internal instance of XMLCatalog- Overrides:
initin classorg.apache.tools.ant.Task- Throws:
org.apache.tools.ant.BuildException
-
configureLiaison
protected void configureLiaison(java.lang.Object stylesheet) throws org.apache.tools.ant.BuildExceptionLoads the stylesheet and set xsl:param parameters.- Parameters:
stylesheet- the file form which to load the stylesheet.- Throws:
org.apache.tools.ant.BuildException- if the stylesheet cannot be loaded.
-
createFactory
public JDXSLTProcess.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.
-
-