org.xwiki.rendering.macro.script
Class AbstractJSR223ScriptMacro<P extends JSR223ScriptMacroParameters>

java.lang.Object
  extended by org.xwiki.rendering.macro.AbstractMacro<P>
      extended by org.xwiki.rendering.macro.script.AbstractScriptMacro<P>
          extended by org.xwiki.rendering.macro.script.AbstractJSR223ScriptMacro<P>
Type Parameters:
P - the type of macro parameters bean.
All Implemented Interfaces:
Comparable<org.xwiki.rendering.macro.Macro<?>>, org.xwiki.component.phase.Initializable, org.xwiki.rendering.macro.Macro<P>, PrivilegedScriptMacro, ScriptMacro

public abstract class AbstractJSR223ScriptMacro<P extends JSR223ScriptMacroParameters>
extends AbstractScriptMacro<P>
implements PrivilegedScriptMacro

Base Class for script evaluation macros based on JSR223.

Since:
1.7M3
Version:
$Id: 98a4b77ab84e4884346bdc87fcca8fa0b180749b $

Field Summary
protected  ScriptEngineManager scriptEngineManager
          The JSR223 Script Engine Manager we use to evaluate JSR223 scripts.
 
Fields inherited from class org.xwiki.rendering.macro.script.AbstractScriptMacro
CONTENT_DESCRIPTION, documentAccessBridge, execution
 
Fields inherited from class org.xwiki.rendering.macro.AbstractMacro
beanManager, DEFAULT_CATEGORY_CONTENT, DEFAULT_CATEGORY_DEVELOPMENT, DEFAULT_CATEGORY_FORMATTING, DEFAULT_CATEGORY_NAVIGATION
 
Constructor Summary
AbstractJSR223ScriptMacro(String macroName)
           
AbstractJSR223ScriptMacro(String macroName, String macroDescription)
           
AbstractJSR223ScriptMacro(String macroName, String macroDescription, Class<? extends JSR223ScriptMacroParameters> parametersBeanClass)
           
AbstractJSR223ScriptMacro(String macroName, String macroDescription, org.xwiki.rendering.macro.descriptor.ContentDescriptor contentDescriptor)
           
AbstractJSR223ScriptMacro(String macroName, String macroDescription, org.xwiki.rendering.macro.descriptor.ContentDescriptor contentDescriptor, Class<? extends JSR223ScriptMacroParameters> parametersBeanClass)
           
 
Method Summary
protected  Object eval(String content, ScriptEngine engine, ScriptContext scriptContext)
          Execute the script.
protected  List<org.xwiki.rendering.block.Block> evaluateBlock(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context)
          Execute provided script and return Block based result.
protected  List<org.xwiki.rendering.block.Block> evaluateBlock(ScriptEngine engine, P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context)
          Execute provided script and return Block based result.
protected  CompiledScript getCompiledScript(String content, Compilable engine)
          Return a compiled version of the provided script.
protected  ScriptContext getScriptContext()
          Get the current ScriptContext and refresh it.
protected  String getScriptEngineName(P parameters, org.xwiki.rendering.transformation.MacroTransformationContext context)
          Method to overwrite to indicate the script engine name.
 void initialize()
           
 boolean supportsInlineMode()
           
 
Methods inherited from class org.xwiki.rendering.macro.script.AbstractScriptMacro
evaluate, evaluateString, execute, getComponentManager, parseScriptResult, parseSourceSyntax
 
Methods inherited from class org.xwiki.rendering.macro.AbstractMacro
compareTo, getDescriptor, getPriority, setDefaultCategory, setDescriptor, setPriority
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 org.xwiki.rendering.macro.AbstractMacro<P extends JSR223ScriptMacroParameters>
Throws:
org.xwiki.component.phase.InitializationException

supportsInlineMode

public boolean supportsInlineMode()
Specified by:
supportsInlineMode in interface org.xwiki.rendering.macro.Macro<P extends JSR223ScriptMacroParameters>

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(P parameters,
                                                              String content,
                                                              org.xwiki.rendering.transformation.MacroTransformationContext context)
                                                       throws org.xwiki.rendering.macro.MacroExecutionException
Description copied from class: AbstractScriptMacro
Execute provided script and return Block based result.

Overrides:
evaluateBlock in class AbstractScriptMacro<P extends JSR223ScriptMacroParameters>
Parameters:
parameters - the macro parameters.
content - the script to execute.
context - the context of the macro transformation.
Returns:
the result of script execution.
Throws:
org.xwiki.rendering.macro.MacroExecutionException - failed to evaluate provided content.

evaluateBlock

protected List<org.xwiki.rendering.block.Block> evaluateBlock(ScriptEngine engine,
                                                              P parameters,
                                                              String content,
                                                              org.xwiki.rendering.transformation.MacroTransformationContext context)
                                                       throws ScriptException,
                                                              org.xwiki.rendering.macro.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
org.xwiki.rendering.macro.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.


Copyright © 2004-2012 XWiki. All Rights Reserved.