Class GroovyTool
- All Implemented Interfaces:
ITool,IVariable,Serializable,Cloneable
Example:
The output will be:
#import ('groovy', 'com.nomagic.reportwizard.tools.script.GroovyTool')
#foreach ($class in $Class)
$groovy.eval("'Class name is ' + c.getName();", "c", $class)
#end
Class name is A
Class name is B
Class name is C
Example:
Groovy file "Text.groovy"Template file
def toCap(word) {
println 'toCap $word'
return word[0].toUpperCase() + word[1..-1]
}
If the $Class contains class name 'foo' and 'bar'. The output will be:
$groovy.execute("Text.groovy")
#foreach ($c in $Class)
$groovy.eval('new Text().toCap('+$c.name+')');
#end
Foo
Bar
All implicit variables such as $Class or $sorter will be automatically imported into JS Script with the same
variable name Example:
def getSupplier()
{
def supplierList = [];
for (var i=0; i<$Dependency.size(); i++)
{
var dependency = $Dependency.get(i);
supplierList.add(dependency.getSupplier());
}
return supplierList;
}
Limitation :
- Curly braces character '{' and '}' cannot be used in eval() function in RTF file. The curly braces are
special characters use by RTF syntax. When you want to evaluate the Groovy function, you should put the
function on separate groovy file.
For example: this statement will not be executed in RTF template. The curly braces are prohibited.$groovy.eval("def foo() { return "Foo"; }")
- Since:
- Mar 16, 2010
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.nomagic.magicreport.engine.ITool
ITool.HTMLString, ITool.RetainedString, ITool.Void -
Field Summary
Fields inherited from class com.nomagic.magicreport.engine.Tool
context, properties -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEvaluate the specified script.Evaluate the script using the bindings argument.Evaluate the script using the set of bindings argument.Execute a file as Groovy source.Execute a file as Groovy source using the bindings argument.Execute a file as Groovy source.voidsetLoaderMode(int loaderMode) voidsetShowError(boolean showError) Methods inherited from class com.nomagic.magicreport.engine.Tool
clone, getContext, getProperties, getProperty, getProperty, notifyObservers, setContext, setPropertiesMethods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, setChanged
-
Constructor Details
-
GroovyTool
public GroovyTool()Create a GroovyTool.
-
-
Method Details
-
setShowError
public void setShowError(boolean showError) -
setLoaderMode
public void setLoaderMode(int loaderMode) -
eval
Evaluate the specified script.For example:
The output will be:$groovy.eval("println 'Hello World!'; x = 123; return x * 10")
[on message view][on output report]Hello World!1230- Parameters:
script- the script language source to be executed.- Returns:
- the value returned from the execution of the script or
ITool.VOIDif return value isnull
-
eval
Evaluate the script using the bindings argument.For example:
The output will be:#foreach ($class in $Class) $groovy.eval("'Class name is ' + c.getName();", "c", $class) #endClass name is A Class name is B Class name is C- Parameters:
script- the script language source to be executed.bindingName- the name being used with binding object.bindingObject- the bindings of attribute object to be used for script execution.- Returns:
- the value returned from the execution of the script or
ITool.VOIDif return value isnull
-
eval
Evaluate the script using the set of bindings argument. The binding map consists of key-value pairs for binding name and binding object.For example:
The output will be:#set ($map = $map.createHashMap()) #set ($void = $map.put("name1", "foo")) #set ($void = $map.put("name2", "bar")) $groovy.eval("'Name is ' + name1 + ' ' + name2;", $map)For example:Name is foo barThe output will be:$groovy.eval("'Name is ' + name1 + ' ' + name2;", {"name1":"foo","name2":"bar"})Name is foo bar- Parameters:
script- the script language source to be executed.bindingMap- the key-value pairs for binding name and binding object.- Returns:
- the value returned from the execution of the script or
ITool.VOIDif return value isnull
-
execute
Execute a file as Groovy source. All characters of the reader are consumed.For example:
Or$groovy.execute("script.groovy")$groovy.execute("c:/myfolder/script.groovy")- Parameters:
fileName- the source of the script.- Returns:
- the value returned from the execution of the script or
ITool.VOIDif return value isnull
-
execute
Execute a file as Groovy source using the bindings argument. All characters from the file are consumed.- Parameters:
fileName- the source of the script.bindingName- the name being used with binding object.bindingObject- the bindings of attribute object to be used for script execution.- Returns:
- the value returned from the execution of the script or
ITool.VOIDif return value isnull
-
execute
Execute a file as Groovy source. The binding map consists of key-value pairs for binding name and binding object. All characters from the file are consumed.- Parameters:
fileName- the source of the script.bindingMap- the key-value pairs for binding name and binding object.- Returns:
- the value returned from the execution of the script or
ITool.VOIDif return value isnull
-