checkState(!sone.isPresent() || (ImageImpl.this.sone == null) || sone.get().equals(ImageImpl.this.sone), "can not change Sone once set");
checkState(!creationTime.isPresent() || ((ImageImpl.this.creationTime == 0) || (ImageImpl.this.creationTime == creationTime.get())), "can not change creation time once set");
checkState(!key.isPresent() || (ImageImpl.this.key == null) || key.get().equals(ImageImpl.this.key), "can not change key once set");
+ if (title.isPresent() && title.get().trim().isEmpty()) {
+ throw new ImageTitleMustNotBeEmpty();
+ }
checkState(!width.isPresent() || (ImageImpl.this.width == 0) || width.get().equals(ImageImpl.this.width), "can not change width once set");
checkState(!height.isPresent() || (ImageImpl.this.height == 0) || height.get().equals(ImageImpl.this.height), "can not change height once set");
};
}
+ public static class ImageTitleMustNotBeEmpty extends IllegalStateException { }
+
//
// FINGERPRINTABLE METHODS
//
String title = request.getHttpRequest().getPartAsStringFailsafe("title", 100).trim();
String description = request.getHttpRequest().getPartAsStringFailsafe("description", 1024).trim();
if (title.length() == 0) {
- templateContext.set("titleMissing", true);
+ throw new RedirectException("emptyImageTitle.html");
}
image.modify().setTitle(title).setDescription(TextFilter.filter(request.getHttpRequest().getHeader("host"), description)).update();
}
import javax.imageio.stream.ImageInputStream;
import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.ImageImpl.ImageTitleMustNotBeEmpty;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.TemporaryImage;
import net.pterodactylus.sone.text.TextFilter;
} catch (IOException ioe1) {
logger.log(Level.WARNING, "Could not read uploaded image!", ioe1);
return;
+ } catch (ImageTitleMustNotBeEmpty itmnbe) {
+ throw new RedirectException("emptyImageTitle.html");
} finally {
Closer.close(imageDataInputStream);
Closer.flush(uploadedImage);
Template deleteAlbumTemplate = parseTemplate("/templates/deleteAlbum.html");
Template deleteImageTemplate = parseTemplate("/templates/deleteImage.html");
Template noPermissionTemplate = parseTemplate("/templates/noPermission.html");
+ Template emptyImageTitleTemplate = parseTemplate("/templates/emptyImageTitle.html");
Template optionsTemplate = parseTemplate("/templates/options.html");
Template rescueTemplate = parseTemplate("/templates/rescue.html");
Template aboutTemplate = parseTemplate("/templates/about.html");
pageToadlets.add(pageToadletFactory.createPageToadlet(new RescuePage(rescueTemplate, this), "Rescue"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new AboutPage(aboutTemplate, this, SonePlugin.VERSION), "About"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("emptyImageTitle.html", emptyImageTitleTemplate, "Page.EmptyImageTitle.Title", this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationPage(emptyTemplate, this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("invalid.html", invalidTemplate, "Page.Invalid.Title", this)));
pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage<FreenetRequest>("css/", "/static/css/", "text/css")));
Page.NoPermission.Page.Title=Unauthorized Access
Page.NoPermission.Text.NoPermission=You tried to do something that you do not have sufficient authorization for. Please refrain from such actions in the future or we will be forced to take counter-measures!
+Page.EmptyImageTitle.Title=Title Must Not Be Empty - Sone
+Page.EmptyImageTitle.Page.Title=Title Must Not Be Empty
+Page.EmptyImageTitle.Text.EmptyImageTitle=You have to give your image a title. Please go back to the previous page and enter a title.
+
Page.DismissNotification.Title=Dismiss Notification - Sone
Page.WotPluginMissing.Text.WotRequired=Because the Web of Trust is an integral part of Sone, the Web of Trust plugin has to be loaded in order to run Sone.
--- /dev/null
+<%include include/head.html>
+
+ <h1><%= Page.EmptyImageTitle.Page.Title|l10n|html></h1>
+
+ <p><%= Page.EmptyImageTitle.Text.EmptyImageTitle|l10n|html></p>
+
+<%include include/tail.html>
--- /dev/null
+package net.pterodactylus.sone.data;
+
+import net.pterodactylus.sone.data.ImageImpl.ImageTitleMustNotBeEmpty;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link ImageImpl}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ImageImplTest {
+
+ private final Image image = new ImageImpl();
+
+ @Test(expected = ImageTitleMustNotBeEmpty.class)
+ public void modifierDoesNotAllowTitleDoBeEmpty() {
+ image.modify().setTitle("").update();
+ }
+
+}