From e234898b050cac1c9b2223fba60eb75a7b8ad90c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 10 Jan 2011 21:09:45 +0100 Subject: [PATCH] Render templates in a thread-safe way. --- .../java/net/pterodactylus/sone/web/AboutPage.java | 7 +++--- .../net/pterodactylus/sone/web/CreatePostPage.java | 9 +++---- .../pterodactylus/sone/web/CreateReplyPage.java | 13 +++++----- .../net/pterodactylus/sone/web/CreateSonePage.java | 9 +++---- .../net/pterodactylus/sone/web/DeletePostPage.java | 13 +++++----- .../pterodactylus/sone/web/DeleteReplyPage.java | 9 +++---- .../net/pterodactylus/sone/web/DeleteSonePage.java | 5 ++-- .../sone/web/DismissNotificationPage.java | 5 ++-- .../pterodactylus/sone/web/EditProfilePage.java | 17 ++++++------- .../net/pterodactylus/sone/web/FollowSonePage.java | 5 ++-- .../java/net/pterodactylus/sone/web/IndexPage.java | 11 +++++---- .../net/pterodactylus/sone/web/KnownSonesPage.java | 7 +++--- .../java/net/pterodactylus/sone/web/LikePage.java | 5 ++-- .../net/pterodactylus/sone/web/LockSonePage.java | 5 ++-- .../java/net/pterodactylus/sone/web/LoginPage.java | 9 +++---- .../net/pterodactylus/sone/web/LogoutPage.java | 5 ++-- .../net/pterodactylus/sone/web/OptionsPage.java | 13 +++++----- .../pterodactylus/sone/web/SoneTemplatePage.java | 17 ++++++------- .../pterodactylus/sone/web/UnfollowSonePage.java | 5 ++-- .../net/pterodactylus/sone/web/UnlikePage.java | 5 ++-- .../net/pterodactylus/sone/web/UnlockSonePage.java | 5 ++-- .../net/pterodactylus/sone/web/ViewPostPage.java | 11 +++++---- .../net/pterodactylus/sone/web/ViewSonePage.java | 11 +++++---- .../pterodactylus/sone/web/page/TemplatePage.java | 28 ++++++++++++---------- 24 files changed, 127 insertions(+), 102 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/AboutPage.java b/src/main/java/net/pterodactylus/sone/web/AboutPage.java index c20c72e..4a0dd22 100644 --- a/src/main/java/net/pterodactylus/sone/web/AboutPage.java +++ b/src/main/java/net/pterodactylus/sone/web/AboutPage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.version.Version; @@ -53,9 +54,9 @@ public class AboutPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); - template.set("version", version); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); + dataProvider.set("version", version); } } diff --git a/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java b/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java index a8e2128..aba4700 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -49,8 +50,8 @@ public class CreatePostPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); if (request.getMethod() == Method.POST) { String text = request.getHttpRequest().getPartAsStringFailsafe("text", 65536).trim(); @@ -61,9 +62,9 @@ public class CreatePostPage extends SoneTemplatePage { webInterface.getCore().createPost(currentSone, recipient, System.currentTimeMillis(), text); throw new RedirectException(returnPage); } - template.set("errorTextEmpty", true); + dataProvider.set("errorTextEmpty", true); } - template.set("returnPage", returnPage); + dataProvider.set("returnPage", returnPage); } } diff --git a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java index 2bfab6f..d4a9775 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -49,8 +50,8 @@ public class CreateReplyPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36); String text = request.getHttpRequest().getPartAsStringFailsafe("text", 65536).trim(); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); @@ -61,11 +62,11 @@ public class CreateReplyPage extends SoneTemplatePage { webInterface.getCore().createReply(currentSone, post, text); throw new RedirectException(returnPage); } - template.set("errorTextEmpty", true); + dataProvider.set("errorTextEmpty", true); } - template.set("postId", postId); - template.set("text", text); - template.set("returnPage", returnPage); + dataProvider.set("postId", postId); + dataProvider.set("text", text); + dataProvider.set("returnPage", returnPage); } } diff --git a/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java b/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java index 1c16d31..04b5d37 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java @@ -30,6 +30,7 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.wot.OwnIdentity; import net.pterodactylus.sone.web.page.Page.Request.Method; import net.pterodactylus.util.logging.Logging; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; import freenet.clients.http.ToadletContext; @@ -93,10 +94,10 @@ public class CreateSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); List ownIdentitiesWithoutSone = getOwnIdentitiesWithoutSone(webInterface.getCore()); - template.set("identitiesWithoutSone", ownIdentitiesWithoutSone); + dataProvider.set("identitiesWithoutSone", ownIdentitiesWithoutSone); if (request.getMethod() == Method.POST) { String id = request.getHttpRequest().getPartAsStringFailsafe("identity", 44); OwnIdentity selectedIdentity = null; @@ -107,7 +108,7 @@ public class CreateSonePage extends SoneTemplatePage { } } if (selectedIdentity == null) { - template.set("errorNoIdentity", true); + dataProvider.set("errorNoIdentity", true); return; } /* create Sone. */ diff --git a/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java b/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java index 4a64ad0..5722ee3 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -49,14 +50,14 @@ public class DeletePostPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); if (request.getMethod() == Method.GET) { String postId = request.getHttpRequest().getParam("post"); String returnPage = request.getHttpRequest().getParam("returnPage"); Post post = webInterface.getCore().getPost(postId); - template.set("post", post); - template.set("returnPage", returnPage); + dataProvider.set("post", post); + dataProvider.set("returnPage", returnPage); return; } else if (request.getMethod() == Method.POST) { String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36); @@ -72,8 +73,8 @@ public class DeletePostPage extends SoneTemplatePage { } else if (request.getHttpRequest().isPartSet("abortDelete")) { throw new RedirectException(returnPage); } - template.set("post", post); - template.set("returnPage", returnPage); + dataProvider.set("post", post); + dataProvider.set("returnPage", returnPage); } } diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java index 00a1a0e..8d90474 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -49,8 +50,8 @@ public class DeleteReplyPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); String replyId = request.getHttpRequest().getPartAsStringFailsafe("reply", 36); Reply reply = webInterface.getCore().getReply(replyId); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); @@ -66,8 +67,8 @@ public class DeleteReplyPage extends SoneTemplatePage { throw new RedirectException(returnPage); } } - template.set("reply", reply); - template.set("returnPage", returnPage); + dataProvider.set("reply", reply); + dataProvider.set("returnPage", returnPage); } } diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java b/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java index ae01573..abe26ea 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -50,8 +51,8 @@ public class DeleteSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); if (request.getMethod() == Method.POST) { if (request.getHttpRequest().isPartSet("deleteSone")) { Sone currentSone = getCurrentSone(request.getToadletContext()); diff --git a/src/main/java/net/pterodactylus/sone/web/DismissNotificationPage.java b/src/main/java/net/pterodactylus/sone/web/DismissNotificationPage.java index b1838da..2d61a95 100644 --- a/src/main/java/net/pterodactylus/sone/web/DismissNotificationPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DismissNotificationPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.util.notify.Notification; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -47,8 +48,8 @@ public class DismissNotificationPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); String notificationId = request.getHttpRequest().getPartAsStringFailsafe("notification", 36); Notification notification = webInterface.getNotifications().getNotification(notificationId); if ((notification != null) && notification.isDismissable()) { diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java index 965caf9..01d4815 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java @@ -21,6 +21,7 @@ import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; import net.pterodactylus.util.number.Numbers; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; import freenet.clients.http.ToadletContext; @@ -51,8 +52,8 @@ public class EditProfilePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); ToadletContext toadletContenxt = request.getToadletContext(); Sone currentSone = getCurrentSone(toadletContenxt); Profile profile = currentSone.getProfile(); @@ -78,12 +79,12 @@ public class EditProfilePage extends SoneTemplatePage { } throw new RedirectException("index.html"); } - template.set("firstName", firstName); - template.set("middleName", middleName); - template.set("lastName", lastName); - template.set("birthDay", birthDay); - template.set("birthMonth", birthMonth); - template.set("birthYear", birthYear); + dataProvider.set("firstName", firstName); + dataProvider.set("middleName", middleName); + dataProvider.set("lastName", lastName); + dataProvider.set("birthDay", birthDay); + dataProvider.set("birthMonth", birthMonth); + dataProvider.set("birthYear", birthYear); } } diff --git a/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java index c71c280..864480a 100644 --- a/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -46,8 +47,8 @@ public class FollowSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); if (request.getMethod() == Method.POST) { String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); diff --git a/src/main/java/net/pterodactylus/sone/web/IndexPage.java b/src/main/java/net/pterodactylus/sone/web/IndexPage.java index a33072f..825267b 100644 --- a/src/main/java/net/pterodactylus/sone/web/IndexPage.java +++ b/src/main/java/net/pterodactylus/sone/web/IndexPage.java @@ -24,6 +24,7 @@ import java.util.List; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -52,8 +53,8 @@ public class IndexPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); Sone currentSone = getCurrentSone(request.getToadletContext()); List allPosts = new ArrayList(); allPosts.addAll(currentSone.getPosts()); @@ -71,16 +72,16 @@ public class IndexPage extends SoneTemplatePage { } } Collections.sort(allPosts, Post.TIME_COMPARATOR); - template.set("posts", allPosts); + dataProvider.set("posts", allPosts); } /** * {@inheritDoc} */ @Override - protected void postProcess(Request request, Template template) { + protected void postProcess(Request request, DataProvider dataProvider) { @SuppressWarnings("unchecked") - List posts = (List) template.get("posts"); + List posts = (List) dataProvider.get("posts"); for (Post post : posts) { webInterface.getCore().markPostKnown(post); for (Reply reply : webInterface.getCore().getReplies(post)) { diff --git a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java index d413f61..774f410 100644 --- a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java +++ b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -51,11 +52,11 @@ public class KnownSonesPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); List knownSones = new ArrayList(webInterface.getCore().getSones()); Collections.sort(knownSones, Sone.NICE_NAME_COMPARATOR); - template.set("knownSones", knownSones); + dataProvider.set("knownSones", knownSones); } } diff --git a/src/main/java/net/pterodactylus/sone/web/LikePage.java b/src/main/java/net/pterodactylus/sone/web/LikePage.java index dd693ef..c84ea57 100644 --- a/src/main/java/net/pterodactylus/sone/web/LikePage.java +++ b/src/main/java/net/pterodactylus/sone/web/LikePage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -49,8 +50,8 @@ public class LikePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); if (request.getMethod() == Method.POST) { String type=request.getHttpRequest().getPartAsStringFailsafe("type", 16); String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36); diff --git a/src/main/java/net/pterodactylus/sone/web/LockSonePage.java b/src/main/java/net/pterodactylus/sone/web/LockSonePage.java index 05c8ad7..7888659 100644 --- a/src/main/java/net/pterodactylus/sone/web/LockSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/LockSonePage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -48,8 +49,8 @@ public class LockSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44); Sone sone = webInterface.getCore().getLocalSone(soneId, false); if (sone != null) { diff --git a/src/main/java/net/pterodactylus/sone/web/LoginPage.java b/src/main/java/net/pterodactylus/sone/web/LoginPage.java index dcfd8a7..ff81562 100644 --- a/src/main/java/net/pterodactylus/sone/web/LoginPage.java +++ b/src/main/java/net/pterodactylus/sone/web/LoginPage.java @@ -26,6 +26,7 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.wot.OwnIdentity; import net.pterodactylus.sone.web.page.Page.Request.Method; import net.pterodactylus.util.logging.Logging; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; import freenet.clients.http.ToadletContext; @@ -60,12 +61,12 @@ public class LoginPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); /* get all own identities. */ List localSones = new ArrayList(webInterface.getCore().getLocalSones()); Collections.sort(localSones, Sone.NICE_NAME_COMPARATOR); - template.set("sones", localSones); + dataProvider.set("sones", localSones); if (request.getMethod() == Method.POST) { String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone-id", 100); Sone selectedSone = webInterface.getCore().getLocalSone(soneId, false); @@ -75,7 +76,7 @@ public class LoginPage extends SoneTemplatePage { } } List ownIdentitiesWithoutSone = CreateSonePage.getOwnIdentitiesWithoutSone(webInterface.getCore()); - template.set("identitiesWithoutSone", ownIdentitiesWithoutSone); + dataProvider.set("identitiesWithoutSone", ownIdentitiesWithoutSone); } /** diff --git a/src/main/java/net/pterodactylus/sone/web/LogoutPage.java b/src/main/java/net/pterodactylus/sone/web/LogoutPage.java index f1c0b48..0b6e6e7 100644 --- a/src/main/java/net/pterodactylus/sone/web/LogoutPage.java +++ b/src/main/java/net/pterodactylus/sone/web/LogoutPage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; import freenet.clients.http.ToadletContext; @@ -45,9 +46,9 @@ public class LogoutPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { setCurrentSone(request.getToadletContext(), null); - super.processTemplate(request, template); + super.processTemplate(request, dataProvider); throw new RedirectException("index.html"); } diff --git a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java index 77f1a07..63ed6a7 100644 --- a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java +++ b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.core.Options; import net.pterodactylus.sone.web.page.Page.Request.Method; import net.pterodactylus.util.number.Numbers; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -49,8 +50,8 @@ public class OptionsPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); Options options = webInterface.getCore().getOptions(); if (request.getMethod() == Method.POST) { Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16)); @@ -64,10 +65,10 @@ public class OptionsPage extends SoneTemplatePage { webInterface.getCore().saveConfiguration(); throw new RedirectException(getPath()); } - template.set("insertion-delay", options.getIntegerOption("InsertionDelay").get()); - template.set("sone-rescue-mode", options.getBooleanOption("SoneRescueMode").get()); - template.set("clear-on-next-restart", options.getBooleanOption("ClearOnNextRestart").get()); - template.set("really-clear-on-next-restart", options.getBooleanOption("ReallyClearOnNextRestart").get()); + dataProvider.set("insertion-delay", options.getIntegerOption("InsertionDelay").get()); + dataProvider.set("sone-rescue-mode", options.getBooleanOption("SoneRescueMode").get()); + dataProvider.set("clear-on-next-restart", options.getBooleanOption("ClearOnNextRestart").get()); + dataProvider.set("really-clear-on-next-restart", options.getBooleanOption("ReallyClearOnNextRestart").get()); } } diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index 3d4cb80..dc41865 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -24,6 +24,7 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.sone.web.page.Page; import net.pterodactylus.sone.web.page.TemplatePage; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; import freenet.clients.http.SessionManager.Session; import freenet.clients.http.ToadletContext; @@ -185,14 +186,14 @@ public class SoneTemplatePage extends TemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); - template.set("currentSone", getCurrentSone(request.getToadletContext(), false)); - template.set("request", request); - template.set("currentVersion", SonePlugin.VERSION); - template.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion()); - template.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion()); - template.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate()); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); + dataProvider.set("currentSone", getCurrentSone(request.getToadletContext(), false)); + dataProvider.set("request", request); + dataProvider.set("currentVersion", SonePlugin.VERSION); + dataProvider.set("hasLatestVersion", webInterface.getCore().getUpdateChecker().hasLatestVersion()); + dataProvider.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion()); + dataProvider.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate()); } /** diff --git a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java index 5b0c652..316e408 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -46,8 +47,8 @@ public class UnfollowSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); if (request.getMethod() == Method.POST) { String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); diff --git a/src/main/java/net/pterodactylus/sone/web/UnlikePage.java b/src/main/java/net/pterodactylus/sone/web/UnlikePage.java index 1ecacc8..d08689f 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnlikePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnlikePage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -49,8 +50,8 @@ public class UnlikePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); if (request.getMethod() == Method.POST) { String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16); String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36); diff --git a/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java b/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java index 938e451..35d69ff 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -47,8 +48,8 @@ public class UnlockSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44); Sone sone = webInterface.getCore().getLocalSone(soneId, false); if (sone != null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java b/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java index 3bc3b36..3c4eddf 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -48,19 +49,19 @@ public class ViewPostPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); String postId = request.getHttpRequest().getParam("post"); Post post = webInterface.getCore().getPost(postId); - template.set("post", post); + dataProvider.set("post", post); } /** * {@inheritDoc} */ @Override - protected void postProcess(Request request, Template template) { - Post post = (Post) template.get("post"); + protected void postProcess(Request request, DataProvider dataProvider) { + Post post = (Post) dataProvider.get("post"); webInterface.getCore().markPostKnown(post); for (Reply reply : webInterface.getCore().getReplies(post)) { webInterface.getCore().markReplyKnown(reply); diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java index d933bc7..9fd6fae 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java @@ -22,6 +22,7 @@ import java.util.List; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; /** @@ -51,19 +52,19 @@ public class ViewSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { + super.processTemplate(request, dataProvider); String soneId = request.getHttpRequest().getParam("sone"); Sone sone = webInterface.getCore().getSone(soneId, false); - template.set("sone", sone); + dataProvider.set("sone", sone); } /** * {@inheritDoc} */ @Override - protected void postProcess(Request request, Template template) { - Sone sone = (Sone) template.get("sone"); + protected void postProcess(Request request, DataProvider dataProvider) { + Sone sone = (Sone) dataProvider.get("sone"); List posts = sone.getPosts(); for (Post post : posts) { webInterface.getCore().markPostKnown(post); diff --git a/src/main/java/net/pterodactylus/sone/web/page/TemplatePage.java b/src/main/java/net/pterodactylus/sone/web/page/TemplatePage.java index e823eb5..e6ee539 100644 --- a/src/main/java/net/pterodactylus/sone/web/page/TemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/page/TemplatePage.java @@ -25,6 +25,7 @@ import java.util.logging.Logger; import net.pterodactylus.sone.web.page.Page.Request.Method; import net.pterodactylus.util.logging.Logging; +import net.pterodactylus.util.template.DataProvider; import net.pterodactylus.util.template.Template; import freenet.clients.http.LinkEnabledCallback; import freenet.clients.http.PageMaker; @@ -46,7 +47,7 @@ public class TemplatePage implements Page, LinkEnabledCallback { private final String path; /** The template to render. */ - protected final Template template; + private final Template template; /** The L10n handler. */ private final BaseL10n l10n; @@ -116,9 +117,10 @@ public class TemplatePage implements Page, LinkEnabledCallback { pageNode.addForwardLink("icon", shortcutIcon); } + DataProvider dataProvider = template.createDataProvider(); try { long start = System.nanoTime(); - processTemplate(request, template); + processTemplate(request, dataProvider); long finish = System.nanoTime(); logger.log(Level.FINEST, "Template was rendered in " + ((finish - start) / 1000) / 1000.0 + "ms."); } catch (RedirectException re1) { @@ -126,10 +128,10 @@ public class TemplatePage implements Page, LinkEnabledCallback { } StringWriter stringWriter = new StringWriter(); - template.render(stringWriter); + template.render(dataProvider, stringWriter); pageNode.content.addChild("%", stringWriter.toString()); - postProcess(request, template); + postProcess(request, dataProvider); return new Response(200, "OK", "text/html", pageNode.outer.generate()); } @@ -159,29 +161,29 @@ public class TemplatePage implements Page, LinkEnabledCallback { * * @param request * The request that is rendered - * @param template - * The template to set variables in + * @param dataProvider + * The data provider to set variables in * @throws RedirectException * if the processing page wants to redirect after processing */ - protected void processTemplate(Request request, Template template) throws RedirectException { + protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { /* do nothing. */ } /** * This method will be called after - * {@link #processTemplate(net.pterodactylus.sone.web.page.Page.Request, Template)} + * {@link #processTemplate(net.pterodactylus.sone.web.page.Page.Request, DataProvider)} * has processed the template and the template was rendered. This method * will not be called if - * {@link #processTemplate(net.pterodactylus.sone.web.page.Page.Request, Template)} + * {@link #processTemplate(net.pterodactylus.sone.web.page.Page.Request, DataProvider)} * throws a {@link RedirectException}! * * @param request * The request being processed - * @param template - * The template that was rendered + * @param dataProvider + * The data provider that supplied the rendered data */ - protected void postProcess(Request request, Template template) { + protected void postProcess(Request request, DataProvider dataProvider) { /* do nothing. */ } @@ -212,7 +214,7 @@ public class TemplatePage implements Page, LinkEnabledCallback { /** * Exception that can be thrown to signal that a subclassed {@link Page} * wants to redirect the user during the - * {@link TemplatePage#processTemplate(net.pterodactylus.sone.web.page.Page.Request, Template)} + * {@link TemplatePage#processTemplate(net.pterodactylus.sone.web.page.Page.Request, DataProvider)} * method call. * * @author David ‘Bombe’ Roden -- 2.7.4