2 * FreenetSone - WebInterface.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.web;
20 import java.io.InputStream;
21 import java.io.InputStreamReader;
22 import java.io.Reader;
23 import java.io.StringReader;
24 import java.io.UnsupportedEncodingException;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.List;
33 import java.util.UUID;
34 import java.util.logging.Level;
35 import java.util.logging.Logger;
37 import net.pterodactylus.sone.core.Core;
38 import net.pterodactylus.sone.core.CoreListener;
39 import net.pterodactylus.sone.data.Post;
40 import net.pterodactylus.sone.data.Reply;
41 import net.pterodactylus.sone.data.Sone;
42 import net.pterodactylus.sone.freenet.L10nFilter;
43 import net.pterodactylus.sone.freenet.wot.Identity;
44 import net.pterodactylus.sone.freenet.wot.Trust;
45 import net.pterodactylus.sone.main.SonePlugin;
46 import net.pterodactylus.sone.notify.ListNotification;
47 import net.pterodactylus.sone.template.CollectionAccessor;
48 import net.pterodactylus.sone.template.CssClassNameFilter;
49 import net.pterodactylus.sone.template.GetPagePlugin;
50 import net.pterodactylus.sone.template.IdentityAccessor;
51 import net.pterodactylus.sone.template.NotificationManagerAccessor;
52 import net.pterodactylus.sone.template.PostAccessor;
53 import net.pterodactylus.sone.template.ReplyAccessor;
54 import net.pterodactylus.sone.template.RequestChangeFilter;
55 import net.pterodactylus.sone.template.SoneAccessor;
56 import net.pterodactylus.sone.template.SubstringFilter;
57 import net.pterodactylus.sone.template.TrustAccessor;
58 import net.pterodactylus.sone.web.ajax.CreatePostAjaxPage;
59 import net.pterodactylus.sone.web.ajax.CreateReplyAjaxPage;
60 import net.pterodactylus.sone.web.ajax.DeletePostAjaxPage;
61 import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage;
62 import net.pterodactylus.sone.web.ajax.DismissNotificationAjaxPage;
63 import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage;
64 import net.pterodactylus.sone.web.ajax.GetLikesAjaxPage;
65 import net.pterodactylus.sone.web.ajax.GetPostAjaxPage;
66 import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
67 import net.pterodactylus.sone.web.ajax.GetStatusAjaxPage;
68 import net.pterodactylus.sone.web.ajax.GetTranslationPage;
69 import net.pterodactylus.sone.web.ajax.LikeAjaxPage;
70 import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage;
71 import net.pterodactylus.sone.web.ajax.MarkPostAsKnownPage;
72 import net.pterodactylus.sone.web.ajax.MarkReplyAsKnownPage;
73 import net.pterodactylus.sone.web.ajax.TrustAjaxPage;
74 import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage;
75 import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage;
76 import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage;
77 import net.pterodactylus.sone.web.page.PageToadlet;
78 import net.pterodactylus.sone.web.page.PageToadletFactory;
79 import net.pterodactylus.sone.web.page.StaticPage;
80 import net.pterodactylus.util.logging.Logging;
81 import net.pterodactylus.util.notify.Notification;
82 import net.pterodactylus.util.notify.NotificationManager;
83 import net.pterodactylus.util.notify.TemplateNotification;
84 import net.pterodactylus.util.template.DateFilter;
85 import net.pterodactylus.util.template.DefaultTemplateFactory;
86 import net.pterodactylus.util.template.MatchFilter;
87 import net.pterodactylus.util.template.PaginationPlugin;
88 import net.pterodactylus.util.template.ReflectionAccessor;
89 import net.pterodactylus.util.template.Template;
90 import net.pterodactylus.util.template.TemplateException;
91 import net.pterodactylus.util.template.TemplateFactory;
92 import net.pterodactylus.util.template.TemplateProvider;
93 import net.pterodactylus.util.template.XmlFilter;
94 import net.pterodactylus.util.thread.Ticker;
95 import freenet.clients.http.SessionManager;
96 import freenet.clients.http.SessionManager.Session;
97 import freenet.clients.http.ToadletContainer;
98 import freenet.clients.http.ToadletContext;
99 import freenet.l10n.BaseL10n;
102 * Bundles functionality that a web interface of a Freenet plugin needs, e.g.
103 * references to l10n helpers.
105 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
107 public class WebInterface implements CoreListener {
110 private static final Logger logger = Logging.getLogger(WebInterface.class);
112 /** The notification manager. */
113 private final NotificationManager notificationManager = new NotificationManager();
115 /** The Sone plugin. */
116 private final SonePlugin sonePlugin;
118 /** The registered toadlets. */
119 private final List<PageToadlet> pageToadlets = new ArrayList<PageToadlet>();
121 /** The form password. */
122 private final String formPassword;
124 /** The template factory. */
125 private DefaultTemplateFactory templateFactory;
127 /** The “new Sone” notification. */
128 private final ListNotification<Sone> newSoneNotification;
130 /** The “new post” notification. */
131 private final ListNotification<Post> newPostNotification;
133 /** The “new reply” notification. */
134 private final ListNotification<Reply> newReplyNotification;
136 /** The “rescuing Sone” notification. */
137 private final ListNotification<Sone> rescuingSonesNotification;
139 /** The “Sone rescued” notification. */
140 private final ListNotification<Sone> sonesRescuedNotification;
142 /** Sone locked notification ticker objects. */
143 private final Map<Sone, Object> lockedSonesTickerObjects = Collections.synchronizedMap(new HashMap<Sone, Object>());
145 /** The “Sone locked” notification. */
146 private final ListNotification<Sone> lockedSonesNotification;
149 * Creates a new web interface.
154 public WebInterface(SonePlugin sonePlugin) {
155 this.sonePlugin = sonePlugin;
156 formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
158 templateFactory = new DefaultTemplateFactory();
159 templateFactory.addAccessor(Object.class, new ReflectionAccessor());
160 templateFactory.addAccessor(Collection.class, new CollectionAccessor());
161 templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
162 templateFactory.addAccessor(Post.class, new PostAccessor(getCore(), templateFactory));
163 templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore(), templateFactory));
164 templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
165 templateFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
166 templateFactory.addAccessor(Trust.class, new TrustAccessor());
167 templateFactory.addFilter("date", new DateFilter());
168 templateFactory.addFilter("l10n", new L10nFilter(getL10n()));
169 templateFactory.addFilter("substring", new SubstringFilter());
170 templateFactory.addFilter("xml", new XmlFilter());
171 templateFactory.addFilter("change", new RequestChangeFilter());
172 templateFactory.addFilter("match", new MatchFilter());
173 templateFactory.addFilter("css", new CssClassNameFilter());
174 templateFactory.addPlugin("getpage", new GetPagePlugin());
175 templateFactory.addPlugin("paginate", new PaginationPlugin());
176 templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory));
177 templateFactory.addTemplateObject("formPassword", formPassword);
179 /* create notifications. */
180 Template newSoneNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newSoneNotification.html"));
181 newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate);
183 Template newPostNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newPostNotification.html"));
184 newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate);
186 Template newReplyNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newReplyNotification.html"));
187 newReplyNotification = new ListNotification<Reply>("new-replies-notification", "replies", newReplyNotificationTemplate);
189 Template rescuingSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/rescuingSonesNotification.html"));
190 rescuingSonesNotification = new ListNotification<Sone>("sones-being-rescued-notification", "sones", rescuingSonesTemplate);
192 Template sonesRescuedTemplate = templateFactory.createTemplate(createReader("/templates/notify/sonesRescuedNotification.html"));
193 sonesRescuedNotification = new ListNotification<Sone>("sones-rescued-notification", "sones", sonesRescuedTemplate);
195 Template lockedSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/lockedSonesNotification.html"));
196 lockedSonesNotification = new ListNotification<Sone>("sones-locked-notification", "sones", lockedSonesTemplate);
204 * Returns the Sone core used by the Sone plugin.
206 * @return The Sone core
208 public Core getCore() {
209 return sonePlugin.core();
213 * Returns the current session, creating a new session if there is no
216 * @param toadletContenxt
217 * The toadlet context
218 * @return The current session, or {@code null} if there is no current
221 public Session getCurrentSession(ToadletContext toadletContenxt) {
222 return getCurrentSession(toadletContenxt, true);
226 * Returns the current session, creating a new session if there is no
227 * current session and {@code create} is {@code true}.
229 * @param toadletContenxt
230 * The toadlet context
232 * {@code true} to create a new session if there is no current
233 * session, {@code false} otherwise
234 * @return The current session, or {@code null} if there is no current
237 public Session getCurrentSession(ToadletContext toadletContenxt, boolean create) {
238 Session session = getSessionManager().useSession(toadletContenxt);
239 if (create && (session == null)) {
240 session = getSessionManager().createSession(UUID.randomUUID().toString(), toadletContenxt);
246 * Returns the currently logged in Sone.
248 * @param toadletContext
249 * The toadlet context
250 * @return The currently logged in Sone, or {@code null} if no Sone is
251 * currently logged in
253 public Sone getCurrentSone(ToadletContext toadletContext) {
254 return getCurrentSone(toadletContext, true);
258 * Returns the currently logged in Sone.
260 * @param toadletContext
261 * The toadlet context
263 * {@code true} to create a new session if no session exists,
264 * {@code false} to not create a new session
265 * @return The currently logged in Sone, or {@code null} if no Sone is
266 * currently logged in
268 public Sone getCurrentSone(ToadletContext toadletContext, boolean create) {
269 return getCurrentSone(getCurrentSession(toadletContext, create));
273 * Returns the currently logged in Sone.
277 * @return The currently logged in Sone, or {@code null} if no Sone is
278 * currently logged in
280 public Sone getCurrentSone(Session session) {
281 if (session == null) {
284 String soneId = (String) session.getAttribute("Sone.CurrentSone");
285 if (soneId == null) {
288 return getCore().getLocalSone(soneId, false);
292 * Sets the currently logged in Sone.
294 * @param toadletContext
295 * The toadlet context
297 * The Sone to set as currently logged in
299 public void setCurrentSone(ToadletContext toadletContext, Sone sone) {
300 Session session = getCurrentSession(toadletContext);
302 session.removeAttribute("Sone.CurrentSone");
304 session.setAttribute("Sone.CurrentSone", sone.getId());
309 * Returns the notification manager.
311 * @return The notification manager
313 public NotificationManager getNotifications() {
314 return notificationManager;
318 * Returns the l10n helper of the node.
320 * @return The node’s l10n helper
322 public BaseL10n getL10n() {
323 return sonePlugin.l10n().getBase();
327 * Returns the session manager of the node.
329 * @return The node’s session manager
331 public SessionManager getSessionManager() {
332 return sonePlugin.pluginRespirator().getSessionManager("Sone");
336 * Returns the node’s form password.
338 * @return The form password
340 public String getFormPassword() {
345 * Returns the posts that have been announced as new in the
346 * {@link #newPostNotification}.
348 * @return The new posts
350 public Set<Post> getNewPosts() {
351 return new HashSet<Post>(newPostNotification.getElements());
355 * Returns the replies that have been announced as new in the
356 * {@link #newReplyNotification}.
358 * @return The new replies
360 public Set<Reply> getNewReplies() {
361 return new HashSet<Reply>(newReplyNotification.getElements());
365 * Sets whether the current start of the plugin is the first start. It is
366 * considered a first start if the configuration file does not exist.
369 * {@code true} if no configuration file existed when Sone was
370 * loaded, {@code false} otherwise
372 public void setFirstStart(boolean firstStart) {
374 Template firstStartNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/firstStartNotification.html"));
375 Notification firstStartNotification = new TemplateNotification("first-start-notification", firstStartNotificationTemplate);
376 notificationManager.addNotification(firstStartNotification);
381 * Sets whether Sone was started with a fresh configuration file.
384 * {@code true} if Sone was started with a fresh configuration,
385 * {@code false} if the existing configuration could be read
387 public void setNewConfig(boolean newConfig) {
388 if (newConfig && !hasFirstStartNotification()) {
389 Template configNotReadNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/configNotReadNotification.html"));
390 Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
391 notificationManager.addNotification(configNotReadNotification);
400 * Returns whether the first start notification is currently displayed.
402 * @return {@code true} if the first-start notification is currently
403 * displayed, {@code false} otherwise
405 private boolean hasFirstStartNotification() {
406 return notificationManager.getNotification("first-start-notification") != null;
414 * Starts the web interface and registers all toadlets.
416 public void start() {
419 /* notification templates. */
420 Template startupNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/startupNotification.html"));
422 final TemplateNotification startupNotification = new TemplateNotification("startup-notification", startupNotificationTemplate);
423 notificationManager.addNotification(startupNotification);
425 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (120 * 1000), new Runnable() {
429 startupNotification.dismiss();
431 }, "Sone Startup Notification Remover");
433 Template wotMissingNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/wotMissingNotification.html"));
434 final TemplateNotification wotMissingNotification = new TemplateNotification("wot-missing-notification", wotMissingNotificationTemplate);
435 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), new Runnable() {
438 @SuppressWarnings("synthetic-access")
440 if (getCore().getIdentityManager().isConnected()) {
441 wotMissingNotification.dismiss();
443 notificationManager.addNotification(wotMissingNotification);
445 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), this, "Sone WoT Connector Checker");
448 }, "Sone WoT Connector Checker");
452 * Stops the web interface and unregisters all toadlets.
455 unregisterToadlets();
456 Ticker.getInstance().stop();
464 * Register all toadlets.
466 private void registerToadlets() {
467 Template emptyTemplate = templateFactory.createTemplate(new StringReader(""));
468 Template loginTemplate = templateFactory.createTemplate(createReader("/templates/login.html"));
469 Template indexTemplate = templateFactory.createTemplate(createReader("/templates/index.html"));
470 Template knownSonesTemplate = templateFactory.createTemplate(createReader("/templates/knownSones.html"));
471 Template createSoneTemplate = templateFactory.createTemplate(createReader("/templates/createSone.html"));
472 Template createPostTemplate = templateFactory.createTemplate(createReader("/templates/createPost.html"));
473 Template createReplyTemplate = templateFactory.createTemplate(createReader("/templates/createReply.html"));
474 Template editProfileTemplate = templateFactory.createTemplate(createReader("/templates/editProfile.html"));
475 Template viewSoneTemplate = templateFactory.createTemplate(createReader("/templates/viewSone.html"));
476 Template viewPostTemplate = templateFactory.createTemplate(createReader("/templates/viewPost.html"));
477 Template deletePostTemplate = templateFactory.createTemplate(createReader("/templates/deletePost.html"));
478 Template deleteReplyTemplate = templateFactory.createTemplate(createReader("/templates/deleteReply.html"));
479 Template deleteSoneTemplate = templateFactory.createTemplate(createReader("/templates/deleteSone.html"));
480 Template noPermissionTemplate = templateFactory.createTemplate(createReader("/templates/noPermission.html"));
481 Template optionsTemplate = templateFactory.createTemplate(createReader("/templates/options.html"));
482 Template aboutTemplate = templateFactory.createTemplate(createReader("/templates/about.html"));
483 Template postTemplate = templateFactory.createTemplate(createReader("/templates/include/viewPost.html"));
484 Template replyTemplate = templateFactory.createTemplate(createReader("/templates/include/viewReply.html"));
486 PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
487 pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
488 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone"));
489 pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones"));
490 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfilePage(editProfileTemplate, this), "EditProfile"));
491 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this)));
492 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyPage(createReplyTemplate, this)));
493 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewSonePage(viewSoneTemplate, this)));
494 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this)));
495 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePage(emptyTemplate, this)));
496 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePage(emptyTemplate, this)));
497 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this)));
498 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this)));
499 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSonePage(emptyTemplate, this)));
500 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSonePage(emptyTemplate, this)));
501 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(emptyTemplate, this)));
502 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSonePage(emptyTemplate, this)));
503 pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustPage(emptyTemplate, this)));
504 pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustPage(emptyTemplate, this)));
505 pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustPage(emptyTemplate, this)));
506 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
507 pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
508 pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(emptyTemplate, this), "Logout"));
509 pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options"));
510 pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.VERSION), "About"));
511 pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
512 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(emptyTemplate, this)));
513 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css")));
514 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript")));
515 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png")));
516 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
517 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
518 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
519 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostAjaxPage(this)));
520 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
521 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
522 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetPostAjaxPage(this, postTemplate)));
523 pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkPostAsKnownPage(this)));
524 pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkReplyAsKnownPage(this)));
525 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
526 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
527 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSoneAjaxPage(this)));
528 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSoneAjaxPage(this)));
529 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this)));
530 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this)));
531 pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustAjaxPage(this)));
532 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikeAjaxPage(this)));
533 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikeAjaxPage(this)));
534 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetLikesAjaxPage(this)));
536 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
537 toadletContainer.getPageMaker().addNavigationCategory("/Sone/index.html", "Navigation.Menu.Name", "Navigation.Menu.Tooltip", sonePlugin);
538 for (PageToadlet toadlet : pageToadlets) {
539 String menuName = toadlet.getMenuName();
540 if (menuName != null) {
541 toadletContainer.register(toadlet, "Navigation.Menu.Name", toadlet.path(), true, "Navigation.Menu.Item." + menuName + ".Name", "Navigation.Menu.Item." + menuName + ".Tooltip", false, toadlet);
543 toadletContainer.register(toadlet, null, toadlet.path(), true, false);
549 * Unregisters all toadlets.
551 private void unregisterToadlets() {
552 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
553 for (PageToadlet pageToadlet : pageToadlets) {
554 toadletContainer.unregister(pageToadlet);
556 toadletContainer.getPageMaker().removeNavigationCategory("Navigation.Menu.Name");
560 * Creates a {@link Reader} from the {@link InputStream} for the resource
561 * with the given name.
563 * @param resourceName
564 * The name of the resource
565 * @return A {@link Reader} for the resource
567 private Reader createReader(String resourceName) {
569 return new InputStreamReader(getClass().getResourceAsStream(resourceName), "UTF-8");
570 } catch (UnsupportedEncodingException uee1) {
576 // CORELISTENER METHODS
583 public void rescuingSone(Sone sone) {
584 rescuingSonesNotification.add(sone);
585 notificationManager.addNotification(rescuingSonesNotification);
592 public void rescuedSone(Sone sone) {
593 rescuingSonesNotification.remove(sone);
594 sonesRescuedNotification.add(sone);
595 notificationManager.addNotification(sonesRescuedNotification);
602 public void newSoneFound(Sone sone) {
603 newSoneNotification.add(sone);
604 if (!hasFirstStartNotification()) {
605 notificationManager.addNotification(newSoneNotification);
613 public void newPostFound(Post post) {
614 newPostNotification.add(post);
615 if (!hasFirstStartNotification()) {
616 notificationManager.addNotification(newPostNotification);
618 getCore().markPostKnown(post);
626 public void newReplyFound(Reply reply) {
627 if (reply.getPost().getSone() == null) {
630 newReplyNotification.add(reply);
631 if (!hasFirstStartNotification()) {
632 notificationManager.addNotification(newReplyNotification);
634 getCore().markReplyKnown(reply);
642 public void markSoneKnown(Sone sone) {
643 newSoneNotification.remove(sone);
650 public void markPostKnown(Post post) {
651 newPostNotification.remove(post);
658 public void markReplyKnown(Reply reply) {
659 newReplyNotification.remove(reply);
666 public void postRemoved(Post post) {
667 newPostNotification.remove(post);
674 public void replyRemoved(Reply reply) {
675 newReplyNotification.remove(reply);
682 public void soneLocked(final Sone sone) {
683 Object tickerObject = Ticker.getInstance().registerEvent(System.currentTimeMillis() + (5 * 60) * 1000, new Runnable() {
686 @SuppressWarnings("synthetic-access")
688 lockedSonesNotification.add(sone);
689 lockedSonesTickerObjects.remove(sone);
690 notificationManager.addNotification(lockedSonesNotification);
692 }, "Sone Locked Notification");
693 lockedSonesTickerObjects.put(sone, tickerObject);
700 public void soneUnlocked(Sone sone) {
701 lockedSonesNotification.remove(sone);
702 Ticker.getInstance().deregisterEvent(lockedSonesTickerObjects.remove(sone));
706 * Template provider implementation that uses
707 * {@link WebInterface#createReader(String)} to load templates for
710 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
712 private class ClassPathTemplateProvider implements TemplateProvider {
714 /** The template factory. */
715 @SuppressWarnings("hiding")
716 private final TemplateFactory templateFactory;
719 * Creates a new template provider that locates templates on the
722 * @param templateFactory
723 * The template factory to create the templates
725 public ClassPathTemplateProvider(TemplateFactory templateFactory) {
726 this.templateFactory = templateFactory;
733 @SuppressWarnings("synthetic-access")
734 public Template getTemplate(String templateName) {
735 Reader templateReader = createReader("/templates/" + templateName);
736 if (templateReader == null) {
739 Template template = templateFactory.createTemplate(templateReader);
742 } catch (TemplateException te1) {
743 logger.log(Level.WARNING, "Could not parse template “" + templateName + "” for inclusion!", te1);