83639c2f6b2992493104e91f2d12932504c4b21d
[WoTNS.git] / src / main / java / net / pterodactylus / wotns / main / WoTNSPlugin.java
1 /*
2  * WoTNS - WoTNSPlugin.java - Copyright © 2011 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.wotns.main;
19
20 import net.pterodactylus.util.logging.Logging;
21 import net.pterodactylus.util.version.Version;
22 import net.pterodactylus.wotns.freenet.plugin.PluginConnector;
23 import net.pterodactylus.wotns.freenet.wot.IdentityManager;
24 import net.pterodactylus.wotns.freenet.wot.WebOfTrustConnector;
25 import net.pterodactylus.wotns.ui.web.WebInterface;
26 import freenet.client.HighLevelSimpleClient;
27 import freenet.clients.http.ToadletContainer;
28 import freenet.l10n.PluginL10n;
29 import freenet.l10n.BaseL10n.LANGUAGE;
30 import freenet.pluginmanager.FredPlugin;
31 import freenet.pluginmanager.FredPluginBaseL10n;
32 import freenet.pluginmanager.FredPluginL10n;
33 import freenet.pluginmanager.FredPluginThreadless;
34 import freenet.pluginmanager.FredPluginVersioned;
35 import freenet.pluginmanager.PluginRespirator;
36
37 /**
38  * Main plugin class for Web of Trust Name Service.
39  *
40  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
41  */
42 public class WoTNSPlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10n, FredPluginVersioned, FredPluginThreadless {
43
44         static {
45                 Logging.setup("WoTNS");
46                 Logging.setupConsoleLogging();
47         }
48
49         /** The current version of the plugin. */
50         private static final Version VERSION = new Version(0, 0, 7);
51
52         /** The plugin respirator. */
53         private PluginRespirator pluginRespirator;
54
55         /** The l10n handler. */
56         private PluginL10n l10n;
57
58         /** The web interface. */
59         private WebInterface webInterface;
60
61         /** The resolver. */
62         private Resolver resolver;
63
64         /** The web of trust connector. */
65         private WebOfTrustConnector webOfTrustConnector;
66
67         /** The identity manager. */
68         private IdentityManager identityManager;
69
70         //
71         // ACCESSORS
72         //
73
74         /**
75          * Returns the high-level simple client for the node.
76          *
77          * @return The high-level simple client
78          */
79         public HighLevelSimpleClient getHighLevelSimpleClient() {
80                 return pluginRespirator.getHLSimpleClient();
81         }
82
83         /**
84          * Returns the toadlet container of the node.
85          *
86          * @return The toadlet container of the node
87          */
88         public ToadletContainer getToadletContainer() {
89                 return pluginRespirator.getToadletContainer();
90         }
91
92         /**
93          * Returns the identity manager.
94          *
95          * @return The identity manager
96          */
97         public IdentityManager getIdentityManager() {
98                 return identityManager;
99         }
100
101         /**
102          * Returns the resolver.
103          *
104          * @return The resolver
105          */
106         public Resolver getResolver() {
107                 return resolver;
108         }
109
110         //
111         // FREDPLUGIN METHODS
112         //
113
114         /**
115          * {@inheritDoc}
116          */
117         @Override
118         public void runPlugin(@SuppressWarnings("hiding") PluginRespirator pluginRespirator) {
119                 this.pluginRespirator = pluginRespirator;
120
121                 PluginConnector pluginConnector = new PluginConnector(pluginRespirator);
122                 webOfTrustConnector = new WebOfTrustConnector(pluginConnector);
123                 identityManager = new IdentityManager(webOfTrustConnector);
124                 identityManager.setContext("WoTNS");
125                 identityManager.start();
126
127                 resolver = new Resolver(identityManager);
128
129                 webInterface = new WebInterface(this);
130
131                 webInterface.start();
132         }
133
134         /**
135          * {@inheritDoc}
136          */
137         @Override
138         public void terminate() {
139                 identityManager.stop();
140                 webOfTrustConnector.stop();
141                 webInterface.stop();
142                 Logging.shutdown();
143         }
144
145         //
146         // FREDPLUGINL10N METHODS
147         //
148
149         /**
150          * {@inheritDoc}
151          */
152         @Override
153         public String getString(String key) {
154                 return l10n.getBase().getString(key);
155         }
156
157         /**
158          * {@inheritDoc}
159          */
160         @Override
161         public void setLanguage(LANGUAGE newLanguage) {
162                 l10n = new PluginL10n(this, newLanguage);
163         }
164
165         //
166         // FREDPLUGINBASEL10N METHODS
167         //
168
169         /**
170          * {@inheritDoc}
171          */
172         @Override
173         public String getL10nFilesBasePath() {
174                 return "i18n";
175         }
176
177         /**
178          * {@inheritDoc}
179          */
180         @Override
181         public String getL10nFilesMask() {
182                 return "WoTNS.${lang}.properties";
183         }
184
185         /**
186          * {@inheritDoc}
187          */
188         @Override
189         public String getL10nOverrideFilesMask() {
190                 return "WoTNS.${lang}.override.properties";
191         }
192
193         /**
194          * {@inheritDoc}
195          */
196         @Override
197         public ClassLoader getPluginClassLoader() {
198                 return WoTNSPlugin.class.getClassLoader();
199         }
200
201         //
202         // FREDPLUGINVERSIONED METHODS
203         //
204
205         /**
206          * {@inheritDoc}
207          */
208         @Override
209         public String getVersion() {
210                 return VERSION.toString();
211         }
212
213 }