nu.validator.htmlparser.impl
Class TreeBuilder<T>

java.lang.Object
  extended by nu.validator.htmlparser.impl.TreeBuilder<T>
All Implemented Interfaces:
TokenHandler

public abstract class TreeBuilder<T>
extends java.lang.Object
implements TokenHandler


Field Summary
protected  Tokenizer tokenizer
           
 
Constructor Summary
protected TreeBuilder(XmlViolationPolicy streamabilityViolationPolicy, boolean coalescingText)
           
 
Method Summary
protected abstract  void addAttributesToElement(T element, org.xml.sax.Attributes attributes)
           
protected abstract  void appendCharacters(T parent, char[] buf, int start, int length)
           
protected abstract  void appendChildrenToNewParent(T oldParent, T newParent)
           
protected abstract  void appendComment(T parent, char[] buf, int start, int length)
           
protected abstract  void appendCommentToDocument(char[] buf, int start, int length)
           
protected  void appendDoctypeToDocument(java.lang.String name, java.lang.String publicIdentifier, java.lang.String systemIdentifier)
           
protected  void bodyClosed(T body)
           
 void characters(char[] buf, int start, int length)
          Receive character tokens.
 void comment(char[] buf, int length)
          Receive a comment token.
protected abstract  T createElement(java.lang.String name, org.xml.sax.Attributes attributes)
           
protected  T createElement(java.lang.String name, org.xml.sax.Attributes attributes, T form)
           
protected abstract  T createHtmlElementSetAsRoot(org.xml.sax.Attributes attributes)
           
protected  T currentNode()
           
protected abstract  void detachFromParent(T element)
           
protected abstract  void detachFromParentAndAppendToNewParent(T child, T newParent)
           
 void doctype(java.lang.String name, java.lang.String publicIdentifier, java.lang.String systemIdentifier, boolean forceQuirks)
          Receive a doctype token.
protected  void documentMode(DocumentMode mode, java.lang.String publicIdentifier, java.lang.String systemIdentifier, boolean html4SpecificAdditionalErrorChecks)
           
protected  void elementPopped(java.lang.String name, T node)
           
protected  void elementPushed(java.lang.String name, T node)
           
protected  void end()
           
 void endTag(java.lang.String name, org.xml.sax.Attributes attributes)
          Receive an end tag token.
 void eof()
          The end-of-file token.
protected  void err(java.lang.String message)
          Reports a Parse Error.
protected  void fatal()
          Reports an condition that would make the infoset incompatible with XML 1.0 as fatal.
protected  void fatal(java.lang.Exception e)
           
protected abstract  boolean hasChildren(T element)
           
protected  void htmlClosed(T html)
           
protected abstract  void insertBefore(T child, T sibling, T parent)
           
protected abstract  void insertCharactersBefore(char[] buf, int start, int length, T sibling, T parent)
           
 boolean isScriptingEnabled()
          Returns the scriptingEnabled.
protected abstract  T parentElementFor(T child)
          Get the parent element.
 void setDoctypeExpectation(DoctypeExpectation doctypeExpectation)
          Sets the doctypeExpectation.
 void setDocumentModeHandler(DocumentModeHandler documentModeHandler)
          Sets the documentModeHandler.
 void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
          Sets the errorHandler.
 void setFragmentContext(java.lang.String context)
           
 void setIgnoringComments(boolean ignoreComments)
           
 void setReportingDoctype(boolean reportingDoctype)
          Sets the reportingDoctype.
 void setScriptingEnabled(boolean scriptingEnabled)
          Sets the scriptingEnabled.
protected abstract  T shallowClone(T element)
           
protected  void start(boolean fragment)
           
 void start(Tokenizer self)
          This method is called at the start of tokenization before any other methods on this interface are called.
 void startTag(java.lang.String name, org.xml.sax.Attributes attributes)
          Receive a start tag token.
 boolean wantsComments()
          If this handler implementation cares about comments, return true.
protected  void warn(java.lang.String message)
          Reports a warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tokenizer

protected Tokenizer tokenizer
Constructor Detail

TreeBuilder

protected TreeBuilder(XmlViolationPolicy streamabilityViolationPolicy,
                      boolean coalescingText)
Method Detail

fatal

protected final void fatal()
                    throws org.xml.sax.SAXException
Reports an condition that would make the infoset incompatible with XML 1.0 as fatal.

Throws:
org.xml.sax.SAXException
org.xml.sax.SAXParseException

fatal

protected final void fatal(java.lang.Exception e)
                    throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

err

protected final void err(java.lang.String message)
                  throws org.xml.sax.SAXException
Reports a Parse Error.

Parameters:
message - the message
Throws:
org.xml.sax.SAXException

warn

protected final void warn(java.lang.String message)
                   throws org.xml.sax.SAXException
Reports a warning

Parameters:
message - the message
Throws:
org.xml.sax.SAXException

start

public final void start(Tokenizer self)
                 throws org.xml.sax.SAXException
Description copied from interface: TokenHandler
This method is called at the start of tokenization before any other methods on this interface are called. Implementations should hold the reference to the Tokenizer in order to set the content model flag and in order to be able to query for Locator data.

Specified by:
start in interface TokenHandler
Parameters:
self - the Tokenizer.
Throws:
org.xml.sax.SAXException - if something went wrong

doctype

public final void doctype(java.lang.String name,
                          java.lang.String publicIdentifier,
                          java.lang.String systemIdentifier,
                          boolean forceQuirks)
                   throws org.xml.sax.SAXException
Description copied from interface: TokenHandler
Receive a doctype token.

Specified by:
doctype in interface TokenHandler
Parameters:
name - the name
publicIdentifier - the public id
systemIdentifier - the system id
forceQuirks - whether the token is correct
Throws:
org.xml.sax.SAXException - if something went wrong

comment

public final void comment(char[] buf,
                          int length)
                   throws org.xml.sax.SAXException
Description copied from interface: TokenHandler
Receive a comment token. The data is junk if the wantsComments() returned false.

Specified by:
comment in interface TokenHandler
Parameters:
buf - a buffer holding the data
length - the number of code units to read
Throws:
org.xml.sax.SAXException - if something went wrong

characters

public final void characters(char[] buf,
                             int start,
                             int length)
                      throws org.xml.sax.SAXException
Description copied from interface: TokenHandler
Receive character tokens. This method has the same semantics as the SAX method of the same name.

Specified by:
characters in interface TokenHandler
Parameters:
buf - a buffer holding the data
start - offset into the buffer
length - the number of code units to read
Throws:
org.xml.sax.SAXException - if something went wrong
See Also:
TokenHandler.characters(char[], int, int)

eof

public final void eof()
               throws org.xml.sax.SAXException
Description copied from interface: TokenHandler
The end-of-file token.

Specified by:
eof in interface TokenHandler
Throws:
org.xml.sax.SAXException - if something went wrong

startTag

public final void startTag(java.lang.String name,
                           org.xml.sax.Attributes attributes)
                    throws org.xml.sax.SAXException
Description copied from interface: TokenHandler
Receive a start tag token.

Specified by:
startTag in interface TokenHandler
Parameters:
name - the tag name
attributes - the attributes
Throws:
org.xml.sax.SAXException - if something went wrong

endTag

public final void endTag(java.lang.String name,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Description copied from interface: TokenHandler
Receive an end tag token.

Specified by:
endTag in interface TokenHandler
Parameters:
name - the tag name
attributes - the attributes
Throws:
org.xml.sax.SAXException - if something went wrong

createElement

protected abstract T createElement(java.lang.String name,
                                   org.xml.sax.Attributes attributes)
                            throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

createElement

protected T createElement(java.lang.String name,
                          org.xml.sax.Attributes attributes,
                          T form)
                   throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

createHtmlElementSetAsRoot

protected abstract T createHtmlElementSetAsRoot(org.xml.sax.Attributes attributes)
                                         throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

detachFromParent

protected abstract void detachFromParent(T element)
                                  throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

hasChildren

protected abstract boolean hasChildren(T element)
                                throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

shallowClone

protected abstract T shallowClone(T element)
                           throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

detachFromParentAndAppendToNewParent

protected abstract void detachFromParentAndAppendToNewParent(T child,
                                                             T newParent)
                                                      throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

appendChildrenToNewParent

protected abstract void appendChildrenToNewParent(T oldParent,
                                                  T newParent)
                                           throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

parentElementFor

protected abstract T parentElementFor(T child)
                               throws org.xml.sax.SAXException
Get the parent element. MUST return null if there is no parent or the parent is not an element.

Throws:
org.xml.sax.SAXException

insertBefore

protected abstract void insertBefore(T child,
                                     T sibling,
                                     T parent)
                              throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

insertCharactersBefore

protected abstract void insertCharactersBefore(char[] buf,
                                               int start,
                                               int length,
                                               T sibling,
                                               T parent)
                                        throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

appendCharacters

protected abstract void appendCharacters(T parent,
                                         char[] buf,
                                         int start,
                                         int length)
                                  throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

appendComment

protected abstract void appendComment(T parent,
                                      char[] buf,
                                      int start,
                                      int length)
                               throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

appendCommentToDocument

protected abstract void appendCommentToDocument(char[] buf,
                                                int start,
                                                int length)
                                         throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

addAttributesToElement

protected abstract void addAttributesToElement(T element,
                                               org.xml.sax.Attributes attributes)
                                        throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

start

protected void start(boolean fragment)
              throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

end

protected void end()
            throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

bodyClosed

protected void bodyClosed(T body)
                   throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

htmlClosed

protected void htmlClosed(T html)
                   throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

appendDoctypeToDocument

protected void appendDoctypeToDocument(java.lang.String name,
                                       java.lang.String publicIdentifier,
                                       java.lang.String systemIdentifier)
                                throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

elementPushed

protected void elementPushed(java.lang.String name,
                             T node)
                      throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

elementPopped

protected void elementPopped(java.lang.String name,
                             T node)
                      throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

documentMode

protected void documentMode(DocumentMode mode,
                            java.lang.String publicIdentifier,
                            java.lang.String systemIdentifier,
                            boolean html4SpecificAdditionalErrorChecks)
                     throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

wantsComments

public boolean wantsComments()
Description copied from interface: TokenHandler
If this handler implementation cares about comments, return true. If not, return false.

Specified by:
wantsComments in interface TokenHandler
Returns:
whether this handler wants comments
See Also:
TokenHandler.wantsComments()

setIgnoringComments

public void setIgnoringComments(boolean ignoreComments)

setErrorHandler

public final void setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Sets the errorHandler.

Parameters:
errorHandler - the errorHandler to set

setFragmentContext

public final void setFragmentContext(java.lang.String context)

currentNode

protected final T currentNode()

isScriptingEnabled

public boolean isScriptingEnabled()
Returns the scriptingEnabled.

Returns:
the scriptingEnabled

setScriptingEnabled

public void setScriptingEnabled(boolean scriptingEnabled)
Sets the scriptingEnabled.

Parameters:
scriptingEnabled - the scriptingEnabled to set

setDoctypeExpectation

public void setDoctypeExpectation(DoctypeExpectation doctypeExpectation)
Sets the doctypeExpectation.

Parameters:
doctypeExpectation - the doctypeExpectation to set

setDocumentModeHandler

public void setDocumentModeHandler(DocumentModeHandler documentModeHandler)
Sets the documentModeHandler.

Parameters:
documentModeHandler - the documentModeHandler to set

setReportingDoctype

public void setReportingDoctype(boolean reportingDoctype)
Sets the reportingDoctype.

Parameters:
reportingDoctype - the reportingDoctype to set


Copyright © 2011. All Rights Reserved.