Class AbstractScriptMacro<P extends ScriptMacroParameters>

Type Parameters:
P - the type of macro parameters bean.
All Implemented Interfaces:
Comparable<Macro<?>>, org.xwiki.component.phase.Initializable, Macro<P>, ScriptMacro, SignableMacro
Direct Known Subclasses:
AbstractJSR223ScriptMacro

public abstract class AbstractScriptMacro<P extends ScriptMacroParameters> extends AbstractSignableMacro<P> implements ScriptMacro
Base Class for script evaluation macros.

It is not obvious to see how macro execution works just from looking at the code. A lot of checking and initialization is done in listeners to the ScriptEvaluatingEvent and ScriptEvaluatedEvent. E.g. the check for programming rights for JSR223 scripts, check for nested script macros and selecting the right class loader is done there.

Since:
1.7M3
Version:
$Id: 0f083196f362d8af0eb79b415394565e026aba91 $
  • Field Details

    • CONTENT_DESCRIPTION

      protected static final String CONTENT_DESCRIPTION
      The default description of the script macro content.
      See Also:
    • documentAccessBridge

      @Inject @Deprecated protected DocumentAccessBridge documentAccessBridge
      Deprecated.
      since 2.5M1 (not used any more)
      Used to find if the current document's author has programming rights.
    • execution

      @Inject protected org.xwiki.context.Execution execution
      Used by subclasses.
  • Constructor Details

    • AbstractScriptMacro

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

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

      public AbstractScriptMacro(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.
    • AbstractScriptMacro

      public AbstractScriptMacro(String macroName, String macroDescription, Class<? extends ScriptMacroParameters> 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.
    • AbstractScriptMacro

      public AbstractScriptMacro(String macroName, String macroDescription, org.xwiki.rendering.macro.descriptor.ContentDescriptor contentDescriptor, Class<? extends ScriptMacroParameters> 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 Details

    • execute

      public List<org.xwiki.rendering.block.Block> execute(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context) throws MacroExecutionException
      Specified by:
      execute in interface Macro<P extends ScriptMacroParameters>
      Throws:
      MacroExecutionException
    • parseScriptResult

      protected List<org.xwiki.rendering.block.Block> parseScriptResult(String content, P parameters, org.xwiki.rendering.transformation.MacroTransformationContext context) throws MacroExecutionException
      Convert script result as a Block list.
      Parameters:
      content - the script result to parse.
      parameters - the macro parameters.
      context - the context of the macro transformation.
      Returns:
      the Blocks.
      Throws:
      MacroExecutionException - Failed to find source parser.
      Since:
      2.1M1
    • evaluate

      @Deprecated protected String evaluate(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context) throws MacroExecutionException
      Execute provided script.
      Parameters:
      parameters - the macro parameters.
      content - the script to execute.
      context - the context of the macro transformation.
      Returns:
      the result of script execution.
      Throws:
      MacroExecutionException - failed to evaluate provided content.
    • evaluateString

      protected String evaluateString(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context) throws MacroExecutionException
      Execute provided script and return String based result.
      Parameters:
      parameters - the macro parameters.
      content - the script to execute.
      context - the context of the macro transformation.
      Returns:
      the result of script execution.
      Throws:
      MacroExecutionException - failed to evaluate provided content.
      Since:
      2.4M2
    • evaluateBlock

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

      protected List<org.xwiki.rendering.block.Block> parseSourceSyntax(String content, org.xwiki.rendering.transformation.MacroTransformationContext context) throws MacroExecutionException
      Parse provided content with the parser of the current wiki syntax.
      Parameters:
      content - the content to parse.
      context - the context of the macro transformation.
      Returns:
      the result of the parsing.
      Throws:
      MacroExecutionException - failed to parse content