org.alfresco.service.cmr.repository
Interface ScriptService

All Known Implementing Classes:
ScriptServiceImpl

public interface ScriptService

Script 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.


Method Summary
 void buildCoreModel(java.util.Map inputMap)
          Add core data-model to provided Map
 java.util.Map 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:
 java.lang.Object executeScript(org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map model)
          Process a script against the supplied data model.
 java.lang.Object executeScript(ScriptLocation scriptLocation, java.util.Map model)
          Process a script against the supplied data model Uses the most approparite script engine or the default if none found.
 java.lang.Object executeScript(java.lang.String scriptClasspath, java.util.Map model)
          Process a script against the supplied data model.
 java.lang.Object executeScript(java.lang.String engine, org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map model)
          Process a script against the supplied data model.
 java.lang.Object executeScript(java.lang.String engine, ScriptLocation scriptLocation, java.util.Map model)
          Process a script against the supplied data model.
 java.lang.Object executeScript(java.lang.String engine, java.lang.String scriptClasspath, java.util.Map model)
          Process a script against the supplied data model.
 java.lang.Object executeScriptString(java.lang.String script, java.util.Map model)
          Process a script against the supplied data model.
 java.lang.Object executeScriptString(java.lang.String engine, java.lang.String script, java.util.Map model)
          Process a script against the supplied data model.
 void registerScriptProcessor(ScriptProcessor scriptProcessor)
          Registers a script processor with the script service
 void resetScriptProcessors()
          Reset all registered script processors
 

Method Detail

executeScript

@Auditable(parameters={"scriptClasspath", "model"})
java.lang.Object executeScript(java.lang.String scriptClasspath,
                                         java.util.Map model)
                               throws org.alfresco.scripts.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 name
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

executeScript

@Auditable(parameters={"engine", "scriptClasspath", "model"})
java.lang.Object executeScript(java.lang.String engine,
                                         java.lang.String scriptClasspath,
                                         java.util.Map model)
                               throws org.alfresco.scripts.ScriptException
Process a script against the supplied data model. Use the

Parameters:
engine - the script engine to use
scriptClasspath - Script location as qualified classpath name
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

executeScript

@Auditable(parameters={"scriptRef", "contentProp", "model"})
java.lang.Object executeScript(org.alfresco.service.cmr.repository.NodeRef scriptRef,
                                         org.alfresco.service.namespace.QName contentProp,
                                         java.util.Map model)
                               throws org.alfresco.scripts.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 location
contentProp - 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

executeScript

@Auditable(parameters={"engine", "scriptRef", "contentProp", "model"})
java.lang.Object executeScript(java.lang.String engine,
                                         org.alfresco.service.cmr.repository.NodeRef scriptRef,
                                         org.alfresco.service.namespace.QName contentProp,
                                         java.util.Map model)
                               throws org.alfresco.scripts.ScriptException
Process a script against the supplied data model.

Parameters:
engine - the script engine to use
scriptRef - Script NodeRef location
contentProp - 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

executeScript

@Auditable(parameters={"scriptLocation", "model"})
java.lang.Object executeScript(ScriptLocation scriptLocation,
                                         java.util.Map model)
                               throws org.alfresco.scripts.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 location
model - 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

executeScript

@Auditable(parameters={"engine", "scriptLocation", "model"})
java.lang.Object executeScript(java.lang.String engine,
                                         ScriptLocation scriptLocation,
                                         java.util.Map model)
                               throws org.alfresco.scripts.ScriptException
Process a script against the supplied data model.

Parameters:
engine - the script engine to use
scriptLocation - object representing the script location
model - 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

executeScriptString

@Auditable(parameters={"script", "model"})
java.lang.Object executeScriptString(java.lang.String script,
                                               java.util.Map model)
                                     throws org.alfresco.scripts.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:
org.alfresco.scripts.ScriptException

executeScriptString

@Auditable(parameters={"engine", "script", "model"})
java.lang.Object executeScriptString(java.lang.String engine,
                                               java.lang.String script,
                                               java.util.Map model)
                                     throws org.alfresco.scripts.ScriptException
Process a script against the supplied data model.

Parameters:
engine - the script engine to use
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

registerScriptProcessor

@Auditable(parameters="scriptProcessor")
void registerScriptProcessor(ScriptProcessor scriptProcessor)
Registers a script processor with the script service

Parameters:
scriptProcessor -

resetScriptProcessors

@Auditable
void resetScriptProcessors()
Reset all registered script processors


buildCoreModel

@Auditable(parameters="inputMap")
void buildCoreModel(java.util.Map 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"})
java.util.Map 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:

'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 Node
companyHome - The CompanyHome ref
userHome - The User home space ref
script - Optional ref to the script itself
document - Optional ref to a document Node
space - Optional ref to a space Node
resolver - Image resolver to resolve icon images etc.
Returns:
A Map of global scope scriptable Node objects


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.