Several extensions are bundled with the include macro that can be used to document interfaces, extract information from XML and properties or simply enrich content inside generated sites.
Most extensions are implemented as helper classes that are compatible with the "source-class" parameter. For simplified access, these helper classes define aliases that allow their invocation with a single Macro parameter using registered implementations of RequestParameterTransformer to implement aliasing.
A complete Usage & Parameter Reference of Bundled Extensions, can be found in the left hand navigation bar below the section Bundled Extensions.
Within the macro the following general operations happen after each other:
Transforming request parameters can be used to shorten macro calls by adding, removing or changing parameters of the macro call before any further processing is applied.
RequestParameterTransformer
defines an interface that may be implemented and registered via service loading
to plug parameter transformers that adjust macro parameters on the fly before any other operation is triggered.
Implementation:1 2 3 4 5 6 7 8 9 10 11 | package my. package ; public class MyRequestParameterTransformer implements RequestParameterTransformer { public void transformParameters(Map<String, Object> requestParams) { Object value = requestParams.get( "my-input-param" ); if (value != null ) { requestParams.put( "myText" , value); requestParams.put( "source" , "classpath:my-template.vm" ); } } } |
1 2 3 | META-INF/services/ org.tinyjee.maven.dim.spi.RequestParameterTransformer |
1 2 | my.package.MyRequestParameterTransformer |
VelocityConfigurator
defines an interface that may be implemented and registered via service loading
to customize the configuration of the velocity template engine and context before the templates are rendered.
Implementation:1 2 3 4 5 6 7 8 9 | package my. package ; public class MyVelocityConfigurator implements VelocityConfigurator { public void configureEngine(VelocityEngine engine) { engine.setProperty(VM_PERM_INLINE_LOCAL, true ); ... } ... } |
1 2 3 | META-INF/services/ org.tinyjee.maven.dim.spi.VelocityConfigurator |
1 2 | my.package.MyVelocityConfigurator |
BrushResolver
defines an interface that may be implemented and registered via service loading to register additional
javascript brushes (= language support) for the syntax highlighting library.
Implementation:1 2 3 4 5 6 7 8 9 10 | package my. package ; public class MyBrushResolver implements BrushResolver { public Collection<URL> resolveBrushes() { return Collections.singleton(getClass().getResource( "/my/package/my-brush.js" )); } public String detectBrushAlias(URL source, Map<Integer, List<String>> sourceContent) { return source.getPath().toLowerCase().endsWith( ".my-extension" ) ? "my-brush-alias" : null ; } } |
1 2 3 | META-INF/services/ org.tinyjee.maven.dim.sh.BrushResolver |
1 2 | my.package.MyBrushResolver |
SnippetSelector
defines an interface that may be implemented and registered via service loading
to add new snippet selection mechanisms.
Implementation:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | package my. package ; public class MySnippetSelector implements SnippetSelector { public String[] getExpressionPrefixes() { return new String[] { "my:" }; } public boolean canSelectSnippetsWith(String expression, URL contentUrl, Map<String, Object> macroParameters) { return expression.toLowerCase().startsWith( "my:" ); } public Iterator<Integer> selectSnippets(String expression, URL contentUrl, LineNumberReader content, Map<String, Object> macroParameters) throws IOException { List<Integer> output = new LinkedList<Integer>(); for (String line = content.readLine(); line != null ; line = content.readLine()) { if (... EXPRESSION MATCHES LINE ...) output.add(content.getLineNumber()); } return output.iterator(); } } |
1 2 3 | META-INF/services/ org.tinyjee.maven.dim.spi.SnippetSelector |
1 2 | my.package.MySnippetSelector |