X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FBookmarksPage.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FBookmarksPage.java;h=d8a18c8e77d58aeb5ce0b08746acdc3f35044389;hb=d34cc2c44a2fb19104988534504f2a96a9f0cb93;hp=0000000000000000000000000000000000000000;hpb=8dea6187151fc392e6274cbca27157f0effafd35;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java new file mode 100644 index 0000000..d8a18c8 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/BookmarksPage.java @@ -0,0 +1,68 @@ +/* + * Sone - BookmarksPage.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; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import net.pterodactylus.sone.data.Post; +import net.pterodactylus.util.collection.Pagination; +import net.pterodactylus.util.number.Numbers; +import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; + +/** + * Page that lets the user browse all his bookmarked posts. + * + * @author David ‘Bombe’ Roden + */ +public class BookmarksPage extends SoneTemplatePage { + + /** + * Creates a new bookmarks page. + * + * @param template + * The template to render + * @param webInterface + * The Sone web interface + */ + public BookmarksPage(Template template, WebInterface webInterface) { + super("bookmarks.html", template, "Page.Bookmarks.Title", webInterface); + } + + // + // SONETEMPLATEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException { + super.processTemplate(request, templateContext); + Set posts = webInterface.getCore().getBookmarkedPosts(); + List sortedPosts = new ArrayList(posts); + Collections.sort(sortedPosts, Post.TIME_COMPARATOR); + Pagination pagination = new Pagination(sortedPosts, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0)); + templateContext.set("pagination", pagination); + templateContext.set("posts", pagination.getItems()); + } + +}