Package org.apache.sling.api.scripting
Interface SlingScript
- 
@ConsumerType public interface SlingScript
TheSlingScriptdefines the API for objects which encapsulate a script. To evaluate a script prepare aSlingBindingsinstance of variables used as global variables to the script and call theeval(SlingBindings)method.You can obtain scripts by resolving a script resource through
ResourceResolver.resolve(String)and then trying to adapt the resource to a script by callingAdaptable.adaptTo(Class). 
- 
- 
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Objectcall(@NotNull SlingBindings props, @NotNull java.lang.String method, java.lang.Object... args)Evaluates this script using the bound variables as global variables to the script and then calls the given method with the arguments.java.lang.Objecteval(@NotNull SlingBindings props)Evaluates this script using the bound variables as global variables to the script.@NotNull ResourcegetScriptResource()Returns the Resource providing the script source code. 
 - 
 
- 
- 
Method Detail
- 
getScriptResource
@NotNull @NotNull Resource getScriptResource()
Returns the Resource providing the script source code.- Returns:
 - The script resource.
 
 
- 
eval
java.lang.Object eval(@NotNull @NotNull SlingBindings props)Evaluates this script using the bound variables as global variables to the script.- Parameters:
 props- TheSlingBindingsproviding the bound variables for evaluating the script. Any bound variables must conform to the requirements of theSlingBindingspredefined variables set.- Returns:
 - The value returned by the script.
 - Throws:
 ScriptEvaluationException- If an error occurs executing the script or preparing the script execution. The cause of the evaluation exception is available as the exception cause.
 
- 
call
java.lang.Object call(@NotNull @NotNull SlingBindings props, @NotNull @NotNull java.lang.String method, java.lang.Object... args)Evaluates this script using the bound variables as global variables to the script and then calls the given method with the arguments.- Parameters:
 props- TheSlingBindingsproviding the bound variables for evaluating the script. Any bound variables must conform to the requirements of theSlingBindingspredefined variables set.method- The name of the method to call.args- The arguments for the method call.- Returns:
 - The value returned by the method from the script.
 - Throws:
 ScriptEvaluationException- If an error occurs executing the script or preparing the script execution. The cause of the evaluation exception is available as the exception cause.
 
 - 
 
 -