Class AptParser
- java.lang.Object
-
- org.apache.maven.doxia.parser.AbstractParser
-
- org.apache.maven.doxia.parser.AbstractTextParser
-
- org.apache.maven.doxia.module.apt.AptParser
-
- All Implemented Interfaces:
LogEnabled
,Markup
,TextMarkup
,AptMarkup
,Parser
@Component(role=Parser.class, hint="apt") public class AptParser extends AbstractTextParser implements AptMarkup
The APT parser.
Based on the APTconvert project.- Since:
- 1.0
- Version:
- $Id$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
AptParser.Block
A block of an apt source document.private class
AptParser.Comment
A Comment Block.private class
AptParser.DefinitionListItem
A DefinitionListItem Block.private class
AptParser.Figure
A Figure Block.private class
AptParser.HorizontalRule
A HorizontalRule Block.private class
AptParser.ListBreak
A ListBreak Block.private class
AptParser.ListItem
A ListItem Block.private class
AptParser.MacroBlock
A MacroBlock Block.private class
AptParser.NumberedListItem
A NumberedListItem Block.private class
AptParser.PageBreak
A PageBreak Block.private class
AptParser.Paragraph
A Paragraph Block.private class
AptParser.Section
A Section Block.private class
AptParser.Section1
A Section1 Block.private class
AptParser.Section2
A Section2 Block.class
AptParser.Section3
A Section3 Block.private class
AptParser.Section4
A Section4 Block.private class
AptParser.Section5
A Section5 Block.private class
AptParser.Table
A Table Block.private class
AptParser.Title
A Title Block.private class
AptParser.Verbatim
A Verbatim Block.
-
Field Summary
Fields Modifier and Type Field Description private AptParser.Block
block
a block of AptSource.private java.lang.String
blockFileName
blockFileName.private int
blockLineNumber
blockLineNumber.private static int
COMMENT_BLOCK
Comment event id.private static int
DEFINITION_LIST_ITEM
Definition list event idprivate static int
FIGURE
Figure event idprivate static int
HORIZONTAL_RULE
Horizontal rule event idprotected java.lang.String
line
a line of AptSource.private static int
LIST_BREAK
List break event idprivate static int
LIST_ITEM
List event idprivate static int
MACRO
Macro event idprivate static int
NUMBER_OF_SPACES
private static int
NUMBERED_LIST_ITEM
Numbered list event idprivate static int
PARAGRAPH
Paragraph event idprivate static int
PG_BREAK
Page break event idprivate static int
SECTION1
Section 1 event idprivate static int
SECTION2
Section 2 event idprivate static int
SECTION3
Section 3 event idprivate static int
SECTION4
Section 4 event idprivate static int
SECTION5
Section 5 event idprotected Sink
sink
the sink to receive the events.private AptSource
source
the AptSource.protected java.lang.String
sourceContent
sourceContent.protected static char[]
SPACES
An array of 85 spaces.static int
TAB_WIDTH
Default tab width.private static int
TABLE
Table event idprivate static int
TITLE
Title event idprivate static java.lang.String[]
TYPE_NAMES
String representations of event idsprivate static int
VERBATIM
Verbatim event idprotected java.util.Map<java.lang.String,java.util.Set<java.lang.String>>
warnMessages
Map of warn messages with a String as key to describe the error type and a Set as value.-
Fields inherited from interface org.apache.maven.doxia.module.apt.AptMarkup
ANCHOR_END_MARKUP, ANCHOR_START_MARKUP, BACKSLASH, BOLD_END_MARKUP, BOLD_START_MARKUP, BOXED_VERBATIM_END_MARKUP, BOXED_VERBATIM_START_MARKUP, COMMENT, HEADER_START_MARKUP, HORIZONTAL_RULE_MARKUP, ITALIC_END_MARKUP, ITALIC_START_MARKUP, LINK_END_MARKUP, LINK_START_1_MARKUP, LINK_START_2_MARKUP, LIST_END_MARKUP, LIST_START_MARKUP, MONOSPACED_END_MARKUP, MONOSPACED_START_MARKUP, NON_BOXED_VERBATIM_END_MARKUP, NON_BOXED_VERBATIM_START_MARKUP, NON_BREAKING_SPACE_MARKUP, NUMBERING, NUMBERING_LOWER_ALPHA_CHAR, NUMBERING_LOWER_ROMAN_CHAR, NUMBERING_UPPER_ALPHA_CHAR, NUMBERING_UPPER_ROMAN_CHAR, PAGE_BREAK, PAGE_BREAK_MARKUP, PERCENT, SECTION_TITLE_START_MARKUP, TAB, TABLE_CELL_SEPARATOR_MARKUP, TABLE_COL_CENTERED_ALIGNED_MARKUP, TABLE_COL_LEFT_ALIGNED_MARKUP, TABLE_COL_RIGHT_ALIGNED_MARKUP, TABLE_ROW_SEPARATOR_MARKUP, TABLE_ROW_START_MARKUP
-
Fields inherited from interface org.apache.maven.doxia.markup.Markup
COLON, EOL, EQUAL, GREATER_THAN, LEFT_CURLY_BRACKET, LEFT_SQUARE_BRACKET, LESS_THAN, MINUS, PLUS, QUOTE, RIGHT_CURLY_BRACKET, RIGHT_SQUARE_BRACKET, SEMICOLON, SLASH, SPACE, STAR
-
Fields inherited from interface org.apache.maven.doxia.parser.Parser
ROLE, TXT_TYPE, UNKNOWN_TYPE, XML_TYPE
-
Fields inherited from interface org.apache.maven.doxia.markup.TextMarkup
PIPE
-
-
Constructor Summary
Constructors Constructor Description AptParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static char
charAt(java.lang.String string, int length, int i)
Returns the character at position i of the given string.private java.lang.String
doGetTraversedLink(java.lang.String text, int begin, int end)
Parse the given text.protected void
doTraverseText(java.lang.String text, int begin, int end, Sink sink)
Parse the given text.private void
expectedBlock(int type)
Checks that the current block is of the expected type.private static void
flushTraversed(java.lang.StringBuilder buffer, Sink sink)
Emits the text so far parsed into the given sink.int
getSourceLineNumber()
Returns the current line number of the Apt source document.java.lang.String
getSourceName()
Returns the name of the Apt source document.private java.lang.String
getTraversedAnchor(java.lang.String text, int begin, int end)
Parse the given text.private java.lang.String
getTraversedLink(java.lang.String text, int begin, int end)
Parse the given text.protected void
init()
Initialize the parser.private static boolean
isHexChar(char c)
Determine if c is an hex character.private static boolean
isOctalChar(char c)
Determine if c is an octal character.private void
logMessage(java.lang.String key, java.lang.String msg)
If debug mode is enabled, log themsg
as is, otherwise add unique msg inwarnMessages
.private void
logWarnings()
private void
nextBlock()
Parse the next block of the Apt source document.private void
nextBlock(boolean firstBlock)
Parse the next block of the Apt source document.protected void
nextLine()
Parse the next line of the Apt source document.void
parse(java.io.Reader source, Sink sink)
Parses the given source model and emits Doxia events into the given sink.void
parse(java.io.Reader source, Sink sink, java.lang.String reference)
Parses the given source model and emits Doxia events into the given sink.protected static java.lang.String
replaceAll(java.lang.String string, java.lang.String oldSub, java.lang.String newSub)
Replace part of a string.protected static int
skipSpace(java.lang.String string, int length, int i)
Skip spaces.private static int
skipTraversedLinkAnchor(java.lang.String text, int begin, int end, java.lang.StringBuilder linkAnchor)
Parse the given text.private void
traverseBody()
Parse the body of the Apt source document.private void
traverseDefinitionList()
Parse a definition list of the Apt source document.private void
traverseHead()
Parse the head of the Apt source document.private void
traverseList()
Parse a list of the Apt source document.private void
traverseNumberedList()
Parse a numbered list of the Apt source document.private void
traverseSection(int level)
Parse a section of the Apt source document.private void
traverseSectionBlocks()
Parse the section blocks of the Apt source document.-
Methods inherited from class org.apache.maven.doxia.parser.AbstractTextParser
getType
-
Methods inherited from class org.apache.maven.doxia.parser.AbstractParser
doxiaVersion, enableLogging, executeMacro, getBasedir, getLog, getMacroManager, isEmitComments, isSecondParsing, parse, setEmitComments, setSecondParsing
-
-
-
-
Field Detail
-
TITLE
private static final int TITLE
Title event id- See Also:
- Constant Field Values
-
SECTION1
private static final int SECTION1
Section 1 event id- See Also:
- Constant Field Values
-
SECTION2
private static final int SECTION2
Section 2 event id- See Also:
- Constant Field Values
-
SECTION3
private static final int SECTION3
Section 3 event id- See Also:
- Constant Field Values
-
SECTION4
private static final int SECTION4
Section 4 event id- See Also:
- Constant Field Values
-
SECTION5
private static final int SECTION5
Section 5 event id- See Also:
- Constant Field Values
-
PARAGRAPH
private static final int PARAGRAPH
Paragraph event id- See Also:
- Constant Field Values
-
VERBATIM
private static final int VERBATIM
Verbatim event id- See Also:
- Constant Field Values
-
FIGURE
private static final int FIGURE
Figure event id- See Also:
- Constant Field Values
-
TABLE
private static final int TABLE
Table event id- See Also:
- Constant Field Values
-
LIST_ITEM
private static final int LIST_ITEM
List event id- See Also:
- Constant Field Values
-
NUMBERED_LIST_ITEM
private static final int NUMBERED_LIST_ITEM
Numbered list event id- See Also:
- Constant Field Values
-
DEFINITION_LIST_ITEM
private static final int DEFINITION_LIST_ITEM
Definition list event id- See Also:
- Constant Field Values
-
HORIZONTAL_RULE
private static final int HORIZONTAL_RULE
Horizontal rule event id- See Also:
- Constant Field Values
-
PG_BREAK
private static final int PG_BREAK
Page break event id- See Also:
- Constant Field Values
-
LIST_BREAK
private static final int LIST_BREAK
List break event id- See Also:
- Constant Field Values
-
MACRO
private static final int MACRO
Macro event id- See Also:
- Constant Field Values
-
COMMENT_BLOCK
private static final int COMMENT_BLOCK
Comment event id.- See Also:
- Constant Field Values
-
TYPE_NAMES
private static final java.lang.String[] TYPE_NAMES
String representations of event ids
-
SPACES
protected static final char[] SPACES
An array of 85 spaces.
-
TAB_WIDTH
public static final int TAB_WIDTH
Default tab width.- See Also:
- Constant Field Values
-
source
private AptSource source
the AptSource.
-
block
private AptParser.Block block
a block of AptSource.
-
blockFileName
private java.lang.String blockFileName
blockFileName.
-
blockLineNumber
private int blockLineNumber
blockLineNumber.
-
sourceContent
protected java.lang.String sourceContent
sourceContent.
-
sink
protected Sink sink
the sink to receive the events.
-
line
protected java.lang.String line
a line of AptSource.
-
warnMessages
protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>> warnMessages
Map of warn messages with a String as key to describe the error type and a Set as value. Using to reduce warn messages.
-
NUMBER_OF_SPACES
private static final int NUMBER_OF_SPACES
- See Also:
- Constant Field Values
-
-
Method Detail
-
parse
public void parse(java.io.Reader source, Sink sink) throws ParseException
Description copied from interface:Parser
Parses the given source model and emits Doxia events into the given sink.- Specified by:
parse
in interfaceParser
- Parameters:
source
- not null reader that provides the source document. You could usenewReader
methods fromReaderFactory
.sink
- A sink that consumes the Doxia events.- Throws:
ParseException
- if the model could not be parsed.
-
parse
public void parse(java.io.Reader source, Sink sink, java.lang.String reference) throws ParseException
Description copied from interface:Parser
Parses the given source model and emits Doxia events into the given sink.- Specified by:
parse
in interfaceParser
- Overrides:
parse
in classAbstractParser
- Parameters:
source
- not null reader that provides the source document. You could usenewReader
methods fromReaderFactory
.sink
- A sink that consumes the Doxia events.reference
- the reference- Throws:
ParseException
- if the model could not be parsed.
-
getSourceName
public java.lang.String getSourceName()
Returns the name of the Apt source document.- Returns:
- the source name.
-
getSourceLineNumber
public int getSourceLineNumber()
Returns the current line number of the Apt source document.- Returns:
- the line number.
-
nextLine
protected void nextLine() throws AptParseException
Parse the next line of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
doTraverseText
protected void doTraverseText(java.lang.String text, int begin, int end, Sink sink) throws AptParseException
Parse the given text.- Parameters:
text
- the text to parse.begin
- offset.end
- offset.sink
- the sink to receive the events.- Throws:
AptParseException
- if something goes wrong.
-
charAt
protected static char charAt(java.lang.String string, int length, int i)
Returns the character at position i of the given string.- Parameters:
string
- the string.length
- length.i
- offset.- Returns:
- the character, or '\0' if i > length.
-
skipSpace
protected static int skipSpace(java.lang.String string, int length, int i)
Skip spaces.- Parameters:
string
- string.length
- length.i
- offset.- Returns:
- int.
-
replaceAll
protected static java.lang.String replaceAll(java.lang.String string, java.lang.String oldSub, java.lang.String newSub)
Replace part of a string.- Parameters:
string
- the stringoldSub
- the substring to replacenewSub
- the replacement string- Returns:
- String
-
init
protected void init()
Initialize the parser. This is called first byParser.parse(java.io.Reader, org.apache.maven.doxia.sink.Sink)
and can be used to set the parser into a clear state so it can be re-used.- Overrides:
init
in classAbstractParser
-
traverseHead
private void traverseHead() throws AptParseException
Parse the head of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
traverseBody
private void traverseBody() throws AptParseException
Parse the body of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
traverseSection
private void traverseSection(int level) throws AptParseException
Parse a section of the Apt source document.- Parameters:
level
- The section level.- Throws:
AptParseException
- if something goes wrong.
-
traverseSectionBlocks
private void traverseSectionBlocks() throws AptParseException
Parse the section blocks of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
traverseList
private void traverseList() throws AptParseException
Parse a list of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
traverseNumberedList
private void traverseNumberedList() throws AptParseException
Parse a numbered list of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
traverseDefinitionList
private void traverseDefinitionList() throws AptParseException
Parse a definition list of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
nextBlock
private void nextBlock() throws AptParseException
Parse the next block of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
nextBlock
private void nextBlock(boolean firstBlock) throws AptParseException
Parse the next block of the Apt source document.- Parameters:
firstBlock
- True if this is the first block of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
expectedBlock
private void expectedBlock(int type) throws AptParseException
Checks that the current block is of the expected type.- Parameters:
type
- the expected type.- Throws:
AptParseException
- if something goes wrong.
-
isOctalChar
private static boolean isOctalChar(char c)
Determine if c is an octal character.- Parameters:
c
- the character.- Returns:
- boolean
-
isHexChar
private static boolean isHexChar(char c)
Determine if c is an hex character.- Parameters:
c
- the character.- Returns:
- boolean
-
flushTraversed
private static void flushTraversed(java.lang.StringBuilder buffer, Sink sink)
Emits the text so far parsed into the given sink.- Parameters:
buffer
- A StringBuilder that contains the text to be flushed.sink
- The sink to receive the text.
-
skipTraversedLinkAnchor
private static int skipTraversedLinkAnchor(java.lang.String text, int begin, int end, java.lang.StringBuilder linkAnchor) throws AptParseException
Parse the given text.- Parameters:
text
- the text to parse.begin
- offset.end
- offset.linkAnchor
- a StringBuilder.- Returns:
- int
- Throws:
AptParseException
- if something goes wrong.
-
getTraversedLink
private java.lang.String getTraversedLink(java.lang.String text, int begin, int end) throws AptParseException
Parse the given text.- Parameters:
text
- the text to parse.begin
- offset.end
- offset.- Returns:
- String
- Throws:
AptParseException
- if something goes wrong.
-
getTraversedAnchor
private java.lang.String getTraversedAnchor(java.lang.String text, int begin, int end) throws AptParseException
Parse the given text.- Parameters:
text
- the text to parse.begin
- offset.end
- offset.- Returns:
- String
- Throws:
AptParseException
- if something goes wrong.
-
doGetTraversedLink
private java.lang.String doGetTraversedLink(java.lang.String text, int begin, int end) throws AptParseException
Parse the given text.- Parameters:
text
- the text to parse.begin
- offset.end
- offset.- Returns:
- String
- Throws:
AptParseException
- if something goes wrong.
-
logMessage
private void logMessage(java.lang.String key, java.lang.String msg)
If debug mode is enabled, log themsg
as is, otherwise add unique msg inwarnMessages
.- Parameters:
key
- not nullmsg
- not null- Since:
- 1.1.1
- See Also:
parse(Reader, Sink)
-
logWarnings
private void logWarnings()
- Since:
- 1.1.2
-
-