- DefaultTemplateFactory templateFactory = new DefaultTemplateFactory();
- templateFactory.addAccessor(Object.class, new ReflectionAccessor());
- templateFactory.addAccessor(Collection.class, new CollectionAccessor());
- templateFactory.addAccessor(Sone.class, new SoneAccessor(core()));
- templateFactory.addAccessor(Post.class, new PostAccessor(core()));
- templateFactory.addAccessor(Reply.class, new ReplyAccessor(core()));
- templateFactory.addAccessor(Identity.class, new IdentityAccessor(core()));
- 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.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"));
- Template createSoneTemplate = templateFactory.createTemplate(createReader("/templates/createSone.html"));
- Template createPostTemplate = templateFactory.createTemplate(createReader("/templates/createPost.html"));
- Template createReplyTemplate = templateFactory.createTemplate(createReader("/templates/createReply.html"));
- Template editProfileTemplate = templateFactory.createTemplate(createReader("/templates/editProfile.html"));
- Template backupProfileTemplate = templateFactory.createTemplate(createReader("/templates/backup.xml"));
- Template viewSoneTemplate = templateFactory.createTemplate(createReader("/templates/viewSone.html"));
- Template viewPostTemplate = templateFactory.createTemplate(createReader("/templates/viewPost.html"));
- Template likePostTemplate = templateFactory.createTemplate(createReader("/templates/like.html"));
- Template unlikePostTemplate = templateFactory.createTemplate(createReader("/templates/unlike.html"));
- Template deletePostTemplate = templateFactory.createTemplate(createReader("/templates/deletePost.html"));
- Template deleteReplyTemplate = templateFactory.createTemplate(createReader("/templates/deleteReply.html"));
- Template followSoneTemplate = templateFactory.createTemplate(createReader("/templates/followSone.html"));
- Template unfollowSoneTemplate = templateFactory.createTemplate(createReader("/templates/unfollowSone.html"));
- Template deleteSoneTemplate = templateFactory.createTemplate(createReader("/templates/deleteSone.html"));
- Template noPermissionTemplate = templateFactory.createTemplate(createReader("/templates/noPermission.html"));
- Template wotPluginMissingTemplate = templateFactory.createTemplate(createReader("/templates/wotPluginMissing.html"));
- 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 helpTemplate = templateFactory.createTemplate(createReader("/templates/help.html"));
-
- PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
- pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new EditProfilePage(editProfileTemplate, this), "EditProfile"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new BackupProfilePage(backupProfileTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyPage(createReplyTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewSonePage(viewSoneTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePage(likePostTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePage(unlikePostTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(followSoneTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSonePage(unfollowSoneTemplate, this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(logoutTemplate, this), "Logout"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.VERSION), "About"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("help.html", helpTemplate, "Page.Help.Title", this), "Help"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("wotPluginMissing.html", wotPluginMissingTemplate, "Page.WotPluginMissing.Title", this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css")));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript")));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png")));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new GetSoneStatusPage(this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new LikeAjaxPage(this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikeAjaxPage(this)));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new GetLikesAjaxPage(this)));
-
- ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
- toadletContainer.getPageMaker().addNavigationCategory("/Sone/index.html", "Navigation.Menu.Name", "Navigation.Menu.Tooltip", sonePlugin);
- for (PageToadlet toadlet : pageToadlets) {
- String menuName = toadlet.getMenuName();
- if (menuName != null) {
- toadletContainer.register(toadlet, "Navigation.Menu.Name", toadlet.path(), true, "Navigation.Menu.Item." + menuName + ".Name", "Navigation.Menu.Item." + menuName + ".Tooltip", false, toadlet);
- } else {
- toadletContainer.register(toadlet, null, toadlet.path(), true, false);
+ Template emptyTemplate = parse(new StringReader(""));
+ Template loginTemplate = loaders.loadTemplate("/templates/login.html");
+ Template indexTemplate = loaders.loadTemplate("/templates/index.html");
+ Template newTemplate = loaders.loadTemplate("/templates/new.html");
+ Template knownSonesTemplate = loaders.loadTemplate("/templates/knownSones.html");
+ Template createSoneTemplate = loaders.loadTemplate("/templates/createSone.html");
+ Template createPostTemplate = loaders.loadTemplate("/templates/createPost.html");
+ Template createReplyTemplate = loaders.loadTemplate("/templates/createReply.html");
+ Template bookmarksTemplate = loaders.loadTemplate("/templates/bookmarks.html");
+ Template searchTemplate = loaders.loadTemplate("/templates/search.html");
+ Template editProfileTemplate = loaders.loadTemplate("/templates/editProfile.html");
+ Template editProfileFieldTemplate = loaders.loadTemplate("/templates/editProfileField.html");
+ Template deleteProfileFieldTemplate = loaders.loadTemplate("/templates/deleteProfileField.html");
+ Template viewSoneTemplate = loaders.loadTemplate("/templates/viewSone.html");
+ Template viewPostTemplate = loaders.loadTemplate("/templates/viewPost.html");
+ Template deletePostTemplate = loaders.loadTemplate("/templates/deletePost.html");
+ Template deleteReplyTemplate = loaders.loadTemplate("/templates/deleteReply.html");
+ Template deleteSoneTemplate = loaders.loadTemplate("/templates/deleteSone.html");
+ Template imageBrowserTemplate = loaders.loadTemplate("/templates/imageBrowser.html");
+ Template createAlbumTemplate = loaders.loadTemplate("/templates/createAlbum.html");
+ Template deleteAlbumTemplate = loaders.loadTemplate("/templates/deleteAlbum.html");
+ Template deleteImageTemplate = loaders.loadTemplate("/templates/deleteImage.html");
+ Template noPermissionTemplate = loaders.loadTemplate("/templates/noPermission.html");
+ Template emptyImageTitleTemplate = loaders.loadTemplate("/templates/emptyImageTitle.html");
+ Template emptyAlbumTitleTemplate = loaders.loadTemplate("/templates/emptyAlbumTitle.html");
+ Template optionsTemplate = loaders.loadTemplate("/templates/options.html");
+ Template rescueTemplate = loaders.loadTemplate("/templates/rescue.html");
+ Template aboutTemplate = loaders.loadTemplate("/templates/about.html");
+ Template invalidTemplate = loaders.loadTemplate("/templates/invalid.html");
+ Template postTemplate = loaders.loadTemplate("/templates/include/viewPost.html");
+ Template replyTemplate = loaders.loadTemplate("/templates/include/viewReply.html");
+ Template openSearchTemplate = loaders.loadTemplate("/templates/xml/OpenSearch.xml");
+
+ pageToadletRegistry.addPage(new RedirectPage<FreenetRequest>("", "index.html"));
+ pageToadletRegistry.addPage(new IndexPage(indexTemplate, this, loaders, postVisibilityFilter));
+ pageToadletRegistry.addPage(new NewPage(newTemplate, this, loaders));
+ pageToadletRegistry.addPage(new CreateSonePage(createSoneTemplate, this, loaders));
+ pageToadletRegistry.addPage(new KnownSonesPage(knownSonesTemplate, this, loaders));
+ pageToadletRegistry.addPage(new EditProfilePage(editProfileTemplate, this, loaders));
+ pageToadletRegistry.addPage(new EditProfileFieldPage(editProfileFieldTemplate, this, loaders));
+ pageToadletRegistry.addPage(new DeleteProfileFieldPage(deleteProfileFieldTemplate, this, loaders));
+ pageToadletRegistry.addPage(new CreatePostPage(createPostTemplate, this, loaders));
+ pageToadletRegistry.addPage(new CreateReplyPage(createReplyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new ViewSonePage(viewSoneTemplate, this, loaders));
+ pageToadletRegistry.addPage(new ViewPostPage(viewPostTemplate, this, loaders));
+ pageToadletRegistry.addPage(new LikePage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new UnlikePage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new DeletePostPage(deletePostTemplate, this, loaders));
+ pageToadletRegistry.addPage(new DeleteReplyPage(deleteReplyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new LockSonePage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new UnlockSonePage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new FollowSonePage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new UnfollowSonePage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new ImageBrowserPage(imageBrowserTemplate, this, loaders));
+ pageToadletRegistry.addPage(new CreateAlbumPage(createAlbumTemplate, this, loaders));
+ pageToadletRegistry.addPage(new EditAlbumPage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new DeleteAlbumPage(deleteAlbumTemplate, this, loaders));
+ pageToadletRegistry.addPage(new UploadImagePage(invalidTemplate, this, loaders));
+ pageToadletRegistry.addPage(new EditImagePage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new DeleteImagePage(deleteImageTemplate, this, loaders));
+ pageToadletRegistry.addPage(new TrustPage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new DistrustPage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new UntrustPage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new MarkAsKnownPage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new BookmarkPage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new UnbookmarkPage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new BookmarksPage(bookmarksTemplate, this, loaders));
+ pageToadletRegistry.addPage(new SearchPage(searchTemplate, this, loaders));
+ pageToadletRegistry.addPage(new DeleteSonePage(deleteSoneTemplate, this, loaders));
+ pageToadletRegistry.addPage(new LoginPage(loginTemplate, this, loaders));
+ pageToadletRegistry.addPage(new LogoutPage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new OptionsPage(optionsTemplate, this, loaders));
+ pageToadletRegistry.addPage(new RescuePage(rescueTemplate, this, loaders));
+ pageToadletRegistry.addPage(new AboutPage(aboutTemplate, this, loaders, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(sonePlugin.getYear()), new PluginHomepage(sonePlugin.getHomepage())));
+ pageToadletRegistry.addPage(new SoneTemplatePage("noPermission.html", this, loaders, noPermissionTemplate, "Page.NoPermission.Title"));
+ pageToadletRegistry.addPage(new SoneTemplatePage("emptyImageTitle.html", this, loaders, emptyImageTitleTemplate, "Page.EmptyImageTitle.Title"));
+ pageToadletRegistry.addPage(new SoneTemplatePage("emptyAlbumTitle.html", this, loaders, emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.Title"));
+ pageToadletRegistry.addPage(new DismissNotificationPage(emptyTemplate, this, loaders));
+ pageToadletRegistry.addPage(new SoneTemplatePage("invalid.html", this, loaders, invalidTemplate, "Page.Invalid.Title"));
+ pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("css/", "/static/css/", "text/css"));
+ pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("javascript/", "/static/javascript/", "text/javascript"));
+ pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("images/", "/static/images/", "image/png"));
+ pageToadletRegistry.addPage(new TemplatePage<FreenetRequest>("OpenSearch.xml", "application/opensearchdescription+xml", templateContextFactory, openSearchTemplate));
+ pageToadletRegistry.addPage(new GetImagePage(this));
+ pageToadletRegistry.addPage(new GetTranslationAjaxPage(this));
+ pageToadletRegistry.addPage(new GetStatusAjaxPage(this, elementLoader, timeTextConverter, l10nFilter, TimeZone.getDefault()));
+ pageToadletRegistry.addPage(new GetNotificationsAjaxPage(this));
+ pageToadletRegistry.addPage(new DismissNotificationAjaxPage(this));
+ pageToadletRegistry.addPage(new CreatePostAjaxPage(this));
+ pageToadletRegistry.addPage(new CreateReplyAjaxPage(this));
+ pageToadletRegistry.addPage(new GetReplyAjaxPage(this, replyTemplate));
+ pageToadletRegistry.addPage(new GetPostAjaxPage(this, postTemplate));
+ pageToadletRegistry.addPage(new GetLinkedElementAjaxPage(this, elementLoader, linkedElementRenderFilter));
+ pageToadletRegistry.addPage(new GetTimesAjaxPage(this, timeTextConverter, l10nFilter, TimeZone.getDefault()));
+ pageToadletRegistry.addPage(new MarkAsKnownAjaxPage(this));
+ pageToadletRegistry.addPage(new DeletePostAjaxPage(this));
+ pageToadletRegistry.addPage(new DeleteReplyAjaxPage(this));
+ pageToadletRegistry.addPage(new LockSoneAjaxPage(this));
+ pageToadletRegistry.addPage(new UnlockSoneAjaxPage(this));
+ pageToadletRegistry.addPage(new FollowSoneAjaxPage(this));
+ pageToadletRegistry.addPage(new UnfollowSoneAjaxPage(this));
+ pageToadletRegistry.addPage(new EditAlbumAjaxPage(this));
+ pageToadletRegistry.addPage(new EditImageAjaxPage(this, parserFilter, shortenFilter, renderFilter));
+ pageToadletRegistry.addPage(new TrustAjaxPage(this));
+ pageToadletRegistry.addPage(new DistrustAjaxPage(this));
+ pageToadletRegistry.addPage(new UntrustAjaxPage(this));
+ pageToadletRegistry.addPage(new LikeAjaxPage(this));
+ pageToadletRegistry.addPage(new UnlikeAjaxPage(this));
+ pageToadletRegistry.addPage(new GetLikesAjaxPage(this));
+ pageToadletRegistry.addPage(new BookmarkAjaxPage(this));
+ pageToadletRegistry.addPage(new UnbookmarkAjaxPage(this));
+ pageToadletRegistry.addPage(new EditProfileFieldAjaxPage(this));
+ pageToadletRegistry.addPage(new DeleteProfileFieldAjaxPage(this));
+ pageToadletRegistry.addPage(new MoveProfileFieldAjaxPage(this));
+
+ pageToadletRegistry.registerToadlets();
+ }
+
+ /**
+ * Returns all {@link Sone#isLocal() local Sone}s that are referenced by
+ * {@link SonePart}s in the given text (after parsing it using
+ * {@link SoneTextParser}).
+ *
+ * @param text
+ * The text to parse
+ * @return All mentioned local Sones
+ */
+ private Collection<Sone> getMentionedSones(String text) {
+ /* we need no context to find mentioned Sones. */
+ Set<Sone> mentionedSones = new HashSet<>();
+ for (Part part : soneTextParser.parse(text, null)) {
+ if (part instanceof SonePart) {
+ mentionedSones.add(((SonePart) part).getSone());