Package org.alfresco.repo.processor
Class ScriptServiceImpl
- java.lang.Object
-
- org.alfresco.repo.processor.ScriptServiceImpl
-
- All Implemented Interfaces:
ScriptService
public class ScriptServiceImpl extends java.lang.Object implements ScriptService
Script service implementation- Author:
- Kevin Roast, Roy Wetherall
-
-
Constructor Summary
Constructors Constructor Description ScriptServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildCoreModel(java.util.Map<java.lang.String,java.lang.Object> inputMap)Add core data-model to provided Mapjava.util.Map<java.lang.String,java.lang.Object>buildDefaultModel(org.alfresco.service.cmr.repository.NodeRef person, org.alfresco.service.cmr.repository.NodeRef companyHome, org.alfresco.service.cmr.repository.NodeRef userHome, org.alfresco.service.cmr.repository.NodeRef script, org.alfresco.service.cmr.repository.NodeRef document, org.alfresco.service.cmr.repository.NodeRef space)Create the default data-model available to scripts as global scope level objects:protected java.lang.Objectexecute(ScriptProcessor processor, java.lang.String location, java.util.Map<java.lang.String,java.lang.Object> model)Execute scriptprotected java.lang.Objectexecute(ScriptProcessor processor, org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,java.lang.Object> model)Execute scriptprotected java.lang.Objectexecute(ScriptProcessor processor, ScriptLocation location, java.util.Map<java.lang.String,java.lang.Object> model)Execute scriptjava.lang.ObjectexecuteScript(java.lang.String engine, java.lang.String scriptClasspath, java.util.Map<java.lang.String,java.lang.Object> model)Process a script against the supplied data model.java.lang.ObjectexecuteScript(java.lang.String scriptClasspath, java.util.Map<java.lang.String,java.lang.Object> model)Process a script against the supplied data model.java.lang.ObjectexecuteScript(java.lang.String engine, org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,java.lang.Object> model)Process a script against the supplied data model.java.lang.ObjectexecuteScript(java.lang.String engine, ScriptLocation location, java.util.Map<java.lang.String,java.lang.Object> model)Process a script against the supplied data model.java.lang.ObjectexecuteScript(org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,java.lang.Object> model)Process a script against the supplied data model.java.lang.ObjectexecuteScript(ScriptLocation location, java.util.Map<java.lang.String,java.lang.Object> model)Process a script against the supplied data model Uses the most approparite script engine or the default if none found.java.lang.ObjectexecuteScriptString(java.lang.String engine, java.lang.String script, java.util.Map<java.lang.String,java.lang.Object> model)Process a script against the supplied data model.java.lang.ObjectexecuteScriptString(java.lang.String script, java.util.Map<java.lang.String,java.lang.Object> model)Process a script against the supplied data model.protected java.lang.ObjectexecuteString(ScriptProcessor processor, java.lang.String script, java.util.Map<java.lang.String,java.lang.Object> model)Execute script stringprotected ScriptProcessorgetScriptProcessor(java.lang.String scriptLocation)Gets a script processor based on the script location stringprotected ScriptProcessorgetScriptProcessor(org.alfresco.service.cmr.repository.NodeRef scriptNode)Gets a scipt processor based on the node reference of a scriptprotected ScriptProcessorgetScriptProcessorImpl(java.lang.String scriptFileName)Gets a script processor based on the scripts file nameprotected ScriptProcessorlookupScriptProcessor(java.lang.String name)Helper method to lookup the script processor based on a namevoidregisterScriptProcessor(ScriptProcessor scriptProcessor)Register a script processorvoidresetScriptProcessors()Reset all registered script processorsvoidsetDefaultScriptProcessor(java.lang.String defaultScriptProcessor)Sets the name of the default script processorvoidsetNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)Set the node servicevoidsetSysAdminParams(SysAdminParams sysAdminParams)Set the sysAdminParamsprotected org.alfresco.scripts.ScriptExceptiontranslateProcessingException(java.lang.String scriptInfo, java.lang.Throwable err)
-
-
-
Method Detail
-
setDefaultScriptProcessor
public void setDefaultScriptProcessor(java.lang.String defaultScriptProcessor)
Sets the name of the default script processor- Parameters:
defaultScriptProcessor- the name of the default script processor
-
setNodeService
public void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)
Set the node service- Parameters:
nodeService- the node service
-
setSysAdminParams
public void setSysAdminParams(SysAdminParams sysAdminParams)
Set the sysAdminParams- Parameters:
sysAdminParams- the sysAdminParams
-
registerScriptProcessor
public void registerScriptProcessor(ScriptProcessor scriptProcessor)
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 java.lang.Object executeScript(java.lang.String scriptClasspath, java.util.Map<java.lang.String,java.lang.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:
ScriptService.executeScript(java.lang.String, java.util.Map)
-
executeScript
public java.lang.Object executeScript(java.lang.String engine, java.lang.String scriptClasspath, java.util.Map<java.lang.String,java.lang.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:
ScriptService.executeScript(java.lang.String, java.lang.String, java.util.Map)
-
executeScript
public java.lang.Object executeScript(org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,java.lang.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:
ScriptService.executeScript(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.util.Map)
-
executeScript
public java.lang.Object executeScript(java.lang.String engine, org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,java.lang.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:
ScriptService.executeScript(java.lang.String, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.util.Map)
-
executeScript
public java.lang.Object executeScript(ScriptLocation location, java.util.Map<java.lang.String,java.lang.Object> model) throws org.alfresco.scripts.ScriptException
Description 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:
ScriptService.executeScript(org.alfresco.service.cmr.repository.ScriptLocation, java.util.Map)
-
executeScript
public java.lang.Object executeScript(java.lang.String engine, ScriptLocation location, java.util.Map<java.lang.String,java.lang.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:
ScriptService.executeScript(java.lang.String, org.alfresco.service.cmr.repository.ScriptLocation, java.util.Map)
-
executeScriptString
public java.lang.Object executeScriptString(java.lang.String script, java.util.Map<java.lang.String,java.lang.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:
ScriptService.executeScriptString(java.lang.String, java.util.Map)
-
executeScriptString
public java.lang.Object executeScriptString(java.lang.String engine, java.lang.String script, java.util.Map<java.lang.String,java.lang.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:
ScriptService.executeScriptString(java.lang.String, java.util.Map)
-
execute
protected java.lang.Object execute(ScriptProcessor processor, ScriptLocation location, java.util.Map<java.lang.String,java.lang.Object> model)
Execute script- Parameters:
location- the location of the scriptmodel- context model- Returns:
- Object the result of the script
-
execute
protected java.lang.Object execute(ScriptProcessor processor, org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,java.lang.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
protected java.lang.Object execute(ScriptProcessor processor, java.lang.String location, java.util.Map<java.lang.String,java.lang.Object> model)
Execute script- Parameters:
location- the classpath string locating the scriptmodel- the context model- Returns:
- Object the result of the script
-
executeString
protected java.lang.Object executeString(ScriptProcessor processor, java.lang.String script, java.util.Map<java.lang.String,java.lang.Object> model)
Execute script string- Parameters:
script- the script stringmodel- the context model- Returns:
- Object the result of the script
-
translateProcessingException
protected org.alfresco.scripts.ScriptException translateProcessingException(java.lang.String scriptInfo, java.lang.Throwable err)
-
lookupScriptProcessor
protected ScriptProcessor lookupScriptProcessor(java.lang.String name)
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
protected ScriptProcessor getScriptProcessor(org.alfresco.service.cmr.repository.NodeRef scriptNode)
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
protected ScriptProcessor getScriptProcessor(java.lang.String scriptLocation)
Gets a script processor based on the script location string- Parameters:
scriptLocation- the script location- Returns:
- ScriptProcessor the script processor
-
getScriptProcessorImpl
protected ScriptProcessor getScriptProcessorImpl(java.lang.String scriptFileName)
Gets a script processor based on the scripts file name- Parameters:
scriptFileName- the scripts file name- Returns:
- ScriptProcessor the matching script processor
-
buildCoreModel
public void buildCoreModel(java.util.Map<java.lang.String,java.lang.Object> inputMap)
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:
ScriptService.buildCoreModel(java.util.Map)
-
buildDefaultModel
public java.util.Map<java.lang.String,java.lang.Object> buildDefaultModel(org.alfresco.service.cmr.repository.NodeRef person, org.alfresco.service.cmr.repository.NodeRef companyHome, org.alfresco.service.cmr.repository.NodeRef userHome, org.alfresco.service.cmr.repository.NodeRef script, org.alfresco.service.cmr.repository.NodeRef document, org.alfresco.service.cmr.repository.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:
ScriptService.buildDefaultModel(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
-
-