Package org.apache.maven.doxia.macro.toc
Class TocMacro
- java.lang.Object
-
- org.apache.maven.doxia.macro.AbstractMacro
-
- org.apache.maven.doxia.macro.toc.TocMacro
-
- All Implemented Interfaces:
LogEnabled
,Macro
@Component(role=Macro.class, hint="toc") public class TocMacro extends AbstractMacro
Macro to display aTable Of Content
in a givenSink
. The input parameters for this macro are:- section
- Display a TOC for the specified section only, or all sections if 0.
Positive int, not mandatory, 0 by default. - fromDepth
- Minimal depth of entries to display in the TOC.
Sections are depth 1, sub-sections depth 2, etc.
Positive int, not mandatory, 0 by default. - toDepth
- Maximum depth of entries to display in the TOC.
Positive int, not mandatory, 5 by default.
- %{toc|section=2|fromDepth=2|toDepth=3}
- Display a TOC for the second section in the document, including all subsections (depth 2) and sub-subsections (depth 3).
- %{toc}
- display a TOC with all section and subsections (similar to %{toc|section=0} )
* {SubSection 1}
Similarly, in an XDOC file, you could write:<macro name="toc"> <param name="section" value="1" /> <param name="fromDepth" value="1" /> <param name="toDepth" value="2" /> </macro>
- Version:
- $Id$
-
-
Constructor Summary
Constructors Constructor Description TocMacro()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(Sink sink, MacroRequest request)
Execute the current macro using the given MacroRequest, and emit events into the given sink.private static int
getInt(MacroRequest request, java.lang.String parameter, int defaultValue)
private void
writeSubSectionN(Sink sink, IndexEntry sectionIndex, int n)
-
Methods inherited from class org.apache.maven.doxia.macro.AbstractMacro
enableLogging, getAttributesFromMap, getLog, required
-
-
-
-
Field Detail
-
section
private int section
The section to display.
-
fromDepth
private int fromDepth
Start depth.
-
toDepth
private int toDepth
End depth.
-
DEFAULT_DEPTH
private static final int DEFAULT_DEPTH
The default end depth.- See Also:
- Constant Field Values
-
-
Method Detail
-
execute
public void execute(Sink sink, MacroRequest request) throws MacroExecutionException
Execute the current macro using the given MacroRequest, and emit events into the given sink.- Parameters:
sink
- The sink to receive the events.request
- The corresponding MacroRequest.- Throws:
MacroExecutionException
- if an error occurred during execution.
-
writeSubSectionN
private void writeSubSectionN(Sink sink, IndexEntry sectionIndex, int n)
- Parameters:
sink
- The sink to write to.sectionIndex
- The section index.n
- The toc depth.
-
getInt
private static int getInt(MacroRequest request, java.lang.String parameter, int defaultValue) throws MacroExecutionException
- Parameters:
request
- The MacroRequest.parameter
- The parameter.defaultValue
- the default value.- Returns:
- the int value of a parameter in the request.
- Throws:
MacroExecutionException
- if something goes wrong.
-
-