jodd.lagarto.dom
Class DOMBuilderTagVisitor

java.lang.Object
  extended by jodd.lagarto.dom.DOMBuilderTagVisitor
All Implemented Interfaces:
TagVisitor

public class DOMBuilderTagVisitor
extends java.lang.Object
implements TagVisitor

Lagarto tag visitor that builds DOM tree.


Field Summary
protected  LagartoDOMBuilder domBuilder
           
protected  boolean enabled
          While enabled, nodes will be added to the DOM tree.
protected  HtmlImplicitClosingRules implRules
           
protected  Node parentNode
           
protected  Document rootNode
           
 
Constructor Summary
DOMBuilderTagVisitor(LagartoDOMBuilder domBuilder)
           
 
Method Summary
protected  LagartoLexer.Position calculatePosition(Tag tag)
          Calculates position of a tag.
 void cdata(java.lang.CharSequence cdata)
          Invoked on CDATA sequence.
 void comment(java.lang.CharSequence comment)
          Invoked on comment.
 void condComment(java.lang.CharSequence expression, boolean isStartingTag, boolean isHidden, java.lang.CharSequence comment)
          Invoked on IE conditional comment.
protected  Element createElementNode(Tag tag)
          Creates new element with correct configuration.
 void doctype(java.lang.String name, java.lang.String publicId, java.lang.String baseUri)
          Invoked on DOCTYPE directive.
 void end()
          Invoked at the end, after all content is visited.
 void error(java.lang.String message)
          Warn about parsing error.
protected  Node findMatchingParentOpenTag(java.lang.String tagName)
          Finds matching parent open tag or null if not found.
protected  void fixUnclosedTagsUpToMatchingParent(Node matchingParent)
          Fixes all unclosed tags up to matching parent.
 Document getDocument()
          Returns root document node of parsed DOM tree.
protected  void removeLastChildNodeIfEmptyText(Node parentNode, boolean closedTag)
          Removes last child node if contains just empty text.
 void script(Tag tag, java.lang.CharSequence body)
          Invoked on script tag.
 void start()
          Invoked on very beginning of the visiting.
 void style(Tag tag, java.lang.CharSequence body)
          Invoked on style tag.
 void tag(Tag tag)
          Invoked on tag (open, close or empty).
 void text(java.lang.CharSequence text)
          Invoked on text i.e. anything other than a tag.
 void xml(Tag tag)
          Invoked on xml declaration.
 void xmp(Tag tag, java.lang.CharSequence body)
          Invoked on xmp tag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

domBuilder

protected final LagartoDOMBuilder domBuilder

implRules

protected final HtmlImplicitClosingRules implRules

rootNode

protected Document rootNode

parentNode

protected Node parentNode

enabled

protected boolean enabled
While enabled, nodes will be added to the DOM tree. Useful for skipping some tags.

Constructor Detail

DOMBuilderTagVisitor

public DOMBuilderTagVisitor(LagartoDOMBuilder domBuilder)
Method Detail

getDocument

public Document getDocument()
Returns root document node of parsed DOM tree.


start

public void start()
Description copied from interface: TagVisitor
Invoked on very beginning of the visiting.

Specified by:
start in interface TagVisitor

end

public void end()
Description copied from interface: TagVisitor
Invoked at the end, after all content is visited.

Specified by:
end in interface TagVisitor

createElementNode

protected Element createElementNode(Tag tag)
Creates new element with correct configuration.


tag

public void tag(Tag tag)
Description copied from interface: TagVisitor
Invoked on tag (open, close or empty).

Warning: the passed tag instance should not be kept beyond this method as the parser reuse it!

Specified by:
tag in interface TagVisitor

removeLastChildNodeIfEmptyText

protected void removeLastChildNodeIfEmptyText(Node parentNode,
                                              boolean closedTag)
Removes last child node if contains just empty text.


findMatchingParentOpenTag

protected Node findMatchingParentOpenTag(java.lang.String tagName)
Finds matching parent open tag or null if not found.


fixUnclosedTagsUpToMatchingParent

protected void fixUnclosedTagsUpToMatchingParent(Node matchingParent)
Fixes all unclosed tags up to matching parent.


xmp

public void xmp(Tag tag,
                java.lang.CharSequence body)
Description copied from interface: TagVisitor
Invoked on xmp tag.

Specified by:
xmp in interface TagVisitor

style

public void style(Tag tag,
                  java.lang.CharSequence body)
Description copied from interface: TagVisitor
Invoked on style tag.

Specified by:
style in interface TagVisitor

script

public void script(Tag tag,
                   java.lang.CharSequence body)
Description copied from interface: TagVisitor
Invoked on script tag.

Specified by:
script in interface TagVisitor

comment

public void comment(java.lang.CharSequence comment)
Description copied from interface: TagVisitor
Invoked on comment.

Specified by:
comment in interface TagVisitor

text

public void text(java.lang.CharSequence text)
Description copied from interface: TagVisitor
Invoked on text i.e. anything other than a tag.

Specified by:
text in interface TagVisitor

cdata

public void cdata(java.lang.CharSequence cdata)
Description copied from interface: TagVisitor
Invoked on CDATA sequence.

Specified by:
cdata in interface TagVisitor

xml

public void xml(Tag tag)
Description copied from interface: TagVisitor
Invoked on xml declaration.

Specified by:
xml in interface TagVisitor

doctype

public void doctype(java.lang.String name,
                    java.lang.String publicId,
                    java.lang.String baseUri)
Description copied from interface: TagVisitor
Invoked on DOCTYPE directive. If publicId is null, it is a SYSTEM directive, otherwise it is PUBLIC.

Specified by:
doctype in interface TagVisitor

condComment

public void condComment(java.lang.CharSequence expression,
                        boolean isStartingTag,
                        boolean isHidden,
                        java.lang.CharSequence comment)
Description copied from interface: TagVisitor
Invoked on IE conditional comment. The expression if unmodified expression. comment is optional additional comment and may be null.

Specified by:
condComment in interface TagVisitor

error

public void error(java.lang.String message)
Description copied from interface: TagVisitor
Warn about parsing error. Usually, parser will try to continue.

Specified by:
error in interface TagVisitor
Parameters:
message - parsing error message

calculatePosition

protected LagartoLexer.Position calculatePosition(Tag tag)
Calculates position of a tag.



Copyright © 2003-2012 Jodd Team