com.agilejava.docbkx.maven
Class AbstractTransformerMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by com.agilejava.docbkx.maven.AbstractTransformerMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

public abstract class AbstractTransformerMojo
extends org.apache.maven.plugin.AbstractMojo

The abstract Mojo base for concrete Mojos that generate some kind of output format from DocBook. This Mojo will search documents in the directory returned by getTargetDirectory(), and apply the stylesheets on these documents. This Mojo will be subclassed by Mojo's that generate a particular type of output.

Author:
Wilfred Springer

Field Summary
protected  String[] catalogs
           
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
AbstractTransformerMojo()
           
 
Method Summary
 void adjustTransformer(Transformer transformer, String sourceFilename, File targetFile)
          The operation to override when it is required to make some adjustments to the Transformer right before it is applied to a certain source file.
protected abstract  void configure(Transformer transformer)
          Configure the Transformer by passing in some parameters.
protected  Object convertBooleanToXsltParam(String value)
          Converts a Boolean parameter to the type expected by the XSLT processor.
protected  Object convertStringToXsltParam(String value)
          Converts a String parameter to the type expected by the XSLT processor.
protected  org.apache.xml.resolver.CatalogManager createCatalogManager()
          Creates a CatalogManager, used to resolve DTDs and other entities.
protected  DocumentBuilder createDocumentBuilder()
          Creates a DocumentBuilder to be used to parse DocBook XML documents.
protected  Source createSource(String inputFilename, File sourceFile, PreprocessingFilter filter)
          Creates a SAXSource configured with the desired XInclude mode.
protected  org.jaxen.XPath createTitleXPath()
          Creates an instance of an XPath expression for picking the title from a document.
protected  TransformerBuilder createTransformerBuilder(URIResolver resolver)
          Constructs the default TransformerBuilder.
protected  File dumpResolvedXML(String initialFilename, nu.xom.Document doc)
          Saves the Docbook XML file with all XInclude resolved.
 void execute()
          Builds the actual output document.
protected  void executeTasks(org.apache.tools.ant.Target antTasks, org.apache.maven.project.MavenProject mavenProject)
           
protected abstract  List getArtifacts()
          Returns the plugin dependencies.
protected abstract  List getCustomizationParameters()
          A list of additional XSL parameters to give to the XSLT engine.
protected abstract  String getDefaultStylesheetLocation()
          Returns the default stylesheet location within the root of the stylesheet distribution.
protected  URL getDefaultStylesheetURL()
          Returns the URL of the default stylesheet.
protected abstract  List getEntities()
          Returns a list of Entities
protected abstract  File getGeneratedSourceDirectory()
          Returns the directory to use to save the resolved docbook XML before it is given to the Transformer.
protected abstract  String[] getIncludes()
          Returns the include patterns, as a comma-seperate collection of patterns.
protected abstract  org.apache.maven.project.MavenProject getMavenProject()
          Returns a reference to the current project.
protected  String getNonDefaultStylesheetLocation()
          The stylesheet location override by a class in the mojo hierarchy.
protected  URL getNonDefaultStylesheetURL()
          Returns the URL of the default stylesheet.
protected abstract  org.apache.tools.ant.Target getPostProcess()
          Returns the tasks that should be executed after the transformation.
protected abstract  org.apache.tools.ant.Target getPreProcess()
          Returns the tasks that should be executed before the transformation.
protected  String getProperty(String propertyname)
          Returns the value of a property of this object using introspection.
protected abstract  File getSourceDirectory()
          Returns the source directory containing the source XML files.
protected abstract  String getStylesheetLocation()
          Returns the actual stylesheet location.
protected  URL getStylesheetURL()
          Returns the URL of the stylesheet.
protected abstract  Properties getSystemProperties()
          Returns the additional System Properties.
protected abstract  File getTargetDirectory()
          Returns the target directory in which all results should be placed.
protected abstract  String getTargetFileExtension()
          Returns the extension of the target files, e.g.
protected abstract  String getType()
          Returns the type of conversion.
protected abstract  boolean getXIncludeSupported()
          Returns a boolean indicating if XInclude should be supported.
protected abstract  boolean isShowXslMessages()
          Returns true if the xslt engine have to print xsl:messages to standard output.
protected abstract  boolean isUseStandardOutput()
          Returns false if the stylesheet is responsible to create the output file(s) using its own naming scheme.
 void postProcess()
          Allows classes to add their own specific post-processing logic.
 void postProcessResult(File result)
          Post-processes the file.
 void preProcess()
          Allows subclasses to add their own specific pre-processing logic.
protected  void setProperty(String propertyname, String value)
          Sets the value of a property of this object using introspection.
protected abstract  void setShowXslMessages(boolean showXslMessages)
           
protected abstract  void setTargetFileExtension(String extension)
          Sets the file extension, this can be usefull to override this value especially for multiple transformations plugins (like XML to FO to PDF).
 
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

catalogs

protected String[] catalogs
Constructor Detail

AbstractTransformerMojo

public AbstractTransformerMojo()
Method Detail

execute

public void execute()
             throws org.apache.maven.plugin.MojoExecutionException,
                    org.apache.maven.plugin.MojoFailureException
Builds the actual output document.

Throws:
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException

createSource

protected Source createSource(String inputFilename,
                              File sourceFile,
                              PreprocessingFilter filter)
                       throws org.apache.maven.plugin.MojoExecutionException
Creates a SAXSource configured with the desired XInclude mode. XOM library is used for advanced XInclude else Xerces XInclude is used.

Parameters:
inputFilename - Is used for temp file generation (XOM)
sourceFile - The docbook source file.
filter - The XML PI filter.
Returns:
An XInclude configured SAXSource
Throws:
org.apache.maven.plugin.MojoExecutionException

dumpResolvedXML

protected File dumpResolvedXML(String initialFilename,
                               nu.xom.Document doc)
                        throws org.apache.maven.plugin.MojoExecutionException
Saves the Docbook XML file with all XInclude resolved.

Parameters:
initialFilename - Filename of the root docbook source file.
doc - XOM Document resolved.
Returns:
The new file generated.
Throws:
org.apache.maven.plugin.MojoExecutionException

getXIncludeSupported

protected abstract boolean getXIncludeSupported()
Returns a boolean indicating if XInclude should be supported.

Returns:
A boolean indicating if XInclude should be supported.

getGeneratedSourceDirectory

protected abstract File getGeneratedSourceDirectory()
Returns the directory to use to save the resolved docbook XML before it is given to the Transformer.

Returns:

getNonDefaultStylesheetLocation

protected String getNonDefaultStylesheetLocation()
The stylesheet location override by a class in the mojo hierarchy.

Returns:
The location of the stylesheet set by one of the superclasses, or null.

isUseStandardOutput

protected abstract boolean isUseStandardOutput()
Returns false if the stylesheet is responsible to create the output file(s) using its own naming scheme.

Returns:
If using the standard output.

isShowXslMessages

protected abstract boolean isShowXslMessages()
Returns true if the xslt engine have to print xsl:messages to standard output.

Returns:
If the xslt engine have to print messages.

setShowXslMessages

protected abstract void setShowXslMessages(boolean showXslMessages)

adjustTransformer

public void adjustTransformer(Transformer transformer,
                              String sourceFilename,
                              File targetFile)
The operation to override when it is required to make some adjustments to the Transformer right before it is applied to a certain source file. The two parameters provide some context, allowing implementers to respond to specific conditions for specific files.

Parameters:
transformer - The Transformer that must be adjusted.
sourceFilename - The name of the source file that is being transformed.
targetFile - The target File.

preProcess

public void preProcess()
                throws org.apache.maven.plugin.MojoExecutionException
Allows subclasses to add their own specific pre-processing logic.

Throws:
org.apache.maven.plugin.MojoExecutionException - If the Mojo fails to pre-process the results.

postProcess

public void postProcess()
                 throws org.apache.maven.plugin.MojoExecutionException
Allows classes to add their own specific post-processing logic.

Throws:
org.apache.maven.plugin.MojoExecutionException - If the Mojo fails to post-process the results.

postProcessResult

public void postProcessResult(File result)
                       throws org.apache.maven.plugin.MojoExecutionException
Post-processes the file. (Might be changed in the future to except an XML representation instead of a file, in order to prevent the file from being parsed.)

Parameters:
result - An individual result.
Throws:
org.apache.maven.plugin.MojoExecutionException

createCatalogManager

protected org.apache.xml.resolver.CatalogManager createCatalogManager()
Creates a CatalogManager, used to resolve DTDs and other entities.

Returns:
A CatalogManager to be used for resolving DTDs and other entities.

createDocumentBuilder

protected DocumentBuilder createDocumentBuilder()
                                         throws org.apache.maven.plugin.MojoExecutionException
Creates a DocumentBuilder to be used to parse DocBook XML documents.

Returns:
A DocumentBuilder instance.
Throws:
org.apache.maven.plugin.MojoExecutionException - If we cannot create an instance of the DocumentBuilder.

createTitleXPath

protected org.jaxen.XPath createTitleXPath()
                                    throws org.apache.maven.plugin.MojoExecutionException
Creates an instance of an XPath expression for picking the title from a document.

Returns:
An XPath expression to pick the title from a document.
Throws:
org.apache.maven.plugin.MojoExecutionException - If the XPath expression cannot be parsed.

createTransformerBuilder

protected TransformerBuilder createTransformerBuilder(URIResolver resolver)
Constructs the default TransformerBuilder.


executeTasks

protected void executeTasks(org.apache.tools.ant.Target antTasks,
                            org.apache.maven.project.MavenProject mavenProject)
                     throws org.apache.maven.plugin.MojoExecutionException
Throws:
org.apache.maven.plugin.MojoExecutionException

configure

protected abstract void configure(Transformer transformer)
Configure the Transformer by passing in some parameters.

Parameters:
transformer - The Transformer that needs to be configured.

getTargetDirectory

protected abstract File getTargetDirectory()
Returns the target directory in which all results should be placed.

Returns:
The target directory in which all results should be placed.

getSourceDirectory

protected abstract File getSourceDirectory()
Returns the source directory containing the source XML files.

Returns:
The source directory containing the source XML files.

getIncludes

protected abstract String[] getIncludes()
Returns the include patterns, as a comma-seperate collection of patterns.


getStylesheetURL

protected URL getStylesheetURL()
Returns the URL of the stylesheet. You can override this operation to return a URL pointing to a stylesheet residing on a location that can be adressed by a URL. By default, it will return a stylesheet that will be loaded from the classpath, using the resource name returned by getStylesheetLocation().

Returns:
The URL of the stylesheet.

getNonDefaultStylesheetURL

protected URL getNonDefaultStylesheetURL()
Returns the URL of the default stylesheet.

Returns:
The URL of the stylesheet.

getDefaultStylesheetURL

protected URL getDefaultStylesheetURL()
Returns the URL of the default stylesheet.

Returns:
The URL of the stylesheet.

getDefaultStylesheetLocation

protected abstract String getDefaultStylesheetLocation()
Returns the default stylesheet location within the root of the stylesheet distribution.

Returns:
The location of the directory containing the stylesheets.

getStylesheetLocation

protected abstract String getStylesheetLocation()
Returns the actual stylesheet location.

Returns:
The actual stylesheet location.

getTargetFileExtension

protected abstract String getTargetFileExtension()
Returns the extension of the target files, e.g. "html" for HTML files, etc.

Returns:
The extension of the target files.

setTargetFileExtension

protected abstract void setTargetFileExtension(String extension)
Sets the file extension, this can be usefull to override this value especially for multiple transformations plugins (like XML to FO to PDF).

Parameters:
extension - The file extension to set

getEntities

protected abstract List getEntities()
Returns a list of Entities


getCustomizationParameters

protected abstract List getCustomizationParameters()
A list of additional XSL parameters to give to the XSLT engine. These parameters overrides regular docbook ones as they are last configured.
For regular docbook parameters prefer the use of this plugin facilities offering named paramters.
These parameters feet well for custom properties you may have defined within your customization layer.

customizationParameters


getSystemProperties

protected abstract Properties getSystemProperties()
Returns the additional System Properties. JVM System Properties are copied back if no problem have occurred during the plugin process.

Returns:
The current forked System Properties.

getPreProcess

protected abstract org.apache.tools.ant.Target getPreProcess()
Returns the tasks that should be executed before the transformation.

Returns:
The tasks that should be executed before the transformation.

getPostProcess

protected abstract org.apache.tools.ant.Target getPostProcess()
Returns the tasks that should be executed after the transformation.

Returns:
The tasks that should be executed after the transformation.

getMavenProject

protected abstract org.apache.maven.project.MavenProject getMavenProject()
Returns a reference to the current project.

Returns:
A reference to the current project.

getArtifacts

protected abstract List getArtifacts()
Returns the plugin dependencies.

Returns:
The plugin dependencies.

getType

protected abstract String getType()
Returns the type of conversion.


convertStringToXsltParam

protected Object convertStringToXsltParam(String value)
Converts a String parameter to the type expected by the XSLT processor.


convertBooleanToXsltParam

protected Object convertBooleanToXsltParam(String value)
Converts a Boolean parameter to the type expected by the XSLT processor.


setProperty

protected void setProperty(String propertyname,
                           String value)
Sets the value of a property of this object using introspection.

Parameters:
propertyname - The field name
value - The value

getProperty

protected String getProperty(String propertyname)
Returns the value of a property of this object using introspection.

Parameters:
propertyname - The filed name
Returns:
The value


Copyright © 2006-2013. All Rights Reserved.