public abstract class AbstractXmlParser extends AbstractParser implements XmlMarkup
XML
parsers.Modifier and Type | Class and Description |
---|---|
static class |
AbstractXmlParser.CachedFileEntityResolver
Implementation of the callback mechanism
EntityResolver . |
BANG, CDATA, DOCTYPE_START, ENTITY_START, XML_NAMESPACE
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
ROLE, TXT_TYPE, UNKNOWN_TYPE, XML_TYPE
Constructor and Description |
---|
AbstractXmlParser() |
Modifier and Type | Method and Description |
---|---|
protected SinkEventAttributeSet |
getAttributesFromParser(XmlPullParser parser)
Converts the attributes of the current start tag of the given parser to a SinkEventAttributeSet.
|
protected Map<String,String> |
getLocalEntities()
Return the defined entities in a local doctype.
|
protected String |
getText(XmlPullParser parser)
getText.
|
int |
getType()
|
protected void |
handleCdsect(XmlPullParser parser,
Sink sink)
Handles CDATA sections.
|
protected void |
handleComment(XmlPullParser parser,
Sink sink)
Handles comments.
|
protected abstract void |
handleEndTag(XmlPullParser parser,
Sink sink)
Goes through the possible end tags.
|
protected void |
handleEntity(XmlPullParser parser,
Sink sink)
Handles entities.
|
protected abstract void |
handleStartTag(XmlPullParser parser,
Sink sink)
Goes through the possible start tags.
|
protected void |
handleText(XmlPullParser parser,
Sink sink)
Handles text events.
|
protected void |
handleUnknown(XmlPullParser parser,
Sink sink,
int type)
Handles an unknown event.
|
protected void |
initXmlParser(XmlPullParser parser)
Initializes the parser with custom entities or other options.
|
protected boolean |
isCollapsibleWhitespace()
isCollapsibleWhitespace.
|
protected boolean |
isIgnorableWhitespace()
isIgnorableWhitespace.
|
protected boolean |
isTrimmableWhitespace()
isTrimmableWhitespace.
|
boolean |
isValidate()
isValidate.
|
void |
parse(Reader source,
Sink sink)
Parses the given source model and emits Doxia events into the given sink.
|
void |
parse(String string,
Sink sink)
Convenience method to parse an arbitrary string and emit events into the given sink.
|
protected void |
setCollapsibleWhitespace(boolean collapsible)
Specify that text will be collapsed.
|
protected void |
setIgnorableWhitespace(boolean ignorable)
Specify that whitespace will be ignored.
|
protected void |
setTrimmableWhitespace(boolean trimmable)
Specify that text will be collapsed.
|
void |
setValidate(boolean validate)
Specify a flag to validate or not the XML content.
|
doxiaVersion, enableLogging, executeMacro, getBasedir, getLog, getMacroManager, init, isEmitComments, isSecondParsing, parse, setEmitComments, setSecondParsing
public AbstractXmlParser()
public void parse(Reader source, Sink sink) throws ParseException
parse
in interface Parser
source
- not null reader that provides the source document.
You could use newReader
methods from ReaderFactory
.sink
- A sink that consumes the Doxia events.ParseException
- if the model could not be parsed.protected void initXmlParser(XmlPullParser parser) throws XmlPullParserException
parser
- A parser, not null.XmlPullParserException
- if there's a problem initializing the parserpublic void parse(String string, Sink sink) throws ParseException
parse
in class AbstractParser
string
- A string that provides the source input.sink
- A sink that consumes the Doxia events.ParseException
- if the string could not be parsed.public final int getType()
getType
in interface Parser
getType
in class AbstractParser
protected SinkEventAttributeSet getAttributesFromParser(XmlPullParser parser)
parser
- A parser, not null.protected abstract void handleStartTag(XmlPullParser parser, Sink sink) throws XmlPullParserException, MacroExecutionException
parser
- A parser, not null.sink
- the sink to receive the events.XmlPullParserException
- if there's a problem parsing the modelMacroExecutionException
- if there's a problem executing a macroprotected abstract void handleEndTag(XmlPullParser parser, Sink sink) throws XmlPullParserException, MacroExecutionException
parser
- A parser, not null.sink
- the sink to receive the events.XmlPullParserException
- if there's a problem parsing the modelMacroExecutionException
- if there's a problem executing a macroprotected void handleText(XmlPullParser parser, Sink sink) throws XmlPullParserException
This is a default implementation, if the parser points to a non-empty text element, it is emitted as a text event into the specified sink.
parser
- A parser, not null.sink
- the sink to receive the events. Not null.XmlPullParserException
- if there's a problem parsing the modelprotected void handleCdsect(XmlPullParser parser, Sink sink) throws XmlPullParserException
This is a default implementation, all data are emitted as text events into the specified sink.
parser
- A parser, not null.sink
- the sink to receive the events. Not null.XmlPullParserException
- if there's a problem parsing the modelprotected void handleComment(XmlPullParser parser, Sink sink) throws XmlPullParserException
This is a default implementation, all data are emitted as comment events into the specified sink.
parser
- A parser, not null.sink
- the sink to receive the events. Not null.XmlPullParserException
- if there's a problem parsing the modelprotected void handleEntity(XmlPullParser parser, Sink sink) throws XmlPullParserException
This is a default implementation, all entities are resolved and emitted as text events into the specified sink, except:
#160
, nbsp
and #x00A0
are emitted as nonBreakingSpace()
events.parser
- A parser, not null.sink
- the sink to receive the events. Not null.XmlPullParserException
- if there's a problem parsing the modelprotected void handleUnknown(XmlPullParser parser, Sink sink, int type)
This is a default implementation, all events are emitted as unknown events into the specified sink.
parser
- the parser to get the event from.sink
- the sink to receive the event.type
- the tag event type. This should be one of HtmlMarkup.TAG_TYPE_SIMPLE,
HtmlMarkup.TAG_TYPE_START, HtmlMarkup.TAG_TYPE_END or HtmlMarkup.ENTITY_TYPE.
It will be passed as the first argument of the required parameters to the Sink
Sink.unknown(String, Object[], org.apache.maven.doxia.sink.SinkEventAttributes)
method.protected boolean isIgnorableWhitespace()
isIgnorableWhitespace.
true
if whitespace will be ignored, false
otherwise.setIgnorableWhitespace(boolean)
protected void setIgnorableWhitespace(boolean ignorable)
<tr> <td/> </tr>is equivalent to
<tr><td/></tr>
ignorable
- true
to ignore whitespace, false
otherwise.protected boolean isCollapsibleWhitespace()
isCollapsibleWhitespace.
true
if text will collapse, false
otherwise.setCollapsibleWhitespace(boolean)
protected void setCollapsibleWhitespace(boolean collapsible)
Text Textis equivalent to
Text Text
collapsible
- true
to allow collapsible text, false
otherwise.protected boolean isTrimmableWhitespace()
isTrimmableWhitespace.
true
if text will be trim, false
otherwise.setTrimmableWhitespace(boolean)
protected void setTrimmableWhitespace(boolean trimmable)
<p> Text </p>is equivalent to
<p>Text</p>
trimmable
- true
to allow trimmable text, false
otherwise.protected String getText(XmlPullParser parser)
getText.
parser
- A parser, not null.XmlPullParser.getText()
taking care of trimmable or collapsible configuration.XmlPullParser.getText()
,
isCollapsibleWhitespace()
,
isTrimmableWhitespace()
protected Map<String,String> getLocalEntities()
<!DOCTYPE foo [ <!ENTITY bar "Š"> <!ENTITY bar1 "š"> ]>
public boolean isValidate()
isValidate.
true
if XML content will be validate, false
otherwise.public void setValidate(boolean validate)
validate
- the validate to setparse(Reader, Sink)
Copyright © 2005–2017 The Apache Software Foundation. All rights reserved.