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.
Based on the APTconvert project.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
A block of an apt source document.private class
A Comment Block.private class
A DefinitionListItem Block.private class
A Figure Block.private class
A HorizontalRule Block.private class
A ListBreak Block.private class
A ListItem Block.private class
A MacroBlock Block.private class
A NumberedListItem Block.private class
A PageBreak Block.private class
A Paragraph Block.private class
A Section Block.private class
A Section1 Block.private class
A Section2 Block.class
A Section3 Block.private class
A Section4 Block.private class
A Section5 Block.private class
A Table Block.private class
A Title Block.private class
A Verbatim Block. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AptParser.Block
a block of AptSource.private String
blockFileName.private int
blockLineNumber.private static final int
Comment event id.private static final int
Definition list event idprivate static final int
Figure event idprivate static final int
Horizontal rule event idprotected String
a line of AptSource.private static final int
List break event idprivate static final int
List event idprivate static final int
Macro event idprivate static final int
private static final int
Numbered list event idprivate static final int
Paragraph event idprivate static final int
Page break event idprivate static final int
Section 1 event idprivate static final int
Section 2 event idprivate static final int
Section 3 event idprivate static final int
Section 4 event idprivate static final int
Section 5 event idprotected Sink
the sink to receive the events.private AptSource
the AptSource.protected String
sourceContent.protected static final char[]
An array of 85 spaces.static final int
Default tab width.private static final int
Table event idprivate static final int
Title event idprivate static final String[]
String representations of event idsprivate static final int
Verbatim event idMap 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected static char
Returns the character at position i of the given string.private String
doGetTraversedLink
(String text, int begin, int end) Parse the given text.protected void
doTraverseText
(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
(StringBuilder buffer, Sink sink) Emits the text so far parsed into the given sink.int
Returns the current line number of the Apt source document.Returns the name of the Apt source document.private String
getTraversedAnchor
(String text, int begin, int end) Parse the given text.private String
getTraversedLink
(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
(String key, String msg) If debug mode is enabled, log themsg
as is, otherwise add unique msg inwarnMessages
.private void
private void
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
Parses the given source model and emits Doxia events into the given sink.void
Parses the given source model and emits Doxia events into the given sink.protected static String
replaceAll
(String string, String oldSub, String newSub) Replace part of a string.protected static int
Skip spaces.private static int
skipTraversedLinkAnchor
(String text, int begin, int end, StringBuilder linkAnchor) Parse the given text.private void
Parse the body of the Apt source document.private void
Parse a definition list of the Apt source document.private void
Parse the head of the Apt source document.private void
Parse a list of the Apt source document.private void
Parse a numbered list of the Apt source document.private void
traverseSection
(int level) Parse a section of the Apt source document.private void
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, parse, setEmitComments, setSecondParsing
-
Field Details
-
TITLE
private static final int TITLETitle event id- See Also:
-
SECTION1
private static final int SECTION1Section 1 event id- See Also:
-
SECTION2
private static final int SECTION2Section 2 event id- See Also:
-
SECTION3
private static final int SECTION3Section 3 event id- See Also:
-
SECTION4
private static final int SECTION4Section 4 event id- See Also:
-
SECTION5
private static final int SECTION5Section 5 event id- See Also:
-
PARAGRAPH
private static final int PARAGRAPHParagraph event id- See Also:
-
VERBATIM
private static final int VERBATIMVerbatim event id- See Also:
-
FIGURE
private static final int FIGUREFigure event id- See Also:
-
TABLE
private static final int TABLETable event id- See Also:
-
LIST_ITEM
private static final int LIST_ITEMList event id- See Also:
-
NUMBERED_LIST_ITEM
private static final int NUMBERED_LIST_ITEMNumbered list event id- See Also:
-
DEFINITION_LIST_ITEM
private static final int DEFINITION_LIST_ITEMDefinition list event id- See Also:
-
HORIZONTAL_RULE
private static final int HORIZONTAL_RULEHorizontal rule event id- See Also:
-
PG_BREAK
private static final int PG_BREAKPage break event id- See Also:
-
LIST_BREAK
private static final int LIST_BREAKList break event id- See Also:
-
MACRO
private static final int MACROMacro event id- See Also:
-
COMMENT_BLOCK
private static final int COMMENT_BLOCKComment event id.- See Also:
-
TYPE_NAMES
String representations of event ids -
SPACES
protected static final char[] SPACESAn array of 85 spaces. -
TAB_WIDTH
public static final int TAB_WIDTHDefault tab width.- See Also:
-
source
the AptSource. -
block
a block of AptSource. -
blockFileName
blockFileName. -
blockLineNumber
private int blockLineNumberblockLineNumber. -
sourceContent
sourceContent. -
sink
the sink to receive the events. -
line
a line of AptSource. -
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:
-
-
Constructor Details
-
AptParser
public AptParser()
-
-
Method Details
-
parse
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.- Throws:
ParseException
- if the model could not be parsed.
-
parse
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.reference
- the reference- Throws:
ParseException
- if the model could not be parsed.
-
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
Parse the next line of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
doTraverseText
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
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
Skip spaces.- Parameters:
string
- string.length
- length.i
- offset.- Returns:
- int.
-
replaceAll
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 byAbstractParser.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
Parse the head of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
traverseBody
Parse the body of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
traverseSection
Parse a section of the Apt source document.- Parameters:
level
- The section level.- Throws:
AptParseException
- if something goes wrong.
-
traverseSectionBlocks
Parse the section blocks of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
traverseList
Parse a list of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
traverseNumberedList
Parse a numbered list of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
traverseDefinitionList
Parse a definition list of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
nextBlock
Parse the next block of the Apt source document.- Throws:
AptParseException
- if something goes wrong.
-
nextBlock
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
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
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(String text, int begin, int end, 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
Parse the given text.- Parameters:
text
- the text to parse.begin
- offset.end
- offset.- Returns:
- String
- Throws:
AptParseException
- if something goes wrong.
-
getTraversedAnchor
Parse the given text.- Parameters:
text
- the text to parse.begin
- offset.end
- offset.- Returns:
- String
- Throws:
AptParseException
- if something goes wrong.
-
doGetTraversedLink
Parse the given text.- Parameters:
text
- the text to parse.begin
- offset.end
- offset.- Returns:
- String
- Throws:
AptParseException
- if something goes wrong.
-
logMessage
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:
-
logWarnings
private void logWarnings()- Since:
- 1.1.2
-