|
HTML Parser Home Page | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.htmlparser.scanners.TagScanner org.htmlparser.scanners.CompositeTagScanner
public class CompositeTagScanner
The main scanning logic for nested tags. When asked to scan, this class gathers nodes into a heirarchy of tags.
Constructor Summary | |
---|---|
CompositeTagScanner()
Create a composite tag scanner. |
Method Summary | |
---|---|
protected void |
addChild(Tag parent,
Node child)
Add a child to the given tag. |
protected Tag |
createVirtualEndTag(Tag tag,
Lexer lexer,
Page page,
int position)
Creates an end tag with the same name as the given tag. |
protected void |
finishTag(Tag tag,
Lexer lexer)
Finish off a tag. |
boolean |
isTagToBeEndedFor(Tag current,
Tag tag)
Determine if the current tag should be terminated by the given tag. |
Tag |
scan(Tag tag,
Lexer lexer,
NodeList stack)
Collect the children. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CompositeTagScanner()
Method Detail |
---|
public Tag scan(Tag tag, Lexer lexer, NodeList stack) throws ParserException
An initial test is performed for an empty XML tag, in which case the start tag and end tag of the returned tag are the same and it has no children.
If it's not an empty XML tag, the lexer is repeatedly asked for subsequent nodes until an end tag is found or a node is encountered that matches the tag ender set or end tag ender set. In the latter case, a virtual end tag is created. Each node found that is not the end tag is added to the list of children. The end tag is special and not a child.
Nodes that also have a CompositeTagScanner as their scanner are recursed into, which provides the nested structure of an HTML page. This method operates in two possible modes, depending on a private boolean. It can recurse on the JVM stack, which has caused some overflow problems in the past, or it can use the supplied stack argument to nest scanning of child tags within itself. The former is left as an option in the code, mostly to help subsequent modifiers visualize what the internal nesting is doing.
scan
in interface Scanner
scan
in class TagScanner
tag
- The tag this scanner is responsible for.lexer
- The source of subsequent nodes.stack
- The parse stack. May contain pending tags that enclose
this tag.
ParserException
- if an unrecoverable problem occurs.protected void addChild(Tag parent, Node child)
parent
- The parent tag.child
- The child node.protected void finishTag(Tag tag, Lexer lexer) throws ParserException
tag
- The tag to finish off.lexer
- A lexer positioned at the end of the tag.
ParserException
protected Tag createVirtualEndTag(Tag tag, Lexer lexer, Page page, int position) throws ParserException
tag
- The tag to end.lexer
- The object containg the node factory.page
- The page the tag is on (virtually).position
- The offset into the page at which the tag is to
be anchored.
ParserException
public final boolean isTagToBeEndedFor(Tag current, Tag tag)
current
- The tag that might need to be ended.tag
- The candidate tag that might end the current one.
true
if the name of the given tag is a member of
the appropriate list.
|
© 2006 Derrick Oswald Sep 17, 2006
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
HTML Parser is an open source library released under Common Public License. |