Package org.apache.maven.doxia.parser
Class AbstractXmlParser
- java.lang.Object
-
- org.apache.maven.doxia.parser.AbstractParser
-
- org.apache.maven.doxia.parser.AbstractXmlParser
-
- All Implemented Interfaces:
LogEnabled,Markup,XmlMarkup,Parser
- Direct Known Subclasses:
DocBookParser,FmlParser,Xhtml5BaseParser,XhtmlBaseParser
public abstract class AbstractXmlParser extends AbstractParser implements XmlMarkup
An abstract class that defines some convenience methods forXMLparsers.- Since:
- 1.0
- Version:
- $Id$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractXmlParser.CachedFileEntityResolverImplementation of the callback mechanismEntityResolver.
-
Field Summary
Fields Modifier and Type Field Description private booleancollapsibleWhitespaceprivate java.util.Map<java.lang.String,java.lang.String>entitiesprivate booleanignorableWhitespaceprivate static java.util.regex.PatternPATTERN_ENTITY_1Entity pattern for HTML entity, i.e.private static java.util.regex.PatternPATTERN_ENTITY_2Entity pattern for Unicode entity, i.e.private booleantrimmableWhitespaceprivate booleanvalidate-
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
-
Fields inherited from interface org.apache.maven.doxia.markup.XmlMarkup
BANG, CDATA, DOCTYPE_START, ENTITY_START, XML_NAMESPACE
-
-
Constructor Summary
Constructors Constructor Description AbstractXmlParser()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidaddDTDEntities(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, java.lang.String text)Handle entities defined in external doctypes as the following:private voidaddEntity(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, java.lang.String entityName, java.lang.String entityValue)private voidaddLocalEntities(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, java.lang.String text)Handle entities defined in a local doctype as the following:protected SinkEventAttributeSetgetAttributesFromParser(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)Converts the attributes of the current start tag of the given parser to a SinkEventAttributeSet.protected java.util.Map<java.lang.String,java.lang.String>getLocalEntities()Return the defined entities in a local doctype.protected java.lang.StringgetText(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)getText.intgetType()protected voidhandleCdsect(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink)Handles CDATA sections.protected voidhandleComment(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink)Handles comments.protected abstract voidhandleEndTag(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink)Goes through the possible end tags.protected voidhandleEntity(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink)Handles entities.protected abstract voidhandleStartTag(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink)Goes through the possible start tags.protected voidhandleText(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink)Handles text events.protected voidhandleUnknown(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink, int type)Handles an unknown event.protected voidinitXmlParser(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)Initializes the parser with custom entities or other options.protected booleanisCollapsibleWhitespace()isCollapsibleWhitespace.protected booleanisIgnorableWhitespace()isIgnorableWhitespace.protected booleanisTrimmableWhitespace()isTrimmableWhitespace.booleanisValidate()isValidate.voidparse(java.io.Reader source, Sink sink)Parses the given source model and emits Doxia events into the given sink.voidparse(java.lang.String string, Sink sink)Convenience method to parse an arbitrary string and emit events into the given sink.private voidparseXml(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink)Parse the model from the XmlPullParser into the given sink.protected voidsetCollapsibleWhitespace(boolean collapsible)Specify that text will be collapsed.protected voidsetIgnorableWhitespace(boolean ignorable)Specify that whitespace will be ignored.protected voidsetTrimmableWhitespace(boolean trimmable)Specify that text will be collapsed.voidsetValidate(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, isEmitComments, isSecondParsing, parse, setEmitComments, setSecondParsing
-
-
-
-
Field Detail
-
PATTERN_ENTITY_1
private static final java.util.regex.Pattern PATTERN_ENTITY_1
Entity pattern for HTML entity, i.e. "|^\\s]+)(\\s)+\"(\\s)*(&[a-zA-Z]{2,6};)(\\s)*\"(\\s)*>
see http://www.w3.org/TR/REC-xml/#NT-EntityDecl.
-
PATTERN_ENTITY_2
private static final java.util.regex.Pattern PATTERN_ENTITY_2
Entity pattern for Unicode entity, i.e. & "|^\\s]+)(\\s)+\"(\\s)*(&(#x?[0-9a-fA-F]{1,5};)*)(\\s)*\"(\\s)*>"
see http://www.w3.org/TR/REC-xml/#NT-EntityDecl.
-
ignorableWhitespace
private boolean ignorableWhitespace
-
collapsibleWhitespace
private boolean collapsibleWhitespace
-
trimmableWhitespace
private boolean trimmableWhitespace
-
entities
private java.util.Map<java.lang.String,java.lang.String> entities
-
validate
private boolean validate
-
-
Method Detail
-
parse
public void parse(java.io.Reader source, Sink sink) throws ParseExceptionParses the given source model and emits Doxia events into the given sink.- 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.
-
initXmlParser
protected void initXmlParser(org.codehaus.plexus.util.xml.pull.XmlPullParser parser) throws org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionInitializes the parser with custom entities or other options.- Parameters:
parser- A parser, not null.- Throws:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if there's a problem initializing the parser
-
parse
public void parse(java.lang.String string, Sink sink) throws ParseExceptionConvenience 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:
parsein classAbstractParser- 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()
- Specified by:
getTypein interfaceParser- Overrides:
getTypein classAbstractParser- Returns:
- the type of Parser
-
getAttributesFromParser
protected SinkEventAttributeSet getAttributesFromParser(org.codehaus.plexus.util.xml.pull.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
-
parseXml
private void parseXml(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink) throws org.codehaus.plexus.util.xml.pull.XmlPullParserException, MacroExecutionExceptionParse the model from the XmlPullParser into the given sink.- Parameters:
parser- A parser, not null.sink- the sink to receive the events.- Throws:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if there's a problem parsing the modelMacroExecutionException- if there's a problem executing a macro
-
handleStartTag
protected abstract void handleStartTag(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink) throws org.codehaus.plexus.util.xml.pull.XmlPullParserException, MacroExecutionExceptionGoes through the possible start tags.- Parameters:
parser- A parser, not null.sink- the sink to receive the events.- Throws:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if there's a problem parsing the modelMacroExecutionException- if there's a problem executing a macro
-
handleEndTag
protected abstract void handleEndTag(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink) throws org.codehaus.plexus.util.xml.pull.XmlPullParserException, MacroExecutionExceptionGoes through the possible end tags.- Parameters:
parser- A parser, not null.sink- the sink to receive the events.- Throws:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if there's a problem parsing the modelMacroExecutionException- if there's a problem executing a macro
-
handleText
protected void handleText(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink) throws org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionHandles 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:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if there's a problem parsing the model
-
handleCdsect
protected void handleCdsect(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink) throws org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionHandles 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:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if there's a problem parsing the model
-
handleComment
protected void handleComment(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink) throws org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionHandles 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:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if there's a problem parsing the model
-
handleEntity
protected void handleEntity(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink) throws org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionHandles entities.This is a default implementation, all entities are resolved and emitted as text events into the specified sink, except:
- the entities with names
#160,nbspand#x00A0are emitted asnonBreakingSpace()events.
- Parameters:
parser- A parser, not null.sink- the sink to receive the events. Not null.- Throws:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if there's a problem parsing the model
- the entities with names
-
handleUnknown
protected void handleUnknown(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Sink sink, int type)Handles an unknown 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 SinkSink.unknown(String, Object[], org.apache.maven.doxia.sink.SinkEventAttributes)method.
-
isIgnorableWhitespace
protected boolean isIgnorableWhitespace()
isIgnorableWhitespace.
- Returns:
trueif whitespace will be ignored,falseotherwise.- 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-trueto ignore whitespace,falseotherwise.- Since:
- 1.1
-
isCollapsibleWhitespace
protected boolean isCollapsibleWhitespace()
isCollapsibleWhitespace.
- Returns:
trueif text will collapse,falseotherwise.- 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 toText Text
- Parameters:
collapsible-trueto allow collapsible text,falseotherwise.- Since:
- 1.1
-
isTrimmableWhitespace
protected boolean isTrimmableWhitespace()
isTrimmableWhitespace.
- Returns:
trueif text will be trim,falseotherwise.- 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-trueto allow trimmable text,falseotherwise.- Since:
- 1.1
-
getText
protected java.lang.String getText(org.codehaus.plexus.util.xml.pull.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 java.util.Map<java.lang.String,java.lang.String> getLocalEntities()
Return the defined entities in a local doctype. I.e.:<!DOCTYPE foo [ <!ENTITY bar "Š"> <!ENTITY bar1 "š"> ]>
- Returns:
- a map of the defined entities in a local doctype.
- Since:
- 1.1
-
isValidate
public boolean isValidate()
isValidate.
- Returns:
trueif XML content will be validate,falseotherwise.- 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)
-
addEntity
private void addEntity(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, java.lang.String entityName, java.lang.String entityValue) throws org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionAdd an entity given byentityNameandentityValuetoentities.
By default, we exclude the default XML entities: &, <, >, " and '.- Parameters:
parser- not nullentityName- not nullentityValue- not null- Throws:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if any- See Also:
XmlPullParser.defineEntityReplacementText(String, String)
-
addLocalEntities
private void addLocalEntities(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, java.lang.String text) throws org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionHandle entities defined in a local doctype as the following:<!DOCTYPE foo [ <!ENTITY bar "Š"> <!ENTITY bar1 "š"> ]>
- Parameters:
parser- not nulltext- not null- Throws:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if any
-
addDTDEntities
private void addDTDEntities(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, java.lang.String text) throws org.codehaus.plexus.util.xml.pull.XmlPullParserExceptionHandle entities defined in external doctypes as the following:<!DOCTYPE foo [ <!-- These are the entity sets for ISO Latin 1 characters for the XHTML --> <!ENTITY % HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for XHTML//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent"> %HTMLlat1; ]>- Parameters:
parser- not nulltext- not null- Throws:
org.codehaus.plexus.util.xml.pull.XmlPullParserException- if any
-
-