helloWorld: function() { alert("Hello World!"); }and also properties, such as for example:
getLabel: function(identifier) { return document.getElementById(identifier).label; }Adding these elements is supported by the JSScriptable interface.
print(message)
, you must define the two following methods:public class MyScriptable extends AbstractJSScriptable { public void print(String message) { context.echo(message); } public String[] getFunctionProperties() { String[] array = { "print" }; return array; } }This will allow this kind of script:
helloWorld: function() { print("Hello World!"); }
ScriptableObject
and must implement the ScriptableExecutor interface, with only one method:JSScriptable
to the executorScriptableObject
, you must implement the getClassName()
method and return the simple name of the executor class. Alternatively, you can subclass the AbstractScriptableExecutor class which implements this method for youpublic Object jsGet_<property name>()
method in the executorpublic void jsSet_<property name>(Object value)
method in the executorpublic void jsFunction_<method name>(Object... params)
method in the executormyExample: function() { value = document.label; // example of a property getter document.label = value; // example of a property setter value = document.getName(); // example of a method applied on a property }
document
property, you must define the two following methods:public class MyScriptable extends AbstractJSScriptable { public String[] getObjectNames() { String[] array = { "document" }; return array; } public Class<? extends ScriptableObject> getExecutorClass() { return MyExecutor.class } }We could also add a
getDocumentName()
method to return the document name:public class MyScriptable extends AbstractJSScriptable { public String[] getObjectNames() { String[] array = { "document" }; return array; } public Class<? extends ScriptableObject> getExecutorClass() { return MyExecutor.class } public String getDocumentName() { return "TheName"; } }With the following executor class:
public class MyExecutor extends AbstractScriptableExecutor { private MyScriptable scriptable; public TheExecutor() { } public void setup(JSScriptable scriptable) { this.scriptable = (MyScriptable) scriptable; } public Object jsFunction_getName() { return scriptable.getDocumentName(); } }This will allow this kind of script:
myFunction: function() { return document.getName(); }
doSomething(int)
method can be provided by another script (which can even not be a Javascript script):myScrip: function() { value = doSomething(10); return value; }
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence