Allow links to images, Sones, and posts.
[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
22 import net.pterodactylus.sone.data.Album;
23 import net.pterodactylus.sone.data.Image;
24 import net.pterodactylus.sone.data.Sone;
25 import net.pterodactylus.sone.web.page.FreenetRequest;
26 import net.pterodactylus.util.template.Template;
27 import net.pterodactylus.util.template.TemplateContext;
28
29 /**
30  * The image browser page is the entry page for the image management.
31  *
32  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33  */
34 public class ImageBrowserPage extends SoneTemplatePage {
35
36         /**
37          * Creates a new image browser page.
38          *
39          * @param template
40          *            The template to render
41          * @param webInterface
42          *            The Sone web interface
43          */
44         public ImageBrowserPage(Template template, WebInterface webInterface) {
45                 super("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, true);
46         }
47
48         //
49         // SONETEMPLATEPAGE METHODS
50         //
51
52         /**
53          * {@inheritDoc}
54          */
55         @Override
56         protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
57                 super.processTemplate(request, templateContext);
58                 String albumId = request.getHttpRequest().getParam("album", null);
59                 if (albumId != null) {
60                         Album album = webInterface.getCore().getAlbum(albumId, false);
61                         templateContext.set("albumRequested", true);
62                         templateContext.set("album", album);
63                         return;
64                 }
65                 String imageId = request.getHttpRequest().getParam("image", null);
66                 if (imageId != null) {
67                         Image image = webInterface.getCore().getImage(imageId, false);
68                         templateContext.set("imageRequested", true);
69                         templateContext.set("image", image);
70                         return;
71                 }
72                 Sone sone = getCurrentSone(request.getToadletContext(), false);
73                 String soneId = request.getHttpRequest().getParam("sone", null);
74                 if (soneId != null) {
75                         sone = webInterface.getCore().getSone(soneId, false);
76                 }
77                 templateContext.set("soneRequested", true);
78                 templateContext.set("sone", sone);
79         }
80
81         /**
82          * {@inheritDoc}
83          */
84         @Override
85         public boolean isLinkExcepted(URI link) {
86                 return true;
87         }
88
89 }