Author: batosai
Date: 2008-10-01 17:09:39 +0000 (Wed, 01 Oct 2008)
New Revision: 22897

Added:
   trunk/plugins/WoT/ui/web/WebPage.java
Modified:
   trunk/plugins/WoT/ui/web/HomePage.java
   trunk/plugins/WoT/ui/web/WebPageImpl.java
Log:
Step two. Still not working but closer to what I want to do ;)

Modified: trunk/plugins/WoT/ui/web/HomePage.java
===================================================================
--- trunk/plugins/WoT/ui/web/HomePage.java      2008-10-01 17:08:03 UTC (rev 
22896)
+++ trunk/plugins/WoT/ui/web/HomePage.java      2008-10-01 17:09:39 UTC (rev 
22897)
@@ -30,7 +30,7 @@
                makeSummary();
        }

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

                HTMLNode list = new HTMLNode("ul");
@@ -39,7 +39,7 @@
                list.addChild(new HTMLNode("li", "Trust relationships : " + 
Trust.getNb(db)));
                list.addChild(new HTMLNode("li", "Scores : " + 
Score.getNb(db)));

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

 }

Added: trunk/plugins/WoT/ui/web/WebPage.java
===================================================================
--- trunk/plugins/WoT/ui/web/WebPage.java                               (rev 0)
+++ trunk/plugins/WoT/ui/web/WebPage.java       2008-10-01 17:09:39 UTC (rev 
22897)
@@ -0,0 +1,32 @@
+/**
+ * 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;
+
+/**
+ * Interface specifying what a WebPage should do.
+ * 
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ */
+public interface WebPage {
+
+       /**
+        * Possibility to add an ErrorBox from outside the Object.
+        * Needed by the controller (WoT) if something goes wrong while 
executing a user request.
+        */
+       public void addErrorBox(String title, String message);
+       
+       /**
+        * Actually generates the content of the page.
+        * Each subclass knows what it has to do.
+        */
+       public void make();
+       
+       /**
+        * @return the HTML code of this WebPage.
+        */
+       public String toHTML();
+       
+}

Modified: trunk/plugins/WoT/ui/web/WebPageImpl.java
===================================================================
--- trunk/plugins/WoT/ui/web/WebPageImpl.java   2008-10-01 17:08:03 UTC (rev 
22896)
+++ trunk/plugins/WoT/ui/web/WebPageImpl.java   2008-10-01 17:09:39 UTC (rev 
22897)
@@ -5,6 +5,9 @@
  */
 package plugins.WoT.ui.web;

+import java.util.ArrayList;
+import java.util.Iterator;
+
 import plugins.WoT.WoT;

 import freenet.clients.http.PageMaker;
@@ -14,72 +17,99 @@
 /**
  * @author Julien Cornuwel (batosai at freenetproject.org)
  */
-public abstract class WebPageImpl {
+public abstract class WebPageImpl implements WebPage {

        protected static String SELF_URI = "/plugins/plugins.WoT.WoT";
        protected PageMaker pm;
        protected HTMLNode pageNode;
        protected WoT wot;
+       protected HTTPRequest request;

+       protected HTMLNode errorBox;
+       protected ArrayList<HTMLNode> contentBoxes;
+       
        /**
-        * Creates a new WebPage.
+        * Creates a new WebPageImpl.
+        * It is abstract because only a subclass can run the desired make() 
method to generate the content.
         * 
         * @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);
+               this.pm = wot.getPageMaker();
+               this.pageNode = pm.getPageNode("Web of Trust", null);
+               this.request = request;
+               
+               this.errorBox = null;
+               this.contentBoxes = new ArrayList<HTMLNode>();
+               
                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() {
+               
+               //FIXME Must have missed something stupid, the generated page 
is empty.
+               //Wil have a look at it later.
+               
+               // We add the ErrorBox if it exists
+               if(errorBox != null) {
+                       pageNode.addChild(errorBox);
+                       System.out.println("There is an errorBox");
+               }
+               
+               // We add every ContentBoxes
+               Iterator<HTMLNode> contentBox = contentBoxes.iterator();
+               while(contentBox.hasNext()) 
pageNode.addChild(contentBox.next());
+               
+               System.out.println("There are " + contentBoxes.size() + " 
contentBoxes");
+               
+               HTMLNode test = pm.getInfobox("infobox-alert", "Test");
+               test.addChild("#", "Test");
+               pageNode.addChild(test);
+               
+               // Generate the HTML output
                return pageNode.generate();
        }
-       
+
        /**
-        * Creates a new infoBox in the WebPage and returns its {@link 
HTMLnode}.
+        * Adds an ErrorBox to the WebPage.
         * 
-        * @param title The title of the desired InfoBox
-        * @return InfoBox' contentNode
+        * @param title The title of the desired ErrorBox
+        * @param message The error message that will be displayed
         */
-       public HTMLNode getInfoBox(String title) {
+       public void addErrorBox(String title, String message) {

-               HTMLNode box = pm.getInfobox(title);
-               
-               HTMLNode contentNode = pm.getContentNode(pageNode);
-               contentNode.addChild(box);
-
-               return pm.getContentNode(box);
-               
+               errorBox = pm.getInfobox("infobox-alert", "Error");
+               errorBox.addChild("#", message);
        }

        /**
-        * Returns a String containing the HTML code of the WebPage
+        * Adds a new InfoBox to the WebPage.
         * 
-        * @return HTML code of this page
+        * @param title The title of the desired InfoBox
+        * @param content The content of the InfoBox
         */
-       public String generateHTML() {
+       protected void addContentBox(String title, HTMLNode content) {

-               return pageNode.generate();
+               HTMLNode box = pm.getInfobox(title);
+               box.addChild(content);
+               contentBoxes.add(box);
        }

        /**
         * Creates the menu of the WebPage
         */
-       public void makeMenu() {
+       private void makeMenu() {
+               
+               // FIXME It seems that the PluginRespirator gives the same 
PageMaker at each request.
+               // That means we keep adding links each time a page is 
generated :(
                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);


Reply via email to