@OpenApiAll
public class GroovyTool
extends com.nomagic.magicreport.engine.Tool
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 :
$groovy.eval("def foo() { return "Foo"; }")
Constructor and Description |
---|
GroovyTool()
Create a GroovyTool.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
eval(java.lang.String script)
Evaluate the specified script.
|
java.lang.Object |
eval(java.lang.String script,
java.util.Map<java.lang.String,java.lang.Object> bindingMap)
Evaluate the script using the set of bindings argument.
|
java.lang.Object |
eval(java.lang.String script,
java.lang.String bindingName,
java.lang.Object bindingObject)
Evaluate the script using the bindings argument.
|
java.lang.Object |
execute(java.lang.String fileName)
Execute a file as Groovy source.
|
java.lang.Object |
execute(java.lang.String fileName,
java.util.Map<java.lang.String,java.lang.Object> bindingMap)
Execute a file as Groovy source.
|
java.lang.Object |
execute(java.lang.String fileName,
java.lang.String bindingName,
java.lang.Object bindingObject)
Execute a file as Groovy source using the bindings argument.
|
clone, getContext, getProperties, getProperty, getProperty, notifyObservers, setContext, setProperties
public java.lang.Object eval(java.lang.String 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
script
- the script language source to be executed.ITool.VOID
if return value is
null
public java.lang.Object eval(java.lang.String script, java.lang.String bindingName, java.lang.Object bindingObject)
For example:
The output will be:
#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
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.ITool.VOID
if return value is
null
public java.lang.Object eval(java.lang.String script, java.util.Map<java.lang.String,java.lang.Object> bindingMap)
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 bar
The output will be:
$groovy.eval("'Name is ' + name1 + ' ' + name2;", {"name1":"foo","name2":"bar"})
Name is foo bar
script
- the script language source to be executed.bindingMap
- the key-value pairs for binding name and binding object.ITool.VOID
if return value is
null
public java.lang.Object execute(java.lang.String fileName)
For example:
Or
$groovy.execute("script.groovy")
$groovy.execute("c:/myfolder/script.groovy")
fileName
- the source of the script.ITool.VOID
if return value is
null
public java.lang.Object execute(java.lang.String fileName, java.lang.String bindingName, java.lang.Object bindingObject)
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.ITool.VOID
if return value is
null
public java.lang.Object execute(java.lang.String fileName, java.util.Map<java.lang.String,java.lang.Object> bindingMap)
fileName
- the source of the script.bindingMap
- the key-value pairs for binding name and binding object.ITool.VOID
if return value is
null