Class 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
  • Field Details

    • TITLE

      private static final int TITLE
      Title event id
      See Also:
    • SECTION1

      private static final int SECTION1
      Section 1 event id
      See Also:
    • SECTION2

      private static final int SECTION2
      Section 2 event id
      See Also:
    • SECTION3

      private static final int SECTION3
      Section 3 event id
      See Also:
    • SECTION4

      private static final int SECTION4
      Section 4 event id
      See Also:
    • SECTION5

      private static final int SECTION5
      Section 5 event id
      See Also:
    • PARAGRAPH

      private static final int PARAGRAPH
      Paragraph event id
      See Also:
    • VERBATIM

      private static final int VERBATIM
      Verbatim event id
      See Also:
    • FIGURE

      private static final int FIGURE
      Figure event id
      See Also:
    • TABLE

      private static final int TABLE
      Table event id
      See Also:
    • LIST_ITEM

      private static final int LIST_ITEM
      List event id
      See Also:
    • NUMBERED_LIST_ITEM

      private static final int NUMBERED_LIST_ITEM
      Numbered list event id
      See Also:
    • DEFINITION_LIST_ITEM

      private static final int DEFINITION_LIST_ITEM
      Definition list event id
      See Also:
    • HORIZONTAL_RULE

      private static final int HORIZONTAL_RULE
      Horizontal rule event id
      See Also:
    • PG_BREAK

      private static final int PG_BREAK
      Page break event id
      See Also:
    • LIST_BREAK

      private static final int LIST_BREAK
      List break event id
      See Also:
    • MACRO

      private static final int MACRO
      Macro event id
      See Also:
    • COMMENT_BLOCK

      private static final int COMMENT_BLOCK
      Comment event id.
      See Also:
    • TYPE_NAMES

      private static final 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:
    • source

      private AptSource source
      the AptSource.
    • block

      private AptParser.Block block
      a block of AptSource.
    • blockFileName

      private String blockFileName
      blockFileName.
    • blockLineNumber

      private int blockLineNumber
      blockLineNumber.
    • sourceContent

      protected String sourceContent
      sourceContent.
    • sink

      protected Sink sink
      the sink to receive the events.
    • line

      protected String line
      a line of AptSource.
    • warnMessages

      protected Map<String,Set<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:
  • Constructor Details

    • AptParser

      public AptParser()
  • Method Details

    • parse

      public void parse(Reader source, Sink sink) throws ParseException
      Parses the given source model and emits Doxia events into the given sink.
      Specified by:
      parse in interface Parser
      Overrides:
      parse in class AbstractParser
      Parameters:
      source - not null reader that provides the source document. You could use newReader methods from ReaderFactory.
      sink - A sink that consumes the Doxia events.
      Throws:
      ParseException - if the model could not be parsed.
    • parse

      public void parse(Reader source, Sink sink, String reference) throws ParseException
      Parses the given source model and emits Doxia events into the given sink.
      Specified by:
      parse in interface Parser
      Parameters:
      source - not null reader that provides the source document. You could use newReader methods from ReaderFactory.
      sink - A sink that consumes the Doxia events.
      reference - the reference
      Throws:
      ParseException - if the model could not be parsed.
    • getSourceName

      public 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(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(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(String string, int length, int i)
      Skip spaces.
      Parameters:
      string - string.
      length - length.
      i - offset.
      Returns:
      int.
    • replaceAll

      protected static String replaceAll(String string, String oldSub, String newSub)
      Replace part of a string.
      Parameters:
      string - the string
      oldSub - the substring to replace
      newSub - the replacement string
      Returns:
      String
    • init

      protected void init()
      Initialize the parser. This is called first by AbstractParser.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 class AbstractParser
    • 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(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(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

      private String getTraversedLink(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 String getTraversedAnchor(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 String doGetTraversedLink(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(String key, String msg)
      If debug mode is enabled, log the msg as is, otherwise add unique msg in warnMessages.
      Parameters:
      key - not null
      msg - not null
      Since:
      1.1.1
      See Also:
    • logWarnings

      private void logWarnings()
      Since:
      1.1.2