org.apache.maven.doxia.parser
Class AbstractXmlParser

java.lang.Object
  extended by org.apache.maven.doxia.parser.AbstractParser
      extended by org.apache.maven.doxia.parser.AbstractXmlParser
All Implemented Interfaces:
LogEnabled, Markup, XmlMarkup, Parser
Direct Known Subclasses:
XhtmlBaseParser

public abstract class AbstractXmlParser
extends AbstractParser
implements XmlMarkup

An abstract class that defines some convenience methods for XML parsers.

Since:
1.0
Version:
$Id: AbstractXmlParser.java 1185112 2011-10-17 11:33:00Z ltheussl $
Author:
Vincent Siveton

Nested Class Summary
static class AbstractXmlParser.CachedFileEntityResolver
          Implementation of the callback mechanism EntityResolver.
 
Field Summary
 
Fields inherited from interface org.apache.maven.doxia.markup.XmlMarkup
BANG, CDATA, DOCTYPE_START, ENTITY_START, XML_NAMESPACE
 
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
 
Constructor Summary
AbstractXmlParser()
           
 
Method Summary
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()
          The parser type value could be Parser.UNKNOWN_TYPE, Parser.TXT_TYPE or Parser.XML_TYPE.
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 unkown event.
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. Convenience method to parse an arbitrary string and emit any xml 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.
 
Methods inherited from class org.apache.maven.doxia.parser.AbstractParser
doxiaVersion, enableLogging, executeMacro, getBasedir, getLog, getMacroManager, init, isSecondParsing, setSecondParsing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractXmlParser

public AbstractXmlParser()
Method Detail

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
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(String string,
                  Sink sink)
           throws ParseException
Convenience method to parse an arbitrary string and emit events into the given sink. Convenience method to parse an arbitrary string and emit any xml events into the given sink.

Overrides:
parse in class AbstractParser
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.

getType

public final int getType()
The parser type value could be Parser.UNKNOWN_TYPE, Parser.TXT_TYPE or Parser.XML_TYPE.

Specified by:
getType in interface Parser
Overrides:
getType in class AbstractParser
Returns:
the type of Parser

getAttributesFromParser

protected SinkEventAttributeSet getAttributesFromParser(XmlPullParser parser)
Converts the attributes of the current start tag of the given parser to a SinkEventAttributeSet.

Parameters:
parser - A parser, not null.
Returns:
a SinkEventAttributeSet or null if the current parser event is not a start tag.
Since:
1.1

handleStartTag

protected abstract void handleStartTag(XmlPullParser parser,
                                       Sink sink)
                                throws XmlPullParserException,
                                       MacroExecutionException
Goes through the possible start tags.

Parameters:
parser - A parser, not null.
sink - the sink to receive the events.
Throws:
XmlPullParserException - if there's a problem parsing the model
MacroExecutionException - if there's a problem executing a macro

handleEndTag

protected abstract void handleEndTag(XmlPullParser parser,
                                     Sink sink)
                              throws XmlPullParserException,
                                     MacroExecutionException
Goes through the possible end tags.

Parameters:
parser - A parser, not null.
sink - the sink to receive the events.
Throws:
XmlPullParserException - if there's a problem parsing the model
MacroExecutionException - if there's a problem executing a macro

handleText

protected void handleText(XmlPullParser parser,
                          Sink sink)
                   throws XmlPullParserException
Handles text events.

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.

Parameters:
parser - A parser, not null.
sink - the sink to receive the events. Not null.
Throws:
XmlPullParserException - if there's a problem parsing the model

handleCdsect

protected void handleCdsect(XmlPullParser parser,
                            Sink sink)
                     throws XmlPullParserException
Handles CDATA sections.

This is a default implementation, all data are emitted as text events into the specified sink.

Parameters:
parser - A parser, not null.
sink - the sink to receive the events. Not null.
Throws:
XmlPullParserException - if there's a problem parsing the model

handleComment

protected void handleComment(XmlPullParser parser,
                             Sink sink)
                      throws XmlPullParserException
Handles comments.

This is a default implementation, all data are emitted as comment events into the specified sink.

Parameters:
parser - A parser, not null.
sink - the sink to receive the events. Not null.
Throws:
XmlPullParserException - if there's a problem parsing the model

handleEntity

protected void handleEntity(XmlPullParser parser,
                            Sink sink)
                     throws XmlPullParserException
Handles entities.

This is a default implementation, all entities are resolved and emitted as text events into the specified sink, except:

Parameters:
parser - A parser, not null.
sink - the sink to receive the events. Not null.
Throws:
XmlPullParserException - if there's a problem parsing the model

handleUnknown

protected void handleUnknown(XmlPullParser parser,
                             Sink sink,
                             int type)
Handles an unkown event.

This is a default implementation, all events are emitted as unknown events into the specified sink.

Parameters:
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.

isIgnorableWhitespace

protected boolean isIgnorableWhitespace()

isIgnorableWhitespace.

Returns:
true if whitespace will be ignored, false otherwise.
Since:
1.1
See Also:
setIgnorableWhitespace(boolean)

setIgnorableWhitespace

protected void setIgnorableWhitespace(boolean ignorable)
Specify that whitespace will be ignored. I.e.:
<tr> <td/> </tr>
is equivalent to
<tr><td/></tr>

Parameters:
ignorable - true to ignore whitespace, false otherwise.
Since:
1.1

isCollapsibleWhitespace

protected boolean isCollapsibleWhitespace()

isCollapsibleWhitespace.

Returns:
true if text will collapse, false otherwise.
Since:
1.1
See Also:
setCollapsibleWhitespace(boolean)

setCollapsibleWhitespace

protected void setCollapsibleWhitespace(boolean collapsible)
Specify that text will be collapsed. I.e.:
Text   Text
is equivalent to
Text Text

Parameters:
collapsible - true to allow collapsible text, false otherwise.
Since:
1.1

isTrimmableWhitespace

protected boolean isTrimmableWhitespace()

isTrimmableWhitespace.

Returns:
true if text will be trim, false otherwise.
Since:
1.1
See Also:
setTrimmableWhitespace(boolean)

setTrimmableWhitespace

protected void setTrimmableWhitespace(boolean trimmable)
Specify that text will be collapsed. I.e.:
<p> Text </p>
is equivalent to
<p>Text</p>

Parameters:
trimmable - true to allow trimmable text, false otherwise.
Since:
1.1

getText

protected String getText(XmlPullParser parser)

getText.

Parameters:
parser - A parser, not null.
Returns:
the XmlPullParser.getText() taking care of trimmable or collapsible configuration.
Since:
1.1
See Also:
XmlPullParser.getText(), isCollapsibleWhitespace(), isTrimmableWhitespace()

getLocalEntities

protected Map<String,String> getLocalEntities()
Return the defined entities in a local doctype. I.e.:
 <!DOCTYPE foo [
   <!ENTITY bar "&#x160;">
   <!ENTITY bar1 "&#x161;">
 ]>
 

Returns:
a map of the defined entities in a local doctype.
Since:
1.1

isValidate

public boolean isValidate()

isValidate.

Returns:
true if XML content will be validate, false otherwise.
Since:
1.1

setValidate

public void setValidate(boolean validate)
Specify a flag to validate or not the XML content.

Parameters:
validate - the validate to set
Since:
1.1
See Also:
parse(Reader, Sink)


Copyright © 2005-2012 The Apache Software Foundation. All Rights Reserved.