Package org.alfresco.repo.jscript
Class RhinoScriptProcessor
- java.lang.Object
-
- org.alfresco.repo.processor.BaseProcessor
-
- org.alfresco.repo.jscript.RhinoScriptProcessor
-
- All Implemented Interfaces:
org.alfresco.processor.Processor,org.alfresco.scripts.ScriptResourceLoader,ScriptProcessor,org.springframework.beans.factory.InitializingBean
public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcessor, org.alfresco.scripts.ScriptResourceLoader, org.springframework.beans.factory.InitializingBean
Implementation of the ScriptProcessor using the Rhino JavaScript library.- Author:
- Kevin Roast
-
-
Field Summary
-
Fields inherited from class org.alfresco.repo.processor.BaseProcessor
extension, name, processorExtensions, scriptService, services, templateService
-
-
Constructor Summary
Constructors Constructor Description RhinoScriptProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Pre initializes two scope objects (one secure and one not) with the standard objects preinitialised.java.lang.Objectexecute(java.lang.String location, java.util.Map<java.lang.String,java.lang.Object> model)Execute scriptjava.lang.Objectexecute(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,java.lang.Object> model)Execute scriptjava.lang.Objectexecute(ScriptLocation location, java.util.Map<java.lang.String,java.lang.Object> model)Execute scriptjava.lang.ObjectexecuteString(java.lang.String source, java.util.Map<java.lang.String,java.lang.Object> model)Execute script stringprotected org.mozilla.javascript.ScriptableinitScope(org.mozilla.javascript.Context cx, boolean secure, boolean sealed)Initializes a scope for script execution.java.lang.StringloadScriptResource(java.lang.String resource)Load a script content from the specific resource path.voidreset()Reset the processor - such as clearing any internal caches etc.voidsetCompile(boolean compile)voidsetShareSealedScopes(boolean shareSealedScopes)voidsetStorePath(java.lang.String storePath)voidsetStoreUrl(java.lang.String storeRef)Set the default store reference-
Methods inherited from class org.alfresco.repo.processor.BaseProcessor
getExtension, getName, getProcessorExtensions, register, registerProcessorExtension, setExtension, setName, setScriptService, setServiceRegistry, setTemplateService
-
-
-
-
Method Detail
-
setStoreUrl
public void setStoreUrl(java.lang.String storeRef)
Set the default store reference- Parameters:
storeRef- The default store reference
-
setStorePath
public void setStorePath(java.lang.String storePath)
- Parameters:
storePath- The store path to set.
-
setCompile
public void setCompile(boolean compile)
- Parameters:
compile- the compile flag to set
-
setShareSealedScopes
public void setShareSealedScopes(boolean shareSealedScopes)
- Parameters:
shareSealedScopes- true to allow sharing of sealed scopes between script executions - set to false to disable this feature and ensure that a new scope is created for each executed script.
-
reset
public void reset()
Description copied from interface:ScriptProcessorReset the processor - such as clearing any internal caches etc.- Specified by:
resetin interfaceScriptProcessor- See Also:
ScriptProcessor.reset()
-
execute
public java.lang.Object execute(ScriptLocation location, java.util.Map<java.lang.String,java.lang.Object> model)
Description copied from interface:ScriptProcessorExecute script- Specified by:
executein interfaceScriptProcessor- Parameters:
location- the location of the scriptmodel- context model- Returns:
- Object the result of the script
- See Also:
ScriptProcessor.execute(org.alfresco.service.cmr.repository.ScriptLocation, java.util.Map)
-
execute
public java.lang.Object execute(java.lang.String location, java.util.Map<java.lang.String,java.lang.Object> model)Description copied from interface:ScriptProcessorExecute script- Specified by:
executein interfaceScriptProcessor- Parameters:
location- the classpath string locating the scriptmodel- the context model- Returns:
- Object the result of the script
- See Also:
ScriptProcessor.execute(java.lang.String, java.util.Map)
-
execute
public java.lang.Object execute(org.alfresco.service.cmr.repository.NodeRef nodeRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,java.lang.Object> model)Description copied from interface:ScriptProcessorExecute script- Specified by:
executein interfaceScriptProcessor- Parameters:
nodeRef- the script node referencecontentProp- the content property of the scriptmodel- the context model- Returns:
- Object the result of the script
- See Also:
ScriptProcessor.execute(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.util.Map)
-
executeString
public java.lang.Object executeString(java.lang.String source, java.util.Map<java.lang.String,java.lang.Object> model)Description copied from interface:ScriptProcessorExecute script string- Specified by:
executeStringin interfaceScriptProcessor- Parameters:
source- the script stringmodel- the context model- Returns:
- Obejct the result of the script
- See Also:
ScriptProcessor.executeString(java.lang.String, java.util.Map)
-
loadScriptResource
public java.lang.String loadScriptResource(java.lang.String resource)
Load a script content from the specific resource path.- Specified by:
loadScriptResourcein interfaceorg.alfresco.scripts.ScriptResourceLoader- Parameters:
resource- Resources can be of the form:classpath:alfresco/includeme.js workspace://SpacesStore/6f73de1b-d3b4-11db-80cb-112e6c2ea048 /Company Home/Data Dictionary/Scripts/includeme.js
- Returns:
- the content from the resource, null if not recognised format
- Throws:
org.alfresco.error.AlfrescoRuntimeException- on any IO or ContentIO error
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.ExceptionPre initializes two scope objects (one secure and one not) with the standard objects preinitialised. This saves on very expensive calls to reinitialize a new scope on every web script execution. See http://www.mozilla.org/rhino/scopes.html- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception- See Also:
InitializingBean.afterPropertiesSet()
-
initScope
protected org.mozilla.javascript.Scriptable initScope(org.mozilla.javascript.Context cx, boolean secure, boolean sealed)Initializes a scope for script execution. The easiest way to embed Rhino is just to create a new scope this way whenever you need one. However, initStandardObjects() is an expensive method to call and it allocates a fair amount of memory.- Parameters:
cx- the thread execution contextsecure- Do we consider the script secure? Whenfalsethis ensures the script may not access insecure java.* libraries or import any other classes for direct access - only the configured root host objects will be available to the script writer.sealed- Should the scope be sealed, making it immutable? This should betrueif a scope is to be reused.- Returns:
- the scope object
-
-