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
andScriptEvaluatedEvent
. 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
Fields Modifier and Type Field Description protected static String
CONTENT_DESCRIPTION
The default description of the script macro content.protected DocumentAccessBridge
documentAccessBridge
Deprecated.since 2.5M1 (not used any more)protected org.xwiki.context.Execution
execution
Used 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
Constructors Constructor Description AbstractScriptMacro(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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected String
evaluate(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 returnBlock
based result.protected String
evaluateString(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context)
Execute provided script and returnString
based 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 aBlock
list.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, verify
-
Methods inherited from class org.xwiki.rendering.macro.AbstractMacro
compareTo, getDescriptor, getNonGeneratedContentMetaData, getNonGeneratedContentMetaData, getNonGeneratedContentMetaData, getNonGeneratedContentMetaData, getPriority, initialize, setDefaultCategories, setDescriptor, setPriority
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.xwiki.rendering.macro.Macro
supportsInlineMode
-
-
-
-
Field Detail
-
CONTENT_DESCRIPTION
protected static final String CONTENT_DESCRIPTION
The default description of the script macro content.- See Also:
- Constant Field Values
-
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 Detail
-
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 Detail
-
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 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 aBlock
list.- Parameters:
content
- the script result to parse.parameters
- the macro parameters.context
- the context of the macro transformation.- Returns:
- the
Block
s. - 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 returnString
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 returnBlock
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
-
-