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 classAptParser.BlockA block of an apt source document.private classAptParser.CommentA Comment Block.private classAptParser.DefinitionListItemA DefinitionListItem Block.private classAptParser.FigureA Figure Block.private classAptParser.HorizontalRuleA HorizontalRule Block.private classAptParser.ListBreakA ListBreak Block.private classAptParser.ListItemA ListItem Block.private classAptParser.MacroBlockA MacroBlock Block.private classAptParser.NumberedListItemA NumberedListItem Block.private classAptParser.PageBreakA PageBreak Block.private classAptParser.ParagraphA Paragraph Block.private classAptParser.SectionA Section Block.private classAptParser.Section1A Section1 Block.private classAptParser.Section2A Section2 Block.classAptParser.Section3A Section3 Block.private classAptParser.Section4A Section4 Block.private classAptParser.Section5A Section5 Block.private classAptParser.TableA Table Block.private classAptParser.TitleA Title Block.private classAptParser.VerbatimA Verbatim Block.
-
Field Summary
Fields Modifier and Type Field Description private AptParser.Blockblocka block of AptSource.private java.lang.StringblockFileNameblockFileName.private intblockLineNumberblockLineNumber.private static intCOMMENT_BLOCKComment event id.private static intDEFINITION_LIST_ITEMDefinition list event idprivate static intFIGUREFigure event idprivate static intHORIZONTAL_RULEHorizontal rule event idprotected java.lang.Stringlinea line of AptSource.private static intLIST_BREAKList break event idprivate static intLIST_ITEMList event idprivate static intMACROMacro event idprivate static intNUMBER_OF_SPACESprivate static intNUMBERED_LIST_ITEMNumbered list event idprivate static intPARAGRAPHParagraph event idprivate static intPG_BREAKPage break event idprivate static intSECTION1Section 1 event idprivate static intSECTION2Section 2 event idprivate static intSECTION3Section 3 event idprivate static intSECTION4Section 4 event idprivate static intSECTION5Section 5 event idprotected Sinksinkthe sink to receive the events.private AptSourcesourcethe AptSource.protected java.lang.StringsourceContentsourceContent.protected static char[]SPACESAn array of 85 spaces.static intTAB_WIDTHDefault tab width.private static intTABLETable event idprivate static intTITLETitle event idprivate static java.lang.String[]TYPE_NAMESString representations of event idsprivate static intVERBATIMVerbatim event idprotected java.util.Map<java.lang.String,java.util.Set<java.lang.String>>warnMessagesMap 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 charcharAt(java.lang.String string, int length, int i)Returns the character at position i of the given string.private java.lang.StringdoGetTraversedLink(java.lang.String text, int begin, int end)Parse the given text.protected voiddoTraverseText(java.lang.String text, int begin, int end, Sink sink)Parse the given text.private voidexpectedBlock(int type)Checks that the current block is of the expected type.private static voidflushTraversed(java.lang.StringBuilder buffer, Sink sink)Emits the text so far parsed into the given sink.intgetSourceLineNumber()Returns the current line number of the Apt source document.java.lang.StringgetSourceName()Returns the name of the Apt source document.private java.lang.StringgetTraversedAnchor(java.lang.String text, int begin, int end)Parse the given text.private java.lang.StringgetTraversedLink(java.lang.String text, int begin, int end)Parse the given text.protected voidinit()Initialize the parser.private static booleanisHexChar(char c)Determine if c is an hex character.private static booleanisOctalChar(char c)Determine if c is an octal character.private voidlogMessage(java.lang.String key, java.lang.String msg)If debug mode is enabled, log themsgas is, otherwise add unique msg inwarnMessages.private voidlogWarnings()private voidnextBlock()Parse the next block of the Apt source document.private voidnextBlock(boolean firstBlock)Parse the next block of the Apt source document.protected voidnextLine()Parse the next line of the Apt source document.voidparse(java.io.Reader source, Sink sink)Parses the given source model and emits Doxia events into the given sink.voidparse(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.StringreplaceAll(java.lang.String string, java.lang.String oldSub, java.lang.String newSub)Replace part of a string.protected static intskipSpace(java.lang.String string, int length, int i)Skip spaces.private static intskipTraversedLinkAnchor(java.lang.String text, int begin, int end, java.lang.StringBuilder linkAnchor)Parse the given text.private voidtraverseBody()Parse the body of the Apt source document.private voidtraverseDefinitionList()Parse a definition list of the Apt source document.private voidtraverseHead()Parse the head of the Apt source document.private voidtraverseList()Parse a list of the Apt source document.private voidtraverseNumberedList()Parse a numbered list of the Apt source document.private voidtraverseSection(int level)Parse a section of the Apt source document.private voidtraverseSectionBlocks()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 ParseExceptionDescription copied from interface:ParserParses the given source model and emits Doxia events into the given sink.- Specified by:
parsein interfaceParser- Parameters:
source- not null reader that provides the source document. You could usenewReadermethods 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 ParseExceptionDescription copied from interface:ParserParses the given source model and emits Doxia events into the given sink.- Specified by:
parsein interfaceParser- Overrides:
parsein classAbstractParser- Parameters:
source- not null reader that provides the source document. You could usenewReadermethods 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 AptParseExceptionParse 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 AptParseExceptionParse 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:
initin classAbstractParser
-
traverseHead
private void traverseHead() throws AptParseExceptionParse the head of the Apt source document.- Throws:
AptParseException- if something goes wrong.
-
traverseBody
private void traverseBody() throws AptParseExceptionParse the body of the Apt source document.- Throws:
AptParseException- if something goes wrong.
-
traverseSection
private void traverseSection(int level) throws AptParseExceptionParse a section of the Apt source document.- Parameters:
level- The section level.- Throws:
AptParseException- if something goes wrong.
-
traverseSectionBlocks
private void traverseSectionBlocks() throws AptParseExceptionParse the section blocks of the Apt source document.- Throws:
AptParseException- if something goes wrong.
-
traverseList
private void traverseList() throws AptParseExceptionParse a list of the Apt source document.- Throws:
AptParseException- if something goes wrong.
-
traverseNumberedList
private void traverseNumberedList() throws AptParseExceptionParse a numbered list of the Apt source document.- Throws:
AptParseException- if something goes wrong.
-
traverseDefinitionList
private void traverseDefinitionList() throws AptParseExceptionParse a definition list of the Apt source document.- Throws:
AptParseException- if something goes wrong.
-
nextBlock
private void nextBlock() throws AptParseExceptionParse the next block of the Apt source document.- Throws:
AptParseException- if something goes wrong.
-
nextBlock
private void nextBlock(boolean firstBlock) throws AptParseExceptionParse 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 AptParseExceptionChecks 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 AptParseExceptionParse 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 AptParseExceptionParse 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 AptParseExceptionParse 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 AptParseExceptionParse 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 themsgas 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
-
-