KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > parserapplications > filterbuilder > wrappers > NotFilterWrapper


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2005 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/NotFilterWrapper.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2005/02/13 20:43:06 $
10
// $Revision: 1.1 $
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.parserapplications.filterbuilder.wrappers;
28
29 import org.htmlparser.Node;
30 import org.htmlparser.NodeFilter;
31 import org.htmlparser.Parser;
32 import org.htmlparser.filters.NotFilter;
33 import org.htmlparser.parserapplications.filterbuilder.Filter;
34 import org.htmlparser.parserapplications.filterbuilder.SubFilterList;
35
36 /**
37  * Wrapper for NotFilters.
38  */

39 public class NotFilterWrapper
40     extends
41         Filter
42 {
43     /**
44      * The drop target container.
45      */

46     protected SubFilterList mContainer;
47     
48     /**
49      * The underlying filter.
50      */

51     protected NotFilter mFilter;
52
53     /**
54      * Create a wrapper over a new NotFilter.
55      */

56     public NotFilterWrapper ()
57     {
58         mFilter = new NotFilter ();
59
60         // add the subfilter container
61
mContainer = new SubFilterList (this, "Predicate", 1);
62         add (mContainer);
63     }
64
65     //
66
// Filter overrides and concrete implementations
67
//
68

69     public String JavaDoc getDescription ()
70     {
71         return ("Not");
72     }
73
74     public String JavaDoc getIconSpec ()
75     {
76         return ("images/NotFilter.gif");
77     }
78
79     public NodeFilter getNodeFilter ()
80     {
81         NodeFilter predicate;
82         NotFilter ret;
83         
84         ret = new NotFilter ();
85
86         predicate = mFilter.getPredicate ();
87         if (null != predicate)
88             ret.setPredicate (((Filter)predicate).getNodeFilter ());
89             
90         return (ret);
91     }
92
93     public void setNodeFilter (NodeFilter filter, Parser context)
94     {
95         mFilter = (NotFilter)filter;
96     }
97
98     public NodeFilter[] getSubNodeFilters ()
99     {
100         NodeFilter predicate;
101         NodeFilter[] ret;
102
103         predicate = mFilter.getPredicate ();
104         if (null != predicate)
105             ret = new NodeFilter[] { predicate };
106         else
107             ret = new NodeFilter[0];
108
109         return (ret);
110     }
111
112     public void setSubNodeFilters (NodeFilter[] filters)
113     {
114         if (0 != filters.length)
115             mFilter.setPredicate (filters[0]);
116         else
117             mFilter.setPredicate (null);
118     }
119
120     public String JavaDoc toJavaCode (StringBuffer JavaDoc out, int[] context)
121     {
122         String JavaDoc name;
123         String JavaDoc ret;
124
125         if (null != mFilter.getPredicate ())
126             name = ((Filter)mFilter.getPredicate ()).toJavaCode (out, context);
127         else
128             name = null;
129         ret = "filter" + context[1]++;
130         spaces (out, context[0]);
131         out.append ("NotFilter ");
132         out.append (ret);
133         out.append (" = new NotFilter ();");
134         newline (out);
135         if (null != name)
136         {
137             spaces (out, context[0]);
138             out.append (ret);
139             out.append (".setPredicate (");
140             out.append (name);
141             out.append (");");
142             newline (out);
143         }
144         
145         return (ret);
146     }
147
148     //
149
// NodeFilter interface
150
//
151

152     public boolean accept (Node node)
153     {
154         return (mFilter.accept (node));
155     }
156 }
157
Popular Tags