Merge branch 'release-0.7.3'
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ImageBrowserPage.java
1 /*
2  * Sone - ImageBrowserPage.java - Copyright © 2011 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.web;
19
20 import java.net.URI;
21 import java.util.HashSet;
22 import java.util.Set;
23
24 import net.pterodactylus.sone.data.Album;
25 import net.pterodactylus.sone.data.Image;
26 import net.pterodactylus.sone.data.Sone;
27 import net.pterodactylus.sone.web.page.FreenetRequest;
28 import net.pterodactylus.util.template.Template;
29 import net.pterodactylus.util.template.TemplateContext;
30
31 /**
32  * The image browser page is the entry page for the image management.
33  *
34  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
35  */
36 public class ImageBrowserPage extends SoneTemplatePage {
37
38         /**
39          * Creates a new image browser page.
40          *
41          * @param template
42          *            The template to render
43          * @param webInterface
44          *            The Sone web interface
45          */
46         public ImageBrowserPage(Template template, WebInterface webInterface) {
47                 super("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, true);
48         }
49
50         //
51         // SONETEMPLATEPAGE METHODS
52         //
53
54         /**
55          * {@inheritDoc}
56          */
57         @Override
58         protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
59                 super.processTemplate(request, templateContext);
60                 String albumId = request.getHttpRequest().getParam("album", null);
61                 if (albumId != null) {
62                         Album album = webInterface.getCore().getAlbum(albumId, false);
63                         templateContext.set("albumRequested", true);
64                         templateContext.set("album", album);
65                         return;
66                 }
67                 String imageId = request.getHttpRequest().getParam("image", null);
68                 if (imageId != null) {
69                         Image image = webInterface.getCore().getImage(imageId, false);
70                         templateContext.set("imageRequested", true);
71                         templateContext.set("image", image);
72                         return;
73                 }
74                 String soneId = request.getHttpRequest().getParam("sone", null);
75                 if (soneId != null) {
76                         Sone sone = webInterface.getCore().getSone(soneId, false);
77                         templateContext.set("soneRequested", true);
78                         templateContext.set("sone", sone);
79                         return;
80                 }
81                 String mode = request.getHttpRequest().getParam("mode", null);
82                 if ("gallery".equals(mode)) {
83                         templateContext.set("galleryRequested", true);
84                         Set<Album> albums = new HashSet<Album>();
85                         for (Sone sone : webInterface.getCore().getSones()) {
86                                 albums.addAll(sone.getAllAlbums());
87                         }
88                         templateContext.set("albums", albums);
89                         return;
90                 }
91                 Sone sone = getCurrentSone(request.getToadletContext(), false);
92                 templateContext.set("soneRequested", true);
93                 templateContext.set("sone", sone);
94         }
95
96         /**
97          * {@inheritDoc}
98          */
99         @Override
100         public boolean isLinkExcepted(URI link) {
101                 return true;
102         }
103
104 }