Interface ScriptService
-
- All Known Implementing Classes:
ScriptServiceImpl
public interface ScriptServiceScript Service.Provides an interface to services for executing a JavaScript engine script file against a Java object based scripting data-model.
The script file can either be in the repository (passed as NodeRef string) or on the classpath. Also a script String can be passed directly to the service via the executeScriptString() methods. Java objects are passed into the scripting engine and methods can be accessed directly from the script.
A script is executed within a single transaction, any modifications to nodes or properties that fail and cause a rollback which will rollback all repository modifications made by the script.
- Author:
- Kevin Roast
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidbuildCoreModel(Map<String,Object> inputMap)Add core data-model to provided MapMap<String,Object>buildDefaultModel(NodeRef person, NodeRef companyHome, NodeRef userHome, NodeRef script, NodeRef document, NodeRef space)Create the default data-model available to scripts as global scope level objects:ObjectexecuteScript(String engine, String scriptClasspath, Map<String,Object> model)Process a script against the supplied data model.ObjectexecuteScript(String scriptClasspath, Map<String,Object> model)Process a script against the supplied data model.ObjectexecuteScript(String engine, NodeRef scriptRef, QName contentProp, Map<String,Object> model)Process a script against the supplied data model.ObjectexecuteScript(String engine, ScriptLocation scriptLocation, Map<String,Object> model)Process a script against the supplied data model.ObjectexecuteScript(NodeRef scriptRef, QName contentProp, Map<String,Object> model)Process a script against the supplied data model.ObjectexecuteScript(ScriptLocation scriptLocation, Map<String,Object> model)Process a script against the supplied data model Uses the most approparite script engine or the default if none found.ObjectexecuteScriptString(String engine, String script, Map<String,Object> model)Process a script against the supplied data model.ObjectexecuteScriptString(String script, Map<String,Object> model)Process a script against the supplied data model.voidregisterScriptProcessor(ScriptProcessor scriptProcessor)Registers a script processor with the script servicevoidresetScriptProcessors()Reset all registered script processors
-
-
-
Method Detail
-
executeScript
@Auditable(parameters={"scriptClasspath","model"}) Object executeScript(String scriptClasspath, Map<String,Object> model) throws ScriptException
Process a script against the supplied data model. Uses the most approparite script engine or the default if none found.- Parameters:
scriptClasspath- Script location as qualified classpath namemodel- Object model to process script against- Returns:
- output of the script (may be null or any valid wrapped JavaScript object)
- Throws:
ScriptException
-
executeScript
@Auditable(parameters={"engine","scriptClasspath","model"}) Object executeScript(String engine, String scriptClasspath, Map<String,Object> model) throws ScriptException
Process a script against the supplied data model. Use the- Parameters:
engine- the script engine to usescriptClasspath- Script location as qualified classpath namemodel- Object model to process script against- Returns:
- output of the script (may be null or any valid wrapped JavaScript object)
- Throws:
ScriptException
-
executeScript
@Auditable(parameters={"scriptRef","contentProp","model"}) Object executeScript(NodeRef scriptRef, QName contentProp, Map<String,Object> model) throws ScriptException
Process a script against the supplied data model. Uses the most approparite script engine or the default if none found.- Parameters:
scriptRef- Script NodeRef locationcontentProp- QName of the property on the node that contains the content, null can be passed to indicate the default property of 'cm:content'model- Object model to process script against- Returns:
- output of the script (may be null or any valid wrapped JavaScript object)
- Throws:
ScriptException
-
executeScript
@Auditable(parameters={"engine","scriptRef","contentProp","model"}) Object executeScript(String engine, NodeRef scriptRef, QName contentProp, Map<String,Object> model) throws ScriptException
Process a script against the supplied data model.- Parameters:
engine- the script engine to usescriptRef- Script NodeRef locationcontentProp- QName of the property on the node that contains the content, null can be passed to indicate the default property of 'cm:content'model- Object model to process script against- Returns:
- output of the script (may be null or any valid wrapped JavaScript object)
- Throws:
ScriptException
-
executeScript
@Auditable(parameters={"scriptLocation","model"}) Object executeScript(ScriptLocation scriptLocation, Map<String,Object> model) throws ScriptException
Process a script against the supplied data model Uses the most approparite script engine or the default if none found.- Parameters:
scriptLocation- object representing the script locationmodel- Object model to process script against- Returns:
- output of the script (may be null or any other valid wrapped JavaScript object)
- Throws:
ScriptException
-
executeScript
@Auditable(parameters={"engine","scriptLocation","model"}) Object executeScript(String engine, ScriptLocation scriptLocation, Map<String,Object> model) throws ScriptException
Process a script against the supplied data model.- Parameters:
engine- the script engine to usescriptLocation- object representing the script locationmodel- Object model to process script against- Returns:
- output of the script (may be null or any other valid wrapped JavaScript object)
- Throws:
ScriptException
-
executeScriptString
@Auditable(parameters={"script","model"}) Object executeScriptString(String script, Map<String,Object> model) throws ScriptException
Process a script against the supplied data model. Uses the default script engine.- Parameters:
script- Script content as a String.model- Object model to process script against- Returns:
- output of the script (may be null or any valid wrapped JavaScript object)
- Throws:
ScriptException
-
executeScriptString
@Auditable(parameters={"engine","script","model"}) Object executeScriptString(String engine, String script, Map<String,Object> model) throws ScriptException
Process a script against the supplied data model.- Parameters:
engine- the script engine to usescript- Script content as a String.model- Object model to process script against- Returns:
- output of the script (may be null or any valid wrapped JavaScript object)
- Throws:
ScriptException
-
registerScriptProcessor
@Auditable(parameters="scriptProcessor") void registerScriptProcessor(ScriptProcessor scriptProcessor)
Registers a script processor with the script service- Parameters:
scriptProcessor- ScriptProcessor
-
resetScriptProcessors
@Auditable void resetScriptProcessors()
Reset all registered script processors
-
buildCoreModel
@Auditable(parameters="inputMap") void buildCoreModel(Map<String,Object> inputMap)
Add core data-model to provided Map- Parameters:
inputMap- initial Map of global scope scriptable Node objects
-
buildDefaultModel
@Auditable(parameters={"person","companyHome","userHome","script","document","document"}) Map<String,Object> buildDefaultModel(NodeRef person, NodeRef companyHome, NodeRef userHome, NodeRef script, NodeRef document, NodeRef space)
Create the default data-model available to scripts as global scope level objects:'companyhome' - the Company Home node
'userhome' - the current user home space node
'person' - the node representing the current user Person
'script' - the node representing the script itself (may not be available)
'document' - document context node (may not be available)
'space' - space context node (may not be available)- Parameters:
person- The current user Person NodecompanyHome- The CompanyHome refuserHome- The User home space refscript- Optional ref to the script itselfdocument- Optional ref to a document Nodespace- Optional ref to a space Node- Returns:
- A Map of global scope scriptable Node objects
-
-