f3ec6d45e4ead8f852e60a504f2d3d530f448608
[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.OwnIdentity;
25 import net.pterodactylus.wotns.freenet.wot.WebOfTrustConnector;
26 import net.pterodactylus.wotns.ui.web.WebInterface;
27 import freenet.client.HighLevelSimpleClient;
28 import freenet.clients.http.ToadletContainer;
29 import freenet.l10n.PluginL10n;
30 import freenet.l10n.BaseL10n.LANGUAGE;
31 import freenet.pluginmanager.FredPlugin;
32 import freenet.pluginmanager.FredPluginBaseL10n;
33 import freenet.pluginmanager.FredPluginL10n;
34 import freenet.pluginmanager.FredPluginThreadless;
35 import freenet.pluginmanager.FredPluginVersioned;
36 import freenet.pluginmanager.PluginRespirator;
37
38 /**
39  * TODO
40  *
41  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
42  */
43 public class WoTNSPlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10n, FredPluginVersioned, FredPluginThreadless {
44
45         static {
46                 Logging.setup("WoTNS");
47                 Logging.setupConsoleLogging();
48         }
49
50         private static final Version VERSION = new Version(0, 1);
51
52         private PluginRespirator pluginRespirator;
53
54         private PluginL10n l10n;
55
56         private WebInterface webInterface;
57
58         private Resolver resolver;
59
60         private WebOfTrustConnector webOfTrustConnector;
61
62         private IdentityManager identityManager;
63
64         //
65         // ACCESSORS
66         //
67
68         public HighLevelSimpleClient getHighLevelSimpleClient() {
69                 return pluginRespirator.getHLSimpleClient();
70         }
71
72         public ToadletContainer getToadletContainer() {
73                 return pluginRespirator.getToadletContainer();
74         }
75
76         public IdentityManager getIdentityManager() {
77                 return identityManager;
78         }
79
80         public Resolver getResolver() {
81                 return resolver;
82         }
83
84         //
85         // FREDPLUGIN METHODS
86         //
87
88         /**
89          * {@inheritDoc}
90          */
91         @Override
92         public void runPlugin(PluginRespirator pluginRespirator) {
93                 this.pluginRespirator = pluginRespirator;
94
95                 PluginConnector pluginConnector = new PluginConnector(pluginRespirator);
96                 webOfTrustConnector = new WebOfTrustConnector(pluginConnector);
97                 identityManager = new IdentityManager(webOfTrustConnector);
98 //              identityManager.setContext("WoTNS");
99                 identityManager.start();
100
101                 resolver = new Resolver(identityManager);
102                 OwnIdentity bombeIdentity = identityManager.getOwnIdentity("e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U");
103                 resolver.setOwnIdentity(bombeIdentity);
104
105                 webInterface = new WebInterface(this);
106
107                 webInterface.start();
108         }
109
110         /**
111          * {@inheritDoc}
112          */
113         @Override
114         public void terminate() {
115                 identityManager.stop();
116                 webOfTrustConnector.stop();
117                 webInterface.stop();
118                 Logging.shutdown();
119         }
120
121         //
122         // FREDPLUGINL10N METHODS
123         //
124
125         /**
126          * {@inheritDoc}
127          */
128         @Override
129         public String getString(String key) {
130                 return l10n.getBase().getString(key);
131         }
132
133         /**
134          * {@inheritDoc}
135          */
136         @Override
137         public void setLanguage(LANGUAGE newLanguage) {
138                 l10n = new PluginL10n(this, newLanguage);
139         }
140
141         //
142         // FREDPLUGINBASEL10N METHODS
143         //
144
145         /**
146          * {@inheritDoc}
147          */
148         @Override
149         public String getL10nFilesBasePath() {
150                 return "i18n";
151         }
152
153         /**
154          * {@inheritDoc}
155          */
156         @Override
157         public String getL10nFilesMask() {
158                 return "WoTNS.${lang}.properties";
159         }
160
161         /**
162          * {@inheritDoc}
163          */
164         @Override
165         public String getL10nOverrideFilesMask() {
166                 return "WoTNS.${lang}.override.properties";
167         }
168
169         /**
170          * {@inheritDoc}
171          */
172         @Override
173         public ClassLoader getPluginClassLoader() {
174                 return WoTNSPlugin.class.getClassLoader();
175         }
176
177         //
178         // FREDPLUGINVERSIONED METHODS
179         //
180
181         /**
182          * {@inheritDoc}
183          */
184         @Override
185         public String getVersion() {
186                 return VERSION.toString();
187         }
188
189 }