Add method to parse an identity from a request.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 15 Sep 2011 14:37:56 +0000 (16:37 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 15 Sep 2011 14:38:36 +0000 (16:38 +0200)
src/main/java/net/pterodactylus/wotns/ui/web/BasicPage.java

index f8ba131..fa8c06f 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.wotns.ui.web;
 
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
 import net.pterodactylus.wotns.freenet.wot.IdentityManager;
 import net.pterodactylus.wotns.freenet.wot.OwnIdentity;
 import net.pterodactylus.wotns.web.FreenetRequest;
@@ -32,6 +33,7 @@ import net.pterodactylus.wotns.web.FreenetTemplatePage;
 public class BasicPage extends FreenetTemplatePage {
 
        protected final WebInterface webInterface;
+
        protected final IdentityManager identityManager;
 
        public BasicPage(WebInterface webInterface, String path, Template template) {
@@ -44,6 +46,21 @@ public class BasicPage extends FreenetTemplatePage {
        // PROTECTED METHODS
        //
 
+       protected OwnIdentity getIdentity(FreenetRequest request) {
+               if (request.getMethod() == Method.POST) {
+                       String ownIdentityId = request.getHttpRequest().getPartAsStringFailsafe("ownIdentity", 43);
+                       return identityManager.getOwnIdentity(ownIdentityId);
+               } else if (request.getMethod() == Method.GET) {
+                       String ownIdentityId = request.getHttpRequest().getParam("ownIdentity");
+                       return identityManager.getOwnIdentity(ownIdentityId);
+               }
+               return null;
+       }
+
+       //
+       // FREENETTEMPLATEPAGE METHODS
+       //
+
        /**
         * {@inheritDoc}
         */