Add method to parse an identity from an arbitrary parameter.
[WoTNS.git] / src / main / java / net / pterodactylus / wotns / ui / web / BasicPage.java
index 25efbe3..2921c7e 100644 (file)
@@ -17,6 +17,9 @@
 
 package net.pterodactylus.wotns.ui.web;
 
+import java.util.Arrays;
+import java.util.Collection;
+
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 import net.pterodactylus.util.web.Method;
@@ -36,10 +39,13 @@ public class BasicPage extends FreenetTemplatePage {
 
        protected final IdentityManager identityManager;
 
-       public BasicPage(WebInterface webInterface, String path, Template template) {
+       private final String title;
+
+       public BasicPage(WebInterface webInterface, String path, String title, Template template) {
                super(path, webInterface.getTemplateContextFactory(), template, "noPermission.html");
                this.webInterface = webInterface;
                this.identityManager = webInterface.getWoTNSPlugin().getIdentityManager();
+               this.title = title;
        }
 
        //
@@ -47,11 +53,15 @@ public class BasicPage extends FreenetTemplatePage {
        //
 
        protected OwnIdentity getOwnIdentity(FreenetRequest request) {
+               return getOwnIdentity(request, "ownIdentity");
+       }
+
+       protected OwnIdentity getOwnIdentity(FreenetRequest request, String parameterName) {
                if (request.getMethod() == Method.POST) {
-                       String ownIdentityId = request.getHttpRequest().getPartAsStringFailsafe("ownIdentity", 43);
+                       String ownIdentityId = request.getHttpRequest().getPartAsStringFailsafe(parameterName, 43);
                        return identityManager.getOwnIdentity(ownIdentityId);
                } else if (request.getMethod() == Method.GET) {
-                       String ownIdentityId = request.getHttpRequest().getParam("ownIdentity");
+                       String ownIdentityId = request.getHttpRequest().getParam(parameterName);
                        return identityManager.getOwnIdentity(ownIdentityId);
                }
                return null;
@@ -65,9 +75,27 @@ public class BasicPage extends FreenetTemplatePage {
         * {@inheritDoc}
         */
        @Override
+       protected String getPageTitle(FreenetRequest request) {
+               return title;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected Collection<String> getStyleSheets() {
+               return Arrays.asList("css/main.css");
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
        protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
+               templateContext.set("request", request.getHttpRequest());
                templateContext.set("ownIdentities", identityManager.getAllOwnIdentities());
                templateContext.set("formPassword", webInterface.getWoTNSPlugin().getToadletContainer().getFormPassword());
        }
+
 }