[Htmlparser-cvs] htmlparser/src/org/htmlparser/lexer/nodes NodeFactory.java,1.1,1.2 RemarkNode.java,
Brought to you by:
derrickoswald
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/nodes In directory sc8-pr-cvs1:/tmp/cvs-serv26197/lexer/nodes Modified Files: NodeFactory.java RemarkNode.java StringNode.java TagNode.java Removed Files: AbstractNode.java Log Message: Removed lexer level AbstractNode. Removed data package from parser level tags. Separated tag creation from recursion in NodeFactory interface. Index: NodeFactory.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/nodes/NodeFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NodeFactory.java 28 Sep 2003 15:33:58 -0000 1.1 --- NodeFactory.java 20 Oct 2003 01:28:02 -0000 1.2 *************** *** 61,64 **** --- 61,68 ---- /** * 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. *************** *** 67,70 **** --- 71,103 ---- */ public Node createTagNode (Lexer lexer, int start, int end, Vector attributes) + throws + ParserException; + + /** + * 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; Index: RemarkNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/nodes/RemarkNode.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** RemarkNode.java 22 Sep 2003 02:39:59 -0000 1.7 --- RemarkNode.java 20 Oct 2003 01:28:02 -0000 1.8 *************** *** 30,33 **** --- 30,34 ---- package org.htmlparser.lexer.nodes; + import org.htmlparser.AbstractNode; import org.htmlparser.lexer.Cursor; import org.htmlparser.lexer.Page; Index: StringNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/nodes/StringNode.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** StringNode.java 3 Oct 2003 02:15:19 -0000 1.9 --- StringNode.java 20 Oct 2003 01:28:02 -0000 1.10 *************** *** 30,33 **** --- 30,34 ---- package org.htmlparser.lexer.nodes; + import org.htmlparser.AbstractNode; import org.htmlparser.lexer.Cursor; import org.htmlparser.lexer.Page; Index: TagNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/nodes/TagNode.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** TagNode.java 18 Oct 2003 20:50:37 -0000 1.17 --- TagNode.java 20 Oct 2003 01:28:02 -0000 1.18 *************** *** 32,35 **** --- 32,36 ---- import java.util.Hashtable; import java.util.Vector; + import org.htmlparser.AbstractNode; import org.htmlparser.lexer.Cursor; *************** *** 162,175 **** singleq = true; doubleq = true; ! for (int i = 0; i < value.length (); i++) ! { ! ch = value.charAt (i); ! if (Character.isWhitespace (ch)) ! needed = true; ! else if ('\'' == ch) ! singleq = false; ! else if ('"' == ch) ! doubleq = false; ! } // now apply quoting --- 163,177 ---- singleq = true; doubleq = true; ! if (null != value) ! for (int i = 0; i < value.length (); i++) ! { ! ch = value.charAt (i); ! if (Character.isWhitespace (ch)) ! needed = true; ! else if ('\'' == ch) ! singleq = false; ! else if ('"' == ch) ! doubleq = false; ! } // now apply quoting *************** *** 205,208 **** --- 207,223 ---- /** + * Remove the attribute with the given key, if it exists. + * @param key The name of the attribute. + */ + public void removeAttribute (String key) + { + Attribute attribute; + + attribute = getAttributeEx (key); + if (null != attribute) + getAttributesEx ().remove (attribute); + } + + /** * Set attribute with given key, value pair where the value is quoted by quote. * @param key The name of the attribute. *************** *** 284,288 **** { // add whitespace between attributes ! if (!((Attribute)attributes.elementAt (length - 1)).isWhitespace ()) attributes.addElement (new Attribute (" ")); attributes.addElement (attribute); --- 299,303 ---- { // add whitespace between attributes ! if ((0 != length) && !((Attribute)attributes.elementAt (length - 1)).isWhitespace ()) attributes.addElement (new Attribute (" ")); attributes.addElement (attribute); *************** *** 586,600 **** attributes = getAttributesEx (); ret.append ("<"); ! if (0 < attributes.size ()) { ! // special handling for the node name ! attribute = (Attribute)attributes.elementAt (0); ! ret.append (attribute.getName ()); ! // the rest ! for (int i = 1; i < attributes.size (); i++) ! { ! attribute = (Attribute)attributes.elementAt (i); ! attribute.toString (ret); ! } } ret.append (">"); --- 601,608 ---- attributes = getAttributesEx (); ret.append ("<"); ! for (int i = 0; i < attributes.size (); i++) { ! attribute = (Attribute)attributes.elementAt (i); ! attribute.toString (ret); } ret.append (">"); --- AbstractNode.java DELETED --- |