Fix wrong project name in file headers.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / CreateSonePage.java
index d55624f..2e2fc41 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * FreenetSone - CreateSonePage.java - Copyright © 2010 David Roden
+ * Sone - CreateSonePage.java - Copyright © 2010 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@ import net.pterodactylus.sone.freenet.wot.OwnIdentity;
 import net.pterodactylus.sone.web.page.Page.Request.Method;
 import net.pterodactylus.util.logging.Logging;
 import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
 import freenet.clients.http.ToadletContext;
 
 /**
@@ -93,10 +94,10 @@ public class CreateSonePage extends SoneTemplatePage {
         * {@inheritDoc}
         */
        @Override
-       protected void processTemplate(Request request, Template template) throws RedirectException {
-               super.processTemplate(request, template);
-               List<OwnIdentity> ownIdentitiesWithoutSone = getOwnIdentitiesWithoutSone(webInterface.core());
-               template.set("identitiesWithoutSone", ownIdentitiesWithoutSone);
+       protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+               super.processTemplate(request, templateContext);
+               List<OwnIdentity> ownIdentitiesWithoutSone = getOwnIdentitiesWithoutSone(webInterface.getCore());
+               templateContext.set("identitiesWithoutSone", ownIdentitiesWithoutSone);
                if (request.getMethod() == Method.POST) {
                        String id = request.getHttpRequest().getPartAsStringFailsafe("identity", 44);
                        OwnIdentity selectedIdentity = null;
@@ -107,12 +108,11 @@ public class CreateSonePage extends SoneTemplatePage {
                                }
                        }
                        if (selectedIdentity == null) {
-                               template.set("errorNoIdentity", true);
+                               templateContext.set("errorNoIdentity", true);
                                return;
                        }
                        /* create Sone. */
-                       webInterface.core().getIdentityManager().addContext(selectedIdentity, "Sone");
-                       Sone sone = webInterface.core().createSone(selectedIdentity);
+                       Sone sone = webInterface.getCore().createSone(selectedIdentity);
                        if (sone == null) {
                                logger.log(Level.SEVERE, "Could not create Sone for OwnIdentity: %s", selectedIdentity);
                                /* TODO - go somewhere else */
@@ -129,7 +129,7 @@ public class CreateSonePage extends SoneTemplatePage {
         */
        @Override
        public boolean isEnabled(ToadletContext toadletContext) {
-               return getCurrentSone(toadletContext) == null;
+               return (getCurrentSone(toadletContext, false) == null) || (webInterface.getCore().getLocalSones().size() == 1);
        }
 
 }