Package org.apache.maven.doxia.parser
Class AbstractParser
java.lang.Object
org.apache.maven.doxia.parser.AbstractParser
- All Implemented Interfaces:
Parser
- Direct Known Subclasses:
AbstractTextParser,AbstractXmlParser
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
-
Field Summary
Fields inherited from interface org.apache.maven.doxia.parser.Parser
TXT_TYPE, UNKNOWN_TYPE, XML_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSinkWrapperFactory(SinkWrapperFactory factory) Registers a givenSinkWrapperFactorywith the parser used in subsequent calls ofparse(...)protected static StringThe current Doxia version.voidexecuteMacro(String macroId, MacroRequest request, org.apache.maven.doxia.sink.Sink sink) Execute a macro on the given sink.protected FileDeprecated.this does not work in multi-module builds, see DOXIA-373protected MacroManagerGets the currentMacroManager.protected List<SinkWrapperFactory> Returns all sink wrapper factories (both registered automatically and manually).intgetType()protected org.apache.maven.doxia.sink.SinkgetWrappedSink(org.apache.maven.doxia.sink.Sink sink) Creates a sink pipeline built from all registeredSinkWrapperFactoryobjects.protected voidinit()Initialize the parser.booleanReturns whether anchors are automatically generated for each index entry found byIndexingSinkor not.booleanisEmitComments.protected booleanIndicates if we are currently parsing a second time.voidParses the given source model and emits Doxia events into the given sink.voidConvenience method to parse an arbitrary string and emit events into the given sink.voidConvenience method to parse an arbitrary string and emit events into the given sink.voidsetEmitAnchorsForIndexableEntries(boolean emitAnchors) Determines whether to automatically generate anchors for each index entry found byIndexingSinkor not.voidsetEmitComments(boolean emitComments) When comments are found in source markup, emit comment Doxia events or just ignore?voidsetSecondParsing(boolean second) SetsecondParsingto true, if this represents a secondary parsing of the same source.
-
Constructor Details
-
AbstractParser
public AbstractParser()
-
-
Method Details
-
getType
public int getType() -
setEmitComments
public void setEmitComments(boolean emitComments) When comments are found in source markup, emit comment Doxia events or just ignore?- Specified by:
setEmitCommentsin interfaceParser- Parameters:
emitComments-true(default value) to emit comment Doxia events
-
isEmitComments
public boolean isEmitComments()isEmitComments.
- Specified by:
isEmitCommentsin interfaceParser- Returns:
- a boolean
-
isEmitAnchorsForIndexableEntries
public boolean isEmitAnchorsForIndexableEntries()Description copied from interface:ParserReturns whether anchors are automatically generated for each index entry found byIndexingSinkor not.- Specified by:
isEmitAnchorsForIndexableEntriesin interfaceParser- Returns:
trueif anchors are emitted otherwisefalse
-
setEmitAnchorsForIndexableEntries
public void setEmitAnchorsForIndexableEntries(boolean emitAnchors) Description copied from interface:ParserDetermines whether to automatically generate anchors for each index entry found byIndexingSinkor not. By default no anchors are generated.- Specified by:
setEmitAnchorsForIndexableEntriesin interfaceParser- Parameters:
emitAnchors-trueto emit anchors otherwisefalse(the default)
-
executeMacro
public void executeMacro(String macroId, MacroRequest request, org.apache.maven.doxia.sink.Sink sink) throws MacroExecutionException, MacroNotFoundException Execute a macro on the given sink.- Parameters:
macroId- an id to lookup the macrorequest- the corresponding MacroRequestsink- the sink to receive the events- Throws:
MacroExecutionException- if an error occurred during executionMacroNotFoundException- if the macro could not be found
-
getBasedir
Deprecated.this does not work in multi-module builds, see DOXIA-373Returns the current base directory.- Returns:
- the base directory
-
parse
Convenience method to parse an arbitrary string and emit events into the given sink.- Parameters:
string- a string that provides the source inputsink- 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, org.apache.maven.doxia.sink.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 inputsink- a sink that consumes the Doxia eventsreference- 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
Parses the given source model and emits Doxia events into the given sink. Shortcut forParser.parse(Reader, Sink, String)with last argument beingnull.- 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.
-
getWrappedSink
protected org.apache.maven.doxia.sink.Sink getWrappedSink(org.apache.maven.doxia.sink.Sink sink) Creates a sink pipeline built from all registeredSinkWrapperFactoryobjects. For secondary parsers (i.e. ones withisSecondParsing()returningtruejust the given original sink is returned.- Parameters:
sink-- Returns:
- the Sink pipeline to be used
-
setSecondParsing
public void setSecondParsing(boolean second) SetsecondParsingto 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:ParserRegisters a givenSinkWrapperFactorywith the parser used in subsequent calls ofparse(...)- Specified by:
addSinkWrapperFactoryin interfaceParser- 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 currentMacroManager.- Returns:
- the current
MacroManager - Since:
- 1.1
-
init
protected void init()Initialize the parser. This is called first byparse(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
The current Doxia version.- Returns:
- the current Doxia version as a String
- Since:
- 1.2
-