From 7b2db06359747ae9638fe4d32c19efe54b62eb78 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 26 Mar 2011 00:32:37 +0100 Subject: [PATCH] Show an error message if an image can not be parsed. --- src/main/java/net/pterodactylus/sone/web/UploadImagePage.java | 3 ++- src/main/java/net/pterodactylus/sone/web/WebInterface.java | 2 +- src/main/resources/i18n/sone.en.properties | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java b/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java index 2b25263..17538a6 100644 --- a/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java +++ b/src/main/java/net/pterodactylus/sone/web/UploadImagePage.java @@ -82,7 +82,8 @@ public class UploadImagePage extends SoneTemplatePage { imageInputStream = fileBucket.getInputStream(); Image uploadedImage = ImageIO.read(imageInputStream); if (uploadedImage == null) { - throw new RedirectException("invalid.html"); + templateContext.set("messages", webInterface.getL10n().getString("Page.UploadImage.Error.InvalidImage")); + return; } image = new net.pterodactylus.sone.data.Image().setSone(currentSone); image.setTitle(name).setDescription(description).setWidth(uploadedImage.getWidth(null)).setHeight(uploadedImage.getHeight(null)); diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 09e3dcd..eedba4d 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -564,7 +564,7 @@ public class WebInterface implements CoreListener { pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSonePage(emptyTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new ImageBrowserPage(imageBrowserTemplate, this), "ImageBrowser")); pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateAlbumPage(createAlbumTemplate, this))); - pageToadlets.add(pageToadletFactory.createPageToadlet(new UploadImagePage(emptyTemplate, this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new UploadImagePage(invalidTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new TrustPage(emptyTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DistrustPage(emptyTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new UntrustPage(emptyTemplate, this))); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 4db1a07..b146e68 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -168,6 +168,7 @@ Page.CreateAlbum.Page.Title=Create Album Page.CreateAlbum.Error.NameMissing=You seem to have forgotten to enter a name for your new album. Page.UploadImage.Title=Upload Image - Sone +Page.UploadImage.Error.InvalidImage=The image you were trying to upload could not be recognized. Please upload only JPEG (*.jpg or *.jpeg), or PNG (*.png) images. Page.Trust.Title=Trust Sone - Sone -- 2.7.4