2 * WoTNS - WoTNSPlugin.java - Copyright © 2011 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.wotns.main;
20 import java.util.logging.Level;
21 import java.util.logging.LogRecord;
23 import net.pterodactylus.util.logging.Logging;
24 import net.pterodactylus.util.logging.LoggingListener;
25 import net.pterodactylus.util.version.Version;
26 import net.pterodactylus.wotns.freenet.plugin.PluginConnector;
27 import net.pterodactylus.wotns.freenet.wot.IdentityManager;
28 import net.pterodactylus.wotns.freenet.wot.WebOfTrustConnector;
29 import net.pterodactylus.wotns.ui.web.WebInterface;
30 import freenet.client.HighLevelSimpleClient;
31 import freenet.clients.http.ToadletContainer;
32 import freenet.l10n.PluginL10n;
33 import freenet.l10n.BaseL10n.LANGUAGE;
34 import freenet.pluginmanager.FredPlugin;
35 import freenet.pluginmanager.FredPluginBaseL10n;
36 import freenet.pluginmanager.FredPluginL10n;
37 import freenet.pluginmanager.FredPluginThreadless;
38 import freenet.pluginmanager.FredPluginVersioned;
39 import freenet.pluginmanager.PluginRespirator;
42 * Main plugin class for Web of Trust Name Service.
44 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
46 public class WoTNSPlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10n, FredPluginVersioned, FredPluginThreadless {
49 Logging.setup("WoTNS");
50 Logging.addLoggingListener(new LoggingListener() {
53 public void logged(LogRecord logRecord) {
54 Class<?> loggerClass = Logging.getLoggerClass(logRecord.getLoggerName());
55 int recordLevel = logRecord.getLevel().intValue();
56 if (recordLevel < Level.FINE.intValue()) {
57 freenet.support.Logger.debug(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown());
58 } else if (recordLevel < Level.INFO.intValue()) {
59 freenet.support.Logger.minor(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown());
60 } else if (recordLevel < Level.WARNING.intValue()) {
61 freenet.support.Logger.normal(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown());
62 } else if (recordLevel < Level.SEVERE.intValue()) {
63 freenet.support.Logger.warning(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown());
65 freenet.support.Logger.error(loggerClass, String.format(logRecord.getMessage(), logRecord.getParameters()), logRecord.getThrown());
71 /** The current version of the plugin. */
72 private static final Version VERSION = new Version(0, 0, 8);
74 /** The plugin respirator. */
75 private PluginRespirator pluginRespirator;
77 /** The l10n handler. */
78 private PluginL10n l10n;
80 /** The web interface. */
81 private WebInterface webInterface;
84 private Resolver resolver;
86 /** The web of trust connector. */
87 private WebOfTrustConnector webOfTrustConnector;
89 /** The identity manager. */
90 private IdentityManager identityManager;
97 * Returns the high-level simple client for the node.
99 * @return The high-level simple client
101 public HighLevelSimpleClient getHighLevelSimpleClient() {
102 return pluginRespirator.getHLSimpleClient();
106 * Returns the toadlet container of the node.
108 * @return The toadlet container of the node
110 public ToadletContainer getToadletContainer() {
111 return pluginRespirator.getToadletContainer();
115 * Returns the identity manager.
117 * @return The identity manager
119 public IdentityManager getIdentityManager() {
120 return identityManager;
124 * Returns the resolver.
126 * @return The resolver
128 public Resolver getResolver() {
133 // FREDPLUGIN METHODS
140 public void runPlugin(PluginRespirator pluginRespirator) {
141 this.pluginRespirator = pluginRespirator;
143 PluginConnector pluginConnector = new PluginConnector(pluginRespirator);
144 webOfTrustConnector = new WebOfTrustConnector(pluginConnector);
145 identityManager = new IdentityManager(webOfTrustConnector);
146 identityManager.setContext("WoTNS");
147 identityManager.start();
149 resolver = new Resolver(identityManager);
151 webInterface = new WebInterface(this);
153 webInterface.start();
160 public void terminate() {
161 identityManager.stop();
162 webOfTrustConnector.stop();
168 // FREDPLUGINL10N METHODS
175 public String getString(String key) {
176 return l10n.getBase().getString(key);
183 public void setLanguage(LANGUAGE newLanguage) {
184 l10n = new PluginL10n(this, newLanguage);
188 // FREDPLUGINBASEL10N METHODS
195 public String getL10nFilesBasePath() {
203 public String getL10nFilesMask() {
204 return "WoTNS.${lang}.properties";
211 public String getL10nOverrideFilesMask() {
212 return "WoTNS.${lang}.override.properties";
219 public ClassLoader getPluginClassLoader() {
220 return WoTNSPlugin.class.getClassLoader();
224 // FREDPLUGINVERSIONED METHODS
231 public String getVersion() {
232 return VERSION.toString();