KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > filters > NodeClassFilter


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2003 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/filters/NodeClassFilter.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2005/02/13 20:36:00 $
10
// $Revision: 1.2 $
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.filters;
28
29 import org.htmlparser.Node;
30 import org.htmlparser.NodeFilter;
31
32 /**
33  * This class accepts all tags of a given class.
34  */

35 public class NodeClassFilter implements NodeFilter
36 {
37     /**
38      * The class to match.
39      */

40     protected Class JavaDoc mClass;
41
42     /**
43      * Creates a new instance of NodeClassFilter that accepts tags of the Html (top level) class.
44      */

45     public NodeClassFilter ()
46     {
47         this (org.htmlparser.tags.Html.class);
48     }
49
50     /**
51      * Creates a new instance of NodeClassFilter that accepts tags of the given class.
52      * @param cls The cls to match.
53      */

54     public NodeClassFilter (Class JavaDoc cls)
55     {
56         mClass = cls;
57     }
58
59     /**
60      * Get the class to match.
61      * @return Returns the class.
62      */

63     public Class JavaDoc getMatchClass ()
64     {
65         return (mClass);
66     }
67
68     /**
69      * Set the class to match.
70      * @param cls The node class to match.
71      */

72     public void setMatchClass (Class JavaDoc cls)
73     {
74         mClass = cls;
75     }
76
77     /**
78      * Accept nodes that are assignable from the class provided in the constructor.
79      * @param node The node to check.
80      */

81     public boolean accept (Node node)
82     {
83         return ((null != mClass) && mClass.isAssignableFrom (node.getClass ()));
84     }
85 }
86
Popular Tags