Show an error message if an image can not be parsed.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 25 Mar 2011 23:32:37 +0000 (00:32 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 25 Mar 2011 23:32:37 +0000 (00:32 +0100)
src/main/java/net/pterodactylus/sone/web/UploadImagePage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/i18n/sone.en.properties

index 2b25263..17538a6 100644 (file)
@@ -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));
index 09e3dcd..eedba4d 100644 (file)
@@ -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)));
index 4db1a07..b146e68 100644 (file)
@@ -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