Class ScriptInvoker

  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<String,Object>
          extended by org.tinyjee.maven.dim.extensions.ScriptInvoker
All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>

public class ScriptInvoker
extends HashMap<String,Object>

ScriptInvoker is a 'source-class' compatible helper class providing a runtime environment that allows to load and execute script code using the JSR-223 interface (scripting for java).

Scripts can provide input for velocity templates or they can produce content directly. When invoked, this extension first populates all given macro parameters within the script context, evaluates the script and copies any changes or newly allocated variables back into the original parameters map. When an additional source was specified these resulting parameters are available in the template via $paramName.
Any text output that is produced by scripts is set into "source-content" and is displayed when no source is given.

The following global variables are exposed in the script context, in addition to the standard template parameters:

This extension is only useful when JSR-223 is available. Starting from Java 6, JavaScript is the only script engine that is available by default. Adding other script engines to the dependency set of module or site-plugin enables scripting languages like: Groovy, Ruby, Python and others that offer integration with JSR-223.


or when using the alias:


Juergen_Kellerer, 2011-10-15
See Also:
Serialized Form

Nested Class Summary
static class ScriptInvoker.AliasHandler
          Implements the "PARAM_ALIAS" alias functionality.
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Field Summary
static String PARAM_ALIAS
          Defines a shortcut for the request properties 'source-class' and 'script'.
static String PARAM_SCRIPT
          Sets the URL or local path to the script file to load and evaluate.
Constructor Summary
ScriptInvoker(File baseDir, Map<String,Object> requestParams)
          Constructs a new Script Invoker.
Method Summary
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
equals, hashCode

Field Detail


public static final String PARAM_ALIAS
Defines a shortcut for the request properties 'source-class' and 'script'.

If this parameter is present inside the request parameters list, the system will effectively behave as if 'source-class' and 'script' where set separately.

See Also:
Constant Field Values


public static final String PARAM_SCRIPT
Sets the URL or local path to the script file to load and evaluate.

The specified file is resolved in exactly the same way as when using the parameter "source" (see Macro reference).


See Also:
Constant Field Values
Constructor Detail


public ScriptInvoker(File baseDir,
                     Map<String,Object> requestParams)
              throws Exception
Constructs a new Script Invoker.

baseDir - the base dir to of the maven module.
requestParams - the request params of the macro call.
Exception - In case of loading or transforming fails.