Use new template engine.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / OptionsPage.java
index 5127611..421b2a2 100644 (file)
@@ -21,6 +21,7 @@ import net.pterodactylus.sone.core.Options;
 import net.pterodactylus.sone.web.page.Page.Request.Method;
 import net.pterodactylus.util.number.Numbers;
 import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
 
 /**
  * This page lets the user edit the options of the Sone plugin.
@@ -49,21 +50,37 @@ public class OptionsPage extends SoneTemplatePage {
         * {@inheritDoc}
         */
        @Override
-       protected void processTemplate(Request request, Template template) throws RedirectException {
-               super.processTemplate(request, template);
+       protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+               super.processTemplate(request, templateContext);
                Options options = webInterface.getCore().getOptions();
                if (request.getMethod() == Method.POST) {
                        Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16));
                        options.getIntegerOption("InsertionDelay").set(insertionDelay);
+                       Integer positiveTrust = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("positive-trust", 3), options.getIntegerOption("PositiveTrust").getReal());
+                       options.getIntegerOption("PositiveTrust").set(positiveTrust);
+                       Integer negativeTrust = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("negative-trust", 3), options.getIntegerOption("NegativeTrust").getReal());
+                       options.getIntegerOption("NegativeTrust").set(negativeTrust);
+                       String trustComment = request.getHttpRequest().getPartAsStringFailsafe("trust-comment", 256);
+                       if (trustComment.trim().length() == 0) {
+                               trustComment = null;
+                       }
+                       options.getStringOption("TrustComment").set(trustComment);
+                       boolean soneRescueMode = Boolean.parseBoolean(request.getHttpRequest().getPartAsStringFailsafe("sone-rescue-mode", 5));
+                       options.getBooleanOption("SoneRescueMode").set(soneRescueMode);
                        boolean clearOnNextRestart = Boolean.parseBoolean(request.getHttpRequest().getPartAsStringFailsafe("clear-on-next-restart", 5));
                        options.getBooleanOption("ClearOnNextRestart").set(clearOnNextRestart);
                        boolean reallyClearOnNextRestart = Boolean.parseBoolean(request.getHttpRequest().getPartAsStringFailsafe("really-clear-on-next-restart", 5));
                        options.getBooleanOption("ReallyClearOnNextRestart").set(reallyClearOnNextRestart);
+                       webInterface.getCore().saveConfiguration();
                        throw new RedirectException(getPath());
                }
-               template.set("insertion-delay", options.getIntegerOption("InsertionDelay").get());
-               template.set("clear-on-next-restart", options.getBooleanOption("ClearOnNextRestart").get());
-               template.set("really-clear-on-next-restart", options.getBooleanOption("ReallyClearOnNextRestart").get());
+               templateContext.set("insertion-delay", options.getIntegerOption("InsertionDelay").get());
+               templateContext.set("positive-trust", options.getIntegerOption("PositiveTrust").get());
+               templateContext.set("negative-trust", options.getIntegerOption("NegativeTrust").get());
+               templateContext.set("trust-comment", options.getStringOption("TrustComment").get());
+               templateContext.set("sone-rescue-mode", options.getBooleanOption("SoneRescueMode").get());
+               templateContext.set("clear-on-next-restart", options.getBooleanOption("ClearOnNextRestart").get());
+               templateContext.set("really-clear-on-next-restart", options.getBooleanOption("ReallyClearOnNextRestart").get());
        }
 
 }