ObjectFindingVisitor.java
1 // HTMLParser Library $Name: v1_6_20060319 $ - A java-based parser for HTML 2 // http://sourceforge.org/projects/htmlparser 3 // Copyright (C) 2004 Joshua Kerievsky 4 // 5 // Revision Control Information 6 // 7 // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/visitors/ObjectFindingVisitor.java,v $ 8 // $Author: derrickoswald $ 9 // $Date: 2004/05/24 00:38:19 $ 10 // $Revision: 1.40 $ 11 // 12 // This library is free software; you can redistribute it and/or 13 // modify it under the terms of the GNU Lesser General Public 14 // License as published by the Free Software Foundation; either 15 // version 2.1 of the License, or (at your option) any later version. 16 // 17 // This library is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 // Lesser General Public License for more details. 21 // 22 // You should have received a copy of the GNU Lesser General Public 23 // License along with this library; if not, write to the Free Software 24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 // 26 27 package org.htmlparser.visitors; 28 29 import org.htmlparser.Node; 30 import org.htmlparser.Tag; 31 import org.htmlparser.util.NodeList; 32 33 public class ObjectFindingVisitor extends NodeVisitor { 34 private Class classTypeToFind; 35 private NodeList tags; 36 37 public ObjectFindingVisitor(Class classTypeToFind) { 38 this(classTypeToFind,true); 39 } 40 41 public ObjectFindingVisitor(Class classTypeToFind,boolean recurse) { 42 super(recurse, true); 43 this.classTypeToFind = classTypeToFind; 44 this.tags = new NodeList(); 45 } 46 47 public int getCount() { 48 return (tags.size ()); 49 } 50 51 public void visitTag(Tag tag) { 52 if (tag.getClass().equals(classTypeToFind)) 53 tags.add(tag); 54 } 55 56 public Node[] getTags() { 57 return tags.toNodeArray(); 58 } 59 }