Add page that delivers the encoded data of a temporary image.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 10 Apr 2011 18:16:25 +0000 (20:16 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Apr 2011 04:41:04 +0000 (06:41 +0200)
src/main/java/net/pterodactylus/sone/web/GetImagePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java

diff --git a/src/main/java/net/pterodactylus/sone/web/GetImagePage.java b/src/main/java/net/pterodactylus/sone/web/GetImagePage.java
new file mode 100644 (file)
index 0000000..fdd72a8
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Sone - GetImagePage.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web;
+
+import net.pterodactylus.sone.data.TemporaryImage;
+import net.pterodactylus.sone.web.page.Page;
+
+/**
+ * Page that delivers a {@link TemporaryImage} to the browser.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class GetImagePage implements Page {
+
+       /** The Sone web interface. */
+       private final WebInterface webInterface;
+
+       /**
+        * Creates a new “get image” page.
+        *
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public GetImagePage(WebInterface webInterface) {
+               this.webInterface = webInterface;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public String getPath() {
+               return "getImage.html";
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public Response handleRequest(Request request) {
+               String imageId = request.getHttpRequest().getParam("image");
+               TemporaryImage temporaryImage = webInterface.getCore().getTemporaryImage(imageId);
+               if (temporaryImage == null) {
+                       return new Response(404, "Not found.", "text/plain; charset=utf-8", "");
+               }
+               return new Response(200, "OK", temporaryImage.getMimeType(), temporaryImage.getImageData()).setHeader("Content-Disposition", "attachment; filename=" + temporaryImage.getId() + "." + temporaryImage.getMimeType().substring(temporaryImage.getMimeType().lastIndexOf("/") + 1));
+       }
+
+}
index 5a16f8c..5b1ae6c 100644 (file)
@@ -583,6 +583,8 @@ public class WebInterface implements CoreListener {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css")));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript")));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png")));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new TemplatePage("OpenSearch.xml", "application/opensearchdescription+xml", templateContextFactory, openSearchTemplate)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new GetImagePage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));