[Htmlparser-cvs] htmlparser/src/org/htmlparser/nodes TagNode.java,1.1,1.2
Brought to you by:
derrickoswald
From: Derrick O. <der...@us...> - 2004-07-02 00:50:06
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32670/src/org/htmlparser/nodes Modified Files: TagNode.java Log Message: Part four of a multiphase refactoring. Most internals now use the Tag interface. This interface has been broadened to add set/get scanner and set/get endtag. Removed the org.htmlparser.tags.Tag class and moved the remaining (minor) functionality to the TagNode class. So now tags inherit directly from TagNode or CompositeTag. ** NOTE: If you have subclassed org.htmlparser.tags.Tag, use org.htmlparser.nodes.TagNode now.** Removed deprecated methods getTagBegin/getTagEnd and deleted unused classes: PeekingIterator and it's Implementation. Index: TagNode.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/nodes/TagNode.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TagNode.java 24 May 2004 16:18:37 -0000 1.1 --- TagNode.java 2 Jul 2004 00:49:27 -0000 1.2 *************** *** 37,40 **** --- 37,42 ---- import org.htmlparser.lexer.Lexer; import org.htmlparser.lexer.Page; + import org.htmlparser.scanners.Scanner; + import org.htmlparser.scanners.TagScanner; import org.htmlparser.util.ParserException; import org.htmlparser.util.SpecialHashtable; *************** *** 44,48 **** /** * TagNode represents a generic tag. ! * */ public class TagNode --- 46,51 ---- /** * TagNode represents a generic tag. ! * If no scanner is registered for a given tag name, this is what you get. ! * This is also the base class for all tags created by the parser. */ public class TagNode *************** *** 53,56 **** --- 56,74 ---- { /** + * An empty set of tag names. + */ + private final static String[] NONE = new String[0]; + + /** + * The scanner for this tag. + */ + private Scanner mScanner; + + /** + * The default scanner for non-composite tags. + */ + protected final static Scanner mDefaultScanner = new TagScanner (); + + /** * The tag attributes. * Objects of type {@link Attribute}. *************** *** 118,122 **** --- 136,163 ---- { super (page, start, end); + + mScanner = mDefaultScanner; mAttributes = attributes; + if ((null == mAttributes) || (0 == mAttributes.size ())) + { + String[] names; + + names = getIds (); + if ((null != names) && (0 != names.length)) + setTagName (names[0]); + else + setTagName (""); // make sure it's not null + } + } + + /** + * Create a tag like the one provided. + * @param node The tag to emulate. + * @param scanner The scanner for this tag. + */ + public TagNode (TagNode tag, TagScanner scanner) + { + this (tag.getPage (), tag.getTagBegin (), tag.getTagEnd (), tag.getAttributesEx ()); + setThisScanner (scanner); } *************** *** 467,470 **** --- 508,516 ---- attribute = new Attribute (name, null, (char)0); attributes = getAttributesEx (); + if (null == attributes) + { + attributes = new Vector (); + setAttributesEx (attributes); + } if (0 == attributes.size ()) // nothing added yet *************** *** 473,477 **** { zeroth = (Attribute)attributes.elementAt (0); ! // check forn attribute that looks like a name if ((null == zeroth.getValue ()) && (0 == zeroth.getQuote ())) attributes.setElementAt (attribute, 0); --- 519,523 ---- { zeroth = (Attribute)attributes.elementAt (0); ! // check for attribute that looks like a name if ((null == zeroth.getValue ()) && (0 == zeroth.getQuote ())) attributes.setElementAt (attribute, 0); *************** *** 877,879 **** --- 923,998 ---- return (getPage ().row (getEndPosition ())); } + + /** + * Return the set of names handled by this tag. + * Since this a a generic tag, it has no ids. + * @return The names to be matched that create tags of this type. + */ + public String[] getIds () + { + return (NONE); + } + + /** + * Return the set of tag names that cause this tag to finish. + * These are the normal (non end tags) that if encountered while + * scanning (a composite tag) will cause the generation of a virtual + * tag. + * Since this a a non-composite tag, the default is no enders. + * @return The names of following tags that stop further scanning. + */ + public String[] getEnders () + { + return (NONE); + } + + /** + * Return the set of end tag names that cause this tag to finish. + * These are the end tags that if encountered while + * scanning (a composite tag) will cause the generation of a virtual + * tag. + * Since this a a non-composite tag, it has no end tag enders. + * @return The names of following end tags that stop further scanning. + */ + public String[] getEndTagEnders () + { + return (NONE); + } + + /** + * Return the scanner associated with this tag. + * @return The scanner associated with this tag. + */ + public Scanner getThisScanner () + { + return (mScanner); + } + + /** + * Set the scanner associated with this tag. + * @param scanner The scanner for this tag. + */ + public void setThisScanner (Scanner scanner) + { + mScanner = scanner; + } + + /** + * Get the end tag for this (composite) tag. + * For a non-composite tag this always returns <code>null</code>. + * @return The tag that terminates this composite tag, i.e. </HTML>. + */ + public Tag getEndTag () + { + return (null); + } + + /** + * Set the end tag for this (composite) tag. + * For a non-composite tag this is a no-op. + * @param end The tag that terminates this composite tag, i.e. </HTML>. + */ + public void setEndTag (Tag end) + { + } } |