From 9022be629f86cd0d85477c65dbd6a8085c48a4d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 23 Oct 2010 13:23:08 +0200 Subject: [PATCH] Use a more general way to like something. --- .../java/net/pterodactylus/sone/web/LikePage.java | 80 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/LikePostPage.java | 76 -------------------- .../net/pterodactylus/sone/web/UnlikePage.java | 80 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/UnlikePostPage.java | 75 -------------------- .../net/pterodactylus/sone/web/WebInterface.java | 8 +-- src/main/resources/templates/include/viewPost.html | 6 +- src/main/resources/templates/like.html | 3 + src/main/resources/templates/likePost.html | 3 - src/main/resources/templates/unlike.html | 3 + src/main/resources/templates/unlikePost.html | 3 - 10 files changed, 174 insertions(+), 163 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/web/LikePage.java delete mode 100644 src/main/java/net/pterodactylus/sone/web/LikePostPage.java create mode 100644 src/main/java/net/pterodactylus/sone/web/UnlikePage.java delete mode 100644 src/main/java/net/pterodactylus/sone/web/UnlikePostPage.java create mode 100644 src/main/resources/templates/like.html delete mode 100644 src/main/resources/templates/likePost.html create mode 100644 src/main/resources/templates/unlike.html delete mode 100644 src/main/resources/templates/unlikePost.html diff --git a/src/main/java/net/pterodactylus/sone/web/LikePage.java b/src/main/java/net/pterodactylus/sone/web/LikePage.java new file mode 100644 index 0000000..e9d79ba --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/LikePage.java @@ -0,0 +1,80 @@ +/* + * Sone - LikePage.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; + +import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.Template; + +/** + * Page that lets the user like a {@link Post}. + * + * @author David ‘Bombe’ Roden + */ +public class LikePage extends SoneTemplatePage { + + /** + * Creates a new “like post” page. + * + * @param template + * The template to render + * @param webInterface + * The Sone web interface + */ + public LikePage(Template template, WebInterface webInterface) { + super("like.html", template, "Page.LikePost.Title", webInterface); + } + + // + // TEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected void processTemplate(Request request, Template template) throws RedirectException { + super.processTemplate(request, template); + if (request.getMethod() == Method.POST) { + String type=request.getHttpRequest().getPartAsStringFailsafe("type", 16); + String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36); + String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64); + Sone currentSone = getCurrentSone(request.getToadletContext()); + if ("post".equals(type)) { + currentSone.addLikedPostId(id); + } else if ("reply".equals(type)) { + currentSone.addLikedReplyId(id); + } + throw new RedirectException(returnPage); + } + } + + // + // SONETEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected boolean requiresLogin() { + return true; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/LikePostPage.java b/src/main/java/net/pterodactylus/sone/web/LikePostPage.java deleted file mode 100644 index 991627e..0000000 --- a/src/main/java/net/pterodactylus/sone/web/LikePostPage.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Sone - LikePostPage.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; - -import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; -import net.pterodactylus.util.template.Template; - -/** - * Page that lets the user like a {@link Post}. - * - * @author David ‘Bombe’ Roden - */ -public class LikePostPage extends SoneTemplatePage { - - /** - * Creates a new “like post” page. - * - * @param template - * The template to render - * @param webInterface - * The Sone web interface - */ - public LikePostPage(Template template, WebInterface webInterface) { - /* TODO */ - super("likePost.html", template, "Page.LikePost.Title", webInterface); - } - - // - // TEMPLATEPAGE METHODS - // - - /** - * {@inheritDoc} - */ - @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); - if (request.getMethod() == Method.POST) { - String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36); - String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64); - Sone currentSone = getCurrentSone(request.getToadletContext()); - currentSone.addLikedPostId(postId); - throw new RedirectException(returnPage); - } - } - - // - // SONETEMPLATEPAGE METHODS - // - - /** - * {@inheritDoc} - */ - @Override - protected boolean requiresLogin() { - return true; - } - -} diff --git a/src/main/java/net/pterodactylus/sone/web/UnlikePage.java b/src/main/java/net/pterodactylus/sone/web/UnlikePage.java new file mode 100644 index 0000000..bedf759 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/UnlikePage.java @@ -0,0 +1,80 @@ +/* + * Sone - UnlikePage.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; + +import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.web.page.Page.Request.Method; +import net.pterodactylus.util.template.Template; + +/** + * Page that lets the user unlike a {@link Post}. + * + * @author David ‘Bombe’ Roden + */ +public class UnlikePage extends SoneTemplatePage { + + /** + * Creates a new “unlike post” page. + * + * @param template + * The template to render + * @param webInterface + * The Sone web interface + */ + public UnlikePage(Template template, WebInterface webInterface) { + super("unlike.html", template, "Page.UnlikePost.Title", webInterface); + } + + // + // TEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected void processTemplate(Request request, Template template) throws RedirectException { + super.processTemplate(request, template); + if (request.getMethod() == Method.POST) { + String type = request.getHttpRequest().getPartAsStringFailsafe("type", 16); + String id = request.getHttpRequest().getPartAsStringFailsafe(type, 36); + String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64); + Sone currentSone = getCurrentSone(request.getToadletContext()); + if ("post".equals(type)) { + currentSone.removeLikedPostId(id); + } else if ("reply".equals(type)) { + currentSone.removeLikedReplyId(id); + } + throw new RedirectException(returnPage); + } + } + + // + // SONETEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected boolean requiresLogin() { + return true; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/UnlikePostPage.java b/src/main/java/net/pterodactylus/sone/web/UnlikePostPage.java deleted file mode 100644 index b325b5e..0000000 --- a/src/main/java/net/pterodactylus/sone/web/UnlikePostPage.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Sone - UnlikePostPage.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; - -import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.web.page.Page.Request.Method; -import net.pterodactylus.util.template.Template; - -/** - * Page that lets the user unlike a {@link Post}. - * - * @author David ‘Bombe’ Roden - */ -public class UnlikePostPage extends SoneTemplatePage { - - /** - * Creates a new “unlike post” page. - * - * @param template - * The template to render - * @param webInterface - * The Sone web interface - */ - public UnlikePostPage(Template template, WebInterface webInterface) { - super("unlikePost.html", template, "Page.UnlikePost.Title", webInterface); - } - - // - // TEMPLATEPAGE METHODS - // - - /** - * {@inheritDoc} - */ - @Override - protected void processTemplate(Request request, Template template) throws RedirectException { - super.processTemplate(request, template); - if (request.getMethod() == Method.POST) { - String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36); - String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64); - Sone currentSone = getCurrentSone(request.getToadletContext()); - currentSone.removeLikedPostId(postId); - throw new RedirectException(returnPage); - } - } - - // - // SONETEMPLATEPAGE METHODS - // - - /** - * {@inheritDoc} - */ - @Override - protected boolean requiresLogin() { - return true; - } - -} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index bb7f740..d809580 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -202,8 +202,8 @@ public class WebInterface extends AbstractService { Template blockSoneTemplate = templateFactory.createTemplate(createReader("/templates/blockSone.html")); Template unblockSoneTemplate = templateFactory.createTemplate(createReader("/templates/unblockSone.html")); Template viewPostTemplate = templateFactory.createTemplate(createReader("/templates/viewPost.html")); - Template likePostTemplate = templateFactory.createTemplate(createReader("/templates/likePost.html")); - Template unlikePostTemplate = templateFactory.createTemplate(createReader("/templates/unlikePost.html")); + Template likePostTemplate = templateFactory.createTemplate(createReader("/templates/like.html")); + Template unlikePostTemplate = templateFactory.createTemplate(createReader("/templates/unlike.html")); Template deletePostTemplate = templateFactory.createTemplate(createReader("/templates/deletePost.html")); Template deleteReplyTemplate = templateFactory.createTemplate(createReader("/templates/deleteReply.html")); Template followSoneTemplate = templateFactory.createTemplate(createReader("/templates/followSone.html")); @@ -226,8 +226,8 @@ public class WebInterface extends AbstractService { pageToadlets.add(pageToadletFactory.createPageToadlet(new BlockSonePage(blockSoneTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new UnblockSonePage(unblockSoneTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePostPage(likePostTemplate, this))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePostPage(unlikePostTemplate, this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new LikePage(likePostTemplate, this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePage(unlikePostTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(followSoneTemplate, this))); diff --git a/src/main/resources/templates/include/viewPost.html b/src/main/resources/templates/include/viewPost.html index 991ccec..d212c39 100644 --- a/src/main/resources/templates/include/viewPost.html +++ b/src/main/resources/templates/include/viewPost.html @@ -7,15 +7,17 @@
⬆
<%ifnull ! currentSone> -
+ +
-
+ +
diff --git a/src/main/resources/templates/like.html b/src/main/resources/templates/like.html new file mode 100644 index 0000000..196af72 --- /dev/null +++ b/src/main/resources/templates/like.html @@ -0,0 +1,3 @@ +<%include include/head.html> + +<%include include/tail.html> diff --git a/src/main/resources/templates/likePost.html b/src/main/resources/templates/likePost.html deleted file mode 100644 index 196af72..0000000 --- a/src/main/resources/templates/likePost.html +++ /dev/null @@ -1,3 +0,0 @@ -<%include include/head.html> - -<%include include/tail.html> diff --git a/src/main/resources/templates/unlike.html b/src/main/resources/templates/unlike.html new file mode 100644 index 0000000..196af72 --- /dev/null +++ b/src/main/resources/templates/unlike.html @@ -0,0 +1,3 @@ +<%include include/head.html> + +<%include include/tail.html> diff --git a/src/main/resources/templates/unlikePost.html b/src/main/resources/templates/unlikePost.html deleted file mode 100644 index 196af72..0000000 --- a/src/main/resources/templates/unlikePost.html +++ /dev/null @@ -1,3 +0,0 @@ -<%include include/head.html> - -<%include include/tail.html> -- 2.7.4