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.UnsupportedEncodingException;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.List;
29 import java.util.UUID;
30 import java.util.logging.Level;
31 import java.util.logging.Logger;
33 import net.pterodactylus.sone.core.Core;
34 import net.pterodactylus.sone.core.CoreListener;
35 import net.pterodactylus.sone.data.Post;
36 import net.pterodactylus.sone.data.Reply;
37 import net.pterodactylus.sone.data.Sone;
38 import net.pterodactylus.sone.freenet.L10nFilter;
39 import net.pterodactylus.sone.freenet.wot.Identity;
40 import net.pterodactylus.sone.main.SonePlugin;
41 import net.pterodactylus.sone.notify.ListNotification;
42 import net.pterodactylus.sone.template.CollectionAccessor;
43 import net.pterodactylus.sone.template.CssClassNameFilter;
44 import net.pterodactylus.sone.template.GetPagePlugin;
45 import net.pterodactylus.sone.template.IdentityAccessor;
46 import net.pterodactylus.sone.template.NotificationManagerAccessor;
47 import net.pterodactylus.sone.template.PostAccessor;
48 import net.pterodactylus.sone.template.ReplyAccessor;
49 import net.pterodactylus.sone.template.RequestChangeFilter;
50 import net.pterodactylus.sone.template.SoneAccessor;
51 import net.pterodactylus.sone.template.SubstringFilter;
52 import net.pterodactylus.sone.web.ajax.CreatePostAjaxPage;
53 import net.pterodactylus.sone.web.ajax.CreateReplyAjaxPage;
54 import net.pterodactylus.sone.web.ajax.DeletePostAjaxPage;
55 import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage;
56 import net.pterodactylus.sone.web.ajax.DismissNotificationAjaxPage;
57 import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage;
58 import net.pterodactylus.sone.web.ajax.GetLikesAjaxPage;
59 import net.pterodactylus.sone.web.ajax.GetPostAjaxPage;
60 import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
61 import net.pterodactylus.sone.web.ajax.GetStatusAjaxPage;
62 import net.pterodactylus.sone.web.ajax.GetTranslationPage;
63 import net.pterodactylus.sone.web.ajax.LikeAjaxPage;
64 import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage;
65 import net.pterodactylus.sone.web.ajax.MarkPostAsKnownPage;
66 import net.pterodactylus.sone.web.ajax.MarkReplyAsKnownPage;
67 import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage;
68 import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage;
69 import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage;
70 import net.pterodactylus.sone.web.page.PageToadlet;
71 import net.pterodactylus.sone.web.page.PageToadletFactory;
72 import net.pterodactylus.sone.web.page.StaticPage;
73 import net.pterodactylus.util.logging.Logging;
74 import net.pterodactylus.util.notify.Notification;
75 import net.pterodactylus.util.notify.NotificationManager;
76 import net.pterodactylus.util.notify.TemplateNotification;
77 import net.pterodactylus.util.template.DateFilter;
78 import net.pterodactylus.util.template.DefaultTemplateFactory;
79 import net.pterodactylus.util.template.MatchFilter;
80 import net.pterodactylus.util.template.PaginationPlugin;
81 import net.pterodactylus.util.template.ReflectionAccessor;
82 import net.pterodactylus.util.template.Template;
83 import net.pterodactylus.util.template.TemplateException;
84 import net.pterodactylus.util.template.TemplateFactory;
85 import net.pterodactylus.util.template.TemplateProvider;
86 import net.pterodactylus.util.template.XmlFilter;
87 import net.pterodactylus.util.thread.Ticker;
88 import freenet.clients.http.SessionManager;
89 import freenet.clients.http.SessionManager.Session;
90 import freenet.clients.http.ToadletContainer;
91 import freenet.clients.http.ToadletContext;
92 import freenet.l10n.BaseL10n;
95 * Bundles functionality that a web interface of a Freenet plugin needs, e.g.
96 * references to l10n helpers.
98 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
100 public class WebInterface implements CoreListener {
103 private static final Logger logger = Logging.getLogger(WebInterface.class);
105 /** The notification manager. */
106 private final NotificationManager notificationManager = new NotificationManager();
108 /** The Sone plugin. */
109 private final SonePlugin sonePlugin;
111 /** The registered toadlets. */
112 private final List<PageToadlet> pageToadlets = new ArrayList<PageToadlet>();
114 /** The form password. */
115 private final String formPassword;
117 /** The template factory. */
118 private DefaultTemplateFactory templateFactory;
120 /** The “new Sone” notification. */
121 private final ListNotification<Sone> newSoneNotification;
123 /** The “new post” notification. */
124 private final ListNotification<Post> newPostNotification;
126 /** The “new reply” notification. */
127 private final ListNotification<Reply> newReplyNotification;
129 /** The “rescuing Sone” notification. */
130 private final ListNotification<Sone> rescuingSonesNotification;
132 /** The “Sone rescued” notification. */
133 private final ListNotification<Sone> sonesRescuedNotification;
136 * Creates a new web interface.
141 public WebInterface(SonePlugin sonePlugin) {
142 this.sonePlugin = sonePlugin;
143 formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
145 templateFactory = new DefaultTemplateFactory();
146 templateFactory.addAccessor(Object.class, new ReflectionAccessor());
147 templateFactory.addAccessor(Collection.class, new CollectionAccessor());
148 templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
149 templateFactory.addAccessor(Post.class, new PostAccessor(getCore(), templateFactory));
150 templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore(), templateFactory));
151 templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
152 templateFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
153 templateFactory.addFilter("date", new DateFilter());
154 templateFactory.addFilter("l10n", new L10nFilter(getL10n()));
155 templateFactory.addFilter("substring", new SubstringFilter());
156 templateFactory.addFilter("xml", new XmlFilter());
157 templateFactory.addFilter("change", new RequestChangeFilter());
158 templateFactory.addFilter("match", new MatchFilter());
159 templateFactory.addFilter("css", new CssClassNameFilter());
160 templateFactory.addPlugin("getpage", new GetPagePlugin());
161 templateFactory.addPlugin("paginate", new PaginationPlugin());
162 templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory));
163 templateFactory.addTemplateObject("formPassword", formPassword);
165 /* create notifications. */
166 Template newSoneNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newSoneNotification.html"));
167 newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate);
169 Template newPostNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newPostNotification.html"));
170 newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate);
172 Template newReplyNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newReplyNotification.html"));
173 newReplyNotification = new ListNotification<Reply>("new-replies-notification", "replies", newReplyNotificationTemplate);
175 Template rescuingSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/rescuingSonesNotification.html"));
176 rescuingSonesNotification = new ListNotification<Sone>("sones-being-rescued-notification", "sones", rescuingSonesTemplate);
178 Template sonesRescuedTemplate = templateFactory.createTemplate(createReader("/templates/notify/sonesRescuedNotification.html"));
179 sonesRescuedNotification = new ListNotification<Sone>("sones-rescued-notification", "sones", sonesRescuedTemplate);
187 * Returns the Sone core used by the Sone plugin.
189 * @return The Sone core
191 public Core getCore() {
192 return sonePlugin.core();
196 * Returns the current session, creating a new session if there is no
199 * @param toadletContenxt
200 * The toadlet context
201 * @return The current session, or {@code null} if there is no current
204 public Session getCurrentSession(ToadletContext toadletContenxt) {
205 return getCurrentSession(toadletContenxt, true);
209 * Returns the current session, creating a new session if there is no
210 * current session and {@code create} is {@code true}.
212 * @param toadletContenxt
213 * The toadlet context
215 * {@code true} to create a new session if there is no current
216 * session, {@code false} otherwise
217 * @return The current session, or {@code null} if there is no current
220 public Session getCurrentSession(ToadletContext toadletContenxt, boolean create) {
221 Session session = getSessionManager().useSession(toadletContenxt);
222 if (create && (session == null)) {
223 session = getSessionManager().createSession(UUID.randomUUID().toString(), toadletContenxt);
229 * Returns the currently logged in Sone.
231 * @param toadletContext
232 * The toadlet context
233 * @return The currently logged in Sone, or {@code null} if no Sone is
234 * currently logged in
236 public Sone getCurrentSone(ToadletContext toadletContext) {
237 return getCurrentSone(getCurrentSession(toadletContext));
241 * Returns the currently logged in Sone.
245 * @return The currently logged in Sone, or {@code null} if no Sone is
246 * currently logged in
248 public Sone getCurrentSone(Session session) {
249 if (session == null) {
252 String soneId = (String) session.getAttribute("Sone.CurrentSone");
253 if (soneId == null) {
256 return getCore().getLocalSone(soneId, false);
260 * Sets the currently logged in Sone.
262 * @param toadletContext
263 * The toadlet context
265 * The Sone to set as currently logged in
267 public void setCurrentSone(ToadletContext toadletContext, Sone sone) {
268 Session session = getCurrentSession(toadletContext);
270 session.removeAttribute("Sone.CurrentSone");
272 session.setAttribute("Sone.CurrentSone", sone.getId());
277 * Returns the notification manager.
279 * @return The notification manager
281 public NotificationManager getNotifications() {
282 return notificationManager;
286 * Returns the l10n helper of the node.
288 * @return The node’s l10n helper
290 public BaseL10n getL10n() {
291 return sonePlugin.l10n().getBase();
295 * Returns the session manager of the node.
297 * @return The node’s session manager
299 public SessionManager getSessionManager() {
300 return sonePlugin.pluginRespirator().getSessionManager("Sone");
304 * Returns the node’s form password.
306 * @return The form password
308 public String getFormPassword() {
313 * Returns the posts that have been announced as new in the
314 * {@link #newPostNotification}.
316 * @return The new posts
318 public Set<Post> getNewPosts() {
319 return new HashSet<Post>(newPostNotification.getElements());
323 * Returns the replies that have been announced as new in the
324 * {@link #newReplyNotification}.
326 * @return The new replies
328 public Set<Reply> getNewReplies() {
329 return new HashSet<Reply>(newReplyNotification.getElements());
333 * Sets whether the current start of the plugin is the first start. It is
334 * considered a first start if the configuration file does not exist.
337 * {@code true} if no configuration file existed when Sone was
338 * loaded, {@code false} otherwise
340 public void setFirstStart(boolean firstStart) {
342 Template firstStartNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/firstStartNotification.html"));
343 Notification firstStartNotification = new TemplateNotification("first-start-notification", firstStartNotificationTemplate);
344 notificationManager.addNotification(firstStartNotification);
349 * Sets whether Sone was started with a fresh configuration file.
352 * {@code true} if Sone was started with a fresh configuration,
353 * {@code false} if the existing configuration could be read
355 public void setNewConfig(boolean newConfig) {
356 if (newConfig && !hasFirstStartNotification()) {
357 Template configNotReadNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/configNotReadNotification.html"));
358 Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
359 notificationManager.addNotification(configNotReadNotification);
368 * Returns whether the first start notification is currently displayed.
370 * @return {@code true} if the first-start notification is currently
371 * displayed, {@code false} otherwise
373 private boolean hasFirstStartNotification() {
374 return notificationManager.getNotification("first-start-notification") != null;
382 * Starts the web interface and registers all toadlets.
384 public void start() {
387 /* notification templates. */
388 Template startupNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/startupNotification.html"));
390 final TemplateNotification startupNotification = new TemplateNotification("startup-notification", startupNotificationTemplate);
391 notificationManager.addNotification(startupNotification);
393 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (120 * 1000), new Runnable() {
397 startupNotification.dismiss();
399 }, "Sone Startup Notification Remover");
401 Template wotMissingNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/wotMissingNotification.html"));
402 final TemplateNotification wotMissingNotification = new TemplateNotification("wot-missing-notification", wotMissingNotificationTemplate);
403 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), new Runnable() {
406 @SuppressWarnings("synthetic-access")
408 if (getCore().getIdentityManager().isConnected()) {
409 wotMissingNotification.dismiss();
411 notificationManager.addNotification(wotMissingNotification);
413 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), this, "Sone WoT Connector Checker");
416 }, "Sone WoT Connector Checker");
420 * Stops the web interface and unregisters all toadlets.
423 unregisterToadlets();
424 Ticker.getInstance().stop();
432 * Register all toadlets.
434 private void registerToadlets() {
435 Template loginTemplate = templateFactory.createTemplate(createReader("/templates/login.html"));
436 Template indexTemplate = templateFactory.createTemplate(createReader("/templates/index.html"));
437 Template knownSonesTemplate = templateFactory.createTemplate(createReader("/templates/knownSones.html"));
438 Template createSoneTemplate = templateFactory.createTemplate(createReader("/templates/createSone.html"));
439 Template createPostTemplate = templateFactory.createTemplate(createReader("/templates/createPost.html"));
440 Template createReplyTemplate = templateFactory.createTemplate(createReader("/templates/createReply.html"));
441 Template editProfileTemplate = templateFactory.createTemplate(createReader("/templates/editProfile.html"));
442 Template viewSoneTemplate = templateFactory.createTemplate(createReader("/templates/viewSone.html"));
443 Template viewPostTemplate = templateFactory.createTemplate(createReader("/templates/viewPost.html"));
444 Template likePostTemplate = templateFactory.createTemplate(createReader("/templates/like.html"));
445 Template unlikePostTemplate = templateFactory.createTemplate(createReader("/templates/unlike.html"));
446 Template deletePostTemplate = templateFactory.createTemplate(createReader("/templates/deletePost.html"));
447 Template deleteReplyTemplate = templateFactory.createTemplate(createReader("/templates/deleteReply.html"));
448 Template lockSoneTemplate = templateFactory.createTemplate(createReader("/templates/lockSone.html"));
449 Template unlockSoneTemplate = templateFactory.createTemplate(createReader("/templates/unlockSone.html"));
450 Template followSoneTemplate = templateFactory.createTemplate(createReader("/templates/followSone.html"));
451 Template unfollowSoneTemplate = templateFactory.createTemplate(createReader("/templates/unfollowSone.html"));
452 Template deleteSoneTemplate = templateFactory.createTemplate(createReader("/templates/deleteSone.html"));
453 Template noPermissionTemplate = templateFactory.createTemplate(createReader("/templates/noPermission.html"));
454 Template dismissNotificationTemplate = templateFactory.createTemplate(createReader("/templates/dismissNotification.html"));
455 Template logoutTemplate = templateFactory.createTemplate(createReader("/templates/logout.html"));
456 Template optionsTemplate = templateFactory.createTemplate(createReader("/templates/options.html"));
457 Template aboutTemplate = templateFactory.createTemplate(createReader("/templates/about.html"));
458 Template postTemplate = templateFactory.createTemplate(createReader("/templates/include/viewPost.html"));
459 Template replyTemplate = templateFactory.createTemplate(createReader("/templates/include/viewReply.html"));
461 PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
462 pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
463 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone"));
464 pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones"));
465 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfilePage(editProfileTemplate, this), "EditProfile"));
466 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this)));
467 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyPage(createReplyTemplate, this)));
468 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewSonePage(viewSoneTemplate, this)));
469 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this)));
470 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePage(likePostTemplate, this)));
471 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePage(unlikePostTemplate, this)));
472 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this)));
473 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this)));
474 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSonePage(lockSoneTemplate, this)));
475 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSonePage(unlockSoneTemplate, this)));
476 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(followSoneTemplate, this)));
477 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSonePage(unfollowSoneTemplate, this)));
478 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
479 pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
480 pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(logoutTemplate, this), "Logout"));
481 pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options"));
482 pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.VERSION), "About"));
483 pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
484 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(dismissNotificationTemplate, this)));
485 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css")));
486 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript")));
487 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png")));
488 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
489 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
490 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
491 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostAjaxPage(this)));
492 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
493 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
494 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetPostAjaxPage(this, postTemplate)));
495 pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkPostAsKnownPage(this)));
496 pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkReplyAsKnownPage(this)));
497 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
498 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
499 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSoneAjaxPage(this)));
500 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSoneAjaxPage(this)));
501 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this)));
502 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this)));
503 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikeAjaxPage(this)));
504 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikeAjaxPage(this)));
505 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetLikesAjaxPage(this)));
507 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
508 toadletContainer.getPageMaker().addNavigationCategory("/Sone/index.html", "Navigation.Menu.Name", "Navigation.Menu.Tooltip", sonePlugin);
509 for (PageToadlet toadlet : pageToadlets) {
510 String menuName = toadlet.getMenuName();
511 if (menuName != null) {
512 toadletContainer.register(toadlet, "Navigation.Menu.Name", toadlet.path(), true, "Navigation.Menu.Item." + menuName + ".Name", "Navigation.Menu.Item." + menuName + ".Tooltip", false, toadlet);
514 toadletContainer.register(toadlet, null, toadlet.path(), true, false);
520 * Unregisters all toadlets.
522 private void unregisterToadlets() {
523 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
524 for (PageToadlet pageToadlet : pageToadlets) {
525 toadletContainer.unregister(pageToadlet);
527 toadletContainer.getPageMaker().removeNavigationCategory("Navigation.Menu.Name");
531 * Creates a {@link Reader} from the {@link InputStream} for the resource
532 * with the given name.
534 * @param resourceName
535 * The name of the resource
536 * @return A {@link Reader} for the resource
538 private Reader createReader(String resourceName) {
540 return new InputStreamReader(getClass().getResourceAsStream(resourceName), "UTF-8");
541 } catch (UnsupportedEncodingException uee1) {
547 // CORELISTENER METHODS
554 public void rescuingSone(Sone sone) {
555 rescuingSonesNotification.add(sone);
556 notificationManager.addNotification(rescuingSonesNotification);
563 public void rescuedSone(Sone sone) {
564 rescuingSonesNotification.remove(sone);
565 sonesRescuedNotification.add(sone);
566 notificationManager.addNotification(sonesRescuedNotification);
573 public void newSoneFound(Sone sone) {
574 newSoneNotification.add(sone);
575 if (!hasFirstStartNotification()) {
576 notificationManager.addNotification(newSoneNotification);
584 public void newPostFound(Post post) {
585 newPostNotification.add(post);
586 if (!hasFirstStartNotification()) {
587 notificationManager.addNotification(newPostNotification);
595 public void newReplyFound(Reply reply) {
596 if (reply.getPost().getSone() == null) {
599 newReplyNotification.add(reply);
600 if (!hasFirstStartNotification()) {
601 notificationManager.addNotification(newReplyNotification);
609 public void markSoneKnown(Sone sone) {
610 newSoneNotification.remove(sone);
617 public void markPostKnown(Post post) {
618 newPostNotification.remove(post);
625 public void markReplyKnown(Reply reply) {
626 newReplyNotification.remove(reply);
633 public void postRemoved(Post post) {
641 public void replyRemoved(Reply reply) {
646 * Template provider implementation that uses
647 * {@link WebInterface#createReader(String)} to load templates for
650 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
652 private class ClassPathTemplateProvider implements TemplateProvider {
654 /** The template factory. */
655 @SuppressWarnings("hiding")
656 private final TemplateFactory templateFactory;
659 * Creates a new template provider that locates templates on the
662 * @param templateFactory
663 * The template factory to create the templates
665 public ClassPathTemplateProvider(TemplateFactory templateFactory) {
666 this.templateFactory = templateFactory;
673 @SuppressWarnings("synthetic-access")
674 public Template getTemplate(String templateName) {
675 Reader templateReader = createReader("/templates/" + templateName);
676 if (templateReader == null) {
679 Template template = templateFactory.createTemplate(templateReader);
682 } catch (TemplateException te1) {
683 logger.log(Level.WARNING, "Could not parse template “" + templateName + "” for inclusion!", te1);