Class ScriptServiceImpl

  • All Implemented Interfaces:
    ScriptService

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

      • ScriptServiceImpl

        public ScriptServiceImpl()
    • Method Detail

      • 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​(org.alfresco.service.cmr.repository.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
      • 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:
        ScriptService.executeScript(java.lang.String, java.util.Map)
      • executeScript

        public Object executeScript​(org.alfresco.service.cmr.repository.NodeRef scriptRef,
                                    org.alfresco.service.namespace.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:
        ScriptService.executeScript(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, java.util.Map)
      • execute

        protected Object execute​(ScriptProcessor processor,
                                 ScriptLocation location,
                                 Map<String,​Object> model)
        Execute script
        Parameters:
        location - the location of the script
        model - context model
        Returns:
        Object the result of the script
      • execute

        protected Object execute​(ScriptProcessor processor,
                                 org.alfresco.service.cmr.repository.NodeRef scriptRef,
                                 org.alfresco.service.namespace.QName contentProp,
                                 Map<String,​Object> model)
        Execute script
        Parameters:
        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:
        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)
        Execute script string
        Parameters:
        script - the script string
        model - the context model
        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​(org.alfresco.service.cmr.repository.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