Class AbstractParser

java.lang.Object
org.apache.maven.doxia.parser.AbstractParser
All Implemented Interfaces:
MacroExecutor, Parser
Direct Known Subclasses:
AbstractTextParser, AbstractXmlParser

public abstract class AbstractParser extends Object implements Parser, MacroExecutor
An abstract base class that defines some convenience methods for parsers. Provides a macro mechanism to give dynamic functionalities for the parsing.
Since:
1.0
Author:
Jason van Zyl
  • Constructor Details

  • Method Details

    • getType

      public int getType()
      The parser type value could be Parser.UNKNOWN_TYPE, Parser.TXT_TYPE or Parser.XML_TYPE.
      Specified by:
      getType in interface Parser
      Returns:
      a int
    • setEmitComments

      public void setEmitComments(boolean emitComments)
      Description copied from interface: Parser
      When comments are found in source markup, emit comment Doxia events or just ignore?
      Specified by:
      setEmitComments in interface Parser
      Parameters:
      emitComments - true (default value) to emit comment Doxia events
    • isEmitComments

      public boolean isEmitComments()

      isEmitComments.

      Specified by:
      isEmitComments in interface Parser
      Returns:
      a boolean
    • isEmitAnchorsForIndexableEntries

      Description copied from interface: Parser
      Returns whether anchors are automatically generated for each index entry found by IndexingSink or not.
      Specified by:
      isEmitAnchorsForIndexableEntries in interface Parser
      Returns:
      true if anchors are emitted otherwise false
    • setEmitAnchorsForIndexableEntries

      public void setEmitAnchorsForIndexableEntries(boolean emitAnchors)
      Description copied from interface: Parser
      Determines whether to automatically generate anchors for each index entry found by IndexingSink or not. By default no anchors are generated.
      Specified by:
      setEmitAnchorsForIndexableEntries in interface Parser
      Parameters:
      emitAnchors - true to emit anchors otherwise false (the default)
    • setMacroExecutor

      public void setMacroExecutor(MacroExecutor macroExecutor)
      Description copied from interface: Parser
      Delegates macro execution to the given MacroExecutor.
      Specified by:
      setMacroExecutor in interface Parser
      Parameters:
      macroExecutor - (may be null to use the built-in macro executor, which resolves all macros to Sink methods)}
    • executeMacro

      public void executeMacro(String macroId, MacroRequest request, Sink sink) throws MacroExecutionException, MacroNotFoundException
      Execute a macro on the given sink.
      Specified by:
      executeMacro in interface MacroExecutor
      Parameters:
      macroId - an id to lookup the macro
      request - the corresponding MacroRequest
      sink - the sink to receive the events
      Throws:
      MacroExecutionException - if an error occurred during execution
      MacroNotFoundException - if the macro could not be found
    • getBasedir

      protected File getBasedir()
      Deprecated.
      this does not work in multi-module builds, see DOXIA-373
      Returns the current base directory.
      Returns:
      the base directory
    • parse

      public void parse(String string, Sink sink) throws ParseException
      Convenience method to parse an arbitrary string and emit events into the given sink.
      Parameters:
      string - a string that provides the source input
      sink - a sink that consumes the Doxia events
      Throws:
      ParseException - if the string could not be parsed
      Since:
      1.1
    • parse

      public void parse(String string, Sink sink, String reference) throws ParseException
      Convenience method to parse an arbitrary string and emit events into the given sink.
      Parameters:
      string - a string that provides the source input
      sink - a sink that consumes the Doxia events
      reference - a string containing the reference to the source of the input string (e.g. filename)
      Throws:
      ParseException - if the string could not be parsed
      Since:
      1.10
    • parse

      public void parse(Reader source, Sink sink) throws ParseException
      Description copied from interface: Parser
      Parses the given source model and emits Doxia events into the given sink. Shortcut for Parser.parse(Reader, Sink, String) with last argument being null.
      Specified by:
      parse in interface Parser
      Parameters:
      source - not null reader that provides the source document.
      sink - A sink that consumes the Doxia events.
      Throws:
      ParseException - if the model could not be parsed.
    • getWrappedSink

      protected Sink getWrappedSink(Sink sink)
      Creates a sink pipeline built from all registered SinkWrapperFactory objects. For secondary parsers (i.e. ones with isSecondParsing() returning true just the given original sink is returned.
      Parameters:
      sink -
      Returns:
      the Sink pipeline to be used
    • setSecondParsing

      public void setSecondParsing(boolean second)
      Set secondParsing to true, if this represents a secondary parsing of the same source.
      Parameters:
      second - true for second parsing
    • isSecondParsing

      protected boolean isSecondParsing()
      Indicates if we are currently parsing a second time.
      Returns:
      true if we are currently parsing a second time
      Since:
      1.1
    • addSinkWrapperFactory

      Description copied from interface: Parser
      Registers a given SinkWrapperFactory with the parser used in subsequent calls of parse(...)
      Specified by:
      addSinkWrapperFactory in interface Parser
      Parameters:
      factory - the factory to create the sink wrapper
    • getSinkWrapperFactories

      Returns all sink wrapper factories (both registered automatically and manually). The collection is ordered in a way that the factories having the lowest priority come first (i.e. in reverse order).
      Returns:
      all sink wrapper factories in the reverse order
      Since:
      2.0.0
    • getMacroManager

      Gets the current MacroManager.
      Returns:
      the current MacroManager
      Since:
      1.1
    • init

      protected void init()
      Initialize the parser. This is called first by 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.
      Since:
      1.1.2
    • doxiaVersion

      protected static String doxiaVersion()
      The current Doxia version.
      Returns:
      the current Doxia version as a String
      Since:
      1.2