org.apache.shindig.gadgets.parse
Class GadgetHtmlParser

java.lang.Object
  extended by org.apache.shindig.gadgets.parse.GadgetHtmlParser
Direct Known Subclasses:
CajaHtmlParser, NekoSimplifiedHtmlParser

public abstract class GadgetHtmlParser
extends Object

Parser for arbitrary HTML content


Field Summary
protected  DOMImplementation documentFactory
           
static String PARSED_DOCUMENTS
           
static String PARSED_FRAGMENTS
           
 
Constructor Summary
protected GadgetHtmlParser(DOMImplementation documentFactory)
           
 
Method Summary
protected static boolean attemptFullDocParseFirst(String content)
           
protected  Document errorDom(DOMException e)
           
 Document parseDom(String source)
           
protected abstract  Document parseDomImpl(String source)
          TODO: remove the need for parseDomImpl as a parsing method.
 void parseFragment(String source, Node result)
          Parses a snippet of markup and appends the result as children to the provided node.
protected abstract  DocumentFragment parseFragmentImpl(String source)
           
protected  void prependToNode(Node to, LinkedList<Node> from)
           
 void setCacheProvider(CacheProvider cacheProvider)
           
 void setSerializerProvider(com.google.inject.Provider<HtmlSerializer> serProvider)
           
protected  boolean shouldCache()
           
protected  void transferChildren(Node to, Node from)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARSED_DOCUMENTS

public static final String PARSED_DOCUMENTS
See Also:
Constant Field Values

PARSED_FRAGMENTS

public static final String PARSED_FRAGMENTS
See Also:
Constant Field Values

documentFactory

protected final DOMImplementation documentFactory
Constructor Detail

GadgetHtmlParser

protected GadgetHtmlParser(DOMImplementation documentFactory)
Method Detail

setCacheProvider

@Inject
public void setCacheProvider(CacheProvider cacheProvider)

setSerializerProvider

@Inject
public void setSerializerProvider(com.google.inject.Provider<HtmlSerializer> serProvider)

attemptFullDocParseFirst

protected static boolean attemptFullDocParseFirst(String content)
Parameters:
content -
Returns:
true if we detect a preamble of doctype or html

parseDom

public Document parseDom(String source)
                  throws GadgetException
Throws:
GadgetException

transferChildren

protected void transferChildren(Node to,
                                Node from)

prependToNode

protected void prependToNode(Node to,
                             LinkedList<Node> from)

parseFragment

public void parseFragment(String source,
                          Node result)
                   throws GadgetException
Parses a snippet of markup and appends the result as children to the provided node.

Parameters:
source - markup to be parsed
result - Node to append results to
Throws:
GadgetException

errorDom

protected Document errorDom(DOMException e)

shouldCache

protected boolean shouldCache()

parseDomImpl

protected abstract Document parseDomImpl(String source)
                                  throws GadgetException
TODO: remove the need for parseDomImpl as a parsing method. Gadget HTML is tag soup handled in custom fashion, or is a legitimate fragment. In either case, we can simply use the fragment parsing implementation and patch up in higher-level calls.

Parameters:
source - a piece of HTML
Returns:
a Document parsed from the HTML
Throws:
GadgetException

parseFragmentImpl

protected abstract DocumentFragment parseFragmentImpl(String source)
                                               throws GadgetException
Parameters:
source - a snippet of HTML markup
Returns:
a DocumentFragment containing the parsed elements
Throws:
GadgetException


Copyright © 2007-2012. All Rights Reserved.