2 * Sone - ImageBrowserPage.java - Copyright © 2011–2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.web;
20 import static com.google.common.collect.FluentIterable.from;
21 import static net.pterodactylus.sone.data.Album.FLATTENER;
22 import static net.pterodactylus.sone.data.Album.NOT_EMPTY;
23 import static net.pterodactylus.sone.data.Album.TITLE_COMPARATOR;
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.List;
30 import net.pterodactylus.sone.data.Album;
31 import net.pterodactylus.sone.data.Image;
32 import net.pterodactylus.sone.data.Sone;
33 import net.pterodactylus.sone.web.page.FreenetRequest;
34 import net.pterodactylus.util.collection.Pagination;
35 import net.pterodactylus.util.number.Numbers;
36 import net.pterodactylus.util.template.Template;
37 import net.pterodactylus.util.template.TemplateContext;
39 import com.google.common.base.Optional;
42 * The image browser page is the entry page for the image management.
44 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
46 public class ImageBrowserPage extends SoneTemplatePage {
49 * Creates a new image browser page.
52 * The template to render
54 * The Sone web interface
56 public ImageBrowserPage(Template template, WebInterface webInterface) {
57 super("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, true);
61 // SONETEMPLATEPAGE METHODS
65 protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
66 super.processTemplate(request, templateContext);
67 String albumId = request.getHttpRequest().getParam("album", null);
68 if (albumId != null) {
69 Optional<Album> album = webInterface.getCore().getAlbum(albumId);
70 templateContext.set("albumRequested", true);
71 templateContext.set("album", album.orNull());
72 templateContext.set("page", request.getHttpRequest().getParam("page"));
75 String imageId = request.getHttpRequest().getParam("image", null);
76 if (imageId != null) {
77 Optional<Image> image = webInterface.getCore().getImage(imageId);
78 templateContext.set("imageRequested", true);
79 templateContext.set("image", image.orNull());
82 String soneId = request.getHttpRequest().getParam("sone", null);
84 Optional<Sone> sone = webInterface.getCore().getSone(soneId);
85 templateContext.set("soneRequested", true);
86 templateContext.set("sone", sone.orNull());
89 String mode = request.getHttpRequest().getParam("mode", null);
90 if ("gallery".equals(mode)) {
91 templateContext.set("galleryRequested", true);
92 List<Album> albums = new ArrayList<Album>();
93 for (Sone sone : webInterface.getCore().getSones()) {
94 albums.addAll(from(sone.getRootAlbum().getAlbums()).transformAndConcat(FLATTENER).filter(NOT_EMPTY).toList());
96 Collections.sort(albums, TITLE_COMPARATOR);
97 Pagination<Album> albumPagination = new Pagination<Album>(albums, 12).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
98 templateContext.set("albumPagination", albumPagination);
99 templateContext.set("albums", albumPagination.getItems());
102 Sone sone = getCurrentSone(request.getToadletContext(), false);
103 templateContext.set("soneRequested", true);
104 templateContext.set("sone", sone);
108 public boolean isLinkExcepted(URI link) {