Author: batosai
Date: 2008-10-01 16:11:49 +0000 (Wed, 01 Oct 2008)
New Revision: 22892

Added:
   trunk/plugins/WoT/ui/web/WebPageImpl.java
Removed:
   trunk/plugins/WoT/ui/web/WebPage.java
Modified:
   trunk/plugins/WoT/ui/web/HomePage.java
Log:
First step to the new web UI.

Modified: trunk/plugins/WoT/ui/web/HomePage.java
===================================================================
--- trunk/plugins/WoT/ui/web/HomePage.java      2008-10-01 14:33:44 UTC (rev 
22891)
+++ trunk/plugins/WoT/ui/web/HomePage.java      2008-10-01 16:11:49 UTC (rev 
22892)
@@ -9,38 +9,37 @@
 import plugins.WoT.OwnIdentity;
 import plugins.WoT.Score;
 import plugins.WoT.Trust;
+import plugins.WoT.WoT;

 import com.db4o.ObjectContainer;

 import freenet.support.HTMLNode;
+import freenet.support.api.HTTPRequest;

 /**
  * @author Julien Cornuwel (batosai at freenetproject.org)
  */

-public class HomePage {
-
-       WebPage web;
+public class HomePage extends WebPageImpl {

-       public HomePage(WebPage web) {
-               this.web = web;
+       public HomePage(WoT wot, HTTPRequest request) {
+               super(wot, request);
        }

-       public void make(ObjectContainer db) {
-               
-               getSummary(db);
+       public void make() {
+               makeSummary();
        }

-       public void getSummary(ObjectContainer db) {
+       public void makeSummary() {
+               ObjectContainer db = wot.getDB();

-               
                HTMLNode list = new HTMLNode("ul");
                list.addChild(new HTMLNode("li", "Own Identities : " + 
OwnIdentity.getNbOwnIdentities(db)));
                list.addChild(new HTMLNode("li", "Known Identities : " + 
Identity.getNbIdentities(db)));
                list.addChild(new HTMLNode("li", "Trust relationships : " + 
Trust.getNb(db)));
                list.addChild(new HTMLNode("li", "Scores : " + 
Score.getNb(db)));

-               web.getInfoBox("Summary").addChild(list);
+               getInfoBox("Summary").addChild(list);
        }

 }

Deleted: trunk/plugins/WoT/ui/web/WebPage.java
===================================================================
--- trunk/plugins/WoT/ui/web/WebPage.java       2008-10-01 14:33:44 UTC (rev 
22891)
+++ trunk/plugins/WoT/ui/web/WebPage.java       2008-10-01 16:11:49 UTC (rev 
22892)
@@ -1,94 +0,0 @@
-/**
- * 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 plugins.WoT.Config;
-
-import com.db4o.ObjectContainer;
-
-import freenet.client.HighLevelSimpleClient;
-import freenet.clients.http.PageMaker;
-import freenet.pluginmanager.PluginRespirator;
-import freenet.support.HTMLNode;
-import freenet.support.api.HTTPRequest;
-
-/**
- * @author Julien Cornuwel (batosai at freenetproject.org)
- */
-public class WebPage {
-       
-       private PluginRespirator pr;
-       private PageMaker pm;
-       private HighLevelSimpleClient client;
-       private HTTPRequest request;
-       private ObjectContainer db;
-       private Config config;
-       public static String SELF_URI = "/plugins/plugins.WoT.WoT";
-       
-       private HTMLNode pageNode;
-       
-       /**
-        * Generates a WebPage of the plugin's interface.
-        * 
-        * @param pr The {@link PluginRespirator} supplied by Freenet
-        * @param db An {@link ObjectContainer} where plugin's datas are stored
-        * @param cfg A {@link Config} object containing the plugin's 
configuration
-        * @param client A {@link HighLevelSimpleClient} to perform requests to 
the node, if needed
-        * @param uri
-        */
-       public WebPage(PluginRespirator pr, ObjectContainer db, Config cfg, 
HighLevelSimpleClient client, HTTPRequest request) {
-               
-               this.pr = pr;
-               this.db = db;
-               this.config = cfg;
-               this.client = client;
-               this.request = request;
-               
-               pm = pr.getPageMaker();
-               pageNode = pm.getPageNode("Web of Trust", null);
-               makeMenu();
-       }
-       
-       /**
-        * Creates a new infoBox in the WebPage and returns its {@link 
HTMLnode}.
-        * 
-        * @param title The title of the desired InfoBox
-        * @return InfoBox' contentNode
-        */
-       public HTMLNode getInfoBox(String title) {
-               
-               HTMLNode box = pm.getInfobox(title);
-               
-               HTMLNode contentNode = pm.getContentNode(pageNode);
-               contentNode.addChild(box);
-
-               return pm.getContentNode(box);
-               
-       }
-       
-       /**
-        * Returns a String containing the HTML code of the WebPage
-        * 
-        * @return HTML code of this page
-        */
-       public String generateHTML() {
-               
-               return pageNode.generate();
-       }
-       
-       /**
-        * Created the menu of the WebPage
-        */
-       public void makeMenu() {
-               
-               pm.addNavigationLink(SELF_URI, "Home", "Home page", false, 
null);
-               pm.addNavigationLink(SELF_URI + "?ownidentities", "Own 
Identities", "Manage your own identities", false, null);
-               pm.addNavigationLink(SELF_URI + "?knownidentities", "Known 
Identities", "Manage others identities", false, null);
-               pm.addNavigationLink(SELF_URI + "?configuration", 
"Configuration", "Configure the WoT plugin", false, null);
-               pm.addNavigationLink("/plugins/", "Plugins page", "Back to 
Plugins page", false, null);
-       }
-
-}

Copied: trunk/plugins/WoT/ui/web/WebPageImpl.java (from rev 22887, 
trunk/plugins/WoT/ui/web/WebPage.java)
===================================================================
--- trunk/plugins/WoT/ui/web/WebPageImpl.java                           (rev 0)
+++ trunk/plugins/WoT/ui/web/WebPageImpl.java   2008-10-01 16:11:49 UTC (rev 
22892)
@@ -0,0 +1,90 @@
+/**
+ * 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 plugins.WoT.WoT;
+
+import freenet.clients.http.PageMaker;
+import freenet.support.HTMLNode;
+import freenet.support.api.HTTPRequest;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ */
+public abstract class WebPageImpl {
+       
+       protected static String SELF_URI = "/plugins/plugins.WoT.WoT";
+       protected PageMaker pm;
+       protected HTMLNode pageNode;
+       protected WoT wot;
+       
+       /**
+        * Creates a new WebPage.
+        * 
+        * @param wot a reference to the WoT, used to get references to 
database, client, whatever is needed.
+        * @param request the request from the user.
+        */
+       public WebPageImpl(WoT wot, HTTPRequest request) {
+               this.wot = wot;
+               pm = wot.getPageMaker();
+               pageNode = pm.getPageNode("Web of Trust", null);
+               makeMenu();
+       }
+       
+       /**
+        * Abstract method actual WebPages (subclasses) will have to implement.
+        * That is where they do their job.
+        */
+       public abstract void make();
+       
+       /**
+        * Generates the HTML code that will be sent to the browser.
+        * 
+        * @return HTML code of the page.
+        */
+       public String toHTML() {
+               return pageNode.generate();
+       }
+       
+       /**
+        * Creates a new infoBox in the WebPage and returns its {@link 
HTMLnode}.
+        * 
+        * @param title The title of the desired InfoBox
+        * @return InfoBox' contentNode
+        */
+       public HTMLNode getInfoBox(String title) {
+               
+               HTMLNode box = pm.getInfobox(title);
+               
+               HTMLNode contentNode = pm.getContentNode(pageNode);
+               contentNode.addChild(box);
+
+               return pm.getContentNode(box);
+               
+       }
+       
+       /**
+        * Returns a String containing the HTML code of the WebPage
+        * 
+        * @return HTML code of this page
+        */
+       public String generateHTML() {
+               
+               return pageNode.generate();
+       }
+       
+       /**
+        * Creates the menu of the WebPage
+        */
+       public void makeMenu() {
+               pm.addNavigationLink(SELF_URI, "Home", "Home page", false, 
null);
+               pm.addNavigationLink(SELF_URI + "?ownidentities", "Own 
Identities", "Manage your own identities", false, null);
+               pm.addNavigationLink(SELF_URI + "?knownidentities", "Known 
Identities", "Manage others identities", false, null);
+               pm.addNavigationLink(SELF_URI + "?configuration", 
"Configuration", "Configure the WoT plugin", false, null);
+               pm.addNavigationLink("/plugins/", "Plugins page", "Back to 
Plugins page", false, null);
+       }
+
+}


Reply via email to