From: David ‘Bombe’ Roden Date: Tue, 13 Sep 2011 08:21:12 +0000 (+0200) Subject: Use web package from utils. X-Git-Tag: 0.7^2~11 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=45f92ec63dbf8134d92ceed67294faa38117b195;p=Sone.git Use web package from utils. --- diff --git a/src/main/java/net/pterodactylus/sone/template/GetPagePlugin.java b/src/main/java/net/pterodactylus/sone/template/GetPagePlugin.java index a25d619..b2a4962 100644 --- a/src/main/java/net/pterodactylus/sone/template/GetPagePlugin.java +++ b/src/main/java/net/pterodactylus/sone/template/GetPagePlugin.java @@ -19,9 +19,10 @@ package net.pterodactylus.sone.template; import java.util.Map; -import net.pterodactylus.sone.web.page.Page.Request; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Plugin; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Request; /** * Extracts a page number from a {@link Request}’s parameters and stores it in @@ -50,7 +51,7 @@ public class GetPagePlugin implements Plugin { pageKey = "page"; } - Request request = (Request) templateContext.get(requestKey); + FreenetRequest request = (FreenetRequest) templateContext.get(requestKey); String pageString = request.getHttpRequest().getParam(parameter); int page = 0; try { diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index 332f504..3494c21 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -35,7 +35,7 @@ import net.pterodactylus.sone.text.PostPart; import net.pterodactylus.sone.text.SonePart; import net.pterodactylus.sone.text.SoneTextParser; import net.pterodactylus.sone.text.SoneTextParserContext; -import net.pterodactylus.sone.web.page.Page.Request; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Filter; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -108,7 +108,7 @@ public class ParserFilter implements Filter { if (sone == null) { sone = core.getSone(soneKey, false); } - Request request = (Request) templateContext.get("request"); + FreenetRequest request = (FreenetRequest) templateContext.get("request"); SoneTextParserContext context = new SoneTextParserContext(request, sone); StringWriter parsedTextWriter = new StringWriter(); try { diff --git a/src/main/java/net/pterodactylus/sone/template/RequestChangeFilter.java b/src/main/java/net/pterodactylus/sone/template/RequestChangeFilter.java index fb31719..a0d80af 100644 --- a/src/main/java/net/pterodactylus/sone/template/RequestChangeFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/RequestChangeFilter.java @@ -26,15 +26,15 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import net.pterodactylus.sone.web.page.Page.Request; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Filter; import net.pterodactylus.util.template.TemplateContext; /** - * This filter expects a {@link Request} as input and outputs a {@link URI} that - * is modified by the parameters. The name of the parameter is handed in as - * “name”, the value may either be stored in “value”, or in a template variable - * whose key is stored in “key”. + * This filter expects a {@link FreenetRequest} as input and outputs a + * {@link URI} that is modified by the parameters. The name of the parameter is + * handed in as “name”, the value may either be stored in “value”, or in a + * template variable whose key is stored in “key”. * * @author David ‘Bombe’ Roden */ @@ -45,7 +45,7 @@ public class RequestChangeFilter implements Filter { */ @Override public Object format(TemplateContext templateContext, Object data, Map parameters) { - Request request = (Request) data; + FreenetRequest request = (FreenetRequest) data; String name = parameters.get("name"); String nameKey = parameters.get("nameKey"); if (nameKey != null) { diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParserContext.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParserContext.java index 4a89016..35b190b 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParserContext.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParserContext.java @@ -18,7 +18,7 @@ package net.pterodactylus.sone.text; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request; +import net.pterodactylus.sone.web.page.FreenetRequest; /** * {@link ParserContext} implementation for the {@link SoneTextParser}. It @@ -30,7 +30,7 @@ import net.pterodactylus.sone.web.page.Page.Request; public class SoneTextParserContext implements ParserContext { /** The request being processed. */ - private final Request request; + private final FreenetRequest request; /** The posting Sone. */ private final Sone postingSone; @@ -43,7 +43,7 @@ public class SoneTextParserContext implements ParserContext { * @param postingSone * The posting Sone */ - public SoneTextParserContext(Request request, Sone postingSone) { + public SoneTextParserContext(FreenetRequest request, Sone postingSone) { this.request = request; this.postingSone = postingSone; } @@ -53,7 +53,7 @@ public class SoneTextParserContext implements ParserContext { * * @return The request being processed */ - public Request getRequest() { + public FreenetRequest getRequest() { return request; } diff --git a/src/main/java/net/pterodactylus/sone/web/AboutPage.java b/src/main/java/net/pterodactylus/sone/web/AboutPage.java index 4c14457..a9698e4 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.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.util.version.Version; @@ -54,7 +55,7 @@ public class AboutPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); templateContext.set("version", version); } diff --git a/src/main/java/net/pterodactylus/sone/web/BookmarkPage.java b/src/main/java/net/pterodactylus/sone/web/BookmarkPage.java index 12a0934..0ebf9d5 100644 --- a/src/main/java/net/pterodactylus/sone/web/BookmarkPage.java +++ b/src/main/java/net/pterodactylus/sone/web/BookmarkPage.java @@ -17,9 +17,10 @@ package net.pterodactylus.sone.web; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user bookmark a post. @@ -46,7 +47,7 @@ public class BookmarkPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String id = request.getHttpRequest().getPartAsStringFailsafe("post", 36); diff --git a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java index d6f63aa..ad1717b 100644 --- a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java +++ b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.collection.Pagination; import net.pterodactylus.util.filter.Filter; import net.pterodactylus.util.filter.Filters; @@ -57,7 +58,7 @@ public class BookmarksPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); Set allPosts = webInterface.getCore().getBookmarkedPosts(); Set loadedPosts = Filters.filteredSet(allPosts, new Filter() { diff --git a/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java b/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java index 147e4ae..22f6efa 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java @@ -20,9 +20,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.text.TextFilter; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * This page lets the user create a new {@link Post}. @@ -51,7 +52,7 @@ public class CreatePostPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); if (request.getMethod() == Method.POST) { diff --git a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java index 2b12352..f28be35 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java @@ -20,9 +20,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.text.TextFilter; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * This page lets the user post a reply to a post. @@ -51,7 +52,7 @@ public class CreateReplyPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36); String text = request.getHttpRequest().getPartAsStringFailsafe("text", 65536).trim(); diff --git a/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java b/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java index 3f940a3..9878358 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreateSonePage.java @@ -28,10 +28,11 @@ import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; 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.sone.web.page.FreenetRequest; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; import freenet.clients.http.ToadletContext; /** @@ -94,7 +95,7 @@ public class CreateSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); List ownIdentitiesWithoutSone = getOwnIdentitiesWithoutSone(webInterface.getCore()); templateContext.set("identitiesWithoutSone", ownIdentitiesWithoutSone); diff --git a/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java b/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java index 7a36d02..c8fd20f 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeletePostPage.java @@ -18,9 +18,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Lets the user delete a post they made. @@ -49,7 +50,7 @@ public class DeletePostPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.GET) { String postId = request.getHttpRequest().getParam("post"); diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteProfileFieldPage.java b/src/main/java/net/pterodactylus/sone/web/DeleteProfileFieldPage.java index 82f2ace..030279b 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteProfileFieldPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteProfileFieldPage.java @@ -20,9 +20,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user confirm the deletion of a profile field. @@ -51,7 +52,7 @@ public class DeleteProfileFieldPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java index 782589f..226e0d3 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java @@ -18,9 +18,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Reply; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * This page lets the user delete a reply. @@ -49,7 +50,7 @@ public class DeleteReplyPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String replyId = request.getHttpRequest().getPartAsStringFailsafe("reply", 36); Reply reply = webInterface.getCore().getReply(replyId); diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java b/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java index 21979b8..bbf533f 100644 --- a/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/DeleteSonePage.java @@ -18,9 +18,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Lets the user delete a Sone. Of course the Sone is not really deleted from @@ -51,7 +52,7 @@ public class DeleteSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { if (request.getHttpRequest().isPartSet("deleteSone")) { diff --git a/src/main/java/net/pterodactylus/sone/web/DismissNotificationPage.java b/src/main/java/net/pterodactylus/sone/web/DismissNotificationPage.java index 15c5675..9d79195 100644 --- a/src/main/java/net/pterodactylus/sone/web/DismissNotificationPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DismissNotificationPage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.notify.Notification; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -48,7 +49,7 @@ public class DismissNotificationPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String notificationId = request.getHttpRequest().getPartAsStringFailsafe("notification", 36); Notification notification = webInterface.getNotifications().getNotification(notificationId); diff --git a/src/main/java/net/pterodactylus/sone/web/DistrustPage.java b/src/main/java/net/pterodactylus/sone/web/DistrustPage.java index 37a792c..473bf1c 100644 --- a/src/main/java/net/pterodactylus/sone/web/DistrustPage.java +++ b/src/main/java/net/pterodactylus/sone/web/DistrustPage.java @@ -19,9 +19,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user distrust another Sone. This will assign a @@ -52,7 +53,7 @@ public class DistrustPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java b/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java index 219bdc5..a06592a 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditProfileFieldPage.java @@ -20,9 +20,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user edit the name of a profile field. @@ -51,7 +52,7 @@ public class EditProfileFieldPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); diff --git a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java index 43dd15b..59c7e3e 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditProfilePage.java @@ -22,10 +22,11 @@ import java.util.List; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; import freenet.clients.http.ToadletContext; /** @@ -55,7 +56,7 @@ public class EditProfilePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); ToadletContext toadletContenxt = request.getToadletContext(); Sone currentSone = getCurrentSone(toadletContenxt); @@ -153,7 +154,7 @@ public class EditProfilePage extends SoneTemplatePage { * @return The parsed ID, or {@code null} if there was no part matching the * given string */ - private String getFieldId(Request request, String partNameStart) { + private String getFieldId(FreenetRequest request, String partNameStart) { for (String partName : request.getHttpRequest().getParts()) { if (partName.startsWith(partNameStart)) { return partName.substring(partNameStart.length()); diff --git a/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java index 81225e9..143e0ba 100644 --- a/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/FollowSonePage.java @@ -18,9 +18,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * This page lets the user follow another Sone. @@ -47,7 +48,7 @@ public class FollowSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { 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 35b88a9..356b4ab 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.Sone; import net.pterodactylus.sone.notify.ListNotificationFilters; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.collection.Pagination; import net.pterodactylus.util.filter.Filter; import net.pterodactylus.util.filter.Filters; @@ -57,7 +58,7 @@ public class IndexPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); final Sone currentSone = getCurrentSone(request.getToadletContext()); List allPosts = new ArrayList(); diff --git a/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java b/src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java index ad63791..52e4239 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.sone.web.page.FreenetRequest; import net.pterodactylus.util.collection.Pagination; import net.pterodactylus.util.collection.ReverseComparator; import net.pterodactylus.util.filter.Filter; @@ -57,7 +58,7 @@ public class KnownSonesPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String sortField = request.getHttpRequest().getParam("sort"); String sortOrder = request.getHttpRequest().getParam("order"); diff --git a/src/main/java/net/pterodactylus/sone/web/LikePage.java b/src/main/java/net/pterodactylus/sone/web/LikePage.java index 56f55ef..c5174c6 100644 --- a/src/main/java/net/pterodactylus/sone/web/LikePage.java +++ b/src/main/java/net/pterodactylus/sone/web/LikePage.java @@ -19,9 +19,10 @@ 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.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user like a {@link Post}. @@ -50,7 +51,7 @@ public class LikePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16); diff --git a/src/main/java/net/pterodactylus/sone/web/LockSonePage.java b/src/main/java/net/pterodactylus/sone/web/LockSonePage.java index d09de66..a56d263 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.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -49,7 +50,7 @@ public class LockSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44); Sone sone = webInterface.getCore().getLocalSone(soneId, false); diff --git a/src/main/java/net/pterodactylus/sone/web/LoginPage.java b/src/main/java/net/pterodactylus/sone/web/LoginPage.java index 8e612ea..6f43b6f 100644 --- a/src/main/java/net/pterodactylus/sone/web/LoginPage.java +++ b/src/main/java/net/pterodactylus/sone/web/LoginPage.java @@ -24,10 +24,11 @@ import java.util.logging.Logger; 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.sone.web.page.FreenetRequest; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; import freenet.clients.http.ToadletContext; /** @@ -61,7 +62,7 @@ public class LoginPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); /* get all own identities. */ List localSones = new ArrayList(webInterface.getCore().getLocalSones()); @@ -87,7 +88,7 @@ public class LoginPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected String getRedirectTarget(Request request) { + protected String getRedirectTarget(FreenetRequest request) { if (getCurrentSone(request.getToadletContext(), false) != null) { return "index.html"; } diff --git a/src/main/java/net/pterodactylus/sone/web/LogoutPage.java b/src/main/java/net/pterodactylus/sone/web/LogoutPage.java index 7cd0587..a7f769f 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.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import freenet.clients.http.ToadletContext; @@ -46,7 +47,7 @@ public class LogoutPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { setCurrentSone(request.getToadletContext(), null); super.processTemplate(request, templateContext); throw new RedirectException("index.html"); diff --git a/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java b/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java index 9f91c84..987fa1f 100644 --- a/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java +++ b/src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java @@ -22,6 +22,7 @@ import java.util.StringTokenizer; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -53,7 +54,7 @@ public class MarkAsKnownPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String type = request.getHttpRequest().getPartAsStringFailsafe("type", 5); if (!type.equals("sone") && !type.equals("post") && !type.equals("reply")) { diff --git a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java index fda6afd..75e73a0 100644 --- a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java +++ b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java @@ -23,10 +23,11 @@ import java.util.List; import net.pterodactylus.sone.core.Core.Preferences; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * This page lets the user edit the options of the Sone plugin. @@ -55,7 +56,7 @@ public class OptionsPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); Preferences preferences = webInterface.getCore().getPreferences(); Sone currentSone = webInterface.getCurrentSone(request.getToadletContext(), false); diff --git a/src/main/java/net/pterodactylus/sone/web/RescuePage.java b/src/main/java/net/pterodactylus/sone/web/RescuePage.java index 40b03f1..f653615 100644 --- a/src/main/java/net/pterodactylus/sone/web/RescuePage.java +++ b/src/main/java/net/pterodactylus/sone/web/RescuePage.java @@ -19,10 +19,11 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.core.SoneRescuer; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user control the rescue mode for a Sone. @@ -52,7 +53,7 @@ public class RescuePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); Sone currentSone = getCurrentSone(request.getToadletContext(), false); SoneRescuer soneRescuer = webInterface.getCore().getSoneRescuer(currentSone); diff --git a/src/main/java/net/pterodactylus/sone/web/SearchPage.java b/src/main/java/net/pterodactylus/sone/web/SearchPage.java index fab7a57..91e2a08 100644 --- a/src/main/java/net/pterodactylus/sone/web/SearchPage.java +++ b/src/main/java/net/pterodactylus/sone/web/SearchPage.java @@ -32,6 +32,7 @@ import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.cache.Cache; import net.pterodactylus.util.cache.CacheException; import net.pterodactylus.util.cache.CacheItem; @@ -96,7 +97,7 @@ public class SearchPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String query = request.getHttpRequest().getParam("query").trim(); if (query.length() == 0) { diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index b7e36f4..095db9e 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -27,8 +27,8 @@ import java.util.Map; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.sone.notify.ListNotificationFilters; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.sone.web.page.FreenetTemplatePage; -import net.pterodactylus.sone.web.page.Page; import net.pterodactylus.util.collection.ListBuilder; import net.pterodactylus.util.collection.MapBuilder; import net.pterodactylus.util.template.Template; @@ -202,7 +202,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { * {@inheritDoc} */ @Override - protected String getPageTitle(Request request) { + protected String getPageTitle(FreenetRequest request) { if (pageTitleKey != null) { return webInterface.getL10n().getString(pageTitleKey); } @@ -213,7 +213,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { * {@inheritDoc} */ @Override - protected List> getAdditionalLinkNodes(Request request) { + protected List> getAdditionalLinkNodes(FreenetRequest request) { return new ListBuilder>().add(new MapBuilder().put("rel", "search").put("type", "application/opensearchdescription+xml").put("title", "Sone").put("href", "http://" + request.getHttpRequest().getHeader("host") + "/Sone/OpenSearch.xml").get()).get(); } @@ -247,7 +247,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); Sone currentSone = getCurrentSone(request.getToadletContext(), false); templateContext.set("core", webInterface.getCore()); @@ -266,7 +266,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { * {@inheritDoc} */ @Override - protected String getRedirectTarget(Page.Request request) { + protected String getRedirectTarget(FreenetRequest request) { if (requiresLogin() && (getCurrentSone(request.getToadletContext(), false) == null)) { HTTPRequest httpRequest = request.getHttpRequest(); String originalUrl = httpRequest.getPath(); diff --git a/src/main/java/net/pterodactylus/sone/web/TrustPage.java b/src/main/java/net/pterodactylus/sone/web/TrustPage.java index b0dadef..f2cf92e 100644 --- a/src/main/java/net/pterodactylus/sone/web/TrustPage.java +++ b/src/main/java/net/pterodactylus/sone/web/TrustPage.java @@ -19,9 +19,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user trust another Sone. This will assign a configurable @@ -52,7 +53,7 @@ public class TrustPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); diff --git a/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java b/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java index 60165b2..def3bf4 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnbookmarkPage.java @@ -20,9 +20,10 @@ package net.pterodactylus.sone.web; import java.util.Set; import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user unbookmark a post. @@ -49,7 +50,7 @@ public class UnbookmarkPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String id = request.getHttpRequest().getPartAsStringFailsafe("post", 36); diff --git a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java index 33b88a1..d8e53ce 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnfollowSonePage.java @@ -18,9 +18,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * This page lets the user unfollow another Sone. @@ -47,7 +48,7 @@ public class UnfollowSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { 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 24ff3ca..f47c4f2 100644 --- a/src/main/java/net/pterodactylus/sone/web/UnlikePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UnlikePage.java @@ -19,9 +19,10 @@ 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.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user unlike a {@link Post}. @@ -50,7 +51,7 @@ public class UnlikePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16); diff --git a/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java b/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java index ccb5959..f527558 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.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -48,7 +49,7 @@ public class UnlockSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44); Sone sone = webInterface.getCore().getLocalSone(soneId, false); diff --git a/src/main/java/net/pterodactylus/sone/web/UntrustPage.java b/src/main/java/net/pterodactylus/sone/web/UntrustPage.java index c5e7dec..d711525 100644 --- a/src/main/java/net/pterodactylus/sone/web/UntrustPage.java +++ b/src/main/java/net/pterodactylus/sone/web/UntrustPage.java @@ -19,9 +19,10 @@ package net.pterodactylus.sone.web; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; /** * Page that lets the user untrust another Sone. This will remove all trust @@ -52,7 +53,7 @@ public class UntrustPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); if (request.getMethod() == Method.POST) { String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256); diff --git a/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java b/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java index b62e19c..4cc9864 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.template.SoneAccessor; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -49,7 +50,7 @@ public class ViewPostPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected String getPageTitle(Request request) { + protected String getPageTitle(FreenetRequest request) { String postId = request.getHttpRequest().getParam("post"); Post post = webInterface.getCore().getPost(postId, false); String title = ""; @@ -65,7 +66,7 @@ public class ViewPostPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String postId = request.getHttpRequest().getParam("post"); boolean raw = request.getHttpRequest().getParam("raw").equals("true"); diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java index 889c74c..5d463c0 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java @@ -29,6 +29,7 @@ import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.template.SoneAccessor; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.collection.Pagination; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.template.Template; @@ -61,7 +62,7 @@ public class ViewSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected String getPageTitle(Request request) { + protected String getPageTitle(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); Sone sone = webInterface.getCore().getSone(soneId, false); if ((sone != null) && (sone.getTime() > 0)) { @@ -75,7 +76,7 @@ public class ViewSonePage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); String soneId = request.getHttpRequest().getParam("sone"); Sone sone = webInterface.getCore().getSone(soneId, false); diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 08202d4..3eb1ac3 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -90,11 +90,9 @@ import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage; 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.PageToadlet; import net.pterodactylus.sone.web.page.PageToadletFactory; -import net.pterodactylus.sone.web.page.RedirectPage; -import net.pterodactylus.sone.web.page.StaticPage; -import net.pterodactylus.sone.web.page.TemplatePage; import net.pterodactylus.util.cache.Cache; import net.pterodactylus.util.cache.CacheException; import net.pterodactylus.util.cache.CacheItem; @@ -125,6 +123,9 @@ import net.pterodactylus.util.template.TemplateParser; import net.pterodactylus.util.template.XmlFilter; import net.pterodactylus.util.thread.Ticker; import net.pterodactylus.util.version.Version; +import net.pterodactylus.util.web.RedirectPage; +import net.pterodactylus.util.web.StaticPage; +import net.pterodactylus.util.web.TemplatePage; import freenet.clients.http.SessionManager; import freenet.clients.http.SessionManager.Session; import freenet.clients.http.ToadletContainer; @@ -569,7 +570,7 @@ public class WebInterface implements CoreListener { Template openSearchTemplate = TemplateParser.parse(createReader("/templates/xml/OpenSearch.xml")); PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/"); - pageToadlets.add(pageToadletFactory.createPageToadlet(new RedirectPage("", "index.html"))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new RedirectPage("", "index.html"))); pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index")); pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateSonePage(createSoneTemplate, this), "CreateSone")); pageToadlets.add(pageToadletFactory.createPageToadlet(new KnownSonesPage(knownSonesTemplate, this), "KnownSones")); @@ -605,10 +606,10 @@ public class WebInterface implements CoreListener { pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(emptyTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("invalid.html", invalidTemplate, "Page.Invalid.Title", this))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css"))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript"))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png"))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new TemplatePage("OpenSearch.xml", "application/opensearchdescription+xml", templateContextFactory, openSearchTemplate))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css"))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript"))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png"))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new TemplatePage("OpenSearch.xml", "application/opensearchdescription+xml", templateContextFactory, openSearchTemplate))); pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new GetNotificationAjaxPage(this))); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.java index 760bd34..0cf7b01 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -45,7 +46,7 @@ public class BookmarkAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String id = request.getHttpRequest().getParam("post", null); if ((id == null) || (id.length() == 0)) { return createErrorJsonObject("invalid-post-id"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java index 0fc1236..c6f4455 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java @@ -21,6 +21,7 @@ import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.text.TextFilter; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -44,7 +45,7 @@ public class CreatePostAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { Sone sone = getCurrentSone(request.getToadletContext()); if (sone == null) { return createErrorJsonObject("auth-required"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java index ce78f58..9f5c882 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java @@ -22,6 +22,7 @@ import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.text.TextFilter; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -49,7 +50,7 @@ public class CreateReplyAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String postId = request.getHttpRequest().getParam("post"); String text = request.getHttpRequest().getParam("text").trim(); String senderId = request.getHttpRequest().getParam("sender"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java index 8d3b414..37ab040 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -46,7 +47,7 @@ public class DeletePostAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String postId = request.getHttpRequest().getParam("post"); Post post = webInterface.getCore().getPost(postId, false); if ((post == null) || (post.getSone() == null)) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java index 4625c13..205fb85 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java @@ -21,6 +21,7 @@ import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -44,7 +45,7 @@ public class DeleteProfileFieldAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String fieldId = request.getHttpRequest().getParam("field"); Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java index e12b2cf..7bea4cf 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -46,7 +47,7 @@ public class DeleteReplyAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String replyId = request.getHttpRequest().getParam("reply"); Reply reply = webInterface.getCore().getReply(replyId); if (reply == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.java index 08e3ee5..232cab6 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.notify.Notification; @@ -42,7 +43,7 @@ public class DismissNotificationAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String notificationId = request.getHttpRequest().getParam("notification"); Notification notification = webInterface.getNotifications().getNotification(notificationId); if (notification == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java index ca770e4..4ba3dbb 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java @@ -21,6 +21,7 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.wot.Trust; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -45,7 +46,7 @@ public class DistrustAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { Sone currentSone = getCurrentSone(request.getToadletContext(), false); if (currentSone == null) { return createErrorJsonObject("auth-required"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.java index 0036545..5351281 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.java @@ -21,6 +21,7 @@ import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -48,7 +49,7 @@ public class EditProfileFieldAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String fieldId = request.getHttpRequest().getParam("field"); Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java index d82ab1d..5c3e5f4 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -42,7 +43,7 @@ public class FollowSoneAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); if (!webInterface.getCore().hasSone(soneId)) { return createErrorJsonObject("invalid-sone-id"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java index a8b991d..539be3d 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java @@ -27,6 +27,7 @@ import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonArray; import net.pterodactylus.util.json.JsonObject; @@ -55,7 +56,7 @@ public class GetLikesAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String type = request.getHttpRequest().getParam("type", null); String id = request.getHttpRequest().getParam(type, null); if ((id == null) || (id.length() == 0)) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java index 8bfe472..198a04f 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationAjaxPage.java @@ -27,6 +27,7 @@ import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.sone.notify.ListNotification; import net.pterodactylus.sone.notify.ListNotificationFilters; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.notify.Notification; import net.pterodactylus.util.notify.TemplateNotification; @@ -75,7 +76,7 @@ public class GetNotificationAjaxPage extends JsonPage { */ @Override @SuppressWarnings("unchecked") - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String[] notificationIds = request.getHttpRequest().getParam("notifications").split(","); JsonObject jsonNotifications = new JsonObject(); Sone currentSone = getCurrentSone(request.getToadletContext(), false); @@ -110,7 +111,7 @@ public class GetNotificationAjaxPage extends JsonPage { * The notification to create a JSON object * @return The JSON object */ - private JsonObject createJsonNotification(Request request, Notification notification) { + private JsonObject createJsonNotification(FreenetRequest request, Notification notification) { JsonObject jsonNotification = new JsonObject(); jsonNotification.put("id", notification.getId()); StringWriter notificationWriter = new StringWriter(); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java index f56c5b7..8be816d 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java @@ -22,6 +22,7 @@ import java.io.StringWriter; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.template.Template; @@ -56,7 +57,7 @@ public class GetPostAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String postId = request.getHttpRequest().getParam("post"); Post post = webInterface.getCore().getPost(postId, false); if (post == null) { @@ -89,7 +90,7 @@ public class GetPostAjaxPage extends JsonPage { * The currently logged in Sone (to store in the template) * @return The JSON representation of the post */ - private JsonObject createJsonPost(Request request, Post post, Sone currentSone) { + private JsonObject createJsonPost(FreenetRequest request, Post post, Sone currentSone) { JsonObject jsonPost = new JsonObject(); jsonPost.put("id", post.getId()); jsonPost.put("sone", post.getSone().getId()); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java index 6cc7d47..2eef58a 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java @@ -22,6 +22,7 @@ import java.io.StringWriter; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.template.Template; @@ -59,7 +60,7 @@ public class GetReplyAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String replyId = request.getHttpRequest().getParam("reply"); Reply reply = webInterface.getCore().getReply(replyId); if ((reply == null) || (reply.getSone() == null)) { @@ -91,7 +92,7 @@ public class GetReplyAjaxPage extends JsonPage { * The currently logged in Sone (to store in the template) * @return The JSON representation of the reply */ - private JsonObject createJsonReply(Request request, Reply reply, Sone currentSone) { + private JsonObject createJsonReply(FreenetRequest request, Reply reply, Sone currentSone) { JsonObject jsonReply = new JsonObject(); jsonReply.put("id", reply.getId()); jsonReply.put("postId", reply.getPost().getId()); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java index f704905..eaa6506 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java @@ -31,6 +31,7 @@ import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.notify.ListNotificationFilters; import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.filter.Filter; import net.pterodactylus.util.filter.Filters; import net.pterodactylus.util.json.JsonArray; @@ -62,7 +63,7 @@ public class GetStatusAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { final Sone currentSone = getCurrentSone(request.getToadletContext(), false); /* load Sones. */ boolean loadAllSones = Boolean.parseBoolean(request.getHttpRequest().getParam("loadAllSones", "false")); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java index f03e6e4..1711a5b 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java @@ -24,6 +24,7 @@ import java.util.Date; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.number.Digits; @@ -51,7 +52,7 @@ public class GetTimesAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String allIds = request.getHttpRequest().getParam("posts"); JsonObject postTimes = new JsonObject(); if (allIds.length() > 0) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetTranslationPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetTranslationPage.java index 725b13a..e0909ca 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetTranslationPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetTranslationPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -45,7 +46,7 @@ public class GetTranslationPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String key = request.getHttpRequest().getParam("key"); String translation = webInterface.getL10n().getString(key); return createSuccessJsonObject().put("value", translation); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java index b027ab8..1e5e8ed 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java @@ -17,11 +17,15 @@ package net.pterodactylus.sone.web.ajax; +import java.io.IOException; + import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; -import net.pterodactylus.sone.web.page.Page; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; import net.pterodactylus.util.json.JsonUtils; +import net.pterodactylus.util.web.Page; +import net.pterodactylus.util.web.Response; import freenet.clients.http.SessionManager.Session; import freenet.clients.http.ToadletContext; @@ -31,7 +35,7 @@ import freenet.clients.http.ToadletContext; * * @author David ‘Bombe’ Roden */ -public abstract class JsonPage implements Page { +public abstract class JsonPage implements Page { /** The path of the page. */ private final String path; @@ -124,7 +128,7 @@ public abstract class JsonPage implements Page { * The request to handle * @return The created JSON object */ - protected abstract JsonObject createJsonObject(Request request); + protected abstract JsonObject createJsonObject(FreenetRequest request); /** * Returns whether this command needs the form password for authentication @@ -187,23 +191,31 @@ public abstract class JsonPage implements Page { * {@inheritDoc} */ @Override - public Response handleRequest(Request request) { + public boolean isPrefixPage() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public Response handleRequest(FreenetRequest request, Response response) throws IOException { if (webInterface.getCore().getPreferences().isRequireFullAccess() && !request.getToadletContext().isAllowedFullAccess()) { - return new Response(403, "Forbidden", "application/json", JsonUtils.format(new JsonObject().put("success", false).put("error", "auth-required"))); + return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(JsonUtils.format(new JsonObject().put("success", false).put("error", "auth-required"))); } if (needsFormPassword()) { String formPassword = request.getHttpRequest().getParam("formPassword"); if (!webInterface.getFormPassword().equals(formPassword)) { - return new Response(403, "Forbidden", "application/json", JsonUtils.format(new JsonObject().put("success", false).put("error", "auth-required"))); + return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(JsonUtils.format(new JsonObject().put("success", false).put("error", "auth-required"))); } } if (requiresLogin()) { if (getCurrentSone(request.getToadletContext(), false) == null) { - return new Response(403, "Forbidden", "application/json", JsonUtils.format(createErrorJsonObject("auth-required"))); + return response.setStatusCode(403).setStatusText("Forbidden").setContentType("application/json").write(JsonUtils.format(new JsonObject().put("success", false).put("error", "auth-required"))); } } JsonObject jsonObject = createJsonObject(request); - return new Response(200, "OK", "application/json", JsonUtils.format(jsonObject)); + return response.setStatusCode(200).setStatusText("OK").setContentType("application/json").write(JsonUtils.format(jsonObject)); } } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java index bf87ead..e4d168f 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -43,7 +44,7 @@ public class LikeAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String type = request.getHttpRequest().getParam("type", null); String id = request.getHttpRequest().getParam(type, null); if ((id == null) || (id.length() == 0)) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java index bca9a35..1d80905 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -43,7 +44,7 @@ public class LockSoneAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); Sone sone = webInterface.getCore().getLocalSone(soneId, false); if (sone == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java index b641ea0..42ee8b2 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java @@ -22,6 +22,7 @@ import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -46,7 +47,7 @@ public class MarkAsKnownAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String type = request.getHttpRequest().getParam("type"); if (!type.equals("sone") && !type.equals("post") && !type.equals("reply")) { return createErrorJsonObject("invalid-type"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.java index 092c1f7..b932a82 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/MoveProfileFieldAjaxPage.java @@ -21,6 +21,7 @@ import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -50,7 +51,7 @@ public class MoveProfileFieldAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); String fieldId = request.getHttpRequest().getParam("field"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java index d6e2750..b27bedf 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java @@ -21,6 +21,7 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.wot.Trust; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -45,7 +46,7 @@ public class TrustAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { Sone currentSone = getCurrentSone(request.getToadletContext(), false); if (currentSone == null) { return createErrorJsonObject("auth-required"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.java index f07dcb0..6a9f8fe 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnbookmarkAjaxPage.java @@ -18,6 +18,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -45,7 +46,7 @@ public class UnbookmarkAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String id = request.getHttpRequest().getParam("post", null); if ((id == null) || (id.length() == 0)) { return createErrorJsonObject("invalid-post-id"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java index 7f719b7..26f1a11 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java @@ -19,6 +19,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -42,7 +43,7 @@ public class UnfollowSoneAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); if (!webInterface.getCore().hasSone(soneId)) { return createErrorJsonObject("invalid-sone-id"); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java index 84b0593..1841806 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -43,7 +44,7 @@ public class UnlikeAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String type = request.getHttpRequest().getParam("type", null); String id = request.getHttpRequest().getParam(type, null); if ((id == null) || (id.length() == 0)) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java index 3160db0..d7430c1 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java @@ -20,6 +20,7 @@ package net.pterodactylus.sone.web.ajax; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -43,7 +44,7 @@ public class UnlockSoneAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { String soneId = request.getHttpRequest().getParam("sone"); Sone sone = webInterface.getCore().getLocalSone(soneId, false); if (sone == null) { diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java index ad613ff..86222e0 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java @@ -21,6 +21,7 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.wot.Trust; import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.json.JsonObject; /** @@ -45,7 +46,7 @@ public class UntrustAjaxPage extends JsonPage { * {@inheritDoc} */ @Override - protected JsonObject createJsonObject(Request request) { + protected JsonObject createJsonObject(FreenetRequest request) { Sone currentSone = getCurrentSone(request.getToadletContext(), false); if (currentSone == null) { return createErrorJsonObject("auth-required"); diff --git a/src/main/java/net/pterodactylus/sone/web/page/FreenetRequest.java b/src/main/java/net/pterodactylus/sone/web/page/FreenetRequest.java new file mode 100644 index 0000000..526f3ed --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/page/FreenetRequest.java @@ -0,0 +1,80 @@ +/* + * Sone - FreenetRequest.java - Copyright © 2011 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.web.page; + +import java.net.URI; + +import net.pterodactylus.util.web.Method; +import net.pterodactylus.util.web.Request; +import freenet.clients.http.ToadletContext; +import freenet.support.api.HTTPRequest; + +/** + * Encapsulates all Freenet-specific properties of a request. + * + * @author David ‘Bombe’ Roden + */ +public class FreenetRequest extends Request { + + /** The underlying HTTP request from Freenet. */ + private final HTTPRequest httpRequest; + + /** The toadlet context. */ + private final ToadletContext toadletContext; + + /** + * Creates a new freenet request. + * + * @param uri + * The URI that is being accessed + * @param method + * The method used to access this page + * @param httpRequest + * The underlying HTTP request from Freenet + * @param toadletContext + * The toadlet context + */ + public FreenetRequest(URI uri, Method method, HTTPRequest httpRequest, ToadletContext toadletContext) { + super(uri, method); + this.httpRequest = httpRequest; + this.toadletContext = toadletContext; + } + + // + // ACCESSORS + // + + /** + * Returns the underlying HTTP request from Freenet. + * + * @return The underlying HTTP request from Freenet + */ + public HTTPRequest getHttpRequest() { + return httpRequest; + } + + /** + * Returns the toadlet context. + * + * @return The toadlet context + */ + public ToadletContext getToadletContext() { + return toadletContext; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java index 5831a1b..8096a6a 100644 --- a/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web.page; +import java.io.IOException; import java.io.StringWriter; import java.util.Collection; import java.util.Collections; @@ -26,11 +27,14 @@ import java.util.Map.Entry; import java.util.logging.Level; 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.Template; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.util.template.TemplateContextFactory; +import net.pterodactylus.util.web.Method; +import net.pterodactylus.util.web.Page; +import net.pterodactylus.util.web.RedirectResponse; +import net.pterodactylus.util.web.Response; import freenet.clients.http.LinkEnabledCallback; import freenet.clients.http.PageMaker; import freenet.clients.http.PageNode; @@ -43,7 +47,7 @@ import freenet.support.HTMLNode; * * @author David ‘Bombe’ Roden */ -public class FreenetTemplatePage implements Page, LinkEnabledCallback { +public class FreenetTemplatePage implements Page, LinkEnabledCallback { /** The logger. */ private static final Logger logger = Logging.getLogger(FreenetTemplatePage.class); @@ -95,7 +99,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback { * The request to serve * @return The title of the page */ - protected String getPageTitle(Request request) { + protected String getPageTitle(FreenetRequest request) { return null; } @@ -103,14 +107,22 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback { * {@inheritDoc} */ @Override - public Response handleRequest(Request request) { + public boolean isPrefixPage() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public Response handleRequest(FreenetRequest request, Response response) throws IOException { String redirectTarget = getRedirectTarget(request); if (redirectTarget != null) { return new RedirectResponse(redirectTarget); } if (isFullAccessOnly() && !request.getToadletContext().isAllowedFullAccess()) { - return new Response(401, "Not authorized", "text/html", "Not authorized"); + return response.setStatusCode(401).setStatusText("Not authorized").setContentType("text/html"); } ToadletContext toadletContext = request.getToadletContext(); if (request.getMethod() == Method.POST) { @@ -153,7 +165,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback { postProcess(request, templateContext); - return new Response(200, "OK", "text/html", pageNode.outer.generate()); + return response.setStatusCode(200).setStatusText("OK").setContentType("text/html").write(pageNode.outer.generate()); } /** @@ -186,7 +198,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback { * @throws RedirectException * if the processing page wants to redirect after processing */ - protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { /* do nothing. */ } @@ -203,7 +215,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback { * @param templateContext * The template context that supplied the rendered data */ - protected void postProcess(Request request, TemplateContext templateContext) { + protected void postProcess(FreenetRequest request, TemplateContext templateContext) { /* do nothing. */ } @@ -215,7 +227,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback { * The request that is processed * @return The URL to redirect to, or {@code null} to not redirect */ - protected String getRedirectTarget(Page.Request request) { + protected String getRedirectTarget(FreenetRequest request) { return null; } @@ -226,7 +238,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback { * The request for which to return the link nodes * @return All link nodes that should be added to the HTML head */ - protected List> getAdditionalLinkNodes(Request request) { + protected List> getAdditionalLinkNodes(FreenetRequest request) { return Collections.emptyList(); } diff --git a/src/main/java/net/pterodactylus/sone/web/page/Page.java b/src/main/java/net/pterodactylus/sone/web/page/Page.java deleted file mode 100644 index 297081e..0000000 --- a/src/main/java/net/pterodactylus/sone/web/page/Page.java +++ /dev/null @@ -1,402 +0,0 @@ -/* - * Sone - Page.java - Copyright © 2010 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.web.page; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.util.HashMap; -import java.util.Map; - -import freenet.clients.http.ToadletContext; -import freenet.support.api.HTTPRequest; - -/** - * A page is responsible for handling HTTP requests and creating appropriate - * responses. - * - * @author David ‘Bombe’ Roden - */ -public interface Page { - - /** - * Returns the path of this toadlet. - * - * @return The path of this toadlet - */ - public String getPath(); - - /** - * Handles a request. - * - * @param request - * The request to handle - * @return The response - */ - public Response handleRequest(Request request); - - /** - * Container for request data. - * - * @author David ‘Bombe’ Roden - */ - public class Request { - - /** - * Enumeration for all possible HTTP request methods. - * - * @author David ‘Bombe’ - * Roden - */ - public enum Method { - - /** GET. */ - GET, - - /** POST. */ - POST, - - /** PUT. */ - PUT, - - /** DELETE. */ - DELETE, - - /** HEAD. */ - HEAD, - - /** OPTIONS. */ - OPTIONS, - - /** TRACE. */ - TRACE, - - } - - /** The URI that was accessed. */ - private final URI uri; - - /** The HTTP method that was used. */ - private final Method method; - - /** The HTTP request. */ - private final HTTPRequest httpRequest; - - /** The toadlet context. */ - private final ToadletContext toadletContext; - - /** - * Creates a new request that holds the given data. - * - * @param uri - * The URI of the request - * @param method - * The HTTP method of the request - * @param httpRequest - * The HTTP request - * @param toadletContext - * The toadlet context of the request - */ - public Request(URI uri, Method method, HTTPRequest httpRequest, ToadletContext toadletContext) { - this.uri = uri; - this.method = method; - this.httpRequest = httpRequest; - this.toadletContext = toadletContext; - } - - /** - * Returns the URI that was accessed. - * - * @return The accessed URI - */ - public URI getUri() { - return uri; - } - - /** - * Returns the HTTP method that was used to access the page. - * - * @return The HTTP method - */ - public Method getMethod() { - return method; - } - - /** - * Returns the HTTP request. - * - * @return The HTTP request - */ - public HTTPRequest getHttpRequest() { - return httpRequest; - } - - /** - * Returns the toadlet context. - * - * @return The toadlet context - */ - public ToadletContext getToadletContext() { - return toadletContext; - } - - } - - /** - * Container for the HTTP response of a {@link Page}. - * - * @author David ‘Bombe’ Roden - */ - public class Response { - - /** The HTTP status code of the response. */ - private final int statusCode; - - /** The HTTP status text of the response. */ - private final String statusText; - - /** The content type of the response. */ - private final String contentType; - - /** The headers of the response. */ - private final Map headers; - - /** The content of the response body. */ - private final InputStream content; - - /** - * Creates a new response. - * - * @param statusCode - * The HTTP status code of the response - * @param statusText - * The HTTP status text of the response - * @param contentType - * The content type of the response - * @param text - * The text in the response body - */ - public Response(int statusCode, String statusText, String contentType, String text) { - this(statusCode, statusText, contentType, getBytes(text)); - } - - /** - * Creates a new response. - * - * @param statusCode - * The HTTP status code of the response - * @param statusText - * The HTTP status text of the response - * @param contentType - * The content type of the response - * @param content - * The content of the reponse body - */ - public Response(int statusCode, String statusText, String contentType, byte[] content) { - this(statusCode, statusText, contentType, new HashMap(), content); - } - - /** - * Creates a new response. - * - * @param statusCode - * The HTTP status code of the response - * @param statusText - * The HTTP status text of the response - * @param contentType - * The content type of the response - * @param headers - * The headers of the response - */ - public Response(int statusCode, String statusText, String contentType, Map headers) { - this(statusCode, statusText, contentType, headers, (InputStream) null); - } - - /** - * Creates a new response. - * - * @param statusCode - * The HTTP status code of the response - * @param statusText - * The HTTP status text of the response - * @param contentType - * The content type of the response - * @param headers - * The headers of the response - * @param content - * The content of the reponse body - */ - public Response(int statusCode, String statusText, String contentType, Map headers, byte[] content) { - this(statusCode, statusText, contentType, headers, new ByteArrayInputStream(content)); - } - - /** - * Creates a new response. - * - * @param statusCode - * The HTTP status code of the response - * @param statusText - * The HTTP status text of the response - * @param contentType - * The content type of the response - * @param headers - * The headers of the response - * @param content - * The content of the reponse body - */ - public Response(int statusCode, String statusText, String contentType, Map headers, InputStream content) { - this.statusCode = statusCode; - this.statusText = statusText; - this.contentType = contentType; - this.headers = headers; - this.content = content; - } - - /** - * Returns the HTTP status code of the response. - * - * @return The HTTP status code - */ - public int getStatusCode() { - return statusCode; - } - - /** - * Returns the HTTP status text. - * - * @return The HTTP status text - */ - public String getStatusText() { - return statusText; - } - - /** - * Returns the content type of the response. - * - * @return The content type of the reponse - */ - public String getContentType() { - return contentType; - } - - /** - * Returns HTTP headers of the response. May be {@code null} if no - * headers are returned. - * - * @return The response headers, or {@code null} if there are no - * response headers - */ - public Map getHeaders() { - return headers; - } - - /** - * Sets the HTTP header with the given name to the given value. Multiple - * headers with the same name are not implemented so that latest call to - * {@link #setHeader(String, String)} determines what is sent to the - * browser. - * - * @param name - * The name of the header - * @param value - * The value of the header - */ - public void setHeader(String name, String value) { - headers.put(name, value); - } - - /** - * Returns the content of the response body. May be {@code null} if the - * response does not have a body. - * - * @return The content of the response body - */ - public InputStream getContent() { - return content; - } - - // - // PRIVATE METHODS - // - - /** - * Returns the UTF-8 representation of the given text. - * - * @param text - * The text to encode - * @return The encoded text - */ - private static byte[] getBytes(String text) { - try { - return text.getBytes("UTF-8"); - } catch (UnsupportedEncodingException uee1) { - /* every JVM needs to support UTF-8. */ - } - return null; - } - - /** - * Creates a header map containing a single header. - * - * @param name - * The name of the header - * @param value - * The value of the header - * @return The map containing the single header - */ - protected static Map createHeader(String name, String value) { - Map headers = new HashMap(); - headers.put(name, value); - return headers; - } - - } - - /** - * {@link Response} implementation that performs an HTTP redirect. - * - * @author David ‘Bombe’ Roden - */ - public class RedirectResponse extends Response { - - /** - * Creates a new redirect response to the new location. - * - * @param newLocation - * The new location - */ - public RedirectResponse(String newLocation) { - this(newLocation, true); - } - - /** - * Creates a new redirect response to the new location. - * - * @param newLocation - * The new location - * @param permanent - * Whether the redirect should be marked as permanent - */ - public RedirectResponse(String newLocation, boolean permanent) { - super(permanent ? 302 : 307, "Redirected", null, createHeader("Location", newLocation)); - } - - } - -} diff --git a/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java b/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java index f594e58..ed01294 100644 --- a/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java +++ b/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java @@ -19,9 +19,11 @@ package net.pterodactylus.sone.web.page; import java.io.IOException; import java.net.URI; -import java.util.Map.Entry; -import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.web.Header; +import net.pterodactylus.util.web.Method; +import net.pterodactylus.util.web.Page; +import net.pterodactylus.util.web.Response; import freenet.client.HighLevelSimpleClient; import freenet.clients.http.LinkEnabledCallback; import freenet.clients.http.Toadlet; @@ -30,7 +32,6 @@ import freenet.clients.http.ToadletContextClosedException; import freenet.support.MultiValueTable; import freenet.support.api.Bucket; import freenet.support.api.HTTPRequest; -import freenet.support.io.BucketTools; import freenet.support.io.Closer; /** @@ -44,7 +45,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback { private final String menuName; /** The page that handles processing. */ - private final Page page; + private final Page page; /** The path prefix for the page. */ private final String pathPrefix; @@ -62,7 +63,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback { * Prefix that is prepended to all {@link Page#getPath()} return * values */ - protected PageToadlet(HighLevelSimpleClient highLevelSimpleClient, String menuName, Page page, String pathPrefix) { + protected PageToadlet(HighLevelSimpleClient highLevelSimpleClient, String menuName, Page page, String pathPrefix) { super(highLevelSimpleClient); this.menuName = menuName; this.page = page; @@ -101,7 +102,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback { * if the toadlet context is closed */ public void handleMethodGET(URI uri, HTTPRequest httpRequest, ToadletContext toadletContext) throws IOException, ToadletContextClosedException { - handleRequest(new Page.Request(uri, Method.GET, httpRequest, toadletContext)); + handleRequest(new FreenetRequest(uri, Method.GET, httpRequest, toadletContext)); } /** @@ -119,7 +120,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback { * if the toadlet context is closed */ public void handleMethodPOST(URI uri, HTTPRequest httpRequest, ToadletContext toadletContext) throws IOException, ToadletContextClosedException { - handleRequest(new Page.Request(uri, Method.POST, httpRequest, toadletContext)); + handleRequest(new FreenetRequest(uri, Method.POST, httpRequest, toadletContext)); } /** @@ -140,32 +141,25 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback { * @throws ToadletContextClosedException * if the toadlet context is closed */ - private void handleRequest(Page.Request pageRequest) throws IOException, ToadletContextClosedException { - Bucket data = null; + private void handleRequest(FreenetRequest pageRequest) throws IOException, ToadletContextClosedException { + Bucket pageBucket = null; try { - Page.Response pageResponse = page.handleRequest(pageRequest); + pageBucket = pageRequest.getToadletContext().getBucketFactory().makeBucket(-1); + Response pageResponse = new Response(pageBucket.getOutputStream()); + page.handleRequest(pageRequest, pageResponse); MultiValueTable headers = new MultiValueTable(); if (pageResponse.getHeaders() != null) { - for (Entry headerEntry : pageResponse.getHeaders().entrySet()) { - headers.put(headerEntry.getKey(), headerEntry.getValue()); + for (Header header : pageResponse.getHeaders()) { + for (String value : header) { + headers.put(header.getName(), value); + } } } - data = pageRequest.getToadletContext().getBucketFactory().makeBucket(-1); - if (pageResponse.getContent() != null) { - try { - BucketTools.copyFrom(data, pageResponse.getContent(), -1); - } finally { - Closer.close(pageResponse.getContent()); - } - } else { - /* get an OutputStream and close it immediately. */ - Closer.close(data.getOutputStream()); - } - writeReply(pageRequest.getToadletContext(), pageResponse.getStatusCode(), pageResponse.getContentType(), pageResponse.getStatusText(), headers, data); + writeReply(pageRequest.getToadletContext(), pageResponse.getStatusCode(), pageResponse.getContentType(), pageResponse.getStatusText(), headers, pageBucket); } catch (Throwable t1) { writeInternalError(t1, pageRequest.getToadletContext()); } finally { - Closer.close(data); + Closer.close(pageBucket); } } diff --git a/src/main/java/net/pterodactylus/sone/web/page/PageToadletFactory.java b/src/main/java/net/pterodactylus/sone/web/page/PageToadletFactory.java index bd0adb9..e788039 100644 --- a/src/main/java/net/pterodactylus/sone/web/page/PageToadletFactory.java +++ b/src/main/java/net/pterodactylus/sone/web/page/PageToadletFactory.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web.page; +import net.pterodactylus.util.web.Page; import freenet.client.HighLevelSimpleClient; /** @@ -54,7 +55,7 @@ public class PageToadletFactory { * The page to wrap * @return The toadlet wrapped around the page */ - public PageToadlet createPageToadlet(Page page) { + public PageToadlet createPageToadlet(Page page) { return createPageToadlet(page, null); } @@ -68,7 +69,7 @@ public class PageToadletFactory { * The name of the menu item * @return The toadlet wrapped around the page */ - public PageToadlet createPageToadlet(Page page, String menuName) { + public PageToadlet createPageToadlet(Page page, String menuName) { return new PageToadlet(highLevelSimpleClient, menuName, page, pathPrefix); } diff --git a/src/main/java/net/pterodactylus/sone/web/page/RedirectPage.java b/src/main/java/net/pterodactylus/sone/web/page/RedirectPage.java deleted file mode 100644 index 2ce34f9..0000000 --- a/src/main/java/net/pterodactylus/sone/web/page/RedirectPage.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Sone - RedirectPage.java - Copyright © 2011 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.web.page; - -/** - * Page implementation that redirects the user to another URL. - * - * @author David ‘Bombe’ Roden - */ -public class RedirectPage implements Page { - - /** The original path. */ - private String originalPath; - - /** The path to redirect the browser to. */ - private String newPath; - - /** - * Creates a new redirect page. - * - * @param originalPath - * The original path - * @param newPath - * The path to redirect the browser to - */ - public RedirectPage(String originalPath, String newPath) { - this.originalPath = originalPath; - this.newPath = newPath; - } - - /** - * {@inheritDoc} - */ - @Override - public String getPath() { - return originalPath; - } - - /** - * {@inheritDoc} - */ - @Override - public Response handleRequest(Request request) { - return new RedirectResponse(newPath); - } - -} diff --git a/src/main/java/net/pterodactylus/sone/web/page/StaticPage.java b/src/main/java/net/pterodactylus/sone/web/page/StaticPage.java deleted file mode 100644 index 3d24fdd..0000000 --- a/src/main/java/net/pterodactylus/sone/web/page/StaticPage.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Sone - StaticPage.java - Copyright © 2010 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.web.page; - -import java.io.InputStream; - -/** - * {@link Page} implementation that delivers static files from the class path. - * - * @author David ‘Bombe’ Roden - */ -public class StaticPage implements Page { - - /** The prefix for {@link #getPath()}. */ - private final String pathPrefix; - - /** The path used as prefix when loading resources. */ - private final String resourcePathPrefix; - - /** The MIME type for the files this path contains. */ - private final String mimeType; - - /** - * Creates a new CSS page. - * - * @param pathPrefix - * The prefix for {@link #getPath()} - * @param resourcePathPrefix - * The path prefix when loading resources - * @param mimeType - * The MIME type of the files this path contains - */ - public StaticPage(String pathPrefix, String resourcePathPrefix, String mimeType) { - this.pathPrefix = pathPrefix; - this.resourcePathPrefix = resourcePathPrefix; - this.mimeType = mimeType; - } - - /** - * {@inheritDoc} - */ - @Override - public String getPath() { - return pathPrefix; - } - - /** - * {@inheritDoc} - */ - @Override - public Response handleRequest(Request request) { - String path = request.getUri().getPath(); - int lastSlash = path.lastIndexOf('/'); - String filename = path.substring(lastSlash + 1); - InputStream fileInputStream = getClass().getResourceAsStream(resourcePathPrefix + filename); - if (fileInputStream == null) { - return new Response(404, "Not found.", null, ""); - } - return new Response(200, "OK", mimeType, null, fileInputStream); - } - -} diff --git a/src/main/java/net/pterodactylus/sone/web/page/TemplatePage.java b/src/main/java/net/pterodactylus/sone/web/page/TemplatePage.java deleted file mode 100644 index 06fc9fc..0000000 --- a/src/main/java/net/pterodactylus/sone/web/page/TemplatePage.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Sone - StaticTemplatePage.java - Copyright © 2011 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.web.page; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.logging.Level; -import java.util.logging.Logger; - -import net.pterodactylus.util.io.Closer; -import net.pterodactylus.util.logging.Logging; -import net.pterodactylus.util.template.Template; -import net.pterodactylus.util.template.TemplateContext; -import net.pterodactylus.util.template.TemplateContextFactory; - -/** - * A template page is a single page that is created from a {@link Template} but - * does not necessarily return HTML. - * - * @author David ‘Bombe’ Roden - */ -public class TemplatePage implements Page { - - /** The logger. */ - private static final Logger logger = Logging.getLogger(TemplatePage.class); - - /** The path of this page. */ - private final String path; - - /** The content type of this page. */ - private final String contentType; - - /** The template context factory. */ - private final TemplateContextFactory templateContextFactory; - - /** The template to render. */ - private final Template template; - - /** - * Creates a new template page. - * - * @param path - * The path of the page - * @param contentType - * The content type of the page - * @param templateContextFactory - * The template context factory - * @param template - * The template to render - */ - public TemplatePage(String path, String contentType, TemplateContextFactory templateContextFactory, Template template) { - this.path = path; - this.contentType = contentType; - this.templateContextFactory = templateContextFactory; - this.template = template; - } - - /** - * {@inheritDoc} - */ - @Override - public String getPath() { - return path; - } - - /** - * {@inheritDoc} - */ - @Override - public Response handleRequest(Request request) { - ByteArrayOutputStream responseOutputStream = new ByteArrayOutputStream(); - OutputStreamWriter responseWriter = null; - try { - responseWriter = new OutputStreamWriter(responseOutputStream, "UTF-8"); - TemplateContext templateContext = templateContextFactory.createTemplateContext(); - templateContext.set("request", request); - template.render(templateContext, responseWriter); - } catch (IOException ioe1) { - logger.log(Level.WARNING, "Could not render template for path “" + path + "”!", ioe1); - } finally { - Closer.close(responseWriter); - Closer.close(responseOutputStream); - } - ByteArrayInputStream responseInputStream = new ByteArrayInputStream(responseOutputStream.toByteArray()); - /* no need to close a ByteArrayInputStream. */ - return new Response(200, "OK", contentType, null, responseInputStream); - } - -}