Add accessors for notifications and the notification manager.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index 4c436c2..01c1861 100644 (file)
@@ -40,6 +40,8 @@ import net.pterodactylus.sone.template.CollectionAccessor;
 import net.pterodactylus.sone.template.CssClassNameFilter;
 import net.pterodactylus.sone.template.GetPagePlugin;
 import net.pterodactylus.sone.template.IdentityAccessor;
+import net.pterodactylus.sone.template.NotificationAccessor;
+import net.pterodactylus.sone.template.NotificationManagerAccessor;
 import net.pterodactylus.sone.template.PostAccessor;
 import net.pterodactylus.sone.template.ReplyAccessor;
 import net.pterodactylus.sone.template.RequestChangeFilter;
@@ -50,6 +52,7 @@ import net.pterodactylus.sone.web.ajax.DeletePostAjaxPage;
 import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage;
 import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetLikesAjaxPage;
+import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetSoneStatusPage;
 import net.pterodactylus.sone.web.ajax.GetTranslationPage;
 import net.pterodactylus.sone.web.ajax.LikeAjaxPage;
@@ -59,6 +62,8 @@ import net.pterodactylus.sone.web.page.PageToadlet;
 import net.pterodactylus.sone.web.page.PageToadletFactory;
 import net.pterodactylus.sone.web.page.StaticPage;
 import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.notify.Notification;
+import net.pterodactylus.util.notify.NotificationManager;
 import net.pterodactylus.util.template.DateFilter;
 import net.pterodactylus.util.template.DefaultTemplateFactory;
 import net.pterodactylus.util.template.MatchFilter;
@@ -93,6 +98,9 @@ public class WebInterface {
        /** The form password. */
        private final String formPassword;
 
+       /** The template factory. */
+       private DefaultTemplateFactory templateFactory;
+
        /**
         * Creates a new web interface.
         *
@@ -102,6 +110,27 @@ public class WebInterface {
        public WebInterface(SonePlugin sonePlugin) {
                this.sonePlugin = sonePlugin;
                formPassword = sonePlugin.pluginRespirator().getToadletContainer().getFormPassword();
+
+               templateFactory = new DefaultTemplateFactory();
+               templateFactory.addAccessor(Object.class, new ReflectionAccessor());
+               templateFactory.addAccessor(Collection.class, new CollectionAccessor());
+               templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
+               templateFactory.addAccessor(Post.class, new PostAccessor(getCore()));
+               templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
+               templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
+               templateFactory.addAccessor(Notification.class, new NotificationAccessor());
+               templateFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
+               templateFactory.addFilter("date", new DateFilter());
+               templateFactory.addFilter("l10n", new L10nFilter(getL10n()));
+               templateFactory.addFilter("substring", new SubstringFilter());
+               templateFactory.addFilter("xml", new XmlFilter());
+               templateFactory.addFilter("change", new RequestChangeFilter());
+               templateFactory.addFilter("match", new MatchFilter());
+               templateFactory.addFilter("css", new CssClassNameFilter());
+               templateFactory.addPlugin("getpage", new GetPagePlugin());
+               templateFactory.addPlugin("paginate", new PaginationPlugin());
+               templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory));
+               templateFactory.addTemplateObject("formPassword", formPassword);
        }
 
        //
@@ -175,25 +204,6 @@ public class WebInterface {
         * Register all toadlets.
         */
        private void registerToadlets() {
-               DefaultTemplateFactory templateFactory = new DefaultTemplateFactory();
-               templateFactory.addAccessor(Object.class, new ReflectionAccessor());
-               templateFactory.addAccessor(Collection.class, new CollectionAccessor());
-               templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
-               templateFactory.addAccessor(Post.class, new PostAccessor(getCore()));
-               templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
-               templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
-               templateFactory.addFilter("date", new DateFilter());
-               templateFactory.addFilter("l10n", new L10nFilter(getL10n()));
-               templateFactory.addFilter("substring", new SubstringFilter());
-               templateFactory.addFilter("xml", new XmlFilter());
-               templateFactory.addFilter("change", new RequestChangeFilter());
-               templateFactory.addFilter("match", new MatchFilter());
-               templateFactory.addFilter("css", new CssClassNameFilter());
-               templateFactory.addPlugin("getpage", new GetPagePlugin());
-               templateFactory.addPlugin("paginate", new PaginationPlugin());
-               templateFactory.setTemplateProvider(new ClassPathTemplateProvider(templateFactory));
-               templateFactory.addTemplateObject("formPassword", formPassword);
-
                Template loginTemplate = templateFactory.createTemplate(createReader("/templates/login.html"));
                Template indexTemplate = templateFactory.createTemplate(createReader("/templates/index.html"));
                Template knownSonesTemplate = templateFactory.createTemplate(createReader("/templates/knownSones.html"));
@@ -215,6 +225,7 @@ public class WebInterface {
                Template logoutTemplate = templateFactory.createTemplate(createReader("/templates/logout.html"));
                Template optionsTemplate = templateFactory.createTemplate(createReader("/templates/options.html"));
                Template aboutTemplate = templateFactory.createTemplate(createReader("/templates/about.html"));
+               Template replyTemplate = templateFactory.createTemplate(createReader("/templates/include/viewReply.html"));
 
                PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
                pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
@@ -244,6 +255,7 @@ public class WebInterface {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetSoneStatusPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyAjaxPage(this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this)));
@@ -301,6 +313,7 @@ public class WebInterface {
        private class ClassPathTemplateProvider implements TemplateProvider {
 
                /** The template factory. */
+               @SuppressWarnings("hiding")
                private final TemplateFactory templateFactory;
 
                /**