com.google.streamhtmlparser
Class HtmlParserFactory

java.lang.Object
  extended by com.google.streamhtmlparser.HtmlParserFactory

public class HtmlParserFactory
extends Object

A factory class to obtain instances of an 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.


Nested Class Summary
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)
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createParser

public static HtmlParser createParser()
Returns an HtmlParser object ready to parse HTML input.

Returns:
an HtmlParser in the provided mode

createParserInMode

public static HtmlParser createParserInMode(HtmlParser.Mode mode,
                                            Set<HtmlParserFactory.ModeOptions> options)
Returns an HtmlParser object initialized with the requested Mode. Provide non null options to provide a more precise initialization with the desired Mode.

Parameters:
mode - the mode to reset the parser with
options - additional options or null for none
Returns:
an HtmlParser in the provided mode
Throws:
AssertionError - when this class failed to initialize

createParser

public static HtmlParser createParser(HtmlParser aHtmlParser)
Returns an 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.

Parameters:
aHtmlParser - a HtmlParser to copy from
Returns:
an HtmlParser that is a copy of the provided one
Throws:
AssertionError - when this class failed to initialize

createParserInAttribute

public 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. 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.

Parameters:
attrtype - the attribute type which the parser should be in
quoted - whether the attribute value is enclosed in double quotes
options - additional options or null for none
Returns:
an HtmlParser initialized in the given attribute type and quoting
Throws:
AssertionError - when this class failed to initialize


Copyright © 2010-2012 Google. All Rights Reserved.