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