Package org.xwiki.rendering.macro.script
Class AbstractScriptMacro<P extends ScriptMacroParameters>
java.lang.Object
org.xwiki.rendering.macro.AbstractMacro<P>
org.xwiki.rendering.macro.AbstractSignableMacro<P>
org.xwiki.rendering.macro.script.AbstractScriptMacro<P>
- 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 Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringThe default description of the script macro content.protected DocumentAccessBridgeDeprecated.since 2.5M1 (not used any more)protected org.xwiki.context.ExecutionUsed by subclasses.Fields inherited from class org.xwiki.rendering.macro.AbstractMacro
beanManager, DEFAULT_CATEGORY_CONTENT, DEFAULT_CATEGORY_DEPRECATED, DEFAULT_CATEGORY_DEVELOPMENT, DEFAULT_CATEGORY_FORMATTING, DEFAULT_CATEGORY_INTERNAL, DEFAULT_CATEGORY_LAYOUT, DEFAULT_CATEGORY_NAVIGATION -
Constructor Summary
ConstructorsConstructorDescriptionAbstractScriptMacro(String macroName) AbstractScriptMacro(String macroName, String macroDescription) AbstractScriptMacro(String macroName, String macroDescription, Class<? extends ScriptMacroParameters> parametersBeanClass) AbstractScriptMacro(String macroName, String macroDescription, org.xwiki.rendering.macro.descriptor.ContentDescriptor contentDescriptor) AbstractScriptMacro(String macroName, String macroDescription, org.xwiki.rendering.macro.descriptor.ContentDescriptor contentDescriptor, Class<? extends ScriptMacroParameters> parametersBeanClass) -
Method Summary
Modifier and TypeMethodDescriptionprotected Stringevaluate(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context) Deprecated.since 2.4M2 useevaluateString(ScriptMacroParameters, String, MacroTransformationContext)insteadprotected List<org.xwiki.rendering.block.Block>evaluateBlock(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context) Execute provided script and returnBlockbased result.protected StringevaluateString(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context) Execute provided script and returnStringbased result.List<org.xwiki.rendering.block.Block>execute(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context) protected List<org.xwiki.rendering.block.Block>parseScriptResult(String content, P parameters, org.xwiki.rendering.transformation.MacroTransformationContext context) Convert script result as aBlocklist.protected List<org.xwiki.rendering.block.Block>parseSourceSyntax(String content, org.xwiki.rendering.transformation.MacroTransformationContext context) Parse provided content with the parser of the current wiki syntax.Methods inherited from class org.xwiki.rendering.macro.AbstractSignableMacro
getComponentManager, sign, verifyMethods inherited from class org.xwiki.rendering.macro.AbstractMacro
compareTo, getDescriptor, getNonGeneratedContentMetaData, getNonGeneratedContentMetaData, getNonGeneratedContentMetaData, getNonGeneratedContentMetaData, getPriority, initialize, setDefaultCategories, setDescriptor, setPriorityMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xwiki.rendering.macro.Macro
prepare, supportsInlineMode
-
Field Details
-
CONTENT_DESCRIPTION
The default description of the script macro content.- See Also:
-
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 executionUsed by subclasses.
-
-
Constructor Details
-
AbstractScriptMacro
- Parameters:
macroName- the name of the macro (eg "groovy")
-
AbstractScriptMacro
- 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:
executein interfaceMacro<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 aBlocklist.- 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 Deprecated.since 2.4M2 useevaluateString(ScriptMacroParameters, String, MacroTransformationContext)insteadExecute 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 returnStringbased 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 returnBlockbased 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
-