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