Add Sone-specific options object.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / WebInterface.java
index f21d256..afa324b 100644 (file)
@@ -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);
                }
        }
 
@@ -747,22 +753,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 +1011,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 +1027,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 +1043,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);
                }
        }