[Htmlparser-cvs] htmlparser/src/org/htmlparser AbstractNode.java,1.16,1.17 Parser.java,1.66,1.67
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-10-20 02:52:47
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser In directory sc8-pr-cvs1:/tmp/cvs-serv26197 Modified Files: AbstractNode.java Parser.java Log Message: Removed lexer level AbstractNode. Removed data package from parser level tags. Separated tag creation from recursion in NodeFactory interface. Index: AbstractNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/AbstractNode.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** AbstractNode.java 5 Oct 2003 13:49:40 -0000 1.16 --- AbstractNode.java 20 Oct 2003 01:28:02 -0000 1.17 *************** *** 30,33 **** --- 30,34 ---- import java.io.Serializable; + import org.htmlparser.lexer.Page; import org.htmlparser.util.NodeList; *************** *** 36,40 **** * AbstractNode, which implements the Node interface, is the base class for all types of nodes, including tags, string elements, etc */ ! public abstract class AbstractNode implements Node, Serializable { /** * The beginning position of the tag in the line --- 37,47 ---- * AbstractNode, which implements the Node interface, is the base class for all types of nodes, including tags, string elements, etc */ ! public abstract class AbstractNode implements Node, Serializable ! { ! /** ! * The page this node came from. ! */ ! protected Page mPage; ! /** * The beginning position of the tag in the line *************** *** 59,70 **** /** * Create an abstract node with the page positions given. ! * @param begin The starting position of the node. ! * @param end The ending position of the node. */ ! public AbstractNode (int begin, int end) { ! nodeBegin = begin; ! nodeEnd = end; parent = null; } --- 66,81 ---- /** * Create an abstract node with the page positions given. ! * Remember the page and start & end cursor positions. ! * @param page The page this tag was read from. ! * @param start The starting offset of this node within the page. ! * @param end The ending offset of this node within the page. */ ! public AbstractNode (Page page, int start, int end) { ! mPage = page; ! nodeBegin = start; ! nodeEnd = end; parent = null; + children = null; } *************** *** 164,177 **** /** * Returns the beginning position of the tag. */ ! public int elementBegin() { ! return nodeBegin; } /** * Returns the ending position fo the tag */ ! public int elementEnd() { ! return nodeEnd; } --- 175,210 ---- /** * Returns the beginning position of the tag. + * @deprecated Use {@link #getStartPosition}. */ ! public int elementBegin() ! { ! return (getStartPosition ()); } /** * Returns the ending position fo the tag + * @deprecated Use {@link #getEndPosition}. */ ! public int elementEnd() ! { ! return (getEndPosition ()); ! } ! ! /** ! * Get the page this node came from. ! * @return The page that supplied this node. ! */ ! public Page getPage () ! { ! return (mPage); ! } ! ! /** ! * Set the page this node came from. ! * @param page The page that supplied this node. ! */ ! public void setPage (Page page) ! { ! mPage = page; } Index: Parser.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/Parser.java,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** Parser.java 13 Oct 2003 21:48:11 -0000 1.66 --- Parser.java 20 Oct 2003 01:28:02 -0000 1.67 *************** *** 1016,1021 **** /** * Create a new tag node. ! * This recurses into the created tag by calling the tag's scanner, ! * if it is in the list of registered scanners. * @param lexer The lexer parsing this tag. * @param start The beginning position of the tag. --- 1016,1023 ---- /** * Create a new tag node. ! * Note that the attributes vector contains at least one element, ! * which is the tag name (standalone attribute) at position zero. ! * This can be used to decide which type of node to create, or ! * gate other processing that may be appropriate. * @param lexer The lexer parsing this tag. * @param start The beginning position of the tag. *************** *** 1027,1030 **** --- 1029,1064 ---- ParserException { + return (new Tag (lexer.getPage (), start, end, attributes)); + } + + /** + * Scan a new tag node. + * Provides composite tags the opportunity to collect their children by + * scanning forward using the same lexer that created the composite tag. + * On isolating a tag, processing in the lexer is: + * <pre><code> + * Node node = getNodeFactory ().createTagNode (this, begin, end, attributes); + * node = getNodeFactory ().scanTagNode (this, node); + * </code></pre> + * This two step process, allows a node factory to only handle node + * creation if it wishes, and delegate the recursion and scanning of child + * nodes to the original factory. + * Without giving too much implementation details, the low level lexer node + * factory simply returns the same tag, while the higher level parser node + * factory checks for a scanner registered for the node type and if there + * is one, calls the scanner to create the specific type of node, which + * advances the lexer past the children of the node. + * @param lexer The lexer that parsed this tag. + * @param tag The tag (just) created by createTagNode. Although this is + * of type Node, it can safely be cast to the type returned by + * {@link #createTagNode createTagNode}. + * @return Either the same node or a new node containing children. + * In any case the lexer should be positioned to proceed with the isolation + * of the next unknown node. + */ + public Node scanTagNode (Lexer lexer, Node tag) + throws + ParserException + { String name; TagScanner save; *************** *** 1032,1036 **** Tag ret; ! ret = new Tag (lexer.getPage (), start, end, attributes); if (!ret.isEndTag ()) { --- 1066,1070 ---- Tag ret; ! ret = (Tag)tag; if (!ret.isEndTag ()) { |