KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > filter > FlagFilterAction


1 package net.suberic.pooka.filter;
2 import net.suberic.pooka.gui.MessageProxy;
3 import net.suberic.pooka.FolderInfo;
4 import net.suberic.pooka.Pooka;
5 import java.util.List JavaDoc;
6 import java.util.LinkedList JavaDoc;
7 import javax.mail.*;
8
9 /**
10  * A FilterAction which sets or unsets a given flag on message(s).
11  */

12 public class FlagFilterAction implements FilterAction {
13   
14   private String JavaDoc folderName = null;
15   private Flags flagToSet;
16   private boolean flagValue;
17   
18   public FlagFilterAction() {
19   }
20   
21   /**
22    * Runs the filterAction on each MessageProxy in the filteredMessages
23    * List.
24    *
25    * @param filteredMessages messages which have met the filter condition
26    * and need to have the FilterAction performed on them.
27    *
28    * @return messages which are removed from their original folder
29    * by the filter.
30    */

31   public List JavaDoc performFilter(List JavaDoc filteredMessages) {
32     for (int i = 0; i < filteredMessages.size(); i++) {
33       try {
34     MessageProxy current = (MessageProxy) filteredMessages.get(i);
35     current.getMessageInfo().getRealMessage().setFlags(flagToSet, flagValue);
36       } catch (MessagingException me) {
37       }
38       
39     }
40     
41     return new LinkedList JavaDoc();
42   }
43
44     /**
45      * Initializes the FilterAction from the sourceProperty given.
46      *
47      * This takes the .flag subproperty of the given sourceProperty
48      * and assigns its value to as the flagToSet. Also takes the .value
49      * subproperty and uses it as the flagValue.
50      */

51     
52     public void initializeFilter(String JavaDoc sourceProperty) {
53     String JavaDoc flagName = Pooka.getProperty(sourceProperty + ".flag", "");
54     flagToSet = Pooka.getSearchManager().getFlags(flagName);
55     String JavaDoc value = Pooka.getProperty(sourceProperty + ".value", "true");
56     if (value.equalsIgnoreCase("true"))
57         flagValue = true;
58     else
59         flagValue = false;
60     }
61
62 }
63
Popular Tags