org.xwiki.rendering.macro.script
Class AbstractScriptMacro<P extends ScriptMacroParameters>

java.lang.Object
  extended by org.xwiki.rendering.macro.AbstractMacro<P>
      extended by org.xwiki.rendering.macro.script.AbstractScriptMacro<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>, ScriptMacro
Direct Known Subclasses:
AbstractJSR223ScriptMacro

public abstract class AbstractScriptMacro<P extends ScriptMacroParameters>
extends org.xwiki.rendering.macro.AbstractMacro<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$

Field Summary
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_DEVELOPMENT, DEFAULT_CATEGORY_FORMATTING, DEFAULT_CATEGORY_NAVIGATION
 
Constructor Summary
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
protected  String evaluate(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context)
          Deprecated. since 2.4M2 use evaluateString(ScriptMacroParameters, String, MacroTransformationContext) instead
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  String evaluateString(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context)
          Execute provided script and return String based result.
 List<org.xwiki.rendering.block.Block> execute(P parameters, String content, org.xwiki.rendering.transformation.MacroTransformationContext context)
          
protected  org.xwiki.component.manager.ComponentManager getComponentManager()
           
protected  List<org.xwiki.rendering.block.Block> parseScriptResult(String content, P parameters, org.xwiki.rendering.transformation.MacroTransformationContext context)
          Convert script result as a Block 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.AbstractMacro
compareTo, getDescriptor, getPriority, initialize, setDefaultCategory, 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

getComponentManager

protected org.xwiki.component.manager.ComponentManager getComponentManager()
Returns:
the component manager
Since:
2.0M1

execute

public List<org.xwiki.rendering.block.Block> execute(P parameters,
                                                     String content,
                                                     org.xwiki.rendering.transformation.MacroTransformationContext context)
                                              throws org.xwiki.rendering.macro.MacroExecutionException

Specified by:
execute in interface org.xwiki.rendering.macro.Macro<P extends ScriptMacroParameters>
Throws:
org.xwiki.rendering.macro.MacroExecutionException
See Also:
Macro.execute(Object, String, MacroTransformationContext)

parseScriptResult

protected List<org.xwiki.rendering.block.Block> parseScriptResult(String content,
                                                                  P parameters,
                                                                  org.xwiki.rendering.transformation.MacroTransformationContext context)
                                                           throws org.xwiki.rendering.macro.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:
org.xwiki.rendering.macro.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 org.xwiki.rendering.macro.MacroExecutionException
Deprecated. since 2.4M2 use evaluateString(ScriptMacroParameters, String, MacroTransformationContext) instead

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:
org.xwiki.rendering.macro.MacroExecutionException - failed to evaluate provided content.

evaluateString

protected String evaluateString(P parameters,
                                String content,
                                org.xwiki.rendering.transformation.MacroTransformationContext context)
                         throws org.xwiki.rendering.macro.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:
org.xwiki.rendering.macro.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 org.xwiki.rendering.macro.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:
org.xwiki.rendering.macro.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 org.xwiki.rendering.macro.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:
org.xwiki.rendering.macro.MacroExecutionException - failed to parse content


Copyright © 2004-2011 XWiki. All Rights Reserved.