public class HtmlParserFactory extends Object
HtmlParser
.
Currently each instance is a new object given these are fairly
light-weight.
In the unlikely case that this class fails to initialize properly
(a developer error), an error is emitted to the error console and the logs
and the specialized parser creation methods will throw
an AssertionError
on all invokations.
Modifier and Type | Class and Description |
---|---|
static class |
HtmlParserFactory.AttributeOptions
To provide additional options when creating an
HtmlParser using
createParserInAttribute(HtmlParser.ATTR_TYPE,
boolean, Set) |
static class |
HtmlParserFactory.ModeOptions
To provide additional options when creating an
HtmlParser using
createParserInMode(HtmlParser.Mode, Set) |
Modifier and Type | Method and Description |
---|---|
static HtmlParser |
createParser()
Returns an
HtmlParser object ready to parse HTML input. |
static HtmlParser |
createParser(HtmlParser aHtmlParser)
Returns an
HtmlParser that is a copy of the one
supplied. |
static HtmlParser |
createParserInAttribute(HtmlParser.ATTR_TYPE attrtype,
boolean quoted,
Set<HtmlParserFactory.AttributeOptions> options)
A very specialized
HtmlParser accessor that returns a parser
in a state where it expects to read the value of an attribute
of an HTML tag. |
static HtmlParser |
createParserInMode(HtmlParser.Mode mode,
Set<HtmlParserFactory.ModeOptions> options)
Returns an
HtmlParser object initialized with the
requested Mode. |
public static HtmlParser createParser()
HtmlParser
object ready to parse HTML input.HtmlParser
in the provided modepublic static HtmlParser createParserInMode(HtmlParser.Mode mode, Set<HtmlParserFactory.ModeOptions> options)
HtmlParser
object initialized with the
requested Mode. Provide non null
options to provide
a more precise initialization with the desired Mode.mode
- the mode to reset the parser withoptions
- additional options or null
for noneHtmlParser
in the provided modeAssertionError
- when this class failed to initializepublic static HtmlParser createParser(HtmlParser aHtmlParser)
HtmlParser
that is a copy of the one
supplied. It holds the same internal state and hence can
proceed with parsing in-lieu of the supplied parser.aHtmlParser
- a HtmlParser
to copy fromHtmlParser
that is a copy of the provided oneAssertionError
- when this class failed to initializepublic static HtmlParser createParserInAttribute(HtmlParser.ATTR_TYPE attrtype, boolean quoted, Set<HtmlParserFactory.AttributeOptions> options)
HtmlParser
accessor that returns a parser
in a state where it expects to read the value of an attribute
of an HTML tag. This is only useful when the parser has not seen a
certain HTML tag and an attribute name and needs to continue parsing
from a state as though it has.
For example, to create a parser in a state akin to that after the parser has parsed "<a href=\"", invoke:
createParserInAttribute(HtmlParser.ATTR_TYPE.URI, true)}
You must provide the proper value of quoting or the parser
will go into an unexpected state.
As a special-case, when called with the HtmlParser.ATTR_TYPE
of HtmlParser.ATTR_TYPE.NONE
, the parser is created in a state
inside an HTML tag where it expects an attribute name not an attribute
value. It becomes equivalent to a parser initialized in the
HTML_IN_TAG
mode.
attrtype
- the attribute type which the parser should be inquoted
- whether the attribute value is enclosed in double quotesoptions
- additional options or null
for noneHtmlParser
initialized in the given attribute type
and quotingAssertionError
- when this class failed to initializeCopyright © 2010–2019 Google. All rights reserved.