KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.suberic.pooka.filter;
2 import net.suberic.pooka.gui.MessageProxy;
3 import java.util.List JavaDoc;
4 import java.util.ArrayList JavaDoc;
5 import net.suberic.pooka.FolderInfo;
6 import net.suberic.pooka.Pooka;
7
8 /**
9  * A filter which moves the given message(s) to another folder.
10  */

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

29   public List JavaDoc performFilter(List JavaDoc filteredMessages) {
30     List JavaDoc moved = new ArrayList JavaDoc();
31     for (int i = 0; i < filteredMessages.size(); i++) {
32       MessageProxy current = (MessageProxy) filteredMessages.get(i);
33       current.moveMessage(getTargetFolder(), false);
34       moved.add(current);
35     }
36     return moved;
37   }
38   
39   /**
40    * Initializes the FilterAction from the sourceProperty given.
41    *
42    * This takes the .targetFolder subproperty of the given sourceProperty
43    * and assigns its value as the folderName String.
44    */

45   
46   public void initializeFilter(String JavaDoc sourceProperty) {
47     folderName = Pooka.getProperty(sourceProperty + ".targetFolder", "");
48   }
49   
50   /**
51    * Returns the targetFolder. If the targetFolder has not yet been
52    * loaded. calls Pooka.getStoreManager.getFolder(folderName) to
53    * cache the targetFolder.
54    */

55   public FolderInfo getTargetFolder() {
56     if (targetFolder == null)
57       targetFolder = Pooka.getStoreManager().getFolder(folderName);
58     
59     return targetFolder;
60   }
61
62 }
63
Popular Tags