Class ScriptServiceImpl

  • All Implemented Interfaces:
    ScriptService

    public class ScriptServiceImpl
    extends java.lang.Object
    implements ScriptService
    Script service implementation
    Author:
    Kevin Roast, Roy Wetherall
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void buildCoreModel​(java.util.Map<java.lang.String,​java.lang.Object> inputMap)
      Add core data-model to provided Map
      java.util.Map<java.lang.String,​java.lang.Object> buildDefaultModel​(org.alfresco.service.cmr.repository.NodeRef person, org.alfresco.service.cmr.repository.NodeRef companyHome, org.alfresco.service.cmr.repository.NodeRef userHome, org.alfresco.service.cmr.repository.NodeRef script, org.alfresco.service.cmr.repository.NodeRef document, org.alfresco.service.cmr.repository.NodeRef space)
      Create the default data-model available to scripts as global scope level objects:
      protected java.lang.Object execute​(ScriptProcessor processor, java.lang.String location, java.util.Map<java.lang.String,​java.lang.Object> model)
      Execute script
      protected java.lang.Object execute​(ScriptProcessor processor, org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,​java.lang.Object> model)
      Execute script
      protected java.lang.Object execute​(ScriptProcessor processor, ScriptLocation location, java.util.Map<java.lang.String,​java.lang.Object> model)
      Execute script
      java.lang.Object executeScript​(java.lang.String engine, java.lang.String scriptClasspath, java.util.Map<java.lang.String,​java.lang.Object> model)
      Process a script against the supplied data model.
      java.lang.Object executeScript​(java.lang.String scriptClasspath, java.util.Map<java.lang.String,​java.lang.Object> model)
      Process a script against the supplied data model.
      java.lang.Object executeScript​(java.lang.String engine, org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,​java.lang.Object> model)
      Process a script against the supplied data model.
      java.lang.Object executeScript​(java.lang.String engine, ScriptLocation location, java.util.Map<java.lang.String,​java.lang.Object> model)
      Process a script against the supplied data model.
      java.lang.Object executeScript​(org.alfresco.service.cmr.repository.NodeRef scriptRef, org.alfresco.service.namespace.QName contentProp, java.util.Map<java.lang.String,​java.lang.Object> model)
      Process a script against the supplied data model.
      java.lang.Object executeScript​(ScriptLocation location, java.util.Map<java.lang.String,​java.lang.Object> model)
      Process a script against the supplied data model Uses the most approparite script engine or the default if none found.
      java.lang.Object executeScriptString​(java.lang.String engine, java.lang.String script, java.util.Map<java.lang.String,​java.lang.Object> model)
      Process a script against the supplied data model.
      java.lang.Object executeScriptString​(java.lang.String script, java.util.Map<java.lang.String,​java.lang.Object> model)
      Process a script against the supplied data model.
      protected java.lang.Object executeString​(ScriptProcessor processor, java.lang.String script, java.util.Map<java.lang.String,​java.lang.Object> model)
      Execute script string
      protected ScriptProcessor getScriptProcessor​(java.lang.String scriptLocation)
      Gets a script processor based on the script location string
      protected ScriptProcessor getScriptProcessor​(org.alfresco.service.cmr.repository.NodeRef scriptNode)
      Gets a scipt processor based on the node reference of a script
      protected ScriptProcessor getScriptProcessorImpl​(java.lang.String scriptFileName)
      Gets a script processor based on the scripts file name
      protected ScriptProcessor lookupScriptProcessor​(java.lang.String name)
      Helper method to lookup the script processor based on a name
      void registerScriptProcessor​(ScriptProcessor scriptProcessor)
      Register a script processor
      void resetScriptProcessors()
      Reset all registered script processors
      void setDefaultScriptProcessor​(java.lang.String defaultScriptProcessor)
      Sets the name of the default script processor
      void setNodeService​(org.alfresco.service.cmr.repository.NodeService nodeService)
      Set the node service
      void setSysAdminParams​(SysAdminParams sysAdminParams)
      Set the sysAdminParams
      protected org.alfresco.scripts.ScriptException translateProcessingException​(java.lang.String scriptInfo, java.lang.Throwable err)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ScriptServiceImpl

        public ScriptServiceImpl()
    • Method Detail

      • setDefaultScriptProcessor

        public void setDefaultScriptProcessor​(java.lang.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 java.lang.Object executeScript​(java.lang.String scriptClasspath,
                                              java.util.Map<java.lang.String,​java.lang.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 java.lang.Object executeScript​(java.lang.String engine,
                                              java.lang.String scriptClasspath,
                                              java.util.Map<java.lang.String,​java.lang.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:
        ScriptService.executeScript(java.lang.String, java.lang.String, java.util.Map)
      • executeScript

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

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

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

        public java.lang.Object executeScriptString​(java.lang.String script,
                                                    java.util.Map<java.lang.String,​java.lang.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:
        ScriptService.executeScriptString(java.lang.String, java.util.Map)
      • executeScriptString

        public java.lang.Object executeScriptString​(java.lang.String engine,
                                                    java.lang.String script,
                                                    java.util.Map<java.lang.String,​java.lang.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:
        ScriptService.executeScriptString(java.lang.String, java.util.Map)
      • execute

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

        protected java.lang.Object execute​(ScriptProcessor processor,
                                           org.alfresco.service.cmr.repository.NodeRef scriptRef,
                                           org.alfresco.service.namespace.QName contentProp,
                                           java.util.Map<java.lang.String,​java.lang.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 java.lang.Object execute​(ScriptProcessor processor,
                                           java.lang.String location,
                                           java.util.Map<java.lang.String,​java.lang.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 java.lang.Object executeString​(ScriptProcessor processor,
                                                 java.lang.String script,
                                                 java.util.Map<java.lang.String,​java.lang.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​(java.lang.String scriptInfo,
                                                                                    java.lang.Throwable err)
      • lookupScriptProcessor

        protected ScriptProcessor lookupScriptProcessor​(java.lang.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​(java.lang.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​(java.lang.String scriptFileName)
        Gets a script processor based on the scripts file name
        Parameters:
        scriptFileName - the scripts file name
        Returns:
        ScriptProcessor the matching script processor