Merge commit '0.3.1-RC3' into next
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
1 /*
2  * FreenetSone - WebInterface.java - Copyright © 2010 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.sone.web;
19
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;
28 import java.util.Set;
29 import java.util.logging.Level;
30 import java.util.logging.Logger;
31
32 import net.pterodactylus.sone.core.Core;
33 import net.pterodactylus.sone.core.CoreListener;
34 import net.pterodactylus.sone.data.Post;
35 import net.pterodactylus.sone.data.Reply;
36 import net.pterodactylus.sone.data.Sone;
37 import net.pterodactylus.sone.freenet.L10nFilter;
38 import net.pterodactylus.sone.freenet.wot.Identity;
39 import net.pterodactylus.sone.main.SonePlugin;
40 import net.pterodactylus.sone.notify.ListNotification;
41 import net.pterodactylus.sone.template.CollectionAccessor;
42 import net.pterodactylus.sone.template.CssClassNameFilter;
43 import net.pterodactylus.sone.template.GetPagePlugin;
44 import net.pterodactylus.sone.template.IdentityAccessor;
45 import net.pterodactylus.sone.template.NotificationManagerAccessor;
46 import net.pterodactylus.sone.template.PostAccessor;
47 import net.pterodactylus.sone.template.ReplyAccessor;
48 import net.pterodactylus.sone.template.RequestChangeFilter;
49 import net.pterodactylus.sone.template.SoneAccessor;
50 import net.pterodactylus.sone.template.SubstringFilter;
51 import net.pterodactylus.sone.web.ajax.CreatePostAjaxPage;
52 import net.pterodactylus.sone.web.ajax.CreateReplyAjaxPage;
53 import net.pterodactylus.sone.web.ajax.DeletePostAjaxPage;
54 import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage;
55 import net.pterodactylus.sone.web.ajax.DismissNotificationAjaxPage;
56 import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage;
57 import net.pterodactylus.sone.web.ajax.GetLikesAjaxPage;
58 import net.pterodactylus.sone.web.ajax.GetPostAjaxPage;
59 import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
60 import net.pterodactylus.sone.web.ajax.GetStatusAjaxPage;
61 import net.pterodactylus.sone.web.ajax.GetTranslationPage;
62 import net.pterodactylus.sone.web.ajax.LikeAjaxPage;
63 import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage;
64 import net.pterodactylus.sone.web.ajax.MarkPostAsKnownPage;
65 import net.pterodactylus.sone.web.ajax.MarkReplyAsKnownPage;
66 import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage;
67 import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage;
68 import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage;
69 import net.pterodactylus.sone.web.page.PageToadlet;
70 import net.pterodactylus.sone.web.page.PageToadletFactory;
71 import net.pterodactylus.sone.web.page.StaticPage;
72 import net.pterodactylus.util.logging.Logging;
73 import net.pterodactylus.util.notify.NotificationManager;
74 import net.pterodactylus.util.notify.TemplateNotification;
75 import net.pterodactylus.util.template.DateFilter;
76 import net.pterodactylus.util.template.DefaultTemplateFactory;
77 import net.pterodactylus.util.template.MatchFilter;
78 import net.pterodactylus.util.template.PaginationPlugin;
79 import net.pterodactylus.util.template.ReflectionAccessor;
80 import net.pterodactylus.util.template.Template;
81 import net.pterodactylus.util.template.TemplateException;
82 import net.pterodactylus.util.template.TemplateFactory;
83 import net.pterodactylus.util.template.TemplateProvider;
84 import net.pterodactylus.util.template.XmlFilter;
85 import net.pterodactylus.util.thread.Ticker;
86 import freenet.clients.http.SessionManager;
87 import freenet.clients.http.ToadletContainer;
88 import freenet.l10n.BaseL10n;
89
90 /**
91  * Bundles functionality that a web interface of a Freenet plugin needs, e.g.
92  * references to l10n helpers.
93  *
94  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
95  */
96 public class WebInterface implements CoreListener {
97
98         /** The logger. */
99         private static final Logger logger = Logging.getLogger(WebInterface.class);
100
101         /** The notification manager. */
102         private final NotificationManager notificationManager = new NotificationManager();
103
104         /** The Sone plugin. */
105         private final SonePlugin sonePlugin;
106
107         /** The registered toadlets. */
108         private final List<PageToadlet> pageToadlets = new ArrayList<PageToadlet>();
109
110         /** The form password. */
111         private final String formPassword;
112
113         /** The template factory. */
114         private DefaultTemplateFactory templateFactory;
115
116         /** The “new Sone” notification. */
117         private final ListNotification<Sone> newSoneNotification;
118
119         /** The “new post” notification. */
120         private final ListNotification<Post> newPostNotification;
121
122         /** The “new reply” notification. */
123         private final ListNotification<Reply> newReplyNotification;
124
125         /** The “rescuing Sone” notification. */
126         private final ListNotification<Sone> rescuingSonesNotification;
127
128         /** The “Sone rescued” notification. */
129         private final ListNotification<Sone> sonesRescuedNotification;
130
131         /**
132          * Creates a new web interface.
133          *
134          * @param sonePlugin
135          *            The Sone plugin
136          */
137         public WebInterface(SonePlugin sonePlugin) {
138                 this.sonePlugin = sonePlugin;
139                 formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
140
141                 templateFactory = new DefaultTemplateFactory();
142                 templateFactory.addAccessor(Object.class, new ReflectionAccessor());
143                 templateFactory.addAccessor(Collection.class, new CollectionAccessor());
144                 templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
145                 templateFactory.addAccessor(Post.class, new PostAccessor(getCore(), templateFactory));
146                 templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore(), templateFactory));
147                 templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
148                 templateFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
149                 templateFactory.addFilter("date", new DateFilter());
150                 templateFactory.addFilter("l10n", new L10nFilter(getL10n()));
151                 templateFactory.addFilter("substring", new SubstringFilter());
152                 templateFactory.addFilter("xml", new XmlFilter());
153                 templateFactory.addFilter("change", new RequestChangeFilter());
154                 templateFactory.addFilter("match", new MatchFilter());
155                 templateFactory.addFilter("css", new CssClassNameFilter());
156                 templateFactory.addPlugin("getpage", new GetPagePlugin());
157                 templateFactory.addPlugin("paginate", new PaginationPlugin());
158                 templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory));
159                 templateFactory.addTemplateObject("formPassword", formPassword);
160
161                 /* create notifications. */
162                 Template newSoneNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newSoneNotification.html"));
163                 newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate);
164
165                 Template newPostNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newPostNotification.html"));
166                 newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate);
167
168                 Template newReplyNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/newReplyNotification.html"));
169                 newReplyNotification = new ListNotification<Reply>("new-replies-notification", "replies", newReplyNotificationTemplate);
170
171                 Template rescuingSonesTemplate = templateFactory.createTemplate(createReader("/templates/notify/rescuingSonesNotification.html"));
172                 rescuingSonesNotification = new ListNotification<Sone>("sones-being-rescued-notification", "sones", rescuingSonesTemplate);
173
174                 Template sonesRescuedTemplate = templateFactory.createTemplate(createReader("/templates/notify/sonesRescuedNotification.html"));
175                 sonesRescuedNotification = new ListNotification<Sone>("sones-rescued-notification", "sones", sonesRescuedTemplate);
176         }
177
178         //
179         // ACCESSORS
180         //
181
182         /**
183          * Returns the Sone core used by the Sone plugin.
184          *
185          * @return The Sone core
186          */
187         public Core getCore() {
188                 return sonePlugin.core();
189         }
190
191         /**
192          * Returns the notification manager.
193          *
194          * @return The notification manager
195          */
196         public NotificationManager getNotifications() {
197                 return notificationManager;
198         }
199
200         /**
201          * Returns the l10n helper of the node.
202          *
203          * @return The node’s l10n helper
204          */
205         public BaseL10n getL10n() {
206                 return sonePlugin.l10n().getBase();
207         }
208
209         /**
210          * Returns the session manager of the node.
211          *
212          * @return The node’s session manager
213          */
214         public SessionManager getSessionManager() {
215                 return sonePlugin.pluginRespirator().getSessionManager("Sone");
216         }
217
218         /**
219          * Returns the node’s form password.
220          *
221          * @return The form password
222          */
223         public String getFormPassword() {
224                 return formPassword;
225         }
226
227         /**
228          * Returns the posts that have been announced as new in the
229          * {@link #newPostNotification}.
230          *
231          * @return The new posts
232          */
233         public Set<Post> getNewPosts() {
234                 return new HashSet<Post>(newPostNotification.getElements());
235         }
236
237         /**
238          * Returns the replies that have been announced as new in the
239          * {@link #newReplyNotification}.
240          *
241          * @return The new replies
242          */
243         public Set<Reply> getNewReplies() {
244                 return new HashSet<Reply>(newReplyNotification.getElements());
245         }
246
247         //
248         // ACTIONS
249         //
250
251         /**
252          * Starts the web interface and registers all toadlets.
253          */
254         public void start() {
255                 registerToadlets();
256
257                 /* notification templates. */
258                 Template startupNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/startupNotification.html"));
259
260                 final TemplateNotification startupNotification = new TemplateNotification("startup-notification", startupNotificationTemplate);
261                 notificationManager.addNotification(startupNotification);
262
263                 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (120 * 1000), new Runnable() {
264
265                         @Override
266                         public void run() {
267                                 startupNotification.dismiss();
268                         }
269                 }, "Sone Startup Notification Remover");
270
271                 Template wotMissingNotificationTemplate = templateFactory.createTemplate(createReader("/templates/notify/wotMissingNotification.html"));
272                 final TemplateNotification wotMissingNotification = new TemplateNotification("wot-missing-notification", wotMissingNotificationTemplate);
273                 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), new Runnable() {
274
275                         @Override
276                         @SuppressWarnings("synthetic-access")
277                         public void run() {
278                                 if (getCore().getIdentityManager().isConnected()) {
279                                         wotMissingNotification.dismiss();
280                                 } else {
281                                         notificationManager.addNotification(wotMissingNotification);
282                                 }
283                                 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), this, "Sone WoT Connector Checker");
284                         }
285
286                 }, "Sone WoT Connector Checker");
287         }
288
289         /**
290          * Stops the web interface and unregisters all toadlets.
291          */
292         public void stop() {
293                 unregisterToadlets();
294                 Ticker.getInstance().stop();
295         }
296
297         //
298         // PRIVATE METHODS
299         //
300
301         /**
302          * Register all toadlets.
303          */
304         private void registerToadlets() {
305                 Template loginTemplate = templateFactory.createTemplate(createReader("/templates/login.html"));
306                 Template indexTemplate = templateFactory.createTemplate(createReader("/templates/index.html"));
307                 Template knownSonesTemplate = templateFactory.createTemplate(createReader("/templates/knownSones.html"));
308                 Template createSoneTemplate = templateFactory.createTemplate(createReader("/templates/createSone.html"));
309                 Template createPostTemplate = templateFactory.createTemplate(createReader("/templates/createPost.html"));
310                 Template createReplyTemplate = templateFactory.createTemplate(createReader("/templates/createReply.html"));
311                 Template editProfileTemplate = templateFactory.createTemplate(createReader("/templates/editProfile.html"));
312                 Template viewSoneTemplate = templateFactory.createTemplate(createReader("/templates/viewSone.html"));
313                 Template viewPostTemplate = templateFactory.createTemplate(createReader("/templates/viewPost.html"));
314                 Template likePostTemplate = templateFactory.createTemplate(createReader("/templates/like.html"));
315                 Template unlikePostTemplate = templateFactory.createTemplate(createReader("/templates/unlike.html"));
316                 Template deletePostTemplate = templateFactory.createTemplate(createReader("/templates/deletePost.html"));
317                 Template deleteReplyTemplate = templateFactory.createTemplate(createReader("/templates/deleteReply.html"));
318                 Template lockSoneTemplate = templateFactory.createTemplate(createReader("/templates/lockSone.html"));
319                 Template unlockSoneTemplate = templateFactory.createTemplate(createReader("/templates/unlockSone.html"));
320                 Template followSoneTemplate = templateFactory.createTemplate(createReader("/templates/followSone.html"));
321                 Template unfollowSoneTemplate = templateFactory.createTemplate(createReader("/templates/unfollowSone.html"));
322                 Template deleteSoneTemplate = templateFactory.createTemplate(createReader("/templates/deleteSone.html"));
323                 Template noPermissionTemplate = templateFactory.createTemplate(createReader("/templates/noPermission.html"));
324                 Template dismissNotificationTemplate = templateFactory.createTemplate(createReader("/templates/dismissNotification.html"));
325                 Template logoutTemplate = templateFactory.createTemplate(createReader("/templates/logout.html"));
326                 Template optionsTemplate = templateFactory.createTemplate(createReader("/templates/options.html"));
327                 Template aboutTemplate = templateFactory.createTemplate(createReader("/templates/about.html"));
328                 Template postTemplate = templateFactory.createTemplate(createReader("/templates/include/viewPost.html"));
329                 Template replyTemplate = templateFactory.createTemplate(createReader("/templates/include/viewReply.html"));
330
331                 PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
332                 pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
333                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone"));
334                 pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones"));
335                 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfilePage(editProfileTemplate, this), "EditProfile"));
336                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this)));
337                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyPage(createReplyTemplate, this)));
338                 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewSonePage(viewSoneTemplate, this)));
339                 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this)));
340                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePage(likePostTemplate, this)));
341                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePage(unlikePostTemplate, this)));
342                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this)));
343                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this)));
344                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSonePage(lockSoneTemplate, this)));
345                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSonePage(unlockSoneTemplate, this)));
346                 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(followSoneTemplate, this)));
347                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSonePage(unfollowSoneTemplate, this)));
348                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
349                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
350                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(logoutTemplate, this), "Logout"));
351                 pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options"));
352                 pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.VERSION), "About"));
353                 pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
354                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(dismissNotificationTemplate, this)));
355                 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css")));
356                 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript")));
357                 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png")));
358                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
359                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
360                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
361                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostAjaxPage(this)));
362                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
363                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
364                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetPostAjaxPage(this, postTemplate)));
365                 pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkPostAsKnownPage(this)));
366                 pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkReplyAsKnownPage(this)));
367                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
368                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
369                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSoneAjaxPage(this)));
370                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSoneAjaxPage(this)));
371                 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this)));
372                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this)));
373                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikeAjaxPage(this)));
374                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikeAjaxPage(this)));
375                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetLikesAjaxPage(this)));
376
377                 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
378                 toadletContainer.getPageMaker().addNavigationCategory("/Sone/index.html", "Navigation.Menu.Name", "Navigation.Menu.Tooltip", sonePlugin);
379                 for (PageToadlet toadlet : pageToadlets) {
380                         String menuName = toadlet.getMenuName();
381                         if (menuName != null) {
382                                 toadletContainer.register(toadlet, "Navigation.Menu.Name", toadlet.path(), true, "Navigation.Menu.Item." + menuName + ".Name", "Navigation.Menu.Item." + menuName + ".Tooltip", false, toadlet);
383                         } else {
384                                 toadletContainer.register(toadlet, null, toadlet.path(), true, false);
385                         }
386                 }
387         }
388
389         /**
390          * Unregisters all toadlets.
391          */
392         private void unregisterToadlets() {
393                 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
394                 for (PageToadlet pageToadlet : pageToadlets) {
395                         toadletContainer.unregister(pageToadlet);
396                 }
397                 toadletContainer.getPageMaker().removeNavigationCategory("Navigation.Menu.Name");
398         }
399
400         /**
401          * Creates a {@link Reader} from the {@link InputStream} for the resource
402          * with the given name.
403          *
404          * @param resourceName
405          *            The name of the resource
406          * @return A {@link Reader} for the resource
407          */
408         private Reader createReader(String resourceName) {
409                 try {
410                         return new InputStreamReader(getClass().getResourceAsStream(resourceName), "UTF-8");
411                 } catch (UnsupportedEncodingException uee1) {
412                         return null;
413                 }
414         }
415
416         //
417         // CORELISTENER METHODS
418         //
419
420         /**
421          * {@inheritDoc}
422          */
423         @Override
424         public void rescuingSone(Sone sone) {
425                 rescuingSonesNotification.add(sone);
426                 notificationManager.addNotification(rescuingSonesNotification);
427         }
428
429         /**
430          * {@inheritDoc}
431          */
432         @Override
433         public void rescuedSone(Sone sone) {
434                 rescuingSonesNotification.remove(sone);
435                 sonesRescuedNotification.add(sone);
436                 notificationManager.addNotification(sonesRescuedNotification);
437         }
438
439         /**
440          * {@inheritDoc}
441          */
442         @Override
443         public void newSoneFound(Sone sone) {
444                 newSoneNotification.add(sone);
445                 notificationManager.addNotification(newSoneNotification);
446         }
447
448         /**
449          * {@inheritDoc}
450          */
451         @Override
452         public void newPostFound(Post post) {
453                 newPostNotification.add(post);
454                 notificationManager.addNotification(newPostNotification);
455         }
456
457         /**
458          * {@inheritDoc}
459          */
460         @Override
461         public void newReplyFound(Reply reply) {
462                 if (reply.getPost().getSone() == null) {
463                         return;
464                 }
465                 newReplyNotification.add(reply);
466                 notificationManager.addNotification(newReplyNotification);
467         }
468
469         /**
470          * {@inheritDoc}
471          */
472         @Override
473         public void markSoneKnown(Sone sone) {
474                 newSoneNotification.remove(sone);
475         }
476
477         /**
478          * {@inheritDoc}
479          */
480         @Override
481         public void markPostKnown(Post post) {
482                 newPostNotification.remove(post);
483         }
484
485         /**
486          * {@inheritDoc}
487          */
488         @Override
489         public void markReplyKnown(Reply reply) {
490                 newReplyNotification.remove(reply);
491         }
492
493         /**
494          * Template provider implementation that uses
495          * {@link WebInterface#createReader(String)} to load templates for
496          * inclusion.
497          *
498          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
499          */
500         private class ClassPathTemplateProvider implements TemplateProvider {
501
502                 /** The template factory. */
503                 @SuppressWarnings("hiding")
504                 private final TemplateFactory templateFactory;
505
506                 /**
507                  * Creates a new template provider that locates templates on the
508                  * classpath.
509                  *
510                  * @param templateFactory
511                  *            The template factory to create the templates
512                  */
513                 public ClassPathTemplateProvider(TemplateFactory templateFactory) {
514                         this.templateFactory = templateFactory;
515                 }
516
517                 /**
518                  * {@inheritDoc}
519                  */
520                 @Override
521                 @SuppressWarnings("synthetic-access")
522                 public Template getTemplate(String templateName) {
523                         Reader templateReader = createReader("/templates/" + templateName);
524                         if (templateReader == null) {
525                                 return null;
526                         }
527                         Template template = templateFactory.createTemplate(templateReader);
528                         try {
529                                 template.parse();
530                         } catch (TemplateException te1) {
531                                 logger.log(Level.WARNING, "Could not parse template “" + templateName + "” for inclusion!", te1);
532                         }
533                         return template;
534                 }
535
536         }
537
538 }