Package org.alfresco.repo.processor
Class ScriptServiceImpl
java.lang.Object
org.alfresco.repo.processor.ScriptServiceImpl
- All Implemented Interfaces:
ScriptService
Script service implementation
- Author:
- Kevin Roast, Roy Wetherall
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbuildCoreModel(Map<String, Object> inputMap) Add core data-model to provided MapbuildDefaultModel(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:protected ObjectExecute scriptprotected ObjectExecute scriptprotected Objectexecute(ScriptProcessor processor, ScriptLocation location, Map<String, Object> model) Execute scriptProcess a script against the supplied data model.executeScript(String scriptClasspath, Map<String, Object> model) Process a script against the supplied data model.Process a script against the supplied data model.executeScript(String engine, ScriptLocation location, Map<String, Object> model) Process a script against the supplied data model.Process a script against the supplied data model.executeScript(ScriptLocation location, Map<String, Object> model) Process a script against the supplied data model Uses the most approparite script engine or the default if none found.Process a script against the supplied data model.executeScriptString(String script, Map<String, Object> model) Process a script against the supplied data model.protected ObjectexecuteString(ScriptProcessor processor, String script, Map<String, Object> model) Execute script stringprotected ScriptProcessorgetScriptProcessor(String scriptLocation) Gets a script processor based on the script location stringprotected ScriptProcessorgetScriptProcessor(NodeRef scriptNode) Gets a scipt processor based on the node reference of a scriptprotected ScriptProcessorgetScriptProcessorImpl(String scriptFileName) Gets a script processor based on the scripts file nameprotected ScriptProcessorlookupScriptProcessor(String name) Helper method to lookup the script processor based on a namevoidregisterScriptProcessor(ScriptProcessor scriptProcessor) Register a script processorvoidReset all registered script processorsvoidsetDefaultScriptProcessor(String defaultScriptProcessor) Sets the name of the default script processorvoidsetNodeService(NodeService nodeService) Set the node servicevoidsetSysAdminParams(SysAdminParams sysAdminParams) Set the sysAdminParamsprotected org.alfresco.scripts.ScriptExceptiontranslateProcessingException(String scriptInfo, Throwable err)
-
Constructor Details
-
ScriptServiceImpl
public ScriptServiceImpl()
-
-
Method Details
-
setDefaultScriptProcessor
Sets the name of the default script processor- Parameters:
defaultScriptProcessor- the name of the default script processor
-
setNodeService
Set the node service- Parameters:
nodeService- the node service
-
setSysAdminParams
Set the sysAdminParams- Parameters:
sysAdminParams- the sysAdminParams
-
registerScriptProcessor
Register a script processor- Specified by:
registerScriptProcessorin interfaceScriptService- Parameters:
scriptProcessor- the script processor to register with the script service
-
resetScriptProcessors
public void resetScriptProcessors()Reset all registered script processors- Specified by:
resetScriptProcessorsin interfaceScriptService
-
executeScript
public Object executeScript(String scriptClasspath, Map<String, Object> model) throws org.alfresco.scripts.ScriptExceptionDescription copied from interface:ScriptServiceProcess a script against the supplied data model. Uses the most approparite script engine or the default if none found.- Specified by:
executeScriptin interfaceScriptService- 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:
org.alfresco.scripts.ScriptException- See Also:
-
executeScript
public Object executeScript(String engine, String scriptClasspath, Map<String, Object> model) throws org.alfresco.scripts.ScriptExceptionDescription copied from interface:ScriptServiceProcess a script against the supplied data model. Use the- Specified by:
executeScriptin interfaceScriptService- 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:
org.alfresco.scripts.ScriptException- See Also:
-
executeScript
public Object executeScript(NodeRef scriptRef, QName contentProp, Map<String, Object> model) throws org.alfresco.scripts.ScriptExceptionDescription copied from interface:ScriptServiceProcess a script against the supplied data model. Uses the most approparite script engine or the default if none found.- Specified by:
executeScriptin interfaceScriptService- 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:
org.alfresco.scripts.ScriptException- See Also:
-
executeScript
public Object executeScript(String engine, NodeRef scriptRef, QName contentProp, Map<String, Object> model) throws org.alfresco.scripts.ScriptExceptionDescription copied from interface:ScriptServiceProcess a script against the supplied data model.- Specified by:
executeScriptin interfaceScriptService- 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:
org.alfresco.scripts.ScriptException- See Also:
-
executeScript
public Object executeScript(ScriptLocation location, Map<String, Object> model) throws org.alfresco.scripts.ScriptExceptionDescription copied from interface:ScriptServiceProcess a script against the supplied data model Uses the most approparite script engine or the default if none found.- Specified by:
executeScriptin interfaceScriptService- Parameters:
location- 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:
org.alfresco.scripts.ScriptException- See Also:
-
executeScript
public Object executeScript(String engine, ScriptLocation location, Map<String, Object> model) throws org.alfresco.scripts.ScriptExceptionDescription copied from interface:ScriptServiceProcess a script against the supplied data model.- Specified by:
executeScriptin interfaceScriptService- Parameters:
engine- the script engine to uselocation- 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:
org.alfresco.scripts.ScriptException- See Also:
-
executeScriptString
public Object executeScriptString(String script, Map<String, Object> model) throws org.alfresco.scripts.ScriptExceptionDescription copied from interface:ScriptServiceProcess a script against the supplied data model. Uses the default script engine.- Specified by:
executeScriptStringin interfaceScriptService- 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:
org.alfresco.scripts.ScriptException- See Also:
-
executeScriptString
public Object executeScriptString(String engine, String script, Map<String, Object> model) throws org.alfresco.scripts.ScriptExceptionDescription copied from interface:ScriptServiceProcess a script against the supplied data model.- Specified by:
executeScriptStringin interfaceScriptService- 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:
org.alfresco.scripts.ScriptException- See Also:
-
execute
protected Object execute(ScriptProcessor processor, ScriptLocation location, Map<String, Object> model) Execute script- Parameters:
location- the location of the scriptmodel- context model- Returns:
- Object the result of the script
-
execute
protected Object execute(ScriptProcessor processor, NodeRef scriptRef, QName contentProp, Map<String, Object> model) Execute script- Parameters:
scriptRef- the script node referencecontentProp- the content property of the scriptmodel- the context model- Returns:
- Object the result of the script
-
execute
Execute script- Parameters:
location- the classpath string locating the scriptmodel- the context model- Returns:
- Object the result of the script
-
executeString
Execute script string- Parameters:
script- the script stringmodel- the context model- Returns:
- Object the result of the script
-
translateProcessingException
-
lookupScriptProcessor
Helper method to lookup the script processor based on a name- Parameters:
name- the name of the script processor- Returns:
- ScriptProcessor the script processor, default processor if no match found
-
getScriptProcessor
Gets a scipt processor based on the node reference of a script- Parameters:
scriptNode- the node reference of the script- Returns:
- ScriptProcessor the script processor
-
getScriptProcessor
Gets a script processor based on the script location string- Parameters:
scriptLocation- the script location- Returns:
- ScriptProcessor the script processor
-
getScriptProcessorImpl
Gets a script processor based on the scripts file name- Parameters:
scriptFileName- the scripts file name- Returns:
- ScriptProcessor the matching script processor
-
buildCoreModel
Description copied from interface:ScriptServiceAdd core data-model to provided Map- Specified by:
buildCoreModelin interfaceScriptService- Parameters:
inputMap- initial Map of global scope scriptable Node objects- See Also:
-
buildDefaultModel
public Map<String,Object> buildDefaultModel(NodeRef person, NodeRef companyHome, NodeRef userHome, NodeRef script, NodeRef document, NodeRef space) Description copied from interface:ScriptServiceCreate 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)- Specified by:
buildDefaultModelin interfaceScriptService- 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
- See Also:
-