2 * FreenetSone - SonePlugin.java - Copyright © 2010 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.sone.main;
21 import java.util.Collections;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
25 import net.pterodactylus.sone.core.Core;
26 import net.pterodactylus.sone.core.FreenetInterface;
27 import net.pterodactylus.sone.freenet.PluginStoreConfigurationBackend;
28 import net.pterodactylus.sone.web.WebInterface;
29 import net.pterodactylus.util.config.Configuration;
30 import net.pterodactylus.util.config.ConfigurationException;
31 import net.pterodactylus.util.config.MapConfigurationBackend;
32 import net.pterodactylus.util.config.XMLConfigurationBackend;
33 import net.pterodactylus.util.logging.Logging;
34 import freenet.client.async.DatabaseDisabledException;
35 import freenet.l10n.BaseL10n.LANGUAGE;
36 import freenet.l10n.PluginL10n;
37 import freenet.pluginmanager.FredPlugin;
38 import freenet.pluginmanager.FredPluginBaseL10n;
39 import freenet.pluginmanager.FredPluginL10n;
40 import freenet.pluginmanager.FredPluginThreadless;
41 import freenet.pluginmanager.PluginRespirator;
44 * This class interfaces with Freenet. It is the class that is loaded by the
45 * node and starts up the whole Sone system.
47 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
49 public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10n, FredPluginThreadless {
52 /* initialize logging. */
53 Logging.setup("sone");
57 private static final Logger logger = Logging.getLogger(SonePlugin.class);
59 /** The plugin respirator. */
60 private PluginRespirator pluginRespirator;
65 /** The web interface. */
66 private WebInterface webInterface;
68 /** The l10n helper. */
69 private PluginL10n l10n;
76 * Returns the plugin respirator for this plugin.
78 * @return The plugin respirator
80 public PluginRespirator pluginRespirator() {
81 return pluginRespirator;
85 * Returns the core started by this plugin.
94 * Returns the plugin’s l10n helper.
96 * @return The plugin’s l10n helper
98 public PluginL10n l10n() {
103 // FREDPLUGIN METHODS
110 public void runPlugin(PluginRespirator pluginRespirator) {
111 this.pluginRespirator = pluginRespirator;
113 /* create a configuration. */
114 Configuration configuration;
116 configuration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator.getStore()));
117 } catch (DatabaseDisabledException dde1) {
118 logger.log(Level.WARNING, "Could not load plugin store, using XML files.");
120 configuration = new Configuration(new XMLConfigurationBackend(new File("sone.xml"), true));
121 } catch (ConfigurationException ce1) {
122 logger.log(Level.SEVERE, "Could not load or create the “sone.xml” configuration file!");
123 configuration = new Configuration(new MapConfigurationBackend(Collections.<String, String> emptyMap()));
127 /* create freenet interface. */
128 FreenetInterface freenetInterface = new FreenetInterface(pluginRespirator.getNode(), pluginRespirator.getHLSimpleClient());
130 /* create the web interface. */
131 webInterface = new WebInterface(this);
135 core.configuration(configuration);
136 core.freenetInterface(freenetInterface);
140 webInterface.start();
147 public void terminate() {
148 /* stop the web interface. */
154 /* TODO wait for core to stop? */
158 // INTERFACE FredPluginL10n
165 public String getString(String key) {
166 return l10n.getBase().getString(key);
173 public void setLanguage(LANGUAGE newLanguage) {
174 l10n = new PluginL10n(this, newLanguage);
178 // INTERFACE FredPluginBaseL10n
185 public String getL10nFilesBasePath() {
193 public String getL10nFilesMask() {
194 return "sone.${lang}.properties";
201 public String getL10nOverrideFilesMask() {
202 return "sone.${lang}.override.properties";
209 public ClassLoader getPluginClassLoader() {
210 return SonePlugin.class.getClassLoader();