KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > spam > SpamController


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
13
// Stich.
14
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
15
//
16
//All Rights Reserved.
17

18 package org.columba.mail.spam;
19
20 import java.util.logging.Logger JavaDoc;
21
22 import org.columba.api.plugin.IExtension;
23 import org.columba.api.plugin.IExtensionHandler;
24 import org.columba.api.plugin.PluginException;
25 import org.columba.api.plugin.PluginHandlerNotFoundException;
26 import org.columba.core.logging.Logging;
27 import org.columba.core.plugin.PluginManager;
28 import org.columba.mail.folder.IMailbox;
29 import org.columba.mail.plugin.IExtensionHandlerKeys;
30
31 /**
32  * High-level wrapper for the spam filter.
33  * <p>
34  * Class should be used by Columba, to add ham or spam messages to the training
35  * database. And to score messages using this training set.
36  * <p>
37  *
38  * @author fdietz
39  */

40 public class SpamController implements ISpamPlugin {
41
42     /** JDK 1.4+ logging framework logger, used for logging. */
43     private static final Logger JavaDoc LOG = Logger
44             .getLogger("org.columba.core.gui.htmlviewer");
45
46     /**
47      * singleton pattern instance of this class
48      */

49     private static SpamController instance;
50
51     private ISpamPlugin spamPlugin;
52
53     /**
54      * private constructor
55      */

56     private SpamController() {
57
58         try {
59             IExtensionHandler handler = PluginManager
60                     .getInstance().getExtensionHandler(IExtensionHandlerKeys.ORG_COLUMBA_MAIL_SPAM);
61
62             IExtension extension = handler.getExtension("SpamAssassin");
63
64             spamPlugin = (ISpamPlugin) extension.instanciateExtension(null);
65
66         } catch (PluginHandlerNotFoundException e) {
67             LOG.severe(e.getMessage());
68             if (Logging.DEBUG)
69                 e.printStackTrace();
70
71         } catch (PluginException e) {
72             LOG.severe(e.getMessage());
73             if (Logging.DEBUG)
74                 e.printStackTrace();
75         }
76     }
77
78     /**
79      * Get instance of class.
80      *
81      * @return spam controller
82      */

83     public static SpamController getInstance() {
84         if (instance == null)
85             instance = new SpamController();
86
87         return instance;
88     }
89
90     public boolean scoreMessage(IMailbox mailbox, Object JavaDoc uid) throws Exception JavaDoc {
91
92         return spamPlugin.scoreMessage(mailbox, uid);
93     }
94
95     public void trainMessageAsSpam(IMailbox mailbox, Object JavaDoc uid)
96             throws Exception JavaDoc {
97         spamPlugin.trainMessageAsSpam(mailbox, uid);
98     }
99
100     public void trainMessageAsHam(IMailbox mailbox, Object JavaDoc uid)
101             throws Exception JavaDoc {
102         spamPlugin.trainMessageAsHam(mailbox, uid);
103     }
104
105     /**
106      * Save frequency DB to file.
107      */

108     public void save() {
109         spamPlugin.save();
110     }
111
112     public void load() {
113         spamPlugin.load();
114     }
115 }
Popular Tags