KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > filter > plugins > SizeFilter


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.filter.plugins;
19
20 import org.columba.core.filter.AbstractFilter;
21 import org.columba.core.filter.FilterCriteria;
22 import org.columba.core.filter.IFilterCriteria;
23 import org.columba.core.folder.api.IFolder;
24 import org.columba.mail.folder.IMailbox;
25
26 /**
27  * Find messages with certain size.
28  *
29  * @author fdietz
30  */

31 public class SizeFilter extends AbstractFilter {
32
33     private String JavaDoc pattern;
34
35     private int condition;
36
37     /**
38      * Constructor for SizeFilter.
39      */

40     public SizeFilter() {
41         super();
42     }
43
44     /**
45      * Transform string to integer representation
46      *
47      * @param p
48      * string containing priority
49      *
50      * @return integer representation of string
51      */

52     protected Integer JavaDoc transformSize(String JavaDoc p) {
53         Integer JavaDoc searchPattern = Integer.valueOf(p);
54
55         return searchPattern;
56     }
57
58     /**
59      * @see org.columba.core.filter.AbstractFilter#process(java.lang.Object,
60      * org.columba.mail.folder.Folder, java.lang.Object,
61      * org.columba.api.command.IWorkerStatusController)
62      */

63     public boolean process(IFolder folder, Object JavaDoc uid)
64             throws Exception JavaDoc {
65         boolean result = false;
66
67         Integer JavaDoc size = transformSize((String JavaDoc) pattern);
68
69         Integer JavaDoc s = (Integer JavaDoc) ((IMailbox)folder).getAttribute(uid, "columba.size");
70
71         if (s == null) {
72             return false;
73         }
74
75         switch (condition) {
76         case FilterCriteria.SIZE_SMALLER:
77
78             if (size.compareTo(s) > 0) {
79                 result = true;
80             }
81
82             break;
83
84         case FilterCriteria.SIZE_BIGGER:
85
86             if (size.compareTo(s) < 0) {
87                 result = true;
88             }
89
90             break;
91         }
92
93         return result;
94     }
95
96     /**
97      * @see org.columba.core.filter.AbstractFilter#setUp(org.columba.mail.filter.FilterCriteria)
98      */

99     public void setUp(IFilterCriteria f) {
100
101         // string to search
102
pattern = f.getPatternString();
103
104         condition = f.getCriteria();
105     }
106 }
Popular Tags