X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FWebInterface.java;h=9fe5bba2944474a66c2b9a08451a80e241889bfb;hp=f21d256df885eabea60e23c072b270de600a2acf;hb=0e8f7804ce344bdd69f5ecc7febe25a60a53561d;hpb=aa676316c57d76a22efb98a2be2851202f906108 diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index f21d256..9fe5bba 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.web; +import static java.util.logging.Logger.getLogger; import static net.pterodactylus.util.template.TemplateParser.parse; import java.io.IOException; @@ -128,7 +129,6 @@ import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.sone.web.page.PageToadlet; import net.pterodactylus.sone.web.page.PageToadletFactory; import net.pterodactylus.util.io.Closer; -import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.notify.Notification; import net.pterodactylus.util.notify.NotificationManager; import net.pterodactylus.util.notify.TemplateNotification; @@ -173,7 +173,7 @@ import freenet.support.api.HTTPRequest; public class WebInterface { /** The logger. */ - private static final Logger logger = Logging.getLogger(WebInterface.class); + private static final Logger logger = getLogger("Sone.Web.Main"); /** The notification manager. */ private final NotificationManager notificationManager = new NotificationManager(); @@ -324,11 +324,17 @@ public class WebInterface { } private Template parseTemplate(String resourceName) { - Reader reader = createReader(resourceName); + InputStream templateInputStream = null; + Reader reader = null; try { + templateInputStream = getClass().getResourceAsStream(resourceName); + reader = new InputStreamReader(templateInputStream, "UTF-8"); return parse(reader); + } catch (UnsupportedEncodingException uee1) { + throw new RuntimeException("UTF-8 not supported."); } finally { Closer.close(reader); + Closer.close(templateInputStream); } } @@ -434,7 +440,7 @@ public class WebInterface { if (soneId == null) { return null; } - return getCore().getLocalSone(soneId, false); + return getCore().getLocalSone(soneId); } /** @@ -635,6 +641,8 @@ public class WebInterface { 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 emptyAlbumTitleTemplate = parseTemplate("/templates/emptyAlbumTitle.html"); Template optionsTemplate = parseTemplate("/templates/options.html"); Template rescueTemplate = parseTemplate("/templates/rescue.html"); Template aboutTemplate = parseTemplate("/templates/about.html"); @@ -686,6 +694,8 @@ public class WebInterface { 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 SoneTemplatePage("emptyAlbumTitle.html", emptyAlbumTitleTemplate, "Page.EmptyAlbumTitle.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("css/", "/static/css/", "text/css"))); @@ -747,22 +757,6 @@ public class WebInterface { } /** - * Creates a {@link Reader} from the {@link InputStream} for the resource - * with the given name. - * - * @param resourceName - * The name of the resource - * @return A {@link Reader} for the resource - */ - private Reader createReader(String resourceName) { - try { - return new InputStreamReader(getClass().getResourceAsStream(resourceName), "UTF-8"); - } catch (UnsupportedEncodingException uee1) { - return null; - } - } - - /** * Returns all {@link Sone#isLocal() local Sone}s that are referenced by * {@link SonePart}s in the given text (after parsing it using * {@link SoneTextParser}). @@ -1021,7 +1015,7 @@ public class WebInterface { public void soneInserting(SoneInsertingEvent soneInsertingEvent) { TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertingEvent.sone()); soneInsertNotification.set("soneStatus", "inserting"); - if (soneInsertingEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) { + if (soneInsertingEvent.sone().getOptions().isSoneInsertNotificationEnabled()) { notificationManager.addNotification(soneInsertNotification); } } @@ -1037,7 +1031,7 @@ public class WebInterface { TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertedEvent.sone()); soneInsertNotification.set("soneStatus", "inserted"); soneInsertNotification.set("insertDuration", soneInsertedEvent.insertDuration() / 1000); - if (soneInsertedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) { + if (soneInsertedEvent.sone().getOptions().isSoneInsertNotificationEnabled()) { notificationManager.addNotification(soneInsertNotification); } } @@ -1053,7 +1047,7 @@ public class WebInterface { TemplateNotification soneInsertNotification = getSoneInsertNotification(soneInsertAbortedEvent.sone()); soneInsertNotification.set("soneStatus", "insert-aborted"); soneInsertNotification.set("insert-error", soneInsertAbortedEvent.cause()); - if (soneInsertAbortedEvent.sone().getOptions().getBooleanOption("EnableSoneInsertNotifications").get()) { + if (soneInsertAbortedEvent.sone().getOptions().isSoneInsertNotificationEnabled()) { notificationManager.addNotification(soneInsertNotification); } }