Author: batosai
Date: 2008-10-02 19:02:46 +0000 (Thu, 02 Oct 2008)
New Revision: 22914

Added:
   trunk/plugins/WoT/ui/web/OwnIdentitiesPage.java
Modified:
   trunk/plugins/WoT/WoT.java
Log:
Added OwnIdentitiesPage class.

Modified: trunk/plugins/WoT/WoT.java
===================================================================
--- trunk/plugins/WoT/WoT.java  2008-10-02 18:45:40 UTC (rev 22913)
+++ trunk/plugins/WoT/WoT.java  2008-10-02 19:02:46 UTC (rev 22914)
@@ -24,6 +24,7 @@
 import plugins.WoT.exceptions.NotTrustedException;
 import plugins.WoT.exceptions.UnknownIdentityException;
 import plugins.WoT.ui.web.HomePage;
+import plugins.WoT.ui.web.OwnIdentitiesPage;
 import plugins.WoT.ui.web.WebPage;

 import com.db4o.Db4o;
@@ -48,7 +49,6 @@
 import freenet.pluginmanager.PluginHTTPException;
 import freenet.pluginmanager.PluginReplySender;
 import freenet.pluginmanager.PluginRespirator;
-import freenet.support.HTMLNode;
 import freenet.support.Logger;
 import freenet.support.SimpleFieldSet;
 import freenet.support.api.Bucket;
@@ -165,7 +165,7 @@

                try {
                        if(request.isParameterSet("ownidentities")) 
-                               return web.makeOwnIdentitiesPage();
+                               page = new OwnIdentitiesPage(this, request);
                        else if(request.isParameterSet("knownidentities")) 
                                return web.makeKnownIdentitiesPage();
                        else if(request.isParameterSet("configuration"))
@@ -176,10 +176,10 @@
                                return 
web.getTrusteesPage(request.getParam("id"));
                        else {
                                page = new HomePage(this, request);             
        
-                               page.make();
-                               page.addErrorBox("coucou", "test");
-                               return page.toHTML();
                        }
+                       page.make();
+                       return page.toHTML();
+                       
                } catch (Exception e) {
                        e.printStackTrace();
                        return e.getMessage();
@@ -236,6 +236,10 @@
                }
        }

+       public String handleHTTPPut(HTTPRequest request) throws 
PluginHTTPException {
+               return "Go to hell";
+       }
+       
        private void deleteIdentity(String id) throws 
DuplicateIdentityException, UnknownIdentityException, DuplicateScoreException, 
DuplicateTrustException {
                Identity identity = Identity.getById(db, id);

@@ -728,4 +732,8 @@
        public ObjectContainer getDB() {
                return db;
        }
+       
+       public PluginRespirator getPR() {
+               return pr;
+       }
 }

Added: trunk/plugins/WoT/ui/web/OwnIdentitiesPage.java
===================================================================
--- trunk/plugins/WoT/ui/web/OwnIdentitiesPage.java                             
(rev 0)
+++ trunk/plugins/WoT/ui/web/OwnIdentitiesPage.java     2008-10-02 19:02:46 UTC 
(rev 22914)
@@ -0,0 +1,105 @@
+/**
+ * This code is part of WoT, a plugin for Freenet. It is distributed 
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT.ui.web;
+
+import java.util.Date;
+
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+
+import plugins.WoT.OwnIdentity;
+import plugins.WoT.WoT;
+import freenet.pluginmanager.PluginRespirator;
+import freenet.support.HTMLNode;
+import freenet.support.api.HTTPRequest;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ */
+public class OwnIdentitiesPage extends WebPageImpl {
+
+       public OwnIdentitiesPage(WoT wot, HTTPRequest request) {
+               super(wot, request);
+       }
+       
+       public void make() {
+               ObjectContainer db = wot.getDB();
+               PluginRespirator pr = wot.getPR();
+               makeOwnIdentitiesList(db, pr);
+               makeRestoreOwnIdentityForm(pr);
+       }
+       
+       private void makeOwnIdentitiesList(ObjectContainer db, PluginRespirator 
pr) {
+
+               HTMLNode boxContent = getContentBox("Summary");
+               
+               ObjectSet<OwnIdentity> ownIdentities = 
OwnIdentity.getAllOwnIdentities(db);
+               if(ownIdentities.size() == 0) {
+                       boxContent.addChild("p", "You have no own identity yet, 
you should create one...");
+               }
+               else {
+                       
+                       HTMLNode identitiesTable = boxContent.addChild("table", 
"border", "0");
+                       HTMLNode row=identitiesTable.addChild("tr");
+                       row.addChild("th", "Name");
+                       row.addChild("th", "Last change");
+                       row.addChild("th", "Last insert");
+                       row.addChild("th", "Publish TrustList ?");
+                       row.addChild("th", "Manage");
+                       
+                       while(ownIdentities.hasNext()) {
+                               OwnIdentity id = ownIdentities.next();
+                               row=identitiesTable.addChild("tr");
+                               row.addChild("td", new String[] {"title", 
"style"}, new String[] {id.getRequestURI().toString(), "cursor: help;"}, 
id.getNickName());
+                               
row.addChild("td",id.getLastChange().toString());
+                               HTMLNode cell = row.addChild("td");
+                               if(id.getLastInsert() == null) {
+                                       cell.addChild("p", "Insert in 
progress...");
+                               }
+                               else if(id.getLastInsert().equals(new Date(0))) 
{
+                                       cell.addChild("p", "Never");
+                               }
+                               else {
+                                       cell.addChild(new HTMLNode("a", "href", 
"/"+id.getRequestURI().toString(), id.getLastInsert().toString()));
+                               }
+                               row.addChild("td", id.doesPublishTrustList() ? 
"Yes" : "No");
+                               
+                               HTMLNode manageCell = row.addChild("td");
+                               
+                               HTMLNode editForm = pr.addFormChild(manageCell, 
SELF_URI, "editIdentity");
+                               editForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "hidden", "page", "editIdentity" });
+                               editForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "hidden", "id", 
id.getRequestURI().toString() });
+                               editForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "submit", "edit", "Details" });
+                                                               
+                               HTMLNode deleteForm = 
pr.addFormChild(manageCell, SELF_URI, "deleteIdentity");
+                               deleteForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "hidden", "page", "deleteIdentity" });
+                               deleteForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "hidden", "id", id.getId() });
+                               deleteForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "submit", "delete", "Delete" });
+                       }
+               }
+       
+               HTMLNode createForm = pr.addFormChild(boxContent, SELF_URI, 
"createIdentity");
+               createForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "hidden", "page", "createIdentity" });
+               createForm.addChild("span", new String[] {"title", "style"}, 
new String[] { "No spaces or special characters.", "border-bottom: 1px dotted; 
cursor: help;"} , "NickName : ");
+               createForm.addChild("input", new String[] {"type", "name", 
"size"}, new String[] {"text", "nickName", "30"});
+               createForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "create", "Create a new identity !" });
+       }
+
+       private void makeRestoreOwnIdentityForm(PluginRespirator pr) {
+               HTMLNode restoreBoxContent = getContentBox("Restore an identity 
from Freenet");
+               restoreBoxContent.addChild("p", "Use this if you lost your 
database for some reason (crash, reinstall...) but still have your identity's 
keys :");
+               
+               HTMLNode restoreForm = pr.addFormChild(restoreBoxContent, 
SELF_URI, "restoreIdentity");
+               restoreForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "hidden", "page", "restoreIdentity" });
+               restoreForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "requestURI", "70", "Request URI" });
+               restoreForm.addChild("br");
+               restoreForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "insertURI", "70", "InsertURI" });
+               restoreForm.addChild("br");
+               restoreForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "restore", "Restore this identity !" });
+       
+               restoreBoxContent.addChild("p", "Please don't use that identity 
(set trust, edit parameters...) until it has been restored from Freenet, or you 
might loose all its content.");
+       }
+}


Reply via email to