KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > filter > FilterRule


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.filter;
17
18 import org.columba.core.config.DefaultItem;
19 import org.columba.core.xml.XmlElement;
20
21 public class FilterRule extends DefaultItem implements IFilterRule {
22     // condition: match all (AND) = 0, match any (OR) = 1
23
// private AdapterNode conditionNode;
24
public FilterRule(XmlElement root) {
25         super(root);
26
27     }
28
29     public FilterRule() {
30         super(new XmlElement());
31
32     }
33
34     /* (non-Javadoc)
35    * @see org.columba.core.filter.IFilterRule#addEmptyCriteria()
36    */

37     public IFilterCriteria addEmptyCriteria() {
38         XmlElement criteria = new XmlElement("criteria");
39         criteria.addAttribute("type", "Subject");
40         criteria.addAttribute("criteria", "contains");
41         criteria.addAttribute("pattern", "pattern");
42
43         getRoot().addElement(criteria);
44
45         IFilterCriteria c = new FilterCriteria(criteria);
46
47         return c;
48     }
49
50     /* (non-Javadoc)
51    * @see org.columba.core.filter.IFilterRule#add(org.columba.core.filter.FilterCriteria)
52    */

53     public void add(IFilterCriteria criteria) {
54         getRoot().addElement(criteria.getRoot());
55     }
56
57     /* (non-Javadoc)
58    * @see org.columba.core.filter.IFilterRule#remove(int)
59    */

60     public void remove(int index) {
61         getRoot().removeElement(index);
62
63         /*
64          * if ((index >= 0) && (index < list.size())) { list.remove(index);
65          *
66          * int result = -1;
67          *
68          * for (int i = 0; i < getRootNode().getChildCount(); i++) { AdapterNode
69          * child = (AdapterNode) getRootNode().getChildAt(i); String name =
70          * child.getName();
71          *
72          * if (name.equals("filtercriteria")) result++;
73          *
74          * if (result == index) { child.remove(); break; } }
75          *
76          * //AdapterNode child = getRootNode().getChildAt(index); }
77          */

78     }
79
80     /* (non-Javadoc)
81    * @see org.columba.core.filter.IFilterRule#removeAll()
82    */

83     public void removeAll() {
84         /*
85          * for (int i = 0; i < count(); i++) { remove(0); }
86          */

87         getRoot().removeAllElements();
88     }
89
90     /* (non-Javadoc)
91    * @see org.columba.core.filter.IFilterRule#removeLast()
92    */

93     public void removeLast() {
94         /*
95          * int index = list.size() - 1;
96          *
97          * remove(index);
98          */

99         getRoot().removeElement(getRoot().count() - 1);
100     }
101
102     /* (non-Javadoc)
103    * @see org.columba.core.filter.IFilterRule#get(int)
104    */

105     public IFilterCriteria get(int index) {
106         return new FilterCriteria(getRoot().getElement(index));
107     }
108
109     /* (non-Javadoc)
110    * @see org.columba.core.filter.IFilterRule#count()
111    */

112     public int count() {
113         return getRoot().count();
114     }
115
116     /* (non-Javadoc)
117    * @see org.columba.core.filter.IFilterRule#getCondition()
118    */

119     public String JavaDoc getCondition() {
120         return getRoot().getAttribute("condition");
121
122         /*
123          * if (conditionNode == null) { System.out.println(
124          * "---------------------------> failure: conditionNode == null !");
125          *
126          * return new String("matchany"); } else return
127          * getTextValue(conditionNode);
128          */

129     }
130
131     /* (non-Javadoc)
132    * @see org.columba.core.filter.IFilterRule#setCondition(java.lang.String)
133    */

134     public void setCondition(String JavaDoc s) {
135         getRoot().addAttribute("condition", s);
136
137         /*
138          * setTextValue(conditionNode, s);
139          */

140     }
141
142     /* (non-Javadoc)
143    * @see org.columba.core.filter.IFilterRule#setCondition(int)
144    */

145     public void setCondition(int condition) {
146         if (condition == MATCH_ALL)
147             setCondition("matchall");
148         else if (condition == MATCH_ANY)
149             setCondition("matchany");
150         else
151             throw new IllegalArgumentException JavaDoc("condition <" + condition
152                     + "> unknown");
153     }
154
155     /*
156      * public FilterCriteria getCriteria(int index) { return (FilterCriteria)
157      * list.get(index); }
158      */

159     /* (non-Javadoc)
160    * @see org.columba.core.filter.IFilterRule#getConditionInt()
161    */

162     public int getConditionInt() {
163         // System.out.println("condigtion: "+ condition );
164
if (getCondition().equals("matchall")) {
165             return MATCH_ALL;
166         }
167
168         if (getCondition().equals("matchany")) {
169             return MATCH_ANY;
170         }
171
172         return -1;
173     }
174 }
175
Popular Tags