Class JSScriptProcessor

All Implemented Interfaces:
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
  • Constructor Details

    • JSScriptProcessor

      public JSScriptProcessor()
  • Method Details

    • 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 String getExtension()
      Description copied from interface: Processor
      The file extension that the processor is associated with, null if none.
      Specified by:
      getExtension in interface Processor
      Returns:
      the extension
    • getName

      public String getName()
      Description copied from interface: Processor
      Get the name of the processor
      Specified by:
      getName in interface Processor
      Returns:
      the name of the processor
    • init

      public void init()
      Description copied from class: BaseRegisterableScriptProcessor
      Inits the processor
      Overrides:
      init in class AbstractScriptProcessor
    • findScript

      public ScriptContent findScript(String path)
      Description copied from interface: ScriptProcessor
      Find a script at the specified path (within registered Web Script stores)
      Specified by:
      findScript in interface ScriptProcessor
      Parameters:
      path - script path
      Returns:
      script location (or null, if not found)
    • executeScript

      public Object executeScript(String path, Map<String,Object> model)
      Description copied from interface: ScriptProcessor
      Execute script
      Specified by:
      executeScript in interface ScriptProcessor
      Parameters:
      path - script path
      model - model
      Returns:
      script result
    • executeScript

      public Object executeScript(ScriptContent location, Map<String,Object> model)
      Description copied from interface: ScriptProcessor
      Execute script
      Specified by:
      executeScript in interface ScriptProcessor
      Parameters:
      location - script location
      model - model
      Returns:
      script result
    • loadScriptResource

      public String loadScriptResource(String resource)
      Load a script content from the specific resource path.
      Specified by:
      loadScriptResource in interface ScriptResourceLoader
      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 Object unwrapValue(Object value)
      Description copied from interface: ScriptProcessor
      Unwrap value returned by script TODO: Remove this method when value conversion is truly hidden within script engine
      Specified by:
      unwrapValue in interface ScriptProcessor
      Parameters:
      value - value to unwrap
      Returns:
      unwrapped value
    • reset

      public void reset()
      Description copied from interface: ScriptProcessor
      Reset script cache
      Specified by:
      reset in interface ScriptProcessor
    • 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 context
      secure - Do we consider the script secure? When false this 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 be true if a scope is to be reused.
      Returns:
      the scope object
    • isDebugMode

      protected boolean isDebugMode()