Class AbstractJSR223ScriptMacro<P extends JSR223ScriptMacroParameters>

    • Field Detail

      • BINDING_OUT

        @Deprecated
        public static final String BINDING_OUT
        Deprecated.
        not used since 10.1RC1 because the bug has been fixed in Groovy
        The name of the "out" binding..
        See Also:
        Constant Field Values
      • scriptEngineManager

        protected ScriptEngineManager scriptEngineManager
        The JSR223 Script Engine Manager we use to evaluate JSR223 scripts.
    • Constructor Detail

      • AbstractJSR223ScriptMacro

        public AbstractJSR223ScriptMacro​(String macroName)
        Parameters:
        macroName - the name of the macro (eg "groovy")
      • AbstractJSR223ScriptMacro

        public AbstractJSR223ScriptMacro​(String macroName,
                                         String macroDescription)
        Parameters:
        macroName - the name of the macro (eg "groovy")
        macroDescription - the text description of the macro.
      • AbstractJSR223ScriptMacro

        public AbstractJSR223ScriptMacro​(String macroName,
                                         String macroDescription,
                                         org.xwiki.rendering.macro.descriptor.ContentDescriptor contentDescriptor)
        Parameters:
        macroName - the name of the macro (eg "groovy")
        macroDescription - the text description of the macro.
        contentDescriptor - the description of the macro content.
      • AbstractJSR223ScriptMacro

        public AbstractJSR223ScriptMacro​(String macroName,
                                         String macroDescription,
                                         Class<? extends JSR223ScriptMacroParameters> parametersBeanClass)
        Parameters:
        macroName - the name of the macro (eg "groovy")
        macroDescription - the text description of the macro.
        parametersBeanClass - class of the parameters bean for this macro.
      • AbstractJSR223ScriptMacro

        public AbstractJSR223ScriptMacro​(String macroName,
                                         String macroDescription,
                                         org.xwiki.rendering.macro.descriptor.ContentDescriptor contentDescriptor,
                                         Class<? extends JSR223ScriptMacroParameters> parametersBeanClass)
        Parameters:
        macroName - the name of the macro (eg "groovy")
        macroDescription - the text description of the macro.
        contentDescriptor - the description of the macro content.
        parametersBeanClass - class of the parameters bean for this macro.
    • Method Detail

      • initialize

        public void initialize()
                        throws org.xwiki.component.phase.InitializationException
        Specified by:
        initialize in interface org.xwiki.component.phase.Initializable
        Overrides:
        initialize in class AbstractMacro<P extends JSR223ScriptMacroParameters>
        Throws:
        org.xwiki.component.phase.InitializationException
      • getScriptEngineName

        protected String getScriptEngineName​(P parameters,
                                             org.xwiki.rendering.transformation.MacroTransformationContext context)
        Method to overwrite to indicate the script engine name.
        Parameters:
        parameters - the macro parameters.
        context - the context of the macro transformation.
        Returns:
        the name of the script engine to use.
      • getScriptContext

        protected ScriptContext getScriptContext()
        Get the current ScriptContext and refresh it.
        Returns:
        the script context.
      • evaluateBlock

        protected List<org.xwiki.rendering.block.Block> evaluateBlock​(ScriptEngine engine,
                                                                      P parameters,
                                                                      String content,
                                                                      org.xwiki.rendering.transformation.MacroTransformationContext context)
                                                               throws ScriptException,
                                                                      MacroExecutionException
        Execute provided script and return Block based result.
        Parameters:
        engine - the script engine to use to evaluate the script.
        parameters - the macro parameters.
        content - the script to execute.
        context - the context of the macro transformation.
        Returns:
        the result of script execution.
        Throws:
        ScriptException - failed to evaluate script
        MacroExecutionException - failed to evaluate provided content.
      • eval

        protected Object eval​(String content,
                              ScriptEngine engine,
                              ScriptContext scriptContext)
                       throws ScriptException
        Execute the script.
        Parameters:
        content - the script to be executed by the script engine
        engine - the script engine
        scriptContext - the script context
        Returns:
        The value returned from the execution of the script.
        Throws:
        ScriptException - if an error occurrs in script. ScriptEngines should create and throw ScriptException wrappers for checked Exceptions thrown by underlying scripting implementations.
      • getCompiledScript

        protected CompiledScript getCompiledScript​(String content,
                                                   Compilable engine)
                                            throws ScriptException
        Return a compiled version of the provided script.
        Parameters:
        content - the script to compile.
        engine - the script engine.
        Returns:
        the compiled version of the script.
        Throws:
        ScriptException - failed to compile the script.