com.atlassian.renderer.v2.macro.code
Class CodeMacro

java.lang.Object
  extended by com.atlassian.renderer.v2.macro.BaseMacro
      extended by com.atlassian.renderer.v2.macro.basic.AbstractPanelMacro
          extended by com.atlassian.renderer.v2.macro.code.CodeMacro
All Implemented Interfaces:
Macro

public class CodeMacro
extends AbstractPanelMacro


Field Summary
 
Fields inherited from interface com.atlassian.renderer.v2.macro.Macro
RAW_PARAMS_KEY
 
Constructor Summary
CodeMacro()
           
CodeMacro(V2SubRenderer subRenderer, java.util.List<SourceCodeFormatter> formatters)
           
 
Method Summary
 java.lang.String execute(java.util.Map parameters, java.lang.String body, RenderContext renderContext)
          Execute the macro.
 RenderMode getBodyRenderMode()
          If the macro has a body, return the mode in which the body of the macro should be rendered.
protected  java.lang.String getPanelContentCSSClass()
           
protected  java.lang.String getPanelCSSClass()
           
protected  java.lang.String getPanelHeaderCSSClass()
           
 TokenType getTokenType(java.util.Map parameters, java.lang.String body, RenderContext context)
          Declares what sort of html elements are returned by the macro.
 void setCodeFormatterRepository(SourceCodeFormatterRepository codeFormatterRepository)
           
 boolean suppressMacroRenderingDuringWysiwyg()
          Suppress the rendering of the macro -- the macro's body may still be rendered (depending on the render mode of the macro), but the HTML the macro adds will not be created.
 
Methods inherited from class com.atlassian.renderer.v2.macro.basic.AbstractPanelMacro
getBodyContent, getSubRenderer, getTitle, hasBody, isInline, setSubRenderer, writeContent, writeHeader, writeHeader
 
Methods inherited from class com.atlassian.renderer.v2.macro.BaseMacro
getWysiwygBodyType, suppressSurroundingTagDuringWysiwygRendering
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeMacro

public CodeMacro(V2SubRenderer subRenderer,
                 java.util.List<SourceCodeFormatter> formatters)

CodeMacro

public CodeMacro()
Method Detail

setCodeFormatterRepository

public void setCodeFormatterRepository(SourceCodeFormatterRepository codeFormatterRepository)

suppressMacroRenderingDuringWysiwyg

public boolean suppressMacroRenderingDuringWysiwyg()
Description copied from interface: Macro
Suppress the rendering of the macro -- the macro's body may still be rendered (depending on the render mode of the macro), but the HTML the macro adds will not be created.

Specified by:
suppressMacroRenderingDuringWysiwyg in interface Macro
Overrides:
suppressMacroRenderingDuringWysiwyg in class BaseMacro
Returns:

getPanelCSSClass

protected java.lang.String getPanelCSSClass()
Specified by:
getPanelCSSClass in class AbstractPanelMacro

getPanelHeaderCSSClass

protected java.lang.String getPanelHeaderCSSClass()
Specified by:
getPanelHeaderCSSClass in class AbstractPanelMacro

getPanelContentCSSClass

protected java.lang.String getPanelContentCSSClass()
Specified by:
getPanelContentCSSClass in class AbstractPanelMacro

getBodyRenderMode

public RenderMode getBodyRenderMode()
Description copied from interface: Macro
If the macro has a body, return the mode in which the body of the macro should be rendered. The body of the macro will be rendered before the macro is executed!

If this method returns null, it causes the macro processor to treat the macro as one that returns wiki-text rather than HTML. The body of the macro will be passed in un-rendered, and the macro's output will be inserted back into the page for further normal processing by the wiki-engine.

Specified by:
getBodyRenderMode in interface Macro
Overrides:
getBodyRenderMode in class AbstractPanelMacro
Returns:
the RenderMode in which the body of this macro should be rendered, or null if the macro is substituting wiki-text

execute

public java.lang.String execute(java.util.Map parameters,
                                java.lang.String body,
                                RenderContext renderContext)
                         throws MacroException
Description copied from interface: Macro
Execute the macro. Macros should write any output to the writer (it will be rendered in the RenderMode returned in Macro.getBodyRenderMode()).

Macros are expected to output HTML. The output of macros will not be subjected to any further processing by the wiki-engine. If your macro produces wiki-text, you are responsible for rendering that text to HTML yourself using a SubRenderer or WikiStyleRenderer. If your macro returns pure wiki-text, you can force further processing in the normal chain by returning null from Macro.getBodyRenderMode()

Specified by:
execute in interface Macro
Overrides:
execute in class AbstractPanelMacro
Parameters:
parameters - the parameters included in the macro
body - the content of the body of the macro
renderContext - the rendering context in which the macro was executed
Returns:
the output of the macro
Throws:
MacroException - if the macro fails in some unremarkable way. If the macro fails in a way that is important to the server maintainer (i.e. something is badly wrong), throw a RuntimeException instead.

getTokenType

public TokenType getTokenType(java.util.Map parameters,
                              java.lang.String body,
                              RenderContext context)
Description copied from class: BaseMacro
Declares what sort of html elements are returned by the macro. TokenType.INLINE elements will have paragraphs drawn around them, or be incorporated into paragraphs they are included in. TokenType.BLOCK elements will be treated as their own paragraph, splitting any paragraphs they would otherwise be in. TokenType.INLINE_BLOCK elements will not have paragraphs drawn around them, but they won't split any paragraphs they appear in either.

Macros that contain elements that shouldn't appear in a paragraph, such as pre, should return TokenType.BLOCK. If it produces a span, replacement text or text decoration, return TokenType.INLINE. If it affects logic of whether its children are displayed but doesn't add its own content, or you aren't sure what to return, return TokenType.INLINE_BLOCK.

The default implementation tries to maintain backward compatibility with most macros. It returns TokenType.INLINE for macros that return true from BaseMacro.isInline() and TokenType.INLINE_BLOCK for macros that return false.

Specified by:
getTokenType in interface Macro
Overrides:
getTokenType in class BaseMacro
Parameters:
parameters - ignored
body - ignored
context - ignored
Returns:
the TokenType that matches the content produced by this macro


Copyright © 2012 Atlassian. All Rights Reserved.