org.tinyjee.maven.dim
Class IncludeMacro

java.lang.Object
  extended by org.apache.maven.doxia.macro.AbstractMacro
      extended by org.tinyjee.maven.dim.IncludeMacro
All Implemented Interfaces:
org.apache.maven.doxia.logging.LogEnabled, Macro, org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable

public class IncludeMacro
extends AbstractMacro
implements org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable

Implements a more feature rich alternative to the bundled "Snippet" macro.

Version:
1.0
Author:
Juergen_Kellerer, 2010-09-03

Field Summary
static String RESOURCES_FOLDER_NAME
          Specifies the folder name of the folder where resources are put.
static String VELOCITY_TEMPLATE_EXTENSION
          Specifies the extension used to detect velocity templates.
 
Fields inherited from interface org.apache.maven.doxia.macro.Macro
EOL, ROLE
 
Constructor Summary
IncludeMacro()
           
 
Method Summary
 void contextualize(org.codehaus.plexus.context.Context context)
           
 void execute(Sink sink, MacroRequest request)
          
protected  Map<String,String> extractTextParameters(Map requestParameters)
          Extracts all text only parameters from the given map of request parameters.
protected  File findSiteAttachedIncludesDirectory(File basePath, Map<String,String> textParameters)
          Finds the directory to use for attaching file includes to the site.
protected  File findSiteSourceDirectory(File baseDir, Map<String,String> params)
          Finds the directory where the site sources are located.
protected  Source findSource(File basePath, Map<String,String> textParameters)
          Finds the source implementation given the provided input.
protected  URL findSourceURL(File basePath, Map<String,String> parameters)
          Attempts to find the URL that locates the source to include.
protected  Parser getContentParser(URL source, Map<String,String> params)
          Returns a content parser for the given source or 'null' if not no parser exists.
 CodeHighlighter getHighlighter()
           
protected  org.apache.maven.doxia.logging.Log getLogger()
          Is a helper method to retrieve a Doxia logger using reflection (to be compatible with earlier versions of Doxia).
protected  void processRawContent(Source source, SortedMap<Integer,List<String>> snippets, Sink sink)
          Sends raw text to the sink.
protected  void processSource(Map<String,String> textParameters, File basePath, Source source, Sink sink)
          Processes the given source to the Sink.
 
Methods inherited from class org.apache.maven.doxia.macro.AbstractMacro
enableLogging, getAttributesFromMap, getLog, required
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCES_FOLDER_NAME

public static final String RESOURCES_FOLDER_NAME
Specifies the folder name of the folder where resources are put.

See Also:
Constant Field Values

VELOCITY_TEMPLATE_EXTENSION

public static final String VELOCITY_TEMPLATE_EXTENSION
Specifies the extension used to detect velocity templates.

See Also:
Constant Field Values
Constructor Detail

IncludeMacro

public IncludeMacro()
Method Detail

getHighlighter

public CodeHighlighter getHighlighter()

contextualize

public void contextualize(org.codehaus.plexus.context.Context context)
                   throws org.codehaus.plexus.context.ContextException
Specified by:
contextualize in interface org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable
Throws:
org.codehaus.plexus.context.ContextException

execute

public void execute(Sink sink,
                    MacroRequest request)
             throws MacroExecutionException

Specified by:
execute in interface Macro
Throws:
MacroExecutionException

findSource

protected Source findSource(File basePath,
                            Map<String,String> textParameters)
                     throws MacroExecutionException
Finds the source implementation given the provided input.

Parameters:
basePath - the base path the macro operates on.
textParameters - the given parameters.
Returns:
the source as resolved by the input parameters or 'null' if no source was specified by the given input.
Throws:
MacroExecutionException - in case of the given input parameters were invalid.

findSourceURL

protected URL findSourceURL(File basePath,
                            Map<String,String> parameters)
                     throws MacroExecutionException
Attempts to find the URL that locates the source to include.

Parameters:
basePath - the base path to resolve files against.
parameters - the given macro parameters.
Returns:
a URL pointing to the source to include or 'null' if a source was not specified.
Throws:
MacroExecutionException - In case of a source was specified but not found.

processSource

protected void processSource(Map<String,String> textParameters,
                             File basePath,
                             Source source,
                             Sink sink)
                      throws MacroExecutionException
Processes the given source to the Sink.

Parameters:
textParameters - a text-only version of the request params.
basePath - the module's base path.
source - the effective source.
sink - the sink to write the output to.
Throws:
MacroExecutionException - in case of the processing failed.

processRawContent

protected void processRawContent(Source source,
                                 SortedMap<Integer,List<String>> snippets,
                                 Sink sink)
                          throws IOException
Sends raw text to the sink.

Parameters:
source - the source to process.
snippets - optional snippet selection.
sink - the sink to write the raw content to.
Throws:
IOException - in case of writing failed.

findSiteAttachedIncludesDirectory

protected File findSiteAttachedIncludesDirectory(File basePath,
                                                 Map<String,String> textParameters)
Finds the directory to use for attaching file includes to the site.

Parameters:
basePath - the current project's base path.
textParameters - any given macro parameters that may influence the selection process.
Returns:
A path to place CSS, Script and arbitrary attached content.

findSiteSourceDirectory

protected File findSiteSourceDirectory(File baseDir,
                                       Map<String,String> params)
Finds the directory where the site sources are located.

Parameters:
baseDir - the base directory ot the module.
params - the parameters of the macro request.
Returns:
the directory where the site sources are located.

extractTextParameters

protected Map<String,String> extractTextParameters(Map requestParameters)
Extracts all text only parameters from the given map of request parameters.

Parameters:
requestParameters - the request parameters.
Returns:
A map containing only strings.

getContentParser

protected Parser getContentParser(URL source,
                                  Map<String,String> params)
Returns a content parser for the given source or 'null' if not no parser exists.

Parameters:
source - the source url to retrieve the parser for (can be 'null').
params - the request params.
Returns:
a content parser for the given source or 'null' if not no parser exists.

getLogger

protected org.apache.maven.doxia.logging.Log getLogger()
Is a helper method to retrieve a Doxia logger using reflection (to be compatible with earlier versions of Doxia).

Returns:
a Doxia logger.