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
FieldsFields inherited from class org.alfresco.repo.processor.BaseProcessor
extension, name, processorExtensions, scriptService, services, templateService -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPre initializes two scope objects (one secure and one not) with the standard objects preinitialised.Execute scriptExecute scriptexecute(ScriptLocation location, Map<String, Object> model) Execute scriptexecuteString(String source, Map<String, Object> model) Execute script stringexecuteString(String source, Map<String, Object> model, boolean secure) Execute script stringprotected org.mozilla.javascript.ScriptableinitScope(org.mozilla.javascript.Context cx, boolean secure, boolean sealed) Initializes a scope for script execution.loadScriptResource(String resource) Load a script content from the specific resource path.voidreset()Reset the processor - such as clearing any internal caches etc.voidsetCleanScope(boolean cleanScope) voidsetCompile(boolean compile) voidsetMaxMemoryUsedInBytes(long maxMemoryUsedInBytes) voidsetMaxScriptExecutionSeconds(int maxScriptExecutionSeconds) voidsetMaxStackDepth(int maxStackDepth) voidsetObserverInstructionCount(int observerInstructionCount) voidsetOptimizationLevel(int optimizationLevel) voidsetShareSealedScopes(boolean shareSealedScopes) voidsetStorePath(String storePath) voidsetStoreUrl(String storeRef) Set the default store referenceMethods inherited from class org.alfresco.repo.processor.BaseProcessor
getExtension, getName, getProcessorExtensions, register, registerProcessorExtension, setExtension, setName, setScriptService, setServiceRegistry, setTemplateServiceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.alfresco.processor.Processor
getExtension, getName, registerProcessorExtension
-
Field Details
-
contextFactory
Custom context factory
-
-
Constructor Details
-
RhinoScriptProcessor
public RhinoScriptProcessor()
-
-
Method Details
-
setStoreUrl
Set the default store reference- Parameters:
storeRef- The default store reference
-
setStorePath
- Parameters:
storePath- The store path to set.
-
setCompile
public void setCompile(boolean compile) - Parameters:
compile- the compile flag to set
-
setOptimizationLevel
public void setOptimizationLevel(int optimizationLevel) - Parameters:
optimizationLevel- -1 interpretive mode, 0 no optimizations, 1-9 optimizations performed
-
setMaxScriptExecutionSeconds
public void setMaxScriptExecutionSeconds(int maxScriptExecutionSeconds) - Parameters:
maxScriptExecutionSeconds- the number of seconds a script is allowed to run
-
setMaxStackDepth
public void setMaxStackDepth(int maxStackDepth) - Parameters:
maxStackDepth- the number of call stack depth allowed
-
setMaxMemoryUsedInBytes
public void setMaxMemoryUsedInBytes(long maxMemoryUsedInBytes) - Parameters:
maxMemoryUsedInBytes- the number of memory a script can use
-
setObserverInstructionCount
public void setObserverInstructionCount(int observerInstructionCount) - Parameters:
observerInstructionCount- the number of instructions that will triggerContextFactory.observeInstructionCount(org.mozilla.javascript.Context, int)
-
setCleanScope
public void setCleanScope(boolean cleanScope) - Parameters:
cleanScope- true to enable scope cleaning at the end of each script execution - set to false to disable this feature.
-
reset
public void reset()Description copied from interface:ScriptProcessorReset the processor - such as clearing any internal caches etc.- Specified by:
resetin interfaceScriptProcessor- See Also:
-
execute
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:
-
execute
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:
-
execute
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:
-
executeString
Description copied from interface:ScriptProcessorExecute script string- Specified by:
executeStringin interfaceScriptProcessor- Parameters:
source- the script stringmodel- the context model- Returns:
- Object the result of the script
- See Also:
-
executeString
Description copied from interface:ScriptProcessorExecute script string- Specified by:
executeStringin interfaceScriptProcessor- Parameters:
source- the script stringmodel- the context modelsecure- the flag that indicates if string is considered secure to be executed, i.e., it will have access to the full execution context instead of being executed in a sandbox context- Returns:
- Object the result of the script
- See Also:
-
loadScriptResource
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
Pre 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:
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
-