From e3da46d8947ab8a542a156069b3b24c13fd011df Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 17 May 2019 21:16:42 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=A8=20Use=20new=20template=20renderer?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/web/WebInterface.java | 94 +++++++++++----------- .../sone/web/page/FreenetTemplatePage.kt | 20 +++-- .../net/pterodactylus/sone/web/pages/AboutPage.kt | 4 +- .../pterodactylus/sone/web/pages/BookmarkPage.kt | 4 +- .../pterodactylus/sone/web/pages/BookmarksPage.kt | 4 +- .../sone/web/pages/CreateAlbumPage.kt | 4 +- .../pterodactylus/sone/web/pages/CreatePostPage.kt | 4 +- .../sone/web/pages/CreateReplyPage.kt | 4 +- .../pterodactylus/sone/web/pages/CreateSonePage.kt | 4 +- .../sone/web/pages/DeleteAlbumPage.kt | 4 +- .../sone/web/pages/DeleteImagePage.kt | 4 +- .../pterodactylus/sone/web/pages/DeletePostPage.kt | 4 +- .../sone/web/pages/DeleteProfileFieldPage.kt | 4 +- .../sone/web/pages/DeleteReplyPage.kt | 4 +- .../pterodactylus/sone/web/pages/DeleteSonePage.kt | 4 +- .../sone/web/pages/DismissNotificationPage.kt | 4 +- .../pterodactylus/sone/web/pages/DistrustPage.kt | 4 +- .../pterodactylus/sone/web/pages/EditAlbumPage.kt | 4 +- .../pterodactylus/sone/web/pages/EditImagePage.kt | 4 +- .../sone/web/pages/EditProfileFieldPage.kt | 4 +- .../sone/web/pages/EditProfilePage.kt | 4 +- .../pterodactylus/sone/web/pages/FollowSonePage.kt | 4 +- .../sone/web/pages/ImageBrowserPage.kt | 4 +- .../net/pterodactylus/sone/web/pages/IndexPage.kt | 4 +- .../pterodactylus/sone/web/pages/KnownSonesPage.kt | 4 +- .../net/pterodactylus/sone/web/pages/LikePage.kt | 4 +- .../pterodactylus/sone/web/pages/LockSonePage.kt | 4 +- .../pterodactylus/sone/web/pages/LoggedInPage.kt | 4 +- .../net/pterodactylus/sone/web/pages/LoginPage.kt | 4 +- .../net/pterodactylus/sone/web/pages/LogoutPage.kt | 4 +- .../sone/web/pages/MarkAsKnownPage.kt | 4 +- .../net/pterodactylus/sone/web/pages/NewPage.kt | 4 +- .../pterodactylus/sone/web/pages/OptionsPage.kt | 4 +- .../net/pterodactylus/sone/web/pages/RescuePage.kt | 4 +- .../net/pterodactylus/sone/web/pages/SearchPage.kt | 8 +- .../sone/web/pages/SoneTemplatePage.kt | 3 +- .../net/pterodactylus/sone/web/pages/TrustPage.kt | 4 +- .../pterodactylus/sone/web/pages/UnbookmarkPage.kt | 4 +- .../sone/web/pages/UnfollowSonePage.kt | 4 +- .../net/pterodactylus/sone/web/pages/UnlikePage.kt | 4 +- .../pterodactylus/sone/web/pages/UnlockSonePage.kt | 4 +- .../pterodactylus/sone/web/pages/UntrustPage.kt | 4 +- .../sone/web/pages/UploadImagePage.kt | 4 +- .../pterodactylus/sone/web/pages/ViewPostPage.kt | 4 +- .../pterodactylus/sone/web/pages/ViewSonePage.kt | 4 +- .../net/pterodactylus/sone/web/AllPagesTest.kt | 4 +- .../sone/web/page/FreenetTemplatePageTest.kt | 13 +-- .../pterodactylus/sone/web/pages/AboutPageTest.kt | 2 +- .../pterodactylus/sone/web/pages/IndexPageTest.kt | 2 +- .../pterodactylus/sone/web/pages/SearchPageTest.kt | 2 +- .../sone/web/pages/SoneTemplatePageTest.kt | 14 ++-- .../pterodactylus/sone/web/pages/WebPageTest.kt | 5 +- 52 files changed, 169 insertions(+), 162 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index d4f3f55..efc4291 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -112,6 +112,7 @@ import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage; import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage; import net.pterodactylus.sone.web.ajax.UntrustAjaxPage; import net.pterodactylus.sone.web.page.FreenetRequest; +import net.pterodactylus.sone.web.page.TemplateRenderer; import net.pterodactylus.sone.web.pages.AboutPage; import net.pterodactylus.sone.web.pages.BookmarkPage; import net.pterodactylus.sone.web.pages.BookmarksPage; @@ -197,6 +198,7 @@ public class WebInterface implements SessionProvider { /** The template context factory. */ private final TemplateContextFactory templateContextFactory; + private final TemplateRenderer templateRenderer; /** The Sone text parser. */ private final SoneTextParser soneTextParser; @@ -263,6 +265,7 @@ public class WebInterface implements SessionProvider { public WebInterface(SonePlugin sonePlugin, Loaders loaders, ListNotificationFilter listNotificationFilter, PostVisibilityFilter postVisibilityFilter, ReplyVisibilityFilter replyVisibilityFilter, ElementLoader elementLoader, TemplateContextFactory templateContextFactory, + TemplateRenderer templateRenderer, ParserFilter parserFilter, ShortenFilter shortenFilter, RenderFilter renderFilter, LinkedElementRenderFilter linkedElementRenderFilter, @@ -273,6 +276,7 @@ public class WebInterface implements SessionProvider { this.postVisibilityFilter = postVisibilityFilter; this.replyVisibilityFilter = replyVisibilityFilter; this.elementLoader = elementLoader; + this.templateRenderer = templateRenderer; this.parserFilter = parserFilter; this.shortenFilter = shortenFilter; this.renderFilter = renderFilter; @@ -635,51 +639,51 @@ public class WebInterface implements SessionProvider { Template openSearchTemplate = loaders.loadTemplate("/templates/xml/OpenSearch.xml"); pageToadletRegistry.addPage(new RedirectPage("", "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(new IndexPage(indexTemplate, this, loaders, templateRenderer, postVisibilityFilter)); + pageToadletRegistry.addPage(new NewPage(newTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new CreateSonePage(createSoneTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new KnownSonesPage(knownSonesTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new EditProfilePage(editProfileTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new EditProfileFieldPage(editProfileFieldTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new DeleteProfileFieldPage(deleteProfileFieldTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new CreatePostPage(createPostTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new CreateReplyPage(createReplyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new ViewSonePage(viewSoneTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new ViewPostPage(viewPostTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new LikePage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new UnlikePage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new DeletePostPage(deletePostTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new DeleteReplyPage(deleteReplyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new LockSonePage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new UnlockSonePage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new FollowSonePage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new UnfollowSonePage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new ImageBrowserPage(imageBrowserTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new CreateAlbumPage(createAlbumTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new EditAlbumPage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new DeleteAlbumPage(deleteAlbumTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new UploadImagePage(invalidTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new EditImagePage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new DeleteImagePage(deleteImageTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new TrustPage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new DistrustPage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new UntrustPage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new MarkAsKnownPage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new BookmarkPage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new UnbookmarkPage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new BookmarksPage(bookmarksTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new SearchPage(searchTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new DeleteSonePage(deleteSoneTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new LoginPage(loginTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new LogoutPage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new OptionsPage(optionsTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new RescuePage(rescueTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new AboutPage(aboutTemplate, this, loaders, templateRenderer, new PluginVersion(SonePlugin.getPluginVersion()), new PluginYear(sonePlugin.getYear()), new PluginHomepage(sonePlugin.getHomepage()))); + pageToadletRegistry.addPage(new SoneTemplatePage("noPermission.html", this, loaders, noPermissionTemplate, templateRenderer, "Page.NoPermission.Title")); + pageToadletRegistry.addPage(new SoneTemplatePage("emptyImageTitle.html", this, loaders, emptyImageTitleTemplate, templateRenderer, "Page.EmptyImageTitle.Title")); + pageToadletRegistry.addPage(new SoneTemplatePage("emptyAlbumTitle.html", this, loaders, emptyAlbumTitleTemplate, templateRenderer, "Page.EmptyAlbumTitle.Title")); + pageToadletRegistry.addPage(new DismissNotificationPage(emptyTemplate, this, loaders, templateRenderer)); + pageToadletRegistry.addPage(new SoneTemplatePage("invalid.html", this, loaders, invalidTemplate, templateRenderer, "Page.Invalid.Title")); pageToadletRegistry.addPage(loaders.loadStaticPage("css/", "/static/css/", "text/css")); pageToadletRegistry.addPage(loaders.loadStaticPage("javascript/", "/static/javascript/", "text/javascript")); pageToadletRegistry.addPage(loaders.loadStaticPage("images/", "/static/images/", "image/png")); diff --git a/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePage.kt index 792c0ba..c9ec173 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePage.kt @@ -21,7 +21,6 @@ import freenet.clients.http.* import net.pterodactylus.sone.main.* import net.pterodactylus.util.template.* import net.pterodactylus.util.web.* -import java.io.* import java.lang.String.* import java.net.* import java.util.logging.* @@ -33,7 +32,7 @@ import java.util.logging.Logger.* */ open class FreenetTemplatePage( private val path: String, - private val templateContextFactory: TemplateContextFactory, + private val templateRenderer: TemplateRenderer, loaders: Loaders, template: Template, private val invalidFormPasswordRedirectTarget: String @@ -84,20 +83,19 @@ open class FreenetTemplatePage( } shortcutIcon?.let { pageNode.addForwardLink("icon", it) } - val templateContext = templateContextFactory.createTemplateContext() - templateContext.mergeContext(template.initialContext) - try { + val output = try { val start = System.nanoTime() - processTemplate(request, templateContext) - val finish = System.nanoTime() - logger.log(Level.FINEST, format("Template was rendered in %.2fms.", (finish - start) / 1000000.0)) + templateRenderer.render(template) { templateContext -> + processTemplate(request, templateContext) + }.also { + val finish = System.nanoTime() + logger.log(Level.FINEST, format("Template was rendered in %.2fms.", (finish - start) / 1000000.0)) + } } catch (re1: RedirectException) { return RedirectResponse(re1.target ?: "") } - val stringWriter = StringWriter() - template.render(templateContext, stringWriter) - pageNode.content.addChild("%", stringWriter.toString()) + pageNode.content.addChild("%", output) return response.setStatusCode(200).setStatusText("OK").setContentType("text/html").write(pageNode.outer.generate()) } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt index 26a1769..3e2820e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/AboutPage.kt @@ -11,10 +11,10 @@ import javax.inject.Inject * A [SoneTemplatePage] that stores information about Sone in the [TemplateContext]. */ @MenuName("About") -class AboutPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, +class AboutPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer, private val pluginVersion: PluginVersion, private val pluginYear: PluginYear, - private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", webInterface, loaders, template = template, pageTitleKey = "Page.About.Title") { + private val pluginHomepage: PluginHomepage): SoneTemplatePage("about.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.About.Title") { override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { templateContext["version"] = pluginVersion.version diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt index c1415b0..c85c3ba 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt @@ -11,8 +11,8 @@ import javax.inject.Inject /** * Page that lets the user bookmark a post. */ -class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) - : SoneTemplatePage("bookmark.html", webInterface, loaders, template = template, pageTitleKey = "Page.Bookmark.Title") { +class BookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) + : SoneTemplatePage("bookmark.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Bookmark.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt index f178e61..c021d0a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarksPage.kt @@ -13,8 +13,8 @@ import javax.inject.Inject * Page that lets the user browse all his bookmarked posts. */ @MenuName("Bookmarks") -class BookmarksPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : - SoneTemplatePage("bookmarks.html", webInterface, loaders, template = template, pageTitleKey = "Page.Bookmarks.Title") { +class BookmarksPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + SoneTemplatePage("bookmarks.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Bookmarks.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { soneRequest.core.bookmarkedPosts.let { posts -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt index 452d5a4..3ffd622 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPage.kt @@ -14,8 +14,8 @@ import javax.inject.Inject /** * Page that lets the user create a new album. */ -class CreateAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, loaders) { +class CreateAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("createAlbum.html", template, "Page.CreateAlbum.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt index 37568f2..9f57ef5 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreatePostPage.kt @@ -14,8 +14,8 @@ import javax.inject.Inject /** * This page lets the user create a new [Post]. */ -class CreatePostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface, loaders) { +class CreatePostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("createPost.html", template, "Page.CreatePost.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt index 599a9ec..3e8bc72 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt @@ -13,8 +13,8 @@ import javax.inject.Inject /** * This page lets the user post a reply to a post. */ -class CreateReplyPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("createReply.html", template, "Page.CreateReply.Title", webInterface, loaders) { +class CreateReplyPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("createReply.html", template, "Page.CreateReply.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { val postId = soneRequest.httpRequest.getPartAsStringFailsafe("post", 36).apply { templateContext["postId"] = this } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt index cb4822b..0acc0bd 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateSonePage.kt @@ -16,8 +16,8 @@ import javax.inject.Inject * The “create Sone” page lets the user create a new Sone. */ @MenuName("CreateSone") -class CreateSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("createSone.html", webInterface, loaders, template = template, pageTitleKey = "Page.CreateSone.Title") { +class CreateSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("createSone.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.CreateSone.Title") { private val logger = Logger.getLogger(CreateSonePage::class.java.name) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt index 4c1b28b..b1969cc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt @@ -12,8 +12,8 @@ import javax.inject.Inject /** * Page that lets the user delete an {@link Album}. */ -class DeleteAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, loaders) { +class DeleteAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt index 11efd94..755cfaa 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt @@ -12,8 +12,8 @@ import javax.inject.Inject /** * Page that lets the user delete an {@link Image}. */ -class DeleteImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, loaders) { +class DeleteImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt index b03d768..f9daed5 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt @@ -12,8 +12,8 @@ import javax.inject.Inject /** * Lets the user delete a post they made. */ -class DeletePostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("deletePost.html", template, "Page.DeletePost.Title", webInterface, loaders) { +class DeletePostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("deletePost.html", template, "Page.DeletePost.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt index 5f57bea..49cdbdf 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt @@ -12,8 +12,8 @@ import javax.inject.Inject /** * Page that lets the user confirm the deletion of a profile field. */ -class DeleteProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface, loaders) { +class DeleteProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("deleteProfileField.html", template, "Page.DeleteProfileField.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt index af62489..85f1f21 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt @@ -12,8 +12,8 @@ import javax.inject.Inject /** * This page lets the user delete a reply. */ -class DeleteReplyPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, loaders) { +class DeleteReplyPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt index c301869..ceaa1e2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePage.kt @@ -15,8 +15,8 @@ import javax.inject.Inject * installation. */ @MenuName("DeleteSone") -class DeleteSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface, loaders) { +class DeleteSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("deleteSone.html", template, "Page.DeleteSone.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt index c7880bc..f240665 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPage.kt @@ -10,8 +10,8 @@ import javax.inject.Inject /** * Page that lets the user dismiss a notification. */ -class DismissNotificationPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("dismissNotification.html", webInterface, loaders, template = template, pageTitleKey = "Page.DismissNotification.Title") { +class DismissNotificationPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("dismissNotification.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.DismissNotification.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { val returnPage = soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt index 1fee1e8..051ac38 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt @@ -15,8 +15,8 @@ import javax.inject.Inject * * @see net.pterodactylus.sone.core.Core#distrustSone(Sone, Sone) */ -class DistrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("distrust.html", template, "Page.Distrust.Title", webInterface, loaders) { +class DistrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("distrust.html", template, "Page.Distrust.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt index 58bbb67..668f6eb 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt @@ -13,8 +13,8 @@ import javax.inject.Inject /** * Page that lets the user edit the name and description of an album. */ -class EditAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, loaders) { +class EditAlbumPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt index c6c6acb..d55a7be 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditImagePage.kt @@ -14,8 +14,8 @@ import javax.inject.Inject /** * Page that lets the user edit title and description of an {@link Image}. */ -class EditImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("editImage.html", template, "Page.EditImage.Title", webInterface, loaders) { +class EditImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("editImage.html", template, "Page.EditImage.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt index 580ee72..0ea1fb7 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt @@ -12,8 +12,8 @@ import javax.inject.Inject /** * Page that lets the user edit the name of a profile field. */ -class EditProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : - LoggedInPage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface, loaders) { +class EditProfileFieldPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + LoggedInPage("editProfileField.html", template, "Page.EditProfileField.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { currentSone.profile.let { profile -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt index f25b5b3..b7524d0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfilePage.kt @@ -15,8 +15,8 @@ import javax.inject.Inject * This page lets the user edit her profile. */ @MenuName("EditProfile") -class EditProfilePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : - LoggedInPage("editProfile.html", template, "Page.EditProfile.Title", webInterface, loaders) { +class EditProfilePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + LoggedInPage("editProfile.html", template, "Page.EditProfile.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { currentSone.profile.let { profile -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt index f4aa2e0..4747715 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/FollowSonePage.kt @@ -12,8 +12,8 @@ import javax.inject.Inject /** * This page lets the user follow another Sone. */ -class FollowSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("followSone.html", template, "Page.FollowSone.Title", webInterface, loaders) { +class FollowSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("followSone.html", template, "Page.FollowSone.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt index e2b2ec2..5a5959e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt @@ -16,8 +16,8 @@ import javax.inject.Inject * The image browser page is the entry page for the image management. */ @MenuName("ImageBrowser") -class ImageBrowserPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, loaders) { +class ImageBrowserPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if ("album" in soneRequest.parameters) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt index aefef39..a6a5683 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/IndexPage.kt @@ -16,8 +16,8 @@ import javax.inject.Inject * of all friends of the current user. */ @MenuName("Index") -class IndexPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, private val postVisibilityFilter: PostVisibilityFilter) : - LoggedInPage("index.html", template, "Page.Index.Title", webInterface, loaders) { +class IndexPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer, private val postVisibilityFilter: PostVisibilityFilter) : + LoggedInPage("index.html", template, "Page.Index.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { (currentSone.posts + diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt index 65f4853..0e890cc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt @@ -14,8 +14,8 @@ import javax.inject.Inject * This page shows all known Sones. */ @MenuName("KnownSones") -class KnownSonesPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("knownSones.html", webInterface, loaders, template = template, pageTitleKey = "Page.KnownSones.Title") { +class KnownSonesPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("knownSones.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.KnownSones.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { getCurrentSone(soneRequest.toadletContext).let { currentSone -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt index 3b0d0c5..4db5099 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LikePage.kt @@ -13,8 +13,8 @@ import javax.inject.Inject /** * Page that lets the user like [net.pterodactylus.sone.data.Post]s and [net.pterodactylus.sone.data.Reply]s. */ -class LikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : - LoggedInPage("like.html", template, "Page.Like.Title", webInterface, loaders) { +class LikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + LoggedInPage("like.html", template, "Page.Like.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt index 2d14ff3..1c7faa9 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LockSonePage.kt @@ -11,8 +11,8 @@ import javax.inject.Inject /** * This page lets the user lock a [net.pterodactylus.sone.data.Sone] to prevent it from being inserted. */ -class LockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("lockSone.html", webInterface, loaders, template = template, pageTitleKey = "Page.LockSone.Title") { +class LockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("lockSone.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.LockSone.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { soneRequest.parameters["returnPage", 256]!!.let { returnPage -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoggedInPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoggedInPage.kt index 72b5822..3e3ad4a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoggedInPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoggedInPage.kt @@ -10,8 +10,8 @@ import net.pterodactylus.util.template.TemplateContext /** * Base class for [SoneTemplatePage] implementations that require a logged in user. */ -abstract class LoggedInPage(path: String, template: Template, pageTitleKey: String, webInterface: WebInterface, loaders: Loaders) : - SoneTemplatePage(path, webInterface, loaders, template = template, pageTitleKey = pageTitleKey, requiresLogin = true) { +abstract class LoggedInPage(path: String, template: Template, pageTitleKey: String, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + SoneTemplatePage(path, webInterface, loaders, template, templateRenderer, pageTitleKey = pageTitleKey, requiresLogin = true) { final override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { handleRequest(soneRequest, getCurrentSone(soneRequest.toadletContext, false)!!, templateContext) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt index 70b96fc..8f65b33 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LoginPage.kt @@ -15,8 +15,8 @@ import javax.inject.Inject * The login page lets the user log in. */ @MenuName("Login") -class LoginPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("login.html", webInterface, loaders, template = template, pageTitleKey = "Page.Login.Title") { +class LoginPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("login.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Login.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt index bfab7c8..38ce74f 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/LogoutPage.kt @@ -13,8 +13,8 @@ import javax.inject.Inject * Logs a user out. */ @MenuName("Logout") -class LogoutPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("logout.html", template, "Page.Logout.Title", webInterface, loaders) { +class LogoutPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("logout.html", template, "Page.Logout.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { setCurrentSone(soneRequest.toadletContext, null) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt index 22f21d8..17fe0cf 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt @@ -12,8 +12,8 @@ import javax.inject.* * Page that lets the user mark a number of [net.pterodactylus.sone.data.Sone]s, [Post]s, or * [Replie][net.pterodactylus.sone.data.Reply]s as known. */ -class MarkAsKnownPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("markAsKnown.html", webInterface, loaders, template = template, pageTitleKey = "Page.MarkAsKnown.Title") { +class MarkAsKnownPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("markAsKnown.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.MarkAsKnown.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { val ids = soneRequest.parameters["id", 65536]!!.split(" ") diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/NewPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/NewPage.kt index d464db7..874c157 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/NewPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/NewPage.kt @@ -15,8 +15,8 @@ import javax.inject.Inject * [PostVisibilityFilter.isPostVisible(Sone, Post)] and sorted by time. */ @MenuName("New") -class NewPage @Inject constructor( template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("new.html", webInterface, loaders, template = template, pageTitleKey = "Page.New.Title") { +class NewPage @Inject constructor( template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("new.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.New.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) = getCurrentSone(soneRequest.toadletContext).let { currentSone -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt index f8049a3..708b918 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/OptionsPage.kt @@ -17,8 +17,8 @@ import javax.inject.Inject * This page lets the user edit the options of the Sone plugin. */ @MenuName("Options") -class OptionsPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("options.html", webInterface, loaders, template = template, pageTitleKey = "Page.Options.Title") { +class OptionsPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("options.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Options.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt index ce25b7d..6546bdc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/RescuePage.kt @@ -14,8 +14,8 @@ import javax.inject.Inject * Page that lets the user control the rescue mode for a Sone. */ @MenuName("Rescue") -class RescuePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("rescue.html", template, "Page.Rescue.Title", webInterface, loaders) { +class RescuePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("rescue.html", template, "Page.Rescue.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { val soneRescuer = soneRequest.core.getSoneRescuer(currentSone) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt index d980072..b44a94e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt @@ -29,11 +29,11 @@ import javax.inject.Inject * This page lets the user search for posts and replies that contain certain * words. */ -class SearchPage(template: Template, webInterface: WebInterface, loaders: Loaders, ticker: Ticker = Ticker.systemTicker()) : - SoneTemplatePage("search.html", webInterface, loaders, template = template, pageTitleKey = "Page.Search.Title") { +class SearchPage(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer, ticker: Ticker = Ticker.systemTicker()) : + SoneTemplatePage("search.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Search.Title") { - @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : - this(template, webInterface, loaders, Ticker.systemTicker()) + @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + this(template, webInterface, loaders, templateRenderer, Ticker.systemTicker()) private val cache: Cache, Pagination> = CacheBuilder.newBuilder().ticker(ticker).expireAfterAccess(5, MINUTES).build() diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt index 1d1ccf1..3c3e98a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt @@ -21,10 +21,11 @@ open class SoneTemplatePage @JvmOverloads constructor( private val webInterface: WebInterface, loaders: Loaders, template: Template, + templateRenderer: TemplateRenderer, private val pageTitleKey: String? = null, private val requiresLogin: Boolean = false, private val pageTitle: (FreenetRequest) -> String = { pageTitleKey?.let(webInterface.l10n::getString) ?: "" } -) : FreenetTemplatePage(path, webInterface.templateContextFactory, loaders, template, "noPermission.html") { +) : FreenetTemplatePage(path, templateRenderer, loaders, template, "noPermission.html") { private val core = webInterface.core private val sessionProvider: SessionProvider = webInterface diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt index 93ccad0..5d6abf3 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt @@ -14,8 +14,8 @@ import javax.inject.Inject * Page that lets the user trust another Sone. This will assign a configurable * amount of trust to an identity. */ -class TrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : - LoggedInPage("trust.html", template, "Page.Trust.Title", webInterface, loaders) { +class TrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + LoggedInPage("trust.html", template, "Page.Trust.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt index 804390e..aed315f 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPage.kt @@ -11,8 +11,8 @@ import javax.inject.* /** * Page that lets the user unbookmark a post. */ -class UnbookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("unbookmark.html", webInterface, loaders, template = template, pageTitleKey = "Page.Unbookmark.Title") { +class UnbookmarkPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("unbookmark.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.Unbookmark.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { when { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt index 39b9749..20cb2b2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePage.kt @@ -13,8 +13,8 @@ import javax.inject.Inject /** * This page lets the user unfollow another Sone. */ -class UnfollowSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : - LoggedInPage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface, loaders) { +class UnfollowSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + LoggedInPage("unfollowSone.html", template, "Page.UnfollowSone.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt index cfb072e..7737638 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlikePage.kt @@ -13,8 +13,8 @@ import javax.inject.Inject /** * Page that lets the user unlike a [net.pterodactylus.sone.data.Post] or [net.pterodactylus.sone.data.Reply]. */ -class UnlikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("unlike.html", template, "Page.Unlike.Title", webInterface, loaders) { +class UnlikePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("unlike.html", template, "Page.Unlike.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt index b39c9da..0c44b3b 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePage.kt @@ -12,8 +12,8 @@ import javax.inject.Inject /** * This page lets the user unlock a [net.pterodactylus.sone.data.Sone] to allow its insertion. */ -class UnlockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("unlockSone.html", webInterface, loaders, template = template, pageTitleKey = "Page.UnlockSone.Title") { +class UnlockSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("unlockSone.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.UnlockSone.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt index b9ed794..ffc066d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt @@ -14,8 +14,8 @@ import javax.inject.Inject * Page that lets the user untrust another Sone. This will remove all trust * assignments for an identity. */ -class UntrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders) : - LoggedInPage("untrust.html", template, "Page.Untrust.Title", webInterface, loaders) { +class UntrustPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : + LoggedInPage("untrust.html", template, "Page.Untrust.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt index fcc1a0a..0a31e4f 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/UploadImagePage.kt @@ -22,8 +22,8 @@ import javax.inject.Inject /** * Page implementation that lets the user upload an image. */ -class UploadImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - LoggedInPage("uploadImage.html", template, "Page.UploadImage.Title", webInterface, loaders) { +class UploadImagePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + LoggedInPage("uploadImage.html", template, "Page.UploadImage.Title", webInterface, loaders, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { if (soneRequest.isPOST) { diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt index f3a5dd1..1067698 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt @@ -12,8 +12,8 @@ import javax.inject.* /** * This page lets the user view a post and all its replies. */ -class ViewPostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("viewPost.html", webInterface, loaders, template = template, pageTitleKey = "Page.ViewPost.Title") { +class ViewPostPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("viewPost.html", webInterface, loaders, template, templateRenderer, pageTitleKey = "Page.ViewPost.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { templateContext["post"] = soneRequest.parameters["post"]?.let(soneRequest.core::getPost) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt index 6f9f743..38868e2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewSonePage.kt @@ -17,8 +17,8 @@ import javax.inject.Inject /** * Lets the user browser another Sone. */ -class ViewSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders): - SoneTemplatePage("viewSone.html", webInterface, loaders, template = template) { +class ViewSonePage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer): + SoneTemplatePage("viewSone.html", webInterface, loaders, template, templateRenderer) { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { templateContext["soneId"] = soneRequest.parameters["sone"] diff --git a/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt b/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt index 30286a3..cf6ab15 100644 --- a/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt +++ b/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt @@ -7,6 +7,7 @@ import net.pterodactylus.sone.main.PluginHomepage import net.pterodactylus.sone.main.PluginVersion import net.pterodactylus.sone.main.PluginYear import net.pterodactylus.sone.test.* +import net.pterodactylus.sone.web.page.* import net.pterodactylus.sone.web.pages.* import net.pterodactylus.util.template.Template import org.hamcrest.Matcher @@ -246,6 +247,7 @@ val baseInjector by lazy { Core::class.isProvidedByMock(), FreenetInterface::class.isProvidedByMock(), Template::class.isProvidedByMock(), - WebInterface::class.isProvidedByDeepMock() + WebInterface::class.isProvidedByDeepMock(), + TemplateRenderer::class.isProvidedByMock() )!! } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePageTest.kt index def7410..b48ba1f 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetTemplatePageTest.kt @@ -13,9 +13,10 @@ import org.mockito.Mockito.* class FreenetTemplatePageTest { private val templateContextFactory = deepMock() + private val templateRenderer = deepMock() private val loaders = mock() private val template = mock