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.PluginRespirator;
43 * This class interfaces with Freenet. It is the class that is loaded by the
44 * node and starts up the whole Sone system.
46 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
48 public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10n {
51 /* initialize logging. */
52 Logging.setup("sone");
56 private static final Logger logger = Logging.getLogger(SonePlugin.class);
58 /** The plugin respirator. */
59 private PluginRespirator pluginRespirator;
64 /** The l10n helper. */
65 private PluginL10n l10n;
72 * Returns the plugin respirator for this plugin.
74 * @return The plugin respirator
76 public PluginRespirator pluginRespirator() {
77 return pluginRespirator;
81 * Returns the core started by this plugin.
90 * Returns the plugin’s l10n helper.
92 * @return The plugin’s l10n helper
94 public PluginL10n l10n() {
106 public void runPlugin(PluginRespirator pluginRespirator) {
107 this.pluginRespirator = pluginRespirator;
109 /* create a configuration. */
110 Configuration configuration;
112 configuration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator.getStore()));
113 } catch (DatabaseDisabledException dde1) {
114 logger.log(Level.WARNING, "Could not load plugin store, using XML files.");
116 configuration = new Configuration(new XMLConfigurationBackend(new File("sone.xml"), true));
117 } catch (ConfigurationException ce1) {
118 logger.log(Level.SEVERE, "Could not load or create the “sone.xml” configuration file!");
119 configuration = new Configuration(new MapConfigurationBackend(Collections.<String, String> emptyMap()));
123 /* create freenet interface. */
124 FreenetInterface freenetInterface = new FreenetInterface(pluginRespirator.getNode(), pluginRespirator.getHLSimpleClient());
126 /* create the web interface. */
127 WebInterface webInterface = new WebInterface(this);
131 core.configuration(configuration);
132 core.freenetInterface(freenetInterface);
136 webInterface.start();
143 public void terminate() {
147 /* TODO wait for core to stop? */
151 // INTERFACE FredPluginL10n
158 public String getString(String key) {
159 return l10n.getBase().getString(key);
166 public void setLanguage(LANGUAGE newLanguage) {
167 l10n = new PluginL10n(this, newLanguage);
171 // INTERFACE FredPluginBaseL10n
178 public String getL10nFilesBasePath() {
186 public String getL10nFilesMask() {
187 return "sone.${lang}.properties";
194 public String getL10nOverrideFilesMask() {
195 return "sone.${lang}.override.properties";
202 public ClassLoader getPluginClassLoader() {
203 return SonePlugin.class.getClassLoader();