Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/visitors
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5117/htmlparser/src/org/htmlparser/visitors
Modified Files:
NodeVisitor.java
Log Message:
Documentation revamp part three.
Reworked some JavaDoc descriptions.
Added "HTML Parser for dummies" introductory text.
Removed checkstyle.jar and fit.jar (and it's cruft).
Index: NodeVisitor.java
===================================================================
RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/visitors/NodeVisitor.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** NodeVisitor.java 24 May 2004 16:18:36 -0000 1.38
--- NodeVisitor.java 24 Apr 2005 17:48:27 -0000 1.39
***************
*** 43,68 ****
* <pre>
* import org.htmlparser.Parser;
! * import org.htmlparser.tags.LinkTag;
* import org.htmlparser.util.ParserException;
* import org.htmlparser.visitors.NodeVisitor;
*
! * public class Visitor extends NodeVisitor
* {
! * public Visitor ()
* {
* }
* public void visitTag (Tag tag)
* {
! * if (tag instanceof LinkTag)
! * System.out.println (tag);
* }
* public static void main (String[] args) throws ParserException
* {
* Parser parser = new Parser ("http://cbc.ca");
! * Visitor visitor = new Visitor ();
* parser.visitAllNodesWith (visitor);
* }
* }
* </pre>
*/
public abstract class NodeVisitor
--- 43,107 ----
* <pre>
* import org.htmlparser.Parser;
! * import org.htmlparser.Tag;
! * import org.htmlparser.Text;
* import org.htmlparser.util.ParserException;
* import org.htmlparser.visitors.NodeVisitor;
*
! * public class MyVisitor extends NodeVisitor
* {
! * public MyVisitor ()
* {
* }
+ *
* public void visitTag (Tag tag)
* {
! * System.out.println ("\n" + tag.getTagName () + tag.getStartPosition ());
! * }
! *
! * public void visitStringNode (Text string)
! * {
! * System.out.println (string);
* }
+ *
* public static void main (String[] args) throws ParserException
* {
* Parser parser = new Parser ("http://cbc.ca");
! * Visitor visitor = new MyVisitor ();
* parser.visitAllNodesWith (visitor);
* }
* }
* </pre>
+ * If you want to handle more than one tag type with the same visitor
+ * you will need to check the tag type in the visitTag method. You can
+ * do that by either checking the tag name:
+ * <pre>
+ * public void visitTag (Tag tag)
+ * {
+ * if (tag.getName ().equals ("BODY"))
+ * ... do something with the BODY tag
+ * else if (tag.getName ().equals ("FRAME"))
+ * ... do something with the FRAME tag
+ * }
+ * </pre>
+ * or you can use <code>instanceof</code> if all the tags you want to handle
+ * have a {@link org.htmlparser.PrototypicalNodeFactory#registerTag registered}
+ * tag (i.e. they are generated by the NodeFactory):
+ * <pre>
+ * public void visitTag (Tag tag)
+ * {
+ * if (tag instanceof BodyTag)
+ * {
+ * BodyTag body = (BodyTag)tag;
+ * ... do something with body
+ * }
+ * else if (tag instanceof FrameTag)
+ * {
+ * FrameTag frame = (FrameTag)tag;
+ * ... do something with frame
+ * }
+ * else // other specific tags and generic TagNode objects
+ * {
+ * }
+ * }
*/
public abstract class NodeVisitor
|