+ soneTextParser = new SoneTextParser(getCore(), getCore());
+
+ templateContextFactory = new TemplateContextFactory();
+ templateContextFactory.addAccessor(Object.class, new ReflectionAccessor());
+ templateContextFactory.addAccessor(Collection.class, new CollectionAccessor());
+ templateContextFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
+ templateContextFactory.addAccessor(Post.class, new PostAccessor(getCore()));
+ templateContextFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
+ templateContextFactory.addAccessor(Album.class, new AlbumAccessor());
+ templateContextFactory.addAccessor(Image.class, new ImageAccessor());
+ templateContextFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
+ templateContextFactory.addAccessor(Trust.class, new TrustAccessor());
+ templateContextFactory.addAccessor(HTTPRequest.class, new HttpRequestAccessor());
+ templateContextFactory.addAccessor(Profile.class, new ProfileAccessor(getCore()));
+ templateContextFactory.addFilter("date", new DateFilter());
+ templateContextFactory.addFilter("html", new HtmlFilter());
+ templateContextFactory.addFilter("replace", new ReplaceFilter());
+ templateContextFactory.addFilter("store", new StoreFilter());
+ templateContextFactory.addFilter("l10n", new L10nFilter(this));
+ templateContextFactory.addFilter("substring", new SubstringFilter());
+ templateContextFactory.addFilter("xml", new XmlFilter());
+ templateContextFactory.addFilter("change", new RequestChangeFilter());
+ templateContextFactory.addFilter("match", new MatchFilter());
+ templateContextFactory.addFilter("css", new CssClassNameFilter());
+ templateContextFactory.addFilter("js", new JavascriptFilter());
+ templateContextFactory.addFilter("parse", parserFilter = new ParserFilter(getCore(), templateContextFactory, soneTextParser));
+ templateContextFactory.addFilter("unknown", new UnknownDateFilter(getL10n(), "View.Sone.Text.UnknownDate"));
+ templateContextFactory.addFilter("format", new FormatFilter());
+ templateContextFactory.addFilter("sort", new CollectionSortFilter());
+ templateContextFactory.addFilter("image-link", new ImageLinkFilter(getCore(), templateContextFactory));
+ templateContextFactory.addFilter("replyGroup", new ReplyGroupFilter());
+ templateContextFactory.addFilter("in", new ContainsFilter());
+ templateContextFactory.addFilter("unique", new UniqueElementFilter());
+ templateContextFactory.addFilter("mod", new ModFilter());
+ templateContextFactory.addFilter("paginate", new PaginationFilter());
+ templateContextFactory.addProvider(TemplateProvider.TEMPLATE_CONTEXT_PROVIDER);
+ templateContextFactory.addProvider(new ClassPathTemplateProvider(WebInterface.class, "/templates/"));
+ templateContextFactory.addTemplateObject("webInterface", this);
+ templateContextFactory.addTemplateObject("formPassword", formPassword);
+
+ /* create notifications. */
+ Template newSoneNotificationTemplate = parseTemplate("/templates/notify/newSoneNotification.html");
+ newSoneNotification = new ListNotification<Sone>("new-sone-notification", "sones", newSoneNotificationTemplate, false);
+
+ Template newPostNotificationTemplate = parseTemplate("/templates/notify/newPostNotification.html");
+ newPostNotification = new ListNotification<Post>("new-post-notification", "posts", newPostNotificationTemplate, false);
+
+ Template localPostNotificationTemplate = parseTemplate("/templates/notify/newPostNotification.html");
+ localPostNotification = new ListNotification<Post>("local-post-notification", "posts", localPostNotificationTemplate, false);
+
+ Template newReplyNotificationTemplate = parseTemplate("/templates/notify/newReplyNotification.html");
+ newReplyNotification = new ListNotification<PostReply>("new-reply-notification", "replies", newReplyNotificationTemplate, false);
+
+ Template localReplyNotificationTemplate = parseTemplate("/templates/notify/newReplyNotification.html");
+ localReplyNotification = new ListNotification<PostReply>("local-reply-notification", "replies", localReplyNotificationTemplate, false);
+
+ Template mentionNotificationTemplate = parseTemplate("/templates/notify/mentionNotification.html");
+ mentionNotification = new ListNotification<Post>("mention-notification", "posts", mentionNotificationTemplate, false);
+
+ Template lockedSonesTemplate = parseTemplate("/templates/notify/lockedSonesNotification.html");
+ lockedSonesNotification = new ListNotification<Sone>("sones-locked-notification", "sones", lockedSonesTemplate);
+
+ Template newVersionTemplate = parseTemplate("/templates/notify/newVersionNotification.html");
+ newVersionNotification = new TemplateNotification("new-version-notification", newVersionTemplate);
+
+ Template insertingImagesTemplate = parseTemplate("/templates/notify/inserting-images-notification.html");
+ insertingImagesNotification = new ListNotification<Image>("inserting-images-notification", "images", insertingImagesTemplate);
+
+ Template insertedImagesTemplate = parseTemplate("/templates/notify/inserted-images-notification.html");
+ insertedImagesNotification = new ListNotification<Image>("inserted-images-notification", "images", insertedImagesTemplate);
+
+ Template imageInsertFailedTemplate = parseTemplate("/templates/notify/image-insert-failed-notification.html");
+ imageInsertFailedNotification = new ListNotification<Image>("image-insert-failed-notification", "images", imageInsertFailedTemplate);
+ }
+
+ private Template parseTemplate(String resourceName) {
+ InputStream templateInputStream = null;
+ Reader reader = null;
+ try {
+ templateInputStream = getClass().getResourceAsStream(resourceName);
+ reader = new InputStreamReader(templateInputStream, "UTF-8");
+ return parse(reader);
+ } catch (UnsupportedEncodingException uee1) {
+ throw new RuntimeException("UTF-8 not supported.");
+ } finally {
+ Closer.close(reader);
+ Closer.close(templateInputStream);
+ }