Set version to 0.0.4.
[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  * TODO
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         private static final Version VERSION = new Version(0, 0, 4);
50
51         private PluginRespirator pluginRespirator;
52
53         private PluginL10n l10n;
54
55         private WebInterface webInterface;
56
57         private Resolver resolver;
58
59         private WebOfTrustConnector webOfTrustConnector;
60
61         private IdentityManager identityManager;
62
63         //
64         // ACCESSORS
65         //
66
67         public HighLevelSimpleClient getHighLevelSimpleClient() {
68                 return pluginRespirator.getHLSimpleClient();
69         }
70
71         public ToadletContainer getToadletContainer() {
72                 return pluginRespirator.getToadletContainer();
73         }
74
75         public IdentityManager getIdentityManager() {
76                 return identityManager;
77         }
78
79         public Resolver getResolver() {
80                 return resolver;
81         }
82
83         //
84         // FREDPLUGIN METHODS
85         //
86
87         /**
88          * {@inheritDoc}
89          */
90         @Override
91         public void runPlugin(PluginRespirator pluginRespirator) {
92                 this.pluginRespirator = pluginRespirator;
93
94                 PluginConnector pluginConnector = new PluginConnector(pluginRespirator);
95                 webOfTrustConnector = new WebOfTrustConnector(pluginConnector);
96                 identityManager = new IdentityManager(webOfTrustConnector);
97                 identityManager.setContext("WoTNS");
98                 identityManager.start();
99
100                 resolver = new Resolver(identityManager);
101                 resolver.setOwnIdentityId("e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U");
102
103                 webInterface = new WebInterface(this);
104
105                 webInterface.start();
106         }
107
108         /**
109          * {@inheritDoc}
110          */
111         @Override
112         public void terminate() {
113                 identityManager.stop();
114                 webOfTrustConnector.stop();
115                 webInterface.stop();
116                 Logging.shutdown();
117         }
118
119         //
120         // FREDPLUGINL10N METHODS
121         //
122
123         /**
124          * {@inheritDoc}
125          */
126         @Override
127         public String getString(String key) {
128                 return l10n.getBase().getString(key);
129         }
130
131         /**
132          * {@inheritDoc}
133          */
134         @Override
135         public void setLanguage(LANGUAGE newLanguage) {
136                 l10n = new PluginL10n(this, newLanguage);
137         }
138
139         //
140         // FREDPLUGINBASEL10N METHODS
141         //
142
143         /**
144          * {@inheritDoc}
145          */
146         @Override
147         public String getL10nFilesBasePath() {
148                 return "i18n";
149         }
150
151         /**
152          * {@inheritDoc}
153          */
154         @Override
155         public String getL10nFilesMask() {
156                 return "WoTNS.${lang}.properties";
157         }
158
159         /**
160          * {@inheritDoc}
161          */
162         @Override
163         public String getL10nOverrideFilesMask() {
164                 return "WoTNS.${lang}.override.properties";
165         }
166
167         /**
168          * {@inheritDoc}
169          */
170         @Override
171         public ClassLoader getPluginClassLoader() {
172                 return WoTNSPlugin.class.getClassLoader();
173         }
174
175         //
176         // FREDPLUGINVERSIONED METHODS
177         //
178
179         /**
180          * {@inheritDoc}
181          */
182         @Override
183         public String getVersion() {
184                 return VERSION.toString();
185         }
186
187 }