KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Search for a certain priority.
28  * <p>
29  * This can be for example "high", "log", "highest", "lowest"
30  *
31  * @author fdietz
32  */

33 public class PriorityFilter extends AbstractFilter {
34     
35     private String JavaDoc searchPattern;
36
37     private int condition;
38
39     /**
40      * Constructor for PriorityFilter.
41      */

42     public PriorityFilter() {
43         super();
44     }
45
46     /**
47      * Transform priority to integer value.
48      *
49      * @param pattern
50      * priority string
51      * @return integer representation of string
52      */

53     protected Integer JavaDoc transformPriority(String JavaDoc pattern) {
54         Integer JavaDoc searchPatternInt = new Integer JavaDoc(3);
55
56         if (pattern.equalsIgnoreCase("Highest")) {
57             searchPatternInt = new Integer JavaDoc(1);
58         } else if (pattern.equalsIgnoreCase("High")) {
59             searchPatternInt = new Integer JavaDoc(2);
60         } else if (pattern.equalsIgnoreCase("Normal")) {
61             searchPatternInt = new Integer JavaDoc(3);
62         } else if (pattern.equalsIgnoreCase("Low")) {
63             searchPatternInt = new Integer JavaDoc(4);
64         } else if (pattern.equalsIgnoreCase("Lowest")) {
65             searchPatternInt = new Integer JavaDoc(5);
66         }
67
68         //Integer priority = Integer.valueOf(pattern);
69
//return priority;
70
return searchPatternInt;
71     }
72
73     /**
74      * @see org.columba.core.filter.AbstractFilter#process(java.lang.Object,
75      * org.columba.mail.folder.Folder, java.lang.Object,
76      * org.columba.api.command.IWorkerStatusController)
77      */

78     public boolean process(IFolder folder, Object JavaDoc uid)
79             throws Exception JavaDoc {
80         boolean result = false;
81
82         String JavaDoc s = (String JavaDoc) searchPattern;
83         Integer JavaDoc searchPatternInt = transformPriority(s);
84
85         Integer JavaDoc priority = (Integer JavaDoc) ((IMailbox)folder).getAttribute(uid,
86                 "columba.priority");
87
88         if (priority == null) {
89             return false;
90         }
91
92         switch (condition) {
93         case FilterCriteria.IS:
94
95             if (priority.compareTo(searchPatternInt) == 0) {
96                 result = true;
97             }
98
99             break;
100
101         case FilterCriteria.IS_NOT:
102
103             if (priority.compareTo(searchPatternInt) != 0) {
104                 result = true;
105             }
106
107             break;
108         }
109
110         return result;
111     }
112
113     /**
114      *
115      * @see org.columba.core.filter.AbstractFilter#setUp(org.columba.mail.filter.FilterCriteria)
116      */

117     public void setUp(IFilterCriteria f) {
118
119         // string to search
120
searchPattern = f.getPatternString();
121
122         condition = f.getCriteria();
123     }
124 }
Popular Tags