KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > ristretto > imap > SearchKey


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Ristretto Mail API.
15  *
16  * The Initial Developers of the Original Code are
17  * Timo Stich and Frederik Dietz.
18  * Portions created by the Initial Developers are Copyright (C) 2004
19  * All Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */

36 package org.columba.ristretto.imap;
37
38 import java.util.Arrays JavaDoc;
39 import java.util.Iterator JavaDoc;
40 import java.util.LinkedList JavaDoc;
41 import java.util.List JavaDoc;
42
43 /**
44  * The search keys that specify a search.
45  *
46  * @author tstich
47  */

48 public class SearchKey {
49     /**
50      * Searchkey type.
51      */

52     public static final String JavaDoc ALL = "ALL";
53     /**
54      * Searchkey type.
55      */

56     public static final String JavaDoc ANSWERED = "ANSWERED";
57     /**
58      * Searchkey type.
59      */

60     public static final String JavaDoc BCC = "BCC";
61     /**
62      * Searchkey type.
63      */

64     public static final String JavaDoc BEFORE = "BEFORE";
65     /**
66      * Searchkey type.
67      */

68     public static final String JavaDoc BODY = "BODY";
69     /**
70      * Searchkey type.
71      */

72     public static final String JavaDoc CC = "CC";
73     /**
74      * Searchkey type.
75      */

76     public static final String JavaDoc DELETED = "DELETED";
77     /**
78      * Searchkey type.
79      */

80     public static final String JavaDoc FLAGGED = "FLAGGED";
81     /**
82      * Searchkey type.
83      */

84     public static final String JavaDoc FROM = "FROM";
85     /**
86      * Searchkey type.
87      */

88     public static final String JavaDoc KEYWORD = "KEYWORD";
89     /**
90      * Searchkey type.
91      */

92     public static final String JavaDoc NEW = "NEW";
93     /**
94      * Searchkey type.
95      */

96     public static final String JavaDoc OLD = "OLD";
97     /**
98      * Searchkey type.
99      */

100     public static final String JavaDoc ON = "ON";
101     /**
102      * Searchkey type.
103      */

104     public static final String JavaDoc RECENT = "RECENT";
105     /**
106      * Searchkey type.
107      */

108     public static final String JavaDoc SEEN = "SEEN";
109     /**
110      * Searchkey type.
111      */

112     public static final String JavaDoc SINCE = "SINCE";
113     /**
114      * Searchkey type.
115      */

116     public static final String JavaDoc SUBJECT = "SUBJECT";
117     /**
118      * Searchkey type.
119      */

120     public static final String JavaDoc TEXT = "TEXT";
121     /**
122      * Searchkey type.
123      */

124     public static final String JavaDoc TO = "TO";
125     /**
126      * Searchkey type.
127      */

128     public static final String JavaDoc UNANSWERED = "UNANSWERED";
129     /**
130      * Searchkey type.
131      */

132     public static final String JavaDoc UNDELETED = "UNDELETED";
133     /**
134      * Searchkey type.
135      */

136     public static final String JavaDoc UNFLAGGED = "UNFLAGGED";
137     /**
138      * Searchkey type.
139      */

140     public static final String JavaDoc UNKEYWORD = "UNKEYWORD";
141     /**
142      * Searchkey type.
143      */

144     public static final String JavaDoc UNSEEN = "UNSEEN";
145     /**
146      * Searchkey type.
147      */

148     public static final String JavaDoc DRAFT = "DRAFT";
149     /**
150      * Searchkey type.
151      */

152     public static final String JavaDoc HEADER = "HEADER";
153     /**
154      * Searchkey type.
155      */

156     public static final String JavaDoc LARGER = "LARGER";
157     /**
158      * Searchkey type.
159      */

160     public static final String JavaDoc NOT = "NOT";
161     /**
162      * Searchkey type.
163      */

164     public static final String JavaDoc OR = "OR";
165     /**
166      * Searchkey type.
167      */

168     public static final String JavaDoc SENTBEFORE = "SENTBEFORE";
169     /**
170      * Searchkey type.
171      */

172     public static final String JavaDoc SENTON = "SENTON";
173     /**
174      * Searchkey type.
175      */

176     public static final String JavaDoc SENTSINCE = "SENTSINCE";
177     /**
178      * Searchkey type.
179      */

180     public static final String JavaDoc SMALLER = "SMALLER";
181     /**
182      * Searchkey type.
183      */

184     public static final String JavaDoc UID = "UID";
185     /**
186      * Searchkey type.
187      */

188     public static final String JavaDoc UNDRAFT = "UNDRAFT";
189
190     
191     
192     private List JavaDoc list;
193     private String JavaDoc key;
194     private Object JavaDoc arg;
195     private Object JavaDoc arg2;
196     
197     /**
198      * Constructs the SearchKey.
199      *
200      * @param key
201      */

202     public SearchKey(String JavaDoc key) {
203         this.key = key;
204     }
205
206     /**
207      * Constructs the SearchKey.
208      *
209      * @param key
210      * @param arg
211      */

212     public SearchKey(String JavaDoc key, String JavaDoc arg) {
213         this.key = key;
214         this.arg = arg;
215     }
216     
217     /**
218      * Constructs the SearchKey.
219      *
220      * @param key
221      * @param arg
222      */

223     public SearchKey(String JavaDoc key, Integer JavaDoc arg) {
224         this.key = key;
225         this.arg = arg;
226     }
227
228     /**
229      * Constructs the SearchKey.
230      *
231      * @param key
232      * @param arg
233      */

234     public SearchKey(String JavaDoc key, IMAPDate arg) {
235         this.key = key;
236         this.arg = arg;
237     }
238     
239     /**
240      * Constructs the SearchKey.
241      *
242      * @param key
243      * @param arg
244      * @param arg2
245      */

246     public SearchKey(String JavaDoc key, String JavaDoc arg, String JavaDoc arg2) {
247         this.key = key;
248         this.arg = arg;
249         this.arg2 = arg2;
250     }
251
252     /**
253      * Constructs the SearchKey.
254      *
255      * @param key
256      * @param arg
257      */

258     public SearchKey(String JavaDoc key, SearchKey arg) {
259         this.key = key;
260         this.arg = arg;
261     }
262
263     /**
264      * Constructs the SearchKey.
265      *
266      * @param key
267      * @param arg
268      * @param arg2
269      */

270     public SearchKey(String JavaDoc key, SearchKey arg, SearchKey arg2) {
271         this.key = key;
272         this.arg = arg;
273         this.arg2 = arg2;
274     }
275
276     /**
277      * Add a Searchkey.
278      *
279      * @param key
280      */

281     public void add( SearchKey key) {
282         if( list == null ) {
283             list = new LinkedList JavaDoc();
284         }
285         
286         list.add(key);
287     }
288
289     /**
290      * Converts the SearchKey to a StringArray.
291      * This is used when sending the search to the
292      * server.
293      *
294      * @return the String[] representation of the SearchKey
295      */

296     public String JavaDoc[] toStringArray() {
297         List JavaDoc result = new LinkedList JavaDoc();
298         if( list != null ) {
299            result.add("(");
300         }
301         
302         result.add(key);
303         if( arg != null ) {
304             if( arg instanceof SearchKey ) {
305                 result.addAll(Arrays.asList(((SearchKey)arg).toStringArray()));
306             } else {
307                 result.add(arg.toString());
308             }
309         }
310         if( arg2 != null ) {
311             if( arg2 instanceof SearchKey ) {
312                 result.addAll(Arrays.asList(((SearchKey)arg2).toStringArray()));
313             } else {
314                 result.add(arg2.toString());
315             }
316         }
317         if( list != null ) {
318             Iterator JavaDoc it = list.iterator();
319             Object JavaDoc next;
320             while( it.hasNext() ) {
321                 next = it.next();
322                 if( next instanceof SearchKey ) {
323                     result.addAll(Arrays.asList(((SearchKey)next).toStringArray()));
324                 } else {
325                     result.add(next.toString());
326                 }
327             }
328             result.add(")");
329         }
330         return (String JavaDoc[]) result.toArray(new String JavaDoc[]{});
331     }
332     
333     /**
334      * @see java.lang.Object#toString()
335      */

336     public String JavaDoc toString() {
337         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
338         
339         if( list != null ) {
340             result.append('(');
341         }
342         result.append(key);
343         if( arg != null ) {
344             result.append(' ');
345             result.append(arg.toString());
346         }
347         if( arg2 != null ) {
348             result.append(' ');
349             result.append(arg2.toString());
350         }
351         if( list != null ) {
352             Iterator JavaDoc it = list.iterator();
353             while( it.hasNext() ) {
354                 result.append(' ');
355                 result.append(it.next().toString());
356             }
357             result.append(')');
358         }
359         return result.toString();
360     }
361     
362 }
363
Popular Tags