Convert “post reply marked as known” into EventBus-based event.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
1 /*
2  * Sone - WebInterface.java - Copyright © 2010–2012 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.IOException;
21 import java.io.InputStream;
22 import java.io.InputStreamReader;
23 import java.io.Reader;
24 import java.io.StringReader;
25 import java.io.UnsupportedEncodingException;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.HashMap;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Set;
34 import java.util.UUID;
35 import java.util.logging.Level;
36 import java.util.logging.Logger;
37
38 import net.pterodactylus.sone.core.Core;
39 import net.pterodactylus.sone.core.CoreListener;
40 import net.pterodactylus.sone.core.event.MarkPostKnownEvent;
41 import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent;
42 import net.pterodactylus.sone.core.event.MarkSoneKnownEvent;
43 import net.pterodactylus.sone.core.event.NewPostFoundEvent;
44 import net.pterodactylus.sone.core.event.NewPostReplyFoundEvent;
45 import net.pterodactylus.sone.core.event.NewSoneFoundEvent;
46 import net.pterodactylus.sone.data.Album;
47 import net.pterodactylus.sone.data.Image;
48 import net.pterodactylus.sone.data.Post;
49 import net.pterodactylus.sone.data.PostReply;
50 import net.pterodactylus.sone.data.Profile;
51 import net.pterodactylus.sone.data.Reply;
52 import net.pterodactylus.sone.data.Sone;
53 import net.pterodactylus.sone.freenet.L10nFilter;
54 import net.pterodactylus.sone.freenet.wot.Identity;
55 import net.pterodactylus.sone.freenet.wot.Trust;
56 import net.pterodactylus.sone.main.SonePlugin;
57 import net.pterodactylus.sone.notify.ListNotification;
58 import net.pterodactylus.sone.template.AlbumAccessor;
59 import net.pterodactylus.sone.template.CollectionAccessor;
60 import net.pterodactylus.sone.template.CssClassNameFilter;
61 import net.pterodactylus.sone.template.HttpRequestAccessor;
62 import net.pterodactylus.sone.template.IdentityAccessor;
63 import net.pterodactylus.sone.template.ImageAccessor;
64 import net.pterodactylus.sone.template.ImageLinkFilter;
65 import net.pterodactylus.sone.template.JavascriptFilter;
66 import net.pterodactylus.sone.template.ParserFilter;
67 import net.pterodactylus.sone.template.PostAccessor;
68 import net.pterodactylus.sone.template.ProfileAccessor;
69 import net.pterodactylus.sone.template.ReplyAccessor;
70 import net.pterodactylus.sone.template.ReplyGroupFilter;
71 import net.pterodactylus.sone.template.RequestChangeFilter;
72 import net.pterodactylus.sone.template.SoneAccessor;
73 import net.pterodactylus.sone.template.SubstringFilter;
74 import net.pterodactylus.sone.template.TrustAccessor;
75 import net.pterodactylus.sone.template.UniqueElementFilter;
76 import net.pterodactylus.sone.template.UnknownDateFilter;
77 import net.pterodactylus.sone.text.Part;
78 import net.pterodactylus.sone.text.SonePart;
79 import net.pterodactylus.sone.text.SoneTextParser;
80 import net.pterodactylus.sone.web.ajax.BookmarkAjaxPage;
81 import net.pterodactylus.sone.web.ajax.CreatePostAjaxPage;
82 import net.pterodactylus.sone.web.ajax.CreateReplyAjaxPage;
83 import net.pterodactylus.sone.web.ajax.DeletePostAjaxPage;
84 import net.pterodactylus.sone.web.ajax.DeleteProfileFieldAjaxPage;
85 import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage;
86 import net.pterodactylus.sone.web.ajax.DismissNotificationAjaxPage;
87 import net.pterodactylus.sone.web.ajax.DistrustAjaxPage;
88 import net.pterodactylus.sone.web.ajax.EditAlbumAjaxPage;
89 import net.pterodactylus.sone.web.ajax.EditImageAjaxPage;
90 import net.pterodactylus.sone.web.ajax.EditProfileFieldAjaxPage;
91 import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage;
92 import net.pterodactylus.sone.web.ajax.GetLikesAjaxPage;
93 import net.pterodactylus.sone.web.ajax.GetNotificationsAjaxPage;
94 import net.pterodactylus.sone.web.ajax.GetPostAjaxPage;
95 import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
96 import net.pterodactylus.sone.web.ajax.GetStatusAjaxPage;
97 import net.pterodactylus.sone.web.ajax.GetTimesAjaxPage;
98 import net.pterodactylus.sone.web.ajax.GetTranslationPage;
99 import net.pterodactylus.sone.web.ajax.LikeAjaxPage;
100 import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage;
101 import net.pterodactylus.sone.web.ajax.MarkAsKnownAjaxPage;
102 import net.pterodactylus.sone.web.ajax.MoveProfileFieldAjaxPage;
103 import net.pterodactylus.sone.web.ajax.TrustAjaxPage;
104 import net.pterodactylus.sone.web.ajax.UnbookmarkAjaxPage;
105 import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage;
106 import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage;
107 import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage;
108 import net.pterodactylus.sone.web.ajax.UntrustAjaxPage;
109 import net.pterodactylus.sone.web.page.FreenetRequest;
110 import net.pterodactylus.sone.web.page.PageToadlet;
111 import net.pterodactylus.sone.web.page.PageToadletFactory;
112 import net.pterodactylus.util.logging.Logging;
113 import net.pterodactylus.util.notify.Notification;
114 import net.pterodactylus.util.notify.NotificationManager;
115 import net.pterodactylus.util.notify.TemplateNotification;
116 import net.pterodactylus.util.template.ClassPathTemplateProvider;
117 import net.pterodactylus.util.template.CollectionSortFilter;
118 import net.pterodactylus.util.template.ContainsFilter;
119 import net.pterodactylus.util.template.DateFilter;
120 import net.pterodactylus.util.template.FormatFilter;
121 import net.pterodactylus.util.template.HtmlFilter;
122 import net.pterodactylus.util.template.MatchFilter;
123 import net.pterodactylus.util.template.ModFilter;
124 import net.pterodactylus.util.template.PaginationFilter;
125 import net.pterodactylus.util.template.ReflectionAccessor;
126 import net.pterodactylus.util.template.ReplaceFilter;
127 import net.pterodactylus.util.template.StoreFilter;
128 import net.pterodactylus.util.template.Template;
129 import net.pterodactylus.util.template.TemplateContextFactory;
130 import net.pterodactylus.util.template.TemplateParser;
131 import net.pterodactylus.util.template.TemplateProvider;
132 import net.pterodactylus.util.template.XmlFilter;
133 import net.pterodactylus.util.thread.Ticker;
134 import net.pterodactylus.util.version.Version;
135 import net.pterodactylus.util.web.RedirectPage;
136 import net.pterodactylus.util.web.StaticPage;
137 import net.pterodactylus.util.web.TemplatePage;
138
139 import com.google.common.collect.Collections2;
140 import com.google.common.collect.ImmutableSet;
141 import com.google.common.eventbus.Subscribe;
142 import com.google.inject.Inject;
143
144 import freenet.clients.http.SessionManager;
145 import freenet.clients.http.SessionManager.Session;
146 import freenet.clients.http.ToadletContainer;
147 import freenet.clients.http.ToadletContext;
148 import freenet.l10n.BaseL10n;
149 import freenet.support.api.HTTPRequest;
150
151 /**
152  * Bundles functionality that a web interface of a Freenet plugin needs, e.g.
153  * references to l10n helpers.
154  *
155  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
156  */
157 public class WebInterface implements CoreListener {
158
159         /** The logger. */
160         private static final Logger logger = Logging.getLogger(WebInterface.class);
161
162         /** The notification manager. */
163         private final NotificationManager notificationManager = new NotificationManager();
164
165         /** The Sone plugin. */
166         private final SonePlugin sonePlugin;
167
168         /** The registered toadlets. */
169         private final List<PageToadlet> pageToadlets = new ArrayList<PageToadlet>();
170
171         /** The form password. */
172         private final String formPassword;
173
174         /** The template context factory. */
175         private final TemplateContextFactory templateContextFactory;
176
177         /** The Sone text parser. */
178         private final SoneTextParser soneTextParser;
179
180         /** The parser filter. */
181         private final ParserFilter parserFilter;
182
183         /** The “new Sone” notification. */
184         private final ListNotification<Sone> newSoneNotification;
185
186         /** The “new post” notification. */
187         private final ListNotification<Post> newPostNotification;
188
189         /** The “new reply” notification. */
190         private final ListNotification<PostReply> newReplyNotification;
191
192         /** The invisible “local post” notification. */
193         private final ListNotification<Post> localPostNotification;
194
195         /** The invisible “local reply” notification. */
196         private final ListNotification<PostReply> localReplyNotification;
197
198         /** The “you have been mentioned” notification. */
199         private final ListNotification<Post> mentionNotification;
200
201         /** Notifications for sone inserts. */
202         private final Map<Sone, TemplateNotification> soneInsertNotifications = new HashMap<Sone, TemplateNotification>();
203
204         /** Sone locked notification ticker objects. */
205         private final Map<Sone, Object> lockedSonesTickerObjects = Collections.synchronizedMap(new HashMap<Sone, Object>());
206
207         /** The “Sone locked” notification. */
208         private final ListNotification<Sone> lockedSonesNotification;
209
210         /** The “new version” notification. */
211         private final TemplateNotification newVersionNotification;
212
213         /** The “inserting images” notification. */
214         private final ListNotification<Image> insertingImagesNotification;
215
216         /** The “inserted images” notification. */
217         private final ListNotification<Image> insertedImagesNotification;
218
219         /** The “image insert failed” notification. */
220         private final ListNotification<Image> imageInsertFailedNotification;
221
222         /**
223          * Creates a new web interface.
224          *
225          * @param sonePlugin
226          *            The Sone plugin
227          */
228         @Inject
229         public WebInterface(SonePlugin sonePlugin) {
230                 this.sonePlugin = sonePlugin;
231                 formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
232                 soneTextParser = new SoneTextParser(getCore(), getCore());
233
234                 templateContextFactory = new TemplateContextFactory();
235                 templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());
236                 templateContextFactory.addAccessor(Collection.class, new CollectionAccessor());
237                 templateContextFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
238                 templateContextFactory.addAccessor(Post.class, new PostAccessor(getCore()));
239                 templateContextFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
240                 templateContextFactory.addAccessor(Album.class, new AlbumAccessor());
241                 templateContextFactory.addAccessor(Image.class, new ImageAccessor());
242                 templateContextFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
243                 templateContextFactory.addAccessor(Trust.class, new TrustAccessor());
244                 templateContextFactory.addAccessor(HTTPRequest.class, new HttpRequestAccessor());
245                 templateContextFactory.addAccessor(Profile.class, new ProfileAccessor(getCore()));
246                 templateContextFactory.addFilter("date", new DateFilter());
247                 templateContextFactory.addFilter("html", new HtmlFilter());
248                 templateContextFactory.addFilter("replace", new ReplaceFilter());
249                 templateContextFactory.addFilter("store", new StoreFilter());
250                 templateContextFactory.addFilter("l10n", new L10nFilter(this));
251                 templateContextFactory.addFilter("substring", new SubstringFilter());
252                 templateContextFactory.addFilter("xml", new XmlFilter());
253                 templateContextFactory.addFilter("change", new RequestChangeFilter());
254                 templateContextFactory.addFilter("match", new MatchFilter());
255                 templateContextFactory.addFilter("css", new CssClassNameFilter());
256                 templateContextFactory.addFilter("js", new JavascriptFilter());
257                 templateContextFactory.addFilter("parse", parserFilter = new ParserFilter(getCore(), templateContextFactory, soneTextParser));
258                 templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate"));
259                 templateContextFactory.addFilter("format", new FormatFilter());
260                 templateContextFactory.addFilter("sort", new CollectionSortFilter());
261                 templateContextFactory.addFilter("image-link", new ImageLinkFilter(getCore(), templateContextFactory));
262                 templateContextFactory.addFilter("replyGroup", new ReplyGroupFilter());
263                 templateContextFactory.addFilter("in", new ContainsFilter());
264                 templateContextFactory.addFilter("unique", new UniqueElementFilter());
265                 templateContextFactory.addFilter("mod", new ModFilter());
266                 templateContextFactory.addFilter("paginate", new PaginationFilter());
267                 templateContextFactory.addProvider(TemplateProvider.TEMPLATE_CONTEXT_PROVIDER);
268                 templateContextFactory.addProvider(new ClassPathTemplateProvider(WebInterface.class, "/templates/"));
269                 templateContextFactory.addTemplateObject("webInterface", this);
270                 templateContextFactory.addTemplateObject("formPassword", formPassword);
271
272                 /* create notifications. */
273                 Template newSoneNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newSoneNotification.html"));
274                 newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate, false);
275
276                 Template newPostNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newPostNotification.html"));
277                 newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate, false);
278
279                 Template localPostNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newPostNotification.html"));
280                 localPostNotification = new ListNotification<Post>("local-post-notification", "posts", localPostNotificationTemplate, false);
281
282                 Template newReplyNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newReplyNotification.html"));
283                 newReplyNotification = new ListNotification<PostReply>("new-reply-notification", "replies", newReplyNotificationTemplate, false);
284
285                 Template localReplyNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/newReplyNotification.html"));
286                 localReplyNotification = new ListNotification<PostReply>("local-reply-notification", "replies", localReplyNotificationTemplate, false);
287
288                 Template mentionNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/mentionNotification.html"));
289                 mentionNotification = new ListNotification<Post>("mention-notification", "posts", mentionNotificationTemplate, false);
290
291                 Template lockedSonesTemplate = TemplateParser.parse(createReader("/templates/notify/lockedSonesNotification.html"));
292                 lockedSonesNotification = new ListNotification<Sone>("sones-locked-notification", "sones", lockedSonesTemplate);
293
294                 Template newVersionTemplate = TemplateParser.parse(createReader("/templates/notify/newVersionNotification.html"));
295                 newVersionNotification = new TemplateNotification("new-version-notification", newVersionTemplate);
296
297                 Template insertingImagesTemplate = TemplateParser.parse(createReader("/templates/notify/inserting-images-notification.html"));
298                 insertingImagesNotification = new ListNotification<Image>("inserting-images-notification", "images", insertingImagesTemplate);
299
300                 Template insertedImagesTemplate = TemplateParser.parse(createReader("/templates/notify/inserted-images-notification.html"));
301                 insertedImagesNotification = new ListNotification<Image>("inserted-images-notification", "images", insertedImagesTemplate);
302
303                 Template imageInsertFailedTemplate = TemplateParser.parse(createReader("/templates/notify/image-insert-failed-notification.html"));
304                 imageInsertFailedNotification = new ListNotification<Image>("image-insert-failed-notification", "images", imageInsertFailedTemplate);
305         }
306
307         //
308         // ACCESSORS
309         //
310
311         /**
312          * Returns the Sone core used by the Sone plugin.
313          *
314          * @return The Sone core
315          */
316         public Core getCore() {
317                 return sonePlugin.core();
318         }
319
320         /**
321          * Returns the template context factory of the web interface.
322          *
323          * @return The template context factory
324          */
325         public TemplateContextFactory getTemplateContextFactory() {
326                 return templateContextFactory;
327         }
328
329         /**
330          * Returns the current session, creating a new session if there is no
331          * current session.
332          *
333          * @param toadletContenxt
334          *            The toadlet context
335          * @return The current session, or {@code null} if there is no current
336          *         session
337          */
338         public Session getCurrentSession(ToadletContext toadletContenxt) {
339                 return getCurrentSession(toadletContenxt, true);
340         }
341
342         /**
343          * Returns the current session, creating a new session if there is no
344          * current session and {@code create} is {@code true}.
345          *
346          * @param toadletContenxt
347          *            The toadlet context
348          * @param create
349          *            {@code true} to create a new session if there is no current
350          *            session, {@code false} otherwise
351          * @return The current session, or {@code null} if there is no current
352          *         session
353          */
354         public Session getCurrentSession(ToadletContext toadletContenxt, boolean create) {
355                 Session session = getSessionManager().useSession(toadletContenxt);
356                 if (create && (session == null)) {
357                         session = getSessionManager().createSession(UUID.randomUUID().toString(), toadletContenxt);
358                 }
359                 return session;
360         }
361
362         /**
363          * Returns the currently logged in Sone.
364          *
365          * @param toadletContext
366          *            The toadlet context
367          * @return The currently logged in Sone, or {@code null} if no Sone is
368          *         currently logged in
369          */
370         public Sone getCurrentSone(ToadletContext toadletContext) {
371                 return getCurrentSone(toadletContext, true);
372         }
373
374         /**
375          * Returns the currently logged in Sone.
376          *
377          * @param toadletContext
378          *            The toadlet context
379          * @param create
380          *            {@code true} to create a new session if no session exists,
381          *            {@code false} to not create a new session
382          * @return The currently logged in Sone, or {@code null} if no Sone is
383          *         currently logged in
384          */
385         public Sone getCurrentSone(ToadletContext toadletContext, boolean create) {
386                 Collection<Sone> localSones = getCore().getLocalSones();
387                 if (localSones.size() == 1) {
388                         return localSones.iterator().next();
389                 }
390                 return getCurrentSone(getCurrentSession(toadletContext, create));
391         }
392
393         /**
394          * Returns the currently logged in Sone.
395          *
396          * @param session
397          *            The session
398          * @return The currently logged in Sone, or {@code null} if no Sone is
399          *         currently logged in
400          */
401         public Sone getCurrentSone(Session session) {
402                 if (session == null) {
403                         return null;
404                 }
405                 String soneId = (String) session.getAttribute("Sone.CurrentSone");
406                 if (soneId == null) {
407                         return null;
408                 }
409                 return getCore().getLocalSone(soneId, false);
410         }
411
412         /**
413          * Sets the currently logged in Sone.
414          *
415          * @param toadletContext
416          *            The toadlet context
417          * @param sone
418          *            The Sone to set as currently logged in
419          */
420         public void setCurrentSone(ToadletContext toadletContext, Sone sone) {
421                 Session session = getCurrentSession(toadletContext);
422                 if (sone == null) {
423                         session.removeAttribute("Sone.CurrentSone");
424                 } else {
425                         session.setAttribute("Sone.CurrentSone", sone.getId());
426                 }
427         }
428
429         /**
430          * Returns the notification manager.
431          *
432          * @return The notification manager
433          */
434         public NotificationManager getNotifications() {
435                 return notificationManager;
436         }
437
438         /**
439          * Returns the l10n helper of the node.
440          *
441          * @return The node’s l10n helper
442          */
443         public BaseL10n getL10n() {
444                 return sonePlugin.l10n().getBase();
445         }
446
447         /**
448          * Returns the session manager of the node.
449          *
450          * @return The node’s session manager
451          */
452         public SessionManager getSessionManager() {
453                 return sonePlugin.pluginRespirator().getSessionManager("Sone");
454         }
455
456         /**
457          * Returns the node’s form password.
458          *
459          * @return The form password
460          */
461         public String getFormPassword() {
462                 return formPassword;
463         }
464
465         /**
466          * Returns the posts that have been announced as new in the
467          * {@link #newPostNotification}.
468          *
469          * @return The new posts
470          */
471         public Set<Post> getNewPosts() {
472                 return ImmutableSet.<Post> builder().addAll(newPostNotification.getElements()).addAll(localPostNotification.getElements()).build();
473         }
474
475         /**
476          * Returns the replies that have been announced as new in the
477          * {@link #newReplyNotification}.
478          *
479          * @return The new replies
480          */
481         public Set<PostReply> getNewReplies() {
482                 return ImmutableSet.<PostReply> builder().addAll(newReplyNotification.getElements()).addAll(localReplyNotification.getElements()).build();
483         }
484
485         /**
486          * Sets whether the current start of the plugin is the first start. It is
487          * considered a first start if the configuration file does not exist.
488          *
489          * @param firstStart
490          *            {@code true} if no configuration file existed when Sone was
491          *            loaded, {@code false} otherwise
492          */
493         public void setFirstStart(boolean firstStart) {
494                 if (firstStart) {
495                         Template firstStartNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/firstStartNotification.html"));
496                         Notification firstStartNotification = new TemplateNotification("first-start-notification", firstStartNotificationTemplate);
497                         notificationManager.addNotification(firstStartNotification);
498                 }
499         }
500
501         /**
502          * Sets whether Sone was started with a fresh configuration file.
503          *
504          * @param newConfig
505          *            {@code true} if Sone was started with a fresh configuration,
506          *            {@code false} if the existing configuration could be read
507          */
508         public void setNewConfig(boolean newConfig) {
509                 if (newConfig && !hasFirstStartNotification()) {
510                         Template configNotReadNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/configNotReadNotification.html"));
511                         Notification configNotReadNotification = new TemplateNotification("config-not-read-notification", configNotReadNotificationTemplate);
512                         notificationManager.addNotification(configNotReadNotification);
513                 }
514         }
515
516         //
517         // PRIVATE ACCESSORS
518         //
519
520         /**
521          * Returns whether the first start notification is currently displayed.
522          *
523          * @return {@code true} if the first-start notification is currently
524          *         displayed, {@code false} otherwise
525          */
526         private boolean hasFirstStartNotification() {
527                 return notificationManager.getNotification("first-start-notification") != null;
528         }
529
530         //
531         // ACTIONS
532         //
533
534         /**
535          * Starts the web interface and registers all toadlets.
536          */
537         public void start() {
538                 registerToadlets();
539
540                 /* notification templates. */
541                 Template startupNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/startupNotification.html"));
542
543                 final TemplateNotification startupNotification = new TemplateNotification("startup-notification", startupNotificationTemplate);
544                 notificationManager.addNotification(startupNotification);
545
546                 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (120 * 1000), new Runnable() {
547
548                         @Override
549                         public void run() {
550                                 startupNotification.dismiss();
551                         }
552                 }, "Sone Startup Notification Remover");
553
554                 Template wotMissingNotificationTemplate = TemplateParser.parse(createReader("/templates/notify/wotMissingNotification.html"));
555                 final TemplateNotification wotMissingNotification = new TemplateNotification("wot-missing-notification", wotMissingNotificationTemplate);
556                 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), new Runnable() {
557
558                         @Override
559                         @SuppressWarnings("synthetic-access")
560                         public void run() {
561                                 if (getCore().getIdentityManager().isConnected()) {
562                                         wotMissingNotification.dismiss();
563                                 } else {
564                                         notificationManager.addNotification(wotMissingNotification);
565                                 }
566                                 Ticker.getInstance().registerEvent(System.currentTimeMillis() + (15 * 1000), this, "Sone WoT Connector Checker");
567                         }
568
569                 }, "Sone WoT Connector Checker");
570         }
571
572         /**
573          * Stops the web interface and unregisters all toadlets.
574          */
575         public void stop() {
576                 unregisterToadlets();
577                 Ticker.getInstance().stop();
578         }
579
580         //
581         // PRIVATE METHODS
582         //
583
584         /**
585          * Register all toadlets.
586          */
587         private void registerToadlets() {
588                 Template emptyTemplate = TemplateParser.parse(new StringReader(""));
589                 Template loginTemplate = TemplateParser.parse(createReader("/templates/login.html"));
590                 Template indexTemplate = TemplateParser.parse(createReader("/templates/index.html"));
591                 Template newTemplate = TemplateParser.parse(createReader("/templates/new.html"));
592                 Template knownSonesTemplate = TemplateParser.parse(createReader("/templates/knownSones.html"));
593                 Template createSoneTemplate = TemplateParser.parse(createReader("/templates/createSone.html"));
594                 Template createPostTemplate = TemplateParser.parse(createReader("/templates/createPost.html"));
595                 Template createReplyTemplate = TemplateParser.parse(createReader("/templates/createReply.html"));
596                 Template bookmarksTemplate = TemplateParser.parse(createReader("/templates/bookmarks.html"));
597                 Template searchTemplate = TemplateParser.parse(createReader("/templates/search.html"));
598                 Template editProfileTemplate = TemplateParser.parse(createReader("/templates/editProfile.html"));
599                 Template editProfileFieldTemplate = TemplateParser.parse(createReader("/templates/editProfileField.html"));
600                 Template deleteProfileFieldTemplate = TemplateParser.parse(createReader("/templates/deleteProfileField.html"));
601                 Template viewSoneTemplate = TemplateParser.parse(createReader("/templates/viewSone.html"));
602                 Template viewPostTemplate = TemplateParser.parse(createReader("/templates/viewPost.html"));
603                 Template deletePostTemplate = TemplateParser.parse(createReader("/templates/deletePost.html"));
604                 Template deleteReplyTemplate = TemplateParser.parse(createReader("/templates/deleteReply.html"));
605                 Template deleteSoneTemplate = TemplateParser.parse(createReader("/templates/deleteSone.html"));
606                 Template imageBrowserTemplate = TemplateParser.parse(createReader("/templates/imageBrowser.html"));
607                 Template createAlbumTemplate = TemplateParser.parse(createReader("/templates/createAlbum.html"));
608                 Template deleteAlbumTemplate = TemplateParser.parse(createReader("/templates/deleteAlbum.html"));
609                 Template deleteImageTemplate = TemplateParser.parse(createReader("/templates/deleteImage.html"));
610                 Template noPermissionTemplate = TemplateParser.parse(createReader("/templates/noPermission.html"));
611                 Template optionsTemplate = TemplateParser.parse(createReader("/templates/options.html"));
612                 Template rescueTemplate = TemplateParser.parse(createReader("/templates/rescue.html"));
613                 Template aboutTemplate = TemplateParser.parse(createReader("/templates/about.html"));
614                 Template invalidTemplate = TemplateParser.parse(createReader("/templates/invalid.html"));
615                 Template postTemplate = TemplateParser.parse(createReader("/templates/include/viewPost.html"));
616                 Template replyTemplate = TemplateParser.parse(createReader("/templates/include/viewReply.html"));
617                 Template openSearchTemplate = TemplateParser.parse(createReader("/templates/xml/OpenSearch.xml"));
618
619                 PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
620                 pageToadlets.add(pageToadletFactory.createPageToadlet(new RedirectPage<FreenetRequest>("", "index.html")));
621                 pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
622                 pageToadlets.add(pageToadletFactory.createPageToadlet(new NewPage(newTemplate, this), "New"));
623                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone"));
624                 pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones"));
625                 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfilePage(editProfileTemplate, this), "EditProfile"));
626                 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfileFieldPage(editProfileFieldTemplate, this)));
627                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteProfileFieldPage(deleteProfileFieldTemplate, this)));
628                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this)));
629                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyPage(createReplyTemplate, this)));
630                 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewSonePage(viewSoneTemplate, this)));
631                 pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this)));
632                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePage(emptyTemplate, this)));
633                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePage(emptyTemplate, this)));
634                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this)));
635                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this)));
636                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSonePage(emptyTemplate, this)));
637                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSonePage(emptyTemplate, this)));
638                 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(emptyTemplate, this)));
639                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSonePage(emptyTemplate, this)));
640                 pageToadlets.add(pageToadletFactory.createPageToadlet(new ImageBrowserPage(imageBrowserTemplate, this), "ImageBrowser"));
641                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateAlbumPage(createAlbumTemplate, this)));
642                 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditAlbumPage(emptyTemplate, this)));
643                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteAlbumPage(deleteAlbumTemplate, this)));
644                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UploadImagePage(invalidTemplate, this)));
645                 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImagePage(emptyTemplate, this)));
646                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteImagePage(deleteImageTemplate, this)));
647                 pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustPage(emptyTemplate, this)));
648                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustPage(emptyTemplate, this)));
649                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustPage(emptyTemplate, this)));
650                 pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkAsKnownPage(emptyTemplate, this)));
651                 pageToadlets.add(pageToadletFactory.createPageToadlet(new BookmarkPage(emptyTemplate, this)));
652                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnbookmarkPage(emptyTemplate, this)));
653                 pageToadlets.add(pageToadletFactory.createPageToadlet(new BookmarksPage(bookmarksTemplate, this), "Bookmarks"));
654                 pageToadlets.add(pageToadletFactory.createPageToadlet(new SearchPage(searchTemplate, this)));
655                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
656                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
657                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(emptyTemplate, this), "Logout"));
658                 pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options"));
659                 pageToadlets.add(pageToadletFactory.createPageToadlet(new RescuePage(rescueTemplate, this), "Rescue"));
660                 pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.VERSION), "About"));
661                 pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
662                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(emptyTemplate, this)));
663                 pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("invalid.html", invalidTemplate, "Page.Invalid.Title", this)));
664                 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage<FreenetRequest>("css/", "/static/css/", "text/css")));
665                 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage<FreenetRequest>("javascript/", "/static/javascript/", "text/javascript")));
666                 pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage<FreenetRequest>("images/", "/static/images/", "image/png")));
667                 pageToadlets.add(pageToadletFactory.createPageToadlet(new TemplatePage<FreenetRequest>("OpenSearch.xml", "application/opensearchdescription+xml", templateContextFactory, openSearchTemplate)));
668                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetImagePage(this)));
669                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
670                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
671                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetNotificationsAjaxPage(this)));
672                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
673                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostAjaxPage(this)));
674                 pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
675                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
676                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetPostAjaxPage(this, postTemplate)));
677                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTimesAjaxPage(this)));
678                 pageToadlets.add(pageToadletFactory.createPageToadlet(new MarkAsKnownAjaxPage(this)));
679                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
680                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
681                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSoneAjaxPage(this)));
682                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSoneAjaxPage(this)));
683                 pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this)));
684                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this)));
685                 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditAlbumAjaxPage(this)));
686                 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditImageAjaxPage(this, parserFilter)));
687                 pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustAjaxPage(this)));
688                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustAjaxPage(this)));
689                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustAjaxPage(this)));
690                 pageToadlets.add(pageToadletFactory.createPageToadlet(new LikeAjaxPage(this)));
691                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikeAjaxPage(this)));
692                 pageToadlets.add(pageToadletFactory.createPageToadlet(new GetLikesAjaxPage(this)));
693                 pageToadlets.add(pageToadletFactory.createPageToadlet(new BookmarkAjaxPage(this)));
694                 pageToadlets.add(pageToadletFactory.createPageToadlet(new UnbookmarkAjaxPage(this)));
695                 pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfileFieldAjaxPage(this)));
696                 pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteProfileFieldAjaxPage(this)));
697                 pageToadlets.add(pageToadletFactory.createPageToadlet(new MoveProfileFieldAjaxPage(this)));
698
699                 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
700                 toadletContainer.getPageMaker().addNavigationCategory("/Sone/index.html", "Navigation.Menu.Sone.Name", "Navigation.Menu.Sone.Tooltip", sonePlugin);
701                 for (PageToadlet toadlet : pageToadlets) {
702                         String menuName = toadlet.getMenuName();
703                         if (menuName != null) {
704                                 toadletContainer.register(toadlet, "Navigation.Menu.Sone.Name", toadlet.path(), true, "Navigation.Menu.Sone.Item." + menuName + ".Name", "Navigation.Menu.Sone.Item." + menuName + ".Tooltip", false, toadlet);
705                         } else {
706                                 toadletContainer.register(toadlet, null, toadlet.path(), true, false);
707                         }
708                 }
709         }
710
711         /**
712          * Unregisters all toadlets.
713          */
714         private void unregisterToadlets() {
715                 ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
716                 for (PageToadlet pageToadlet : pageToadlets) {
717                         toadletContainer.unregister(pageToadlet);
718                 }
719                 toadletContainer.getPageMaker().removeNavigationCategory("Navigation.Menu.Sone.Name");
720         }
721
722         /**
723          * Creates a {@link Reader} from the {@link InputStream} for the resource
724          * with the given name.
725          *
726          * @param resourceName
727          *            The name of the resource
728          * @return A {@link Reader} for the resource
729          */
730         private Reader createReader(String resourceName) {
731                 try {
732                         return new InputStreamReader(getClass().getResourceAsStream(resourceName), "UTF-8");
733                 } catch (UnsupportedEncodingException uee1) {
734                         return null;
735                 }
736         }
737
738         /**
739          * Returns all {@link Sone#isLocal() local Sone}s that are referenced by
740          * {@link SonePart}s in the given text (after parsing it using
741          * {@link SoneTextParser}).
742          *
743          * @param text
744          *            The text to parse
745          * @return All mentioned local Sones
746          */
747         private Collection<Sone> getMentionedSones(String text) {
748                 /* we need no context to find mentioned Sones. */
749                 Set<Sone> mentionedSones = new HashSet<Sone>();
750                 try {
751                         for (Part part : soneTextParser.parse(null, new StringReader(text))) {
752                                 if (part instanceof SonePart) {
753                                         mentionedSones.add(((SonePart) part).getSone());
754                                 }
755                         }
756                 } catch (IOException ioe1) {
757                         logger.log(Level.WARNING, String.format("Could not parse post text: %s", text), ioe1);
758                 }
759                 return Collections2.filter(mentionedSones, Sone.LOCAL_SONE_FILTER);
760         }
761
762         /**
763          * Returns the Sone insert notification for the given Sone. If no
764          * notification for the given Sone exists, a new notification is created and
765          * cached.
766          *
767          * @param sone
768          *            The Sone to get the insert notification for
769          * @return The Sone insert notification
770          */
771         private TemplateNotification getSoneInsertNotification(Sone sone) {
772                 synchronized (soneInsertNotifications) {
773                         TemplateNotification templateNotification = soneInsertNotifications.get(sone);
774                         if (templateNotification == null) {
775                                 templateNotification = new TemplateNotification(TemplateParser.parse(createReader("/templates/notify/soneInsertNotification.html")));
776                                 templateNotification.set("insertSone", sone);
777                                 soneInsertNotifications.put(sone, templateNotification);
778                         }
779                         return templateNotification;
780                 }
781         }
782
783         //
784         // EVENT HANDLERS
785         //
786
787         /**
788          * {@inheritDoc}
789          */
790         @Subscribe
791         public void newSoneFound(NewSoneFoundEvent newSoneFoundEvent) {
792                 newSoneNotification.add(newSoneFoundEvent.sone());
793                 if (!hasFirstStartNotification()) {
794                         notificationManager.addNotification(newSoneNotification);
795                 }
796         }
797
798         /**
799          * {@inheritDoc}
800          */
801         @Subscribe
802         public void newPostFound(NewPostFoundEvent newPostFoundEvent) {
803                 Post post = newPostFoundEvent.post();
804                 boolean isLocal = post.getSone().isLocal();
805                 if (isLocal) {
806                         localPostNotification.add(post);
807                 } else {
808                         newPostNotification.add(post);
809                 }
810                 if (!hasFirstStartNotification()) {
811                         notificationManager.addNotification(isLocal ? localPostNotification : newPostNotification);
812                         if (!getMentionedSones(post.getText()).isEmpty() && !isLocal) {
813                                 mentionNotification.add(post);
814                                 notificationManager.addNotification(mentionNotification);
815                         }
816                 } else {
817                         getCore().markPostKnown(post);
818                 }
819         }
820
821         /**
822          * {@inheritDoc}
823          */
824         @Subscribe
825         public void newReplyFound(NewPostReplyFoundEvent newPostReplyFoundEvent) {
826                 PostReply reply = newPostReplyFoundEvent.postReply();
827                 boolean isLocal = reply.getSone().isLocal();
828                 if (isLocal) {
829                         localReplyNotification.add(reply);
830                 } else {
831                         newReplyNotification.add(reply);
832                 }
833                 if (!hasFirstStartNotification()) {
834                         notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification);
835                         if (!getMentionedSones(reply.getText()).isEmpty() && !isLocal && (reply.getPost().getSone() != null) && (reply.getTime() <= System.currentTimeMillis())) {
836                                 mentionNotification.add(reply.getPost());
837                                 notificationManager.addNotification(mentionNotification);
838                         }
839                 } else {
840                         getCore().markReplyKnown(reply);
841                 }
842         }
843
844         /**
845          * {@inheritDoc}
846          */
847         @Subscribe
848         public void markSoneKnown(MarkSoneKnownEvent markSoneKnownEvent) {
849                 newSoneNotification.remove(markSoneKnownEvent.sone());
850         }
851
852         /**
853          * {@inheritDoc}
854          */
855         @Subscribe
856         public void markPostKnown(MarkPostKnownEvent markPostKnownEvent) {
857                 newPostNotification.remove(markPostKnownEvent.post());
858                 localPostNotification.remove(markPostKnownEvent.post());
859                 mentionNotification.remove(markPostKnownEvent.post());
860         }
861
862         /**
863          * {@inheritDoc}
864          */
865         @Subscribe
866         public void markReplyKnown(MarkPostReplyKnownEvent markPostReplyKnownEvent) {
867                 newReplyNotification.remove(markPostReplyKnownEvent.postReply());
868                 localReplyNotification.remove(markPostReplyKnownEvent.postReply());
869                 mentionNotification.remove(markPostReplyKnownEvent.postReply().getPost());
870         }
871
872         //
873         // CORELISTENER METHODS
874         //
875
876         /**
877          * {@inheritDoc}
878          */
879         @Override
880         public void soneRemoved(Sone sone) {
881                 newSoneNotification.remove(sone);
882         }
883
884         /**
885          * {@inheritDoc}
886          */
887         @Override
888         public void postRemoved(Post post) {
889                 newPostNotification.remove(post);
890                 localPostNotification.remove(post);
891                 mentionNotification.remove(post);
892         }
893
894         /**
895          * {@inheritDoc}
896          */
897         @Override
898         public void replyRemoved(PostReply reply) {
899                 newReplyNotification.remove(reply);
900                 localReplyNotification.remove(reply);
901                 if (!getMentionedSones(reply.getText()).isEmpty()) {
902                         boolean isMentioned = false;
903                         for (PostReply existingReply : getCore().getReplies(reply.getPost())) {
904                                 isMentioned |= !reply.isKnown() && !getMentionedSones(existingReply.getText()).isEmpty();
905                         }
906                         if (!isMentioned) {
907                                 mentionNotification.remove(reply.getPost());
908                         }
909                 }
910         }
911
912         /**
913          * {@inheritDoc}
914          */
915         @Override
916         public void soneLocked(final Sone sone) {
917                 Object tickerObject = Ticker.getInstance().registerEvent(System.currentTimeMillis() + (5 * 60) * 1000, new Runnable() {
918
919                         @Override
920                         @SuppressWarnings("synthetic-access")
921                         public void run() {
922                                 lockedSonesNotification.add(sone);
923                                 lockedSonesTickerObjects.remove(sone);
924                                 notificationManager.addNotification(lockedSonesNotification);
925                         }
926                 }, "Sone Locked Notification");
927                 lockedSonesTickerObjects.put(sone, tickerObject);
928         }
929
930         /**
931          * {@inheritDoc}
932          */
933         @Override
934         public void soneUnlocked(Sone sone) {
935                 lockedSonesNotification.remove(sone);
936                 Ticker.getInstance().deregisterEvent(lockedSonesTickerObjects.remove(sone));
937         }
938
939         /**
940          * {@inheritDoc}
941          */
942         @Override
943         public void soneInserting(Sone sone) {
944                 TemplateNotification soneInsertNotification = getSoneInsertNotification(sone);
945                 soneInsertNotification.set("soneStatus", "inserting");
946                 if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
947                         notificationManager.addNotification(soneInsertNotification);
948                 }
949         }
950
951         /**
952          * {@inheritDoc}
953          */
954         @Override
955         public void soneInserted(Sone sone, long insertDuration) {
956                 TemplateNotification soneInsertNotification = getSoneInsertNotification(sone);
957                 soneInsertNotification.set("soneStatus", "inserted");
958                 soneInsertNotification.set("insertDuration", insertDuration / 1000);
959                 if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
960                         notificationManager.addNotification(soneInsertNotification);
961                 }
962         }
963
964         /**
965          * {@inheritDoc}
966          */
967         @Override
968         public void soneInsertAborted(Sone sone, Throwable cause) {
969                 TemplateNotification soneInsertNotification = getSoneInsertNotification(sone);
970                 soneInsertNotification.set("soneStatus", "insert-aborted");
971                 soneInsertNotification.set("insert-error", cause);
972                 if (sone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) {
973                         notificationManager.addNotification(soneInsertNotification);
974                 }
975         }
976
977         /**
978          * {@inheritDoc}
979          */
980         @Override
981         public void updateFound(Version version, long releaseTime, long latestEdition) {
982                 newVersionNotification.getTemplateContext().set("latestVersion", version);
983                 newVersionNotification.getTemplateContext().set("latestEdition", latestEdition);
984                 newVersionNotification.getTemplateContext().set("releaseTime", releaseTime);
985                 notificationManager.addNotification(newVersionNotification);
986         }
987
988         /**
989          * {@inheritDoc}
990          */
991         @Override
992         public void imageInsertStarted(Image image) {
993                 insertingImagesNotification.add(image);
994                 notificationManager.addNotification(insertingImagesNotification);
995         }
996
997         /**
998          * {@inheritDoc}
999          */
1000         @Override
1001         public void imageInsertAborted(Image image) {
1002                 insertingImagesNotification.remove(image);
1003         }
1004
1005         /**
1006          * {@inheritDoc}
1007          */
1008         @Override
1009         public void imageInsertFinished(Image image) {
1010                 insertingImagesNotification.remove(image);
1011                 insertedImagesNotification.add(image);
1012                 notificationManager.addNotification(insertedImagesNotification);
1013         }
1014
1015         /**
1016          * {@inheritDoc}
1017          */
1018         @Override
1019         public void imageInsertFailed(Image image, Throwable cause) {
1020                 insertingImagesNotification.remove(image);
1021                 imageInsertFailedNotification.add(image);
1022                 notificationManager.addNotification(imageInsertFailedNotification);
1023         }
1024
1025 }