KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > spam > command > LearnMessageAsHamCommand


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.mail.spam.command;
18
19 import org.columba.api.command.ICommandReference;
20 import org.columba.api.command.IWorkerStatusController;
21 import org.columba.core.command.Command;
22 import org.columba.core.command.StatusObservableImpl;
23 import org.columba.core.logging.Logging;
24 import org.columba.mail.command.IMailFolderCommandReference;
25 import org.columba.mail.folder.IMailbox;
26 import org.columba.mail.spam.SpamController;
27
28 /**
29  * Learn selected messages as ham.
30  *
31  * @author fdietz
32  */

33 public class LearnMessageAsHamCommand extends Command {
34     
35     private static final java.util.logging.Logger JavaDoc LOG =
36         java.util.logging.Logger.getLogger("org.columba.mail.spam.command"); //$NON-NLS-1$
37

38     /**
39      * @param references
40      */

41     public LearnMessageAsHamCommand(ICommandReference reference) {
42         super(reference);
43     }
44
45     /**
46      * @see org.columba.api.command.Command#execute(org.columba.api.command.Worker)
47      */

48     public void execute(IWorkerStatusController worker) throws Exception JavaDoc {
49
50         // get array of source references
51
IMailFolderCommandReference r = (IMailFolderCommandReference) getReference();
52
53         // get array of message UIDs
54
Object JavaDoc[] uids = r.getUids();
55
56         // get source folder
57
IMailbox srcFolder = (IMailbox) r.getSourceFolder();
58
59         // register for status events
60
((StatusObservableImpl) srcFolder.getObservable()).setWorker(worker);
61
62         // update status message
63
if (uids.length > 1) {
64             // TODO (@author fdietz): i18n
65
worker.setDisplayText("Training messages...");
66             worker.setProgressBarMaximum(uids.length);
67         }
68
69         long startTime = System.currentTimeMillis();
70
71         for (int j = 0; j < uids.length; j++) {
72             if (worker.cancelled()) {
73                 break;
74             }
75
76             try {
77
78                 // train message as ham
79
SpamController.getInstance().trainMessageAsHam(srcFolder,
80                         uids[j]);
81
82                 if (uids.length > 1) {
83                     worker.setProgressBarValue(j);
84                 }
85             } catch (Exception JavaDoc e) {
86                 if (Logging.DEBUG) {
87                     e.printStackTrace();
88                 }
89             }
90         }
91
92         long endTime = System.currentTimeMillis();
93
94         LOG.info("took me=" + (endTime - startTime) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
95

96     }
97 }
Popular Tags