Class ScriptServiceImpl

java.lang.Object
org.alfresco.repo.processor.ScriptServiceImpl
All Implemented Interfaces:
ScriptService

public class ScriptServiceImpl extends Object implements ScriptService
Script service implementation
Author:
Kevin Roast, Roy Wetherall
  • Constructor Details

    • ScriptServiceImpl

      public ScriptServiceImpl()
  • Method Details

    • setDefaultScriptProcessor

      public void setDefaultScriptProcessor(String defaultScriptProcessor)
      Sets the name of the default script processor
      Parameters:
      defaultScriptProcessor - the name of the default script processor
    • setNodeService

      public void setNodeService(NodeService nodeService)
      Set the node service
      Parameters:
      nodeService - the node service
    • setSysAdminParams

      public void setSysAdminParams(SysAdminParams sysAdminParams)
      Set the sysAdminParams
      Parameters:
      sysAdminParams - the sysAdminParams
    • registerScriptProcessor

      public void registerScriptProcessor(ScriptProcessor scriptProcessor)
      Register a script processor
      Specified by:
      registerScriptProcessor in interface ScriptService
      Parameters:
      scriptProcessor - the script processor to register with the script service
    • resetScriptProcessors

      public void resetScriptProcessors()
      Reset all registered script processors
      Specified by:
      resetScriptProcessors in interface ScriptService
    • executeScript

      public Object executeScript(String scriptClasspath, Map<String,Object> model) throws org.alfresco.scripts.ScriptException
      Description copied from interface: ScriptService
      Process a script against the supplied data model. Uses the most approparite script engine or the default if none found.
      Specified by:
      executeScript in interface ScriptService
      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
      See Also:
    • executeScript

      public Object executeScript(String engine, String scriptClasspath, Map<String,Object> model) throws org.alfresco.scripts.ScriptException
      Description copied from interface: ScriptService
      Process a script against the supplied data model. Use the
      Specified by:
      executeScript in interface ScriptService
      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
      See Also:
    • executeScript

      public Object executeScript(NodeRef scriptRef, QName contentProp, Map<String,Object> model) throws org.alfresco.scripts.ScriptException
      Description copied from interface: ScriptService
      Process a script against the supplied data model. Uses the most approparite script engine or the default if none found.
      Specified by:
      executeScript in interface ScriptService
      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
      See Also:
    • executeScript

      public Object executeScript(String engine, NodeRef scriptRef, QName contentProp, Map<String,Object> model) throws org.alfresco.scripts.ScriptException
      Description copied from interface: ScriptService
      Process a script against the supplied data model.
      Specified by:
      executeScript in interface ScriptService
      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
      See Also:
    • executeScript

      public Object executeScript(ScriptLocation location, Map<String,Object> model) throws org.alfresco.scripts.ScriptException
      Description copied from interface: ScriptService
      Process a script against the supplied data model Uses the most approparite script engine or the default if none found.
      Specified by:
      executeScript in interface ScriptService
      Parameters:
      location - 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
      See Also:
    • executeScript

      public Object executeScript(String engine, ScriptLocation location, Map<String,Object> model) throws org.alfresco.scripts.ScriptException
      Description copied from interface: ScriptService
      Process a script against the supplied data model.
      Specified by:
      executeScript in interface ScriptService
      Parameters:
      engine - the script engine to use
      location - 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
      See Also:
    • executeScriptString

      public Object executeScriptString(String script, Map<String,Object> model) throws org.alfresco.scripts.ScriptException
      Description copied from interface: ScriptService
      Process a script against the supplied data model. Uses the default script engine.
      Specified by:
      executeScriptString in interface ScriptService
      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
      See Also:
    • executeScriptString

      public Object executeScriptString(String script, Map<String,Object> model, boolean secure) throws org.alfresco.scripts.ScriptException
      Description copied from interface: ScriptService
      Process a script against the supplied data model. Uses the default script engine.
      Specified by:
      executeScriptString in interface ScriptService
      Parameters:
      script - Script content as a String.
      model - Object model to process script against
      secure - A flag indicating if string script is considered secure (e.g., if it comes from the classpath) If true it will have access to the full execution context, if false the script will be executed in a sandbox context (more restricted)
      Returns:
      output of the script (may be null or any valid wrapped JavaScript object)
      Throws:
      org.alfresco.scripts.ScriptException
      See Also:
    • executeScriptString

      public Object executeScriptString(String engine, String script, Map<String,Object> model) throws org.alfresco.scripts.ScriptException
      Description copied from interface: ScriptService
      Process a script against the supplied data model.
      Specified by:
      executeScriptString in interface ScriptService
      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
      See Also:
    • executeScriptString

      public Object executeScriptString(String engine, String script, Map<String,Object> model, boolean secure) throws org.alfresco.scripts.ScriptException
      Description copied from interface: ScriptService
      Process a script against the supplied data model.
      Specified by:
      executeScriptString in interface ScriptService
      Parameters:
      engine - the script engine to use
      script - Script content as a String.
      model - Object model to process script against
      secure - A flag indicating if string script is considered secure
      Returns:
      output of the script (may be null or any valid wrapped JavaScript object)
      Throws:
      org.alfresco.scripts.ScriptException
      See Also:
    • execute

      protected Object execute(ScriptProcessor processor, ScriptLocation location, Map<String,Object> model)
      Execute script
      Parameters:
      processor - the script processor that will be responsible for supplied script execution
      location - the location of the script
      model - context model
      Returns:
      Object the result of the script
    • execute

      protected Object execute(ScriptProcessor processor, NodeRef scriptRef, QName contentProp, Map<String,Object> model)
      Execute script
      Parameters:
      processor - the script processor that will be responsible for supplied script execution
      scriptRef - the script node reference
      contentProp - the content property of the script
      model - the context model
      Returns:
      Object the result of the script
    • execute

      protected Object execute(ScriptProcessor processor, String location, Map<String,Object> model)
      Execute script
      Parameters:
      processor - the script processor that will be responsible for supplied script execution
      location - the classpath string locating the script
      model - the context model
      Returns:
      Object the result of the script
    • executeString

      protected Object executeString(ScriptProcessor processor, String script, Map<String,Object> model, boolean secure)
      Execute script string
      Parameters:
      processor - the script processor that will be responsible for supplied script execution
      script - the script string
      model - the context model
      secure - the flag indicating if string script is considered secure (e.g., if it comes from classpath) if true it will have access to the full execution context, if false the script will be executed in a sandbox context
      Returns:
      Object the result of the script
    • translateProcessingException

      protected org.alfresco.scripts.ScriptException translateProcessingException(String scriptInfo, Throwable err)
    • lookupScriptProcessor

      protected ScriptProcessor lookupScriptProcessor(String name)
      Helper method to lookup the script processor based on a name
      Parameters:
      name - the name of the script processor
      Returns:
      ScriptProcessor the script processor, default processor if no match found
    • getScriptProcessor

      protected ScriptProcessor getScriptProcessor(NodeRef scriptNode)
      Gets a scipt processor based on the node reference of a script
      Parameters:
      scriptNode - the node reference of the script
      Returns:
      ScriptProcessor the script processor
    • getScriptProcessor

      protected ScriptProcessor getScriptProcessor(String scriptLocation)
      Gets a script processor based on the script location string
      Parameters:
      scriptLocation - the script location
      Returns:
      ScriptProcessor the script processor
    • getScriptProcessorImpl

      protected ScriptProcessor getScriptProcessorImpl(String scriptFileName)
      Gets a script processor based on the scripts file name
      Parameters:
      scriptFileName - the scripts file name
      Returns:
      ScriptProcessor the matching script processor
    • buildCoreModel

      public void buildCoreModel(Map<String,Object> inputMap)
      Description copied from interface: ScriptService
      Add core data-model to provided Map
      Specified by:
      buildCoreModel in interface ScriptService
      Parameters:
      inputMap - initial Map of global scope scriptable Node objects
      See Also:
    • buildDefaultModel

      public Map<String,Object> buildDefaultModel(NodeRef person, NodeRef companyHome, NodeRef userHome, NodeRef script, NodeRef document, NodeRef space)
      Description copied from interface: ScriptService
      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)

      Specified by:
      buildDefaultModel in interface ScriptService
      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
      Returns:
      A Map of global scope scriptable Node objects
      See Also: