Date: Thu, 28 Mar 2024 11:05:11 +0100 (CET) Message-ID: <509944830.146.1711620311750@nm-docs> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_145_1254192195.1711620311750" ------=_Part_145_1254192195.1711620311750 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
eval(String script)
This method will evaluate a Groovy code from a string and return the res= ult.
$groovy= .eval("println 'Hello World!'")
eval(String script, String bindingName, Object bindingObject)
This method will evaluate a Groovy code with a single binding object and= specified binding name. The code will be evaluated from a string. The bind= ing name will be used as the name for this object.
#foreac= h ($c in $Class) $groovy.eval("println classname", "classname", $c.name) #end
eval(String script, Map bindingMap)
This method will evaluate a Groovy code with a set of binding arguments = (a name and an object). The code will be evaluated from a string. The bindi= ng map consists of key-value pairs for the binding name and the binding obj= ect.
#set ($= dict =3D $map.createHashMap()) #set ($void =3D $dict.put("first", "foo")) #set ($void =3D $dict.put("last", "bar")) $groovy.eval("println first + last", $dict)
Or
$groovy= .eval("println first + ' ' + last", {"first":"foo", "last":"bar"})
The second code contains curly brackets; '{' and '}' characters, which a= re not allowed to be used in any RTF template. For the RTF template, use the first code instead.
execute(String filename)
This method will execute a Groovy file. The 'filename' parameter refers = to a name of the Groovy file, an absolute path to the Groovy file, or a rel= ative path starting from the template to the Groovy file.
$groovy= .execute("filename.groovy")
If the Groovy file contains Groovy functions, you can recall the functio= ns by using 'eval()' methods.
$groovy= .execute('filename.groovy') $groovy.eval("new groovy().functionname()")
execute(String filename, String bindingName, Object bindingObjec= t)
This method will execute a Groovy file with a single binding object and = specified binding name. The 'filename' parameter refers to a name of the Gr= oovy file, an absolute path to the Groovy file, or a relative path starting= from the template to the Groovy file. The binding name will be used as the= name for this object.
File filename.groovy
"Class = name is " + $c.name
The template code
#foreac= h ($c in $Class) $groovy.execute("filename.groovy", 'c', $c) #end
execute(String filename, Map bindingMap)
This method will execute a Groovy file with a set of binding arguments (= a name and an object). The 'filename' parameter refers to a name of th= e Groovy file, an absolute path to the Groovy file, or a relative path star= ting from the template to the Groovy file. The binding map consists of key-= value pairs for the binding name and the binding object.
File filename.groovy
first += " " + last
The template code
#set ($= dict =3D $map.createHashMap()) #set ($void =3D $dict.put("first", "foo")) #set ($void =3D $dict.put("last", "bar")) $groovy.execute("filename.groovy", $dict)