@OpenApiAll
public class RubyScriptTool
extends com.nomagic.magicreport.engine.Tool
Example:
The output will be:
#import ('ruby', 'com.nomagic.reportwizard.tools.script.RubyScriptTool')
#foreach ($class in $Class)
$ruby.eval('"Class name is " + c.name', 'c', $class)
#end
Class name is A
Class name is B
Class name is C
Example:
Ruby file "String.rb"
Template file
def deCamelCase(str)
return str.gsub!(/(.)([A-Z])/,'\1 \2')
end
If the $Class contains class name
$ruby.execute("String.rb")
#foreach ($c in $Class)
$ruby.eval('deCamelCase($c.name)')
#end
setName
and isEqualNode
. The output
will be:
set Name
is Equal Node
All implicit variables such as $Class or $sorter will be automatically imported into Ruby Script with the same
variable name Example:
def supplierList
result = [];
$Dependency.each do |item|
result << item.supplier
end
return result;
end
Limitation :
Modifier and Type | Field and Description |
---|---|
static int |
SINGLETON_SCOPE
This model uses a well known Singleton pattern, and the only one instance of a local context will exist on
JVM.
|
static int |
THREADSAFE_SCOPE
Script's parsings and evaluations should be safely performed on a multi-threaded environment such as Servlet
container.
|
Constructor and Description |
---|
RubyScriptTool()
Create a Ruby Script Engine.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Called to inform this engine is no longer use and that it should destroy any resources that it has
allocated.
|
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 Ruby Script source.
|
java.lang.Object |
execute(java.lang.String fileName,
java.util.Map<java.lang.String,java.lang.Object> bindingMap)
Execute a file as Ruby Script source.
|
java.lang.Object |
execute(java.lang.String fileName,
java.lang.String bindingName,
java.lang.Object bindingObject)
Execute a file as Ruby Script source using the bindings argument.
|
void |
init(int scope)
Initialize Ruby Script engine.
|
clone, getContext, getProperties, getProperty, getProperty, notifyObservers, setContext, setProperties
public static final int SINGLETON_SCOPE
public static final int THREADSAFE_SCOPE
public RubyScriptTool()
public void init(int scope)
THREADSAFE_SCOPE
)scope
- define scope of attributes.public java.lang.Object eval(java.lang.String script) throws javax.script.ScriptException
script
- the script language source to be executed.javax.script.ScriptException
- when evaluation errorpublic java.lang.Object eval(java.lang.String script, java.lang.String bindingName, java.lang.Object bindingObject) throws javax.script.ScriptException
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.javax.script.ScriptException
- when evaluation errorpublic java.lang.Object eval(java.lang.String script, java.util.Map<java.lang.String,java.lang.Object> bindingMap) throws javax.script.ScriptException
script
- the script language source to be executed.bindingMap
- the key-value pairs for binding name and binding object.javax.script.ScriptException
- when evaluation errorpublic java.lang.Object execute(java.lang.String fileName) throws java.io.FileNotFoundException, javax.script.ScriptException
For example:
Or
evaluator.execute("script.rb")
evaluator.execute("c:/myfolder/script.rb")
fileName
- the source of the script.java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file, or for
some other reason cannot be opened for reading.javax.script.ScriptException
- when evaluation errorpublic java.lang.Object execute(java.lang.String fileName, java.lang.String bindingName, java.lang.Object bindingObject) throws java.io.FileNotFoundException, javax.script.ScriptException
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.java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file, or for
some other reason cannot be opened for reading.javax.script.ScriptException
- when evaluation errorpublic java.lang.Object execute(java.lang.String fileName, java.util.Map<java.lang.String,java.lang.Object> bindingMap) throws java.io.FileNotFoundException, javax.script.ScriptException
fileName
- the source of the script.bindingMap
- the key-value pairs for binding name and binding object.java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file, or for
some other reason cannot be opened for reading.javax.script.ScriptException
- when evaluation errorpublic void destroy()