Class JSScriptProcessor
- java.lang.Object
-
- org.springframework.extensions.webscripts.processor.BaseProcessor
-
- org.springframework.extensions.webscripts.processor.BaseRegisterableScriptProcessor
-
- org.springframework.extensions.webscripts.processor.AbstractScriptProcessor
-
- org.springframework.extensions.webscripts.processor.JSScriptProcessor
-
- All Implemented Interfaces:
java.util.EventListener,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationListener,Processor,ScriptResourceLoader,ScriptProcessor
public class JSScriptProcessor extends AbstractScriptProcessor implements ScriptResourceLoader
JS Script Processor for Surf Web Framework- Author:
- davidc, kevinr
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJSScriptProcessor.PresentationWrapFactoryWrap Factory for Rhino Script Engine
-
Field Summary
-
Fields inherited from class org.springframework.extensions.webscripts.processor.BaseProcessor
processorExtensions
-
-
Constructor Summary
Constructors Constructor Description JSScriptProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectexecuteScript(java.lang.String path, java.util.Map<java.lang.String,java.lang.Object> model)Execute scriptjava.lang.ObjectexecuteScript(ScriptContent location, java.util.Map<java.lang.String,java.lang.Object> model)Execute scriptScriptContentfindScript(java.lang.String path)Find a script at the specified path (within registered Web Script stores)java.lang.StringgetExtension()The file extension that the processor is associated with, null if none.java.lang.StringgetName()Get the name of the processorvoidinit()Inits the processorprotected voidinitProcessor()Inits the processor.protected org.mozilla.javascript.ScriptableinitScope(org.mozilla.javascript.Context cx, boolean secure, boolean sealed)Initializes a scope for script execution.protected booleanisDebugMode()java.lang.StringloadScriptResource(java.lang.String resource)Load a script content from the specific resource path.voidreset()Reset script cachevoidsetCompile(boolean compile)voidsetConfigService(org.springframework.extensions.config.ConfigService configService)Sets the config service.voidsetShareSealedScopes(boolean shareSealedScopes)java.lang.ObjectunwrapValue(java.lang.Object value)Unwrap value returned by script TODO: Remove this method when value conversion is truly hidden within script engine-
Methods inherited from class org.springframework.extensions.webscripts.processor.AbstractScriptProcessor
addProcessorModelExtensions, getScriptLoader, getSearchPath, initLoaders, register, setSearchPath
-
Methods inherited from class org.springframework.extensions.webscripts.processor.BaseRegisterableScriptProcessor
getScriptProcessorRegistry, onApplicationEvent, setApplicationContext, setScriptProcessorRegistry
-
Methods inherited from class org.springframework.extensions.webscripts.processor.BaseProcessor
registerProcessorExtension
-
-
-
-
Method Detail
-
setConfigService
public void setConfigService(org.springframework.extensions.config.ConfigService configService)
Sets the config service.- Parameters:
configService- The ConfigService
-
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.
-
getExtension
public java.lang.String getExtension()
Description copied from interface:ProcessorThe file extension that the processor is associated with, null if none.- Specified by:
getExtensionin interfaceProcessor- Returns:
- the extension
-
getName
public java.lang.String getName()
Description copied from interface:ProcessorGet the name of the processor
-
init
public void init()
Description copied from class:BaseRegisterableScriptProcessorInits the processor- Overrides:
initin classAbstractScriptProcessor
-
findScript
public ScriptContent findScript(java.lang.String path)
Description copied from interface:ScriptProcessorFind a script at the specified path (within registered Web Script stores)- Specified by:
findScriptin interfaceScriptProcessor- Parameters:
path- script path- Returns:
- script location (or null, if not found)
-
executeScript
public java.lang.Object executeScript(java.lang.String path, java.util.Map<java.lang.String,java.lang.Object> model)Description copied from interface:ScriptProcessorExecute script- Specified by:
executeScriptin interfaceScriptProcessor- Parameters:
path- script pathmodel- model- Returns:
- script result
-
executeScript
public java.lang.Object executeScript(ScriptContent location, java.util.Map<java.lang.String,java.lang.Object> model)
Description copied from interface:ScriptProcessorExecute script- Specified by:
executeScriptin interfaceScriptProcessor- Parameters:
location- script locationmodel- model- Returns:
- script result
-
loadScriptResource
public java.lang.String loadScriptResource(java.lang.String resource)
Load a script content from the specific resource path.- Specified by:
loadScriptResourcein interfaceScriptResourceLoader- Parameters:
resource- Script resource to load. Supports either classpath: prefix syntax or a resource path within the webscript stores.- Returns:
- the content from the resource, null if not recognised format
-
unwrapValue
public java.lang.Object unwrapValue(java.lang.Object value)
Description copied from interface:ScriptProcessorUnwrap value returned by script TODO: Remove this method when value conversion is truly hidden within script engine- Specified by:
unwrapValuein interfaceScriptProcessor- Parameters:
value- value to unwrap- Returns:
- unwrapped value
-
reset
public void reset()
Description copied from interface:ScriptProcessorReset script cache- Specified by:
resetin interfaceScriptProcessor
-
initProcessor
protected void initProcessor()
Inits the processor.
-
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
-
isDebugMode
protected boolean isDebugMode()
-
-