org.springframework.beandoc.output
Class XslTransformer

java.lang.Object
  extended by org.springframework.beandoc.output.XslTransformer
All Implemented Interfaces:
Transformer
Direct Known Subclasses:
ConsolidatedTransformer, DotFileTransformer

public class XslTransformer
extends Object
implements Transformer

Base implementation of the Transformer interface that uses XSLT (via TRaX) in order to generate output files. If no XSL stylesheet resources are specified when the object is constructed (or via setters before being used) then default XSL stylesheets will be used that are stored in the same package as this class.

This class is therefore quite flexible as a Transformer implementation in allowing the user to specify different XSL stylesheets to have complete control over how the output is generated. Subclasses are only responsible for providing a file name for each output file that needs to be generated by the Transformer. The only requirement for subclasses is that they provide an output file name for each relevant input file via the abstract getOutputForDocument(java.lang.String) and a stylesheet URI through the setTemplateName(java.lang.String) method.

Since:
1.0
Author:
Darren Davison

Field Summary
protected  org.springframework.beandoc.output.FilenameStrategy filenameStrategy
           
protected  org.apache.commons.logging.Log logger
           
protected  Map staticParameters
           
 
Constructor Summary
XslTransformer()
          default constructor
XslTransformer(String templateName)
          loads and compiles the stylesheets using specified values.
 
Method Summary
protected  void doXslTransform(org.jdom.Document doc, File outputDir)
          perform the actual tree transformation to the output directory for the given Document
protected  String getOutputForDocument(String inputFileName)
          Return the name of the output file (relative to the configured output directory) that this transformer will use to generate output to.
protected  Map getParameters(org.jdom.Document doc)
          Subclasses may optionally generate and return a Map of stylesheet parameters that will be included in the transform.
 Map getStaticParameters()
           
 String getTemplateName()
          The String value representing the resource pointing to an XSL stylesheet used in generating documentation output.
protected  void handleTransform(org.jdom.Document[] contextDocuments, File outputDirectory)
          Creates an output file in the specified location for each supplied document re-using the same compiled stylesheet for each.
protected  void initTransform(org.jdom.Document[] contextDocuments, File outputDirectory)
          Perform any initialization or one-off tasks prior to the actual transformation of the context documents with the configured stylesheet.
protected  void postTransform()
          Perform any finalization or one-off tasks after the actual transformation of the context documents with the configured stylesheet.
 void setFilenameStrategy(org.springframework.beandoc.output.FilenameStrategy filenameStrategy)
          set the output filename strategy to use.
 void setLocale(Locale locale)
          Override the system default locale and specify which locale output should be generated for.
 void setStaticParameters(Map staticParameters)
          Provide a Map of XSL parameter values for this class that can be used to make up all or part of the Map of actual parameters used in the stylesheet.
 void setTemplateName(String templateName)
          loads and compile the stylesheet used in generating document output.
 void transform(org.jdom.Document[] contextDocuments, File outputDir)
          Implements the Transformer API and sanity checks some configuration aspects before beginning the transformation workflow.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger

filenameStrategy

protected org.springframework.beandoc.output.FilenameStrategy filenameStrategy

staticParameters

protected Map staticParameters
Constructor Detail

XslTransformer

public XslTransformer()
default constructor


XslTransformer

public XslTransformer(String templateName)
loads and compiles the stylesheets using specified values. Both parameters are interpreted as standard Spring Resources and can contain any value that the underlying resource loading classes can understand. See the Spring JavaDocs for more information on resource handling.

Parameters:
templateName - the XSL resource used to generate output
Method Detail

transform

public final void transform(org.jdom.Document[] contextDocuments,
                            File outputDir)
Implements the Transformer API and sanity checks some configuration aspects before beginning the transformation workflow. The initTransform method is first called, returning on any thrown Exception. After successful initialisation and XSL processing, the postTransform() method is called to perform cleanup or additional tasks.

Specified by:
transform in interface Transformer
Parameters:
contextDocuments - an array of JDOM Document objects
outputDir - the directory to place any output in
See Also:
initTransform(org.jdom.Document[], java.io.File)

initTransform

protected void initTransform(org.jdom.Document[] contextDocuments,
                             File outputDirectory)
                      throws Exception
Perform any initialization or one-off tasks prior to the actual transformation of the context documents with the configured stylesheet. Default implementation does nothing.

Parameters:
contextDocuments - the array of DOM trees about to be transformed
outputDirectory - the file handle for the output directory
Throws:
Exception

handleTransform

protected void handleTransform(org.jdom.Document[] contextDocuments,
                               File outputDirectory)
Creates an output file in the specified location for each supplied document re-using the same compiled stylesheet for each. Subclasses can override this behaviour if, for example, they don't want to have each document handled in sequence. In this case, the subclass can still make use of the doXslTransform method aas a library function.

Parameters:
contextDocuments - the array of DOM trees about to be transformed
outputDirectory - the file handle for the output directory

doXslTransform

protected void doXslTransform(org.jdom.Document doc,
                              File outputDir)
perform the actual tree transformation to the output directory for the given Document

Parameters:
doc - the document to transform
outputDir - the file handle of the output location

getParameters

protected Map getParameters(org.jdom.Document doc)
Subclasses may optionally generate and return a Map of stylesheet parameters that will be included in the transform. The default implementation returns the Map of staticParameters (if any).

Parameters:
doc - the Document about to be transformed
Returns:
a Map of stylesheet parameter names and their corresponding values. The parameter names must be defined in the stylesheet itself.

getOutputForDocument

protected String getOutputForDocument(String inputFileName)
Return the name of the output file (relative to the configured output directory) that this transformer will use to generate output to. Default impl. uses the filenameStrategy.

Parameters:
inputFileName - the original file name (not including path) of the context file
Returns:
the output file name to use

postTransform

protected void postTransform()
Perform any finalization or one-off tasks after the actual transformation of the context documents with the configured stylesheet. Default implementation does nothing.


getTemplateName

public String getTemplateName()
The String value representing the resource pointing to an XSL stylesheet used in generating documentation output.

Returns:
a Spring resource identifier

setTemplateName

public void setTemplateName(String templateName)
                     throws InvalidTransformerException
loads and compile the stylesheet used in generating document output. If the supplied template name cannot be compiled to a binary template representation, a BeanDocException will be thrown here.

Parameters:
templateName - a standard Spring Resource that can contain any value that the underlying resource loading classes can understand. See the Spring JavaDocs for more information on resource handling.
Throws:
InvalidTransformerException

getStaticParameters

public Map getStaticParameters()
Returns:
the Map of static XSL parameters that may or may not be returned as part of the getParameters(Document) method

setStaticParameters

public void setStaticParameters(Map staticParameters)
Provide a Map of XSL parameter values for this class that can be used to make up all or part of the Map of actual parameters used in the stylesheet.

Parameters:
staticParameters - a Map of parameters that will probably be used as part of a Map returned from the getParameters(Document) method

setFilenameStrategy

public void setFilenameStrategy(org.springframework.beandoc.output.FilenameStrategy filenameStrategy)
set the output filename strategy to use.

Parameters:
filenameStrategy -

setLocale

public void setLocale(Locale locale)
Override the system default locale and specify which locale output should be generated for.

Parameters:
locale -


Copyright © 2004-2011 Spring BeanDoc. All Rights Reserved.