Author: saces
Date: 2008-09-12 17:08:44 +0000 (Fri, 12 Sep 2008)
New Revision: 22630

Added:
   trunk/plugins/FMSPlugin/
   trunk/plugins/FMSPlugin/FMS.java
   trunk/plugins/FMSPlugin/FMSDealer.java
   trunk/plugins/FMSPlugin/FMSIdentity.java
   trunk/plugins/FMSPlugin/FMSIdentityManager.java
   trunk/plugins/FMSPlugin/FMSMessage.java
   trunk/plugins/FMSPlugin/FMSOwnIdentity.java
   trunk/plugins/FMSPlugin/FMSPlugin.java
   trunk/plugins/FMSPlugin/Version.java
   trunk/plugins/FMSPlugin/WotImporter.java
   trunk/plugins/FMSPlugin/XMLParser.java
   trunk/plugins/FMSPlugin/XMLUtils.java
   trunk/plugins/FMSPlugin/fms/
   trunk/plugins/FMSPlugin/fms/IdentityFetcher.java
   trunk/plugins/FMSPlugin/fms/IdentityInserter.java
   trunk/plugins/FMSPlugin/fms/IdentityVerifierer.java
   trunk/plugins/FMSPlugin/ui/
   trunk/plugins/FMSPlugin/ui/Backup.java
   trunk/plugins/FMSPlugin/ui/Errors.java
   trunk/plugins/FMSPlugin/ui/IdentityEditor.java
   trunk/plugins/FMSPlugin/ui/Messages.java
   trunk/plugins/FMSPlugin/ui/Status.java
Log:
move FMSPlugin into official source tree

Added: trunk/plugins/FMSPlugin/FMS.java
===================================================================
--- trunk/plugins/FMSPlugin/FMS.java                            (rev 0)
+++ trunk/plugins/FMSPlugin/FMS.java    2008-09-12 17:08:44 UTC (rev 22630)
@@ -0,0 +1,36 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin;
+
+import com.db4o.ObjectContainer;
+
+import freenet.clients.http.PageMaker;
+import freenet.pluginmanager.PluginRespirator;
+import freenet.support.HTMLNode;
+import freenet.support.io.TempBucketFactory;
+
+/**
+ * @author saces
+ *
+ */
+public class FMS {
+       
+       public final PageMaker pm;
+       public final PluginRespirator pr;
+       public final ObjectContainer db_config;
+       public final ObjectContainer db_cache;
+       public final TempBucketFactory tempBF;
+       
+       FMS(TempBucketFactory tempBucketFactory, PageMaker pagemaker, 
PluginRespirator pluginrespirator, ObjectContainer dbConfig, ObjectContainer 
dbCache){
+               pm = pagemaker;
+               pr = pluginrespirator;
+               db_config = dbConfig;
+               db_cache = dbCache;
+               tempBF = tempBucketFactory;
+       }
+       
+       final public HTMLNode getPageNode() {
+               return pm.getPageNode(FMSPlugin.SELF_TITLE, null);
+       }
+}


Property changes on: trunk/plugins/FMSPlugin/FMS.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/FMSDealer.java
===================================================================
--- trunk/plugins/FMSPlugin/FMSDealer.java                              (rev 0)
+++ trunk/plugins/FMSPlugin/FMSDealer.java      2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,31 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin;
+
+import freenet.support.Executor;
+import freenet.support.Logger;
+
+public class FMSDealer {
+       
+       private final Executor _executor;
+       
+       // services
+       private FMSIdentityManager identManager;
+       
+       FMSDealer(Executor executor) {
+               this._executor = executor;
+               _executor.execute(new Runnable() {
+                       public void run() {
+                               startDealer();
+                       }}, "Dealer starter");
+       }
+       
+       private void startDealer() {
+               Logger.error(this, "Starting dealer", new Error("TODO"));
+       }
+
+       synchronized void killMe() {
+               Logger.error(this, "Killing dealer", new Error("TODO"));
+       }
+}


Property changes on: trunk/plugins/FMSPlugin/FMSDealer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/FMSIdentity.java
===================================================================
--- trunk/plugins/FMSPlugin/FMSIdentity.java                            (rev 0)
+++ trunk/plugins/FMSPlugin/FMSIdentity.java    2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,23 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin;
+
+public class FMSIdentity {
+       
+       private final String nickName;
+       private final String requestUri;
+       
+       public FMSIdentity(String nickname, String requesturi) {
+               nickName = nickname;
+               requestUri = requesturi;
+       }
+       
+       public String getNickName() {
+               return nickName;
+       }
+
+       public String getRequestURI() {
+               return requestUri;
+       }
+}


Property changes on: trunk/plugins/FMSPlugin/FMSIdentity.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/FMSIdentityManager.java
===================================================================
--- trunk/plugins/FMSPlugin/FMSIdentityManager.java                             
(rev 0)
+++ trunk/plugins/FMSPlugin/FMSIdentityManager.java     2008-09-12 17:08:44 UTC 
(rev 22630)
@@ -0,0 +1,26 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin;
+
+import freenet.support.Executor;
+
+/**
+ * @author saces
+ *
+ */
+public class FMSIdentityManager {
+
+       private final Executor _executor;
+
+       public FMSIdentityManager(Executor executor) {
+               _executor = executor;
+
+       }
+
+       void killMe() {
+               // TODO Auto-generated method stub
+               
+       }
+
+}


Property changes on: trunk/plugins/FMSPlugin/FMSIdentityManager.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/FMSMessage.java
===================================================================
--- trunk/plugins/FMSPlugin/FMSMessage.java                             (rev 0)
+++ trunk/plugins/FMSPlugin/FMSMessage.java     2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,12 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin;
+
+/**
+ * @author saces
+ *
+ */
+public class FMSMessage {
+
+}


Property changes on: trunk/plugins/FMSPlugin/FMSMessage.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/FMSOwnIdentity.java
===================================================================
--- trunk/plugins/FMSPlugin/FMSOwnIdentity.java                         (rev 0)
+++ trunk/plugins/FMSPlugin/FMSOwnIdentity.java 2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,60 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.Date;
+
+/**
+ * @author saces
+ *
+ */
+public class FMSOwnIdentity extends FMSIdentity {
+       
+       private final String insertUri;
+       private final boolean publishTrustList;
+
+       public FMSOwnIdentity(String nickname, String requesturi, String 
inserturi, boolean publishtrustlist) {
+               super(nickname, requesturi);
+               insertUri = inserturi;
+               publishTrustList = publishtrustlist;
+       }
+
+       public String getLastChange() {
+               return "LastChange";
+       }
+
+       public Date getLastInsert() {
+               return new Date(0);
+       }
+
+       public String getInsertURI() {
+               return insertUri;
+       }
+       
+       public boolean doesPublishTrustList() {
+               return publishTrustList;
+       }
+       
+       public final void exportXML(OutputStream out) throws IOException {
+               Writer w = new BufferedWriter(new OutputStreamWriter(out));
+               w.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+               w.write("<Identity\n");
+               w.write("\t<Name><![CDATA[");
+               XMLUtils.writeEsc(w, getNickName());
+               w.write("]]></Name>\n");
+               
+               w.write("\t<SingleUse>false</SingleUse>\n");
+               w.write("\t<PublishTrustList>false</PublishTrustList>\n");
+               w.write("\t<PublishBoardList>false</PublishBoardList>\n");
+
+               w.write("<Identity\n");
+               w.flush();
+               w.close();
+       }
+}


Property changes on: trunk/plugins/FMSPlugin/FMSOwnIdentity.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/FMSPlugin.java
===================================================================
--- trunk/plugins/FMSPlugin/FMSPlugin.java                              (rev 0)
+++ trunk/plugins/FMSPlugin/FMSPlugin.java      2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,297 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import plugins.FMSPlugin.ui.Backup;
+import plugins.FMSPlugin.ui.Errors;
+import plugins.FMSPlugin.ui.IdentityEditor;
+import plugins.FMSPlugin.ui.Messages;
+import plugins.FMSPlugin.ui.Status;
+
+import com.db4o.Db4o;
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+import com.db4o.config.Configuration;
+
+import freenet.client.HighLevelSimpleClient;
+import freenet.clients.http.PageMaker;
+import freenet.clients.http.PageMaker.THEME;
+import freenet.keys.FreenetURI;
+import freenet.l10n.L10n.LANGUAGE;
+import freenet.pluginmanager.FredPluginToadlet;
+import freenet.pluginmanager.NotFoundPluginHTTPException;
+import freenet.pluginmanager.PluginHTTPException;
+import freenet.pluginmanager.PluginRespirator;
+import freenet.pluginmanager.RedirectPluginHTTPException;
+import freenet.support.Logger;
+import freenet.support.api.HTTPRequest;
+
+/**
+ * @author saces
+ *
+ */
+public class FMSPlugin implements FredPluginToadlet {
+
+       public static String SELF_URI = "/plugins/plugins.FMSPlugin.FMSPlugin";
+       public static String SELF_TITLE = "FMS clone";
+       //private static String WOT_NAME = "plugins.WoT.WoTplugin";
+
+       public final String MESSAGEBASE = "fms";
+
+       private PluginRespirator pr;
+
+       private PageMaker pm;
+
+       private LANGUAGE language;
+
+       private HighLevelSimpleClient client;
+
+       private FMSDealer dealer;
+
+       private ObjectContainer db_config;
+       private ObjectContainer db_cache;
+
+       private FMS fms;
+
+       public void runPlugin(PluginRespirator pr2) {
+
+               Logger.error(this, "Start");
+
+               pr = pr2;
+
+               pm = pr.getPageMaker();
+               pm.addNavigationLink("/", "Fproxy", "Back to Fpoxy", false, 
null);
+               pm.addNavigationLink(SELF_URI + "/status", "Dealer status", 
"Show what happens in background", 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 + "/messages", "Messages", "View 
Messages", false, null);
+
+               client = pr.getHLSimpleClient();
+
+               Configuration config_config = Db4o.newConfiguration();
+               
config_config.objectClass(FMSOwnIdentity.class).objectField("requestUri").indexed(true);
+               
config_config.objectClass(FMSIdentity.class).objectField("requestUri").indexed(true);
+               db_config = Db4o.openFile(config_config, "fms_conf.db4o");
+
+               Configuration cache_config = Db4o.newConfiguration();
+               db_cache = Db4o.openFile(cache_config, "fms_cache.db4o");
+
+               // while develop wipe cache on startup
+               ObjectSet<Object> result = db_cache.queryByExample(new 
Object());
+               if (result.size() > 0) {
+                       for (Object o : result) {
+                               db_cache.delete(o);
+                       }
+                       db_cache.commit();
+               }
+
+               dealer = new FMSDealer(pr.getNode().executor);
+
+               fms = new FMS(pr.getNode().clientCore.tempBucketFactory, pm, 
pr, db_config, db_cache);
+               
+       }
+
+       public void terminate() {
+               dealer.killMe();
+               db_config.close();
+               db_cache.close();
+       }
+
+       public String handleHTTPGet(HTTPRequest request) throws 
PluginHTTPException {
+
+               if (request.isParameterSet("formPassword")) {
+                       String pass = request.getParam("formPassword");
+                       if ((pass.length() == 0) || 
!pass.equals(pr.getNode().clientCore.formPassword)) {
+                               return Errors.makeErrorPage(fms, "Buh! Invalid 
form password");
+                       }
+               }
+
+               String page = request.getPath().substring(SELF_URI.length());
+               if ((page.length() < 1) || ("/".equals(page)))
+                       return Status.makeStartStopPage(fms);
+
+               if ("/status".equals(page)) {
+                       return Status.makeStatusPage(fms);
+               }
+
+               if ("/ownidentities".equals(page))
+                       return IdentityEditor.makeOwnIdentitiesPage(fms, 
request);
+
+               if ("/knownidentities".equals(page))
+                       return IdentityEditor.makeKnownIdentitiesPage(fms, 
request);
+
+               if ("/messages".equals(page))
+                       return Messages.makeMessagesPage(fms, request);
+
+               throw new NotFoundPluginHTTPException("Resource not found in 
FMSPlugin", page);
+       }
+
+       public String handleHTTPPut(HTTPRequest request) throws 
PluginHTTPException {
+               throw new RedirectPluginHTTPException("", SELF_URI);
+       }
+
+       public String handleHTTPPost(HTTPRequest request) throws 
PluginHTTPException {
+               String pass = request.getPartAsString("formPassword", 32);
+               if ((pass.length() == 0) || 
!pass.equals(pr.getNode().clientCore.formPassword)) {
+                       return Errors.makeErrorPage(fms, "Buh! Invalid form 
password");
+               }
+
+               String page = request.getPath().substring(SELF_URI.length());
+
+               if (page.length() < 1)
+                       throw new NotFoundPluginHTTPException("Resource not 
found", page);
+               // return makeStartStopPage();
+
+               if (page.equals("/impexport")) {
+                       if (!request.isPartSet("filename")) {
+                               return Errors.makeErrorPage(fms, "Invalid 
Request on ?impexport?: missing filename");
+                       }
+                       String fileName = request.getPartAsString("filename", 
1024);
+                       if (request.isPartSet("importall")) {
+                               try {
+                                       Backup.importConfigDb(db_config, 
fileName);
+                               } catch (Exception e) {
+                                       Logger.error(this, "Error While 
importing from: " + fileName, e);
+                                       return Errors.makeErrorPage(fms, 
"Server BuhBuh! " + e.getMessage());
+                               }
+                               throw new RedirectPluginHTTPException("", 
SELF_URI);
+                       }
+                       if (request.isPartSet("exportall")) {
+                               try {
+                                       Backup.exportConfigDb(db_config, 
fileName);
+                               } catch (IOException e) {
+                                       Logger.error(this, "Error While 
exporting to: " + fileName, e);
+                                       return Errors.makeErrorPage(fms, 
"Server BuhBuh! " + e.getMessage());
+                               }
+                               Logger.error(this, "Succesful export to: " + 
fileName);
+                               throw new RedirectPluginHTTPException("", 
SELF_URI);
+                       }
+                       return Errors.makeErrorPage(fms, "Invalid Request on 
?ownIdentities?");
+               }
+               if (page.equals("/createownidentity")) {
+                       List<String> err = new ArrayList<String>();
+                       String nick = request.getPartAsString("nick", 
1024).trim();
+                       String requestUri = 
request.getPartAsString("requestURI", 1024);
+                       String insertUri = request.getPartAsString("insertURI", 
1024);
+                       boolean publish = 
"true".equals(request.getPartAsString("publishTrustList", 24));
+
+                       IdentityEditor.checkNick(err, nick);
+
+                       if ((requestUri.length() == 0) && (insertUri.length() 
== 0)) {
+                               FreenetURI[] kp = client.generateKeyPair("fms");
+                               insertUri = kp[0].toString();
+                               requestUri = kp[1].toString();
+                               err.add("URI was empty, I generated one for 
you.");
+                               return 
IdentityEditor.makeNewOwnIdentityPage(fms, nick, requestUri, insertUri, 
publish, err);
+                       }
+
+                       IdentityEditor.checkInsertURI(err, insertUri);
+                       IdentityEditor.checkRequestURI(err, requestUri);
+
+                       if (err.size() == 0) {
+                               FMSOwnIdentity oi = new FMSOwnIdentity(nick, 
requestUri, insertUri, publish);
+                               IdentityEditor.addNewOwnIdentity(db_config, oi, 
err);
+                       }
+
+                       if (err.size() == 0) {
+                               throw new RedirectPluginHTTPException("", 
SELF_URI + "/ownidentities");
+                       }
+
+                       return IdentityEditor.makeNewOwnIdentityPage(fms, nick, 
requestUri, insertUri, publish, err);
+               }
+
+               if (page.equals("/addknownidentity")) {
+                       List<String> err = new ArrayList<String>();
+
+                       String requestUri = 
request.getPartAsString("requestURI", 1024);
+
+                       if (requestUri.length() == 0) {
+                               err.add("Are you jokingly? URI was empty.");
+                               return 
IdentityEditor.makeNewKnownIdentityPage(fms, requestUri, err);
+                       }
+
+                       IdentityEditor.checkRequestURI(err, requestUri);
+
+                       if (err.size() == 0) {
+                               FMSIdentity i = new FMSIdentity("", requestUri);
+                               IdentityEditor.addNewKnownIdentity(db_config, 
i, err);
+                       }
+
+                       if (err.size() == 0) {
+                               throw new RedirectPluginHTTPException("", 
SELF_URI + "/knownidentities");
+                       }
+
+                       return IdentityEditor.makeNewKnownIdentityPage(fms, 
requestUri, err);
+               }
+
+               if (page.equals("/deleteOwnIdentity")) {
+                       List<String> err = new ArrayList<String>();
+
+                       String requestUri = request.getPartAsString("identity", 
1024);
+                       if (requestUri.length() == 0) {
+                               err.add("Are you jokingly? URI was empty.");
+                               return 
IdentityEditor.makeDeleteOwnIdentityPage(fms, requestUri, err);
+                       }
+
+                       if (request.isPartSet("confirmed")) {
+                               IdentityEditor.deleteIdentity(fms, requestUri, 
err);
+                       } else {
+                               err.add("Please confirm.");
+                       }
+
+                       if (err.size() > 0) {
+                               return 
IdentityEditor.makeDeleteOwnIdentityPage(fms, requestUri, err);
+                       }
+                       throw new RedirectPluginHTTPException("", SELF_URI + 
"/ownidentities");
+                       // return IdentityEditor.makeDeleteOwnIdentityPage(fms, 
requestUri,
+                       // err);
+               }
+
+               if (page.equals("/deleteIdentity")) {
+                       List<String> err = new ArrayList<String>();
+
+                       String requestUri = request.getPartAsString("identity", 
1024);
+                       if (requestUri.length() == 0) {
+                               err.add("Are you jokingly? URI was empty.");
+                               return 
IdentityEditor.makeDeleteKnownIdentityPage(fms, requestUri, err);
+                       }
+
+                       if (request.isPartSet("confirmed")) {
+                               IdentityEditor.deleteIdentity(fms, requestUri, 
err);
+                       } else {
+                               err.add("Please confirm.");
+                       }
+
+                       if (err.size() > 0) {
+                               return 
IdentityEditor.makeDeleteKnownIdentityPage(fms, requestUri, err);
+                       }
+                       throw new RedirectPluginHTTPException("", SELF_URI + 
"/knownidentities");
+               }
+               throw new NotFoundPluginHTTPException("Resource not found", 
page);
+       }
+
+       public String getVersion() {
+               return "tp r" + Version.svnRevision;
+       }
+
+       public String getString(String key) {
+               // language.;
+               // Logger.error(this, "Request translation for "+key);
+               return key;
+       }
+
+       public void setLanguage(LANGUAGE newLanguage) {
+               Logger.error(this, "Set LANGUAGE to: " + newLanguage.isoCode);
+               language = newLanguage;
+       }
+
+       public void setTheme(THEME theme) {
+               // TODO Auto-generated method stub
+               
+       }
+}


Property changes on: trunk/plugins/FMSPlugin/FMSPlugin.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/Version.java
===================================================================
--- trunk/plugins/FMSPlugin/Version.java                                (rev 0)
+++ trunk/plugins/FMSPlugin/Version.java        2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,13 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin;
+
+/**
+ * @author saces
+ *
+ */
+public class Version {
+       static final String svnRevision = "@custom@";
+}
+


Property changes on: trunk/plugins/FMSPlugin/Version.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/WotImporter.java
===================================================================
--- trunk/plugins/FMSPlugin/WotImporter.java                            (rev 0)
+++ trunk/plugins/FMSPlugin/WotImporter.java    2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,26 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin;
+
+import freenet.pluginmanager.FredPluginTalker;
+import freenet.support.SimpleFieldSet;
+import freenet.support.api.Bucket;
+
+/**
+ * @author saces
+ *
+ */
+public class WotImporter implements FredPluginTalker {
+       
+       void importAll() {
+               
+       }
+
+       public void onReply(String pluginname, String indentifier,
+                       SimpleFieldSet params, Bucket data) {
+               // TODO Auto-generated method stub
+               
+       }
+
+}


Property changes on: trunk/plugins/FMSPlugin/WotImporter.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/XMLParser.java
===================================================================
--- trunk/plugins/FMSPlugin/XMLParser.java                              (rev 0)
+++ trunk/plugins/FMSPlugin/XMLParser.java      2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,20 @@
+package plugins.FMSPlugin;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.SAXException;
+
+/**
+ * @author saces
+ *
+ */
+public class XMLParser {
+       SAXParser saxParser;
+       
+       XMLParser() throws ParserConfigurationException, SAXException {
+               // TODO configure, paranoia settings?
+               saxParser = SAXParserFactory.newInstance().newSAXParser();
+       }
+}


Property changes on: trunk/plugins/FMSPlugin/XMLParser.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/XMLUtils.java
===================================================================
--- trunk/plugins/FMSPlugin/XMLUtils.java                               (rev 0)
+++ trunk/plugins/FMSPlugin/XMLUtils.java       2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,44 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @author saces
+ *
+ */
+public class XMLUtils {
+       
+       public final static void writeEsc(Writer w, String s) throws 
IOException {
+               writeEsc(w, s, false);
+       }
+       
+       private static void writeEsc(Writer w, String s, boolean isAttVal) 
throws IOException {
+               for (int i = 0; i < s.length(); i++) {
+                       switch (s.charAt(i)) {
+                       case '&':
+                               w.write("&amp;");
+                               break;
+                       case '<':
+                               w.write("&lt;");
+                               break;
+                       case '>':
+                               w.write("&gt;");
+                               break;
+                       case '\"':
+                               if (isAttVal) {
+                                       w.write("&quot;");
+                               } else {
+                                       w.write('\"');
+                               }
+                               break;
+                       default:
+                               w.write(s.charAt(i));
+                       }
+               }
+       }
+}
+


Property changes on: trunk/plugins/FMSPlugin/XMLUtils.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/fms/IdentityFetcher.java
===================================================================
--- trunk/plugins/FMSPlugin/fms/IdentityFetcher.java                            
(rev 0)
+++ trunk/plugins/FMSPlugin/fms/IdentityFetcher.java    2008-09-12 17:08:44 UTC 
(rev 22630)
@@ -0,0 +1,7 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin.fms;
+
+public class IdentityFetcher {
+}


Property changes on: trunk/plugins/FMSPlugin/fms/IdentityFetcher.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/fms/IdentityInserter.java
===================================================================
--- trunk/plugins/FMSPlugin/fms/IdentityInserter.java                           
(rev 0)
+++ trunk/plugins/FMSPlugin/fms/IdentityInserter.java   2008-09-12 17:08:44 UTC 
(rev 22630)
@@ -0,0 +1,7 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin.fms;
+
+public class IdentityInserter {
+}


Property changes on: trunk/plugins/FMSPlugin/fms/IdentityInserter.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/fms/IdentityVerifierer.java
===================================================================
--- trunk/plugins/FMSPlugin/fms/IdentityVerifierer.java                         
(rev 0)
+++ trunk/plugins/FMSPlugin/fms/IdentityVerifierer.java 2008-09-12 17:08:44 UTC 
(rev 22630)
@@ -0,0 +1,7 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin.fms;
+
+public class IdentityVerifierer {
+}


Property changes on: trunk/plugins/FMSPlugin/fms/IdentityVerifierer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/ui/Backup.java
===================================================================
--- trunk/plugins/FMSPlugin/ui/Backup.java                              (rev 0)
+++ trunk/plugins/FMSPlugin/ui/Backup.java      2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,220 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin.ui;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import plugins.FMSPlugin.FMSIdentity;
+import plugins.FMSPlugin.FMSOwnIdentity;
+import plugins.FMSPlugin.XMLUtils;
+
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+
+/**
+ * @author saces
+ *
+ */
+public class Backup {
+
+       private static SAXParser saxParser;
+
+       public final static void exportConfigDb(ObjectContainer config_db, 
String filename) throws IOException {
+
+               File test = new File(filename).getAbsoluteFile();
+               Writer w = new BufferedWriter(new FileWriter(test));
+
+               w.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+               w.write("<fms-kidding>\n");
+               w.write("\t<OwnIdentities>\n");
+               ObjectSet<FMSOwnIdentity> ownIdentities = 
config_db.queryByExample(FMSOwnIdentity.class);
+
+               while (ownIdentities.hasNext()) {
+                       FMSOwnIdentity id = ownIdentities.next();
+                       w.write("\t\t<OwnIdentity>\n");
+                       w.write("\t\t\t<Nick>");
+                       XMLUtils.writeEsc(w, id.getNickName());
+                       w.write("</Nick>\n");
+                       w.write("\t\t\t<RequestURI>");
+                       w.write(id.getRequestURI());
+                       w.write("</RequestURI>\n");
+                       w.write("\t\t\t<InsertURI>");
+                       w.write(id.getInsertURI());
+                       w.write("</InsertURI>\n");
+                       w.write("\t\t\t<PublishTrustList>");
+                       w.write(id.doesPublishTrustList() ? "true" : "false");
+                       w.write("</PublishTrustList>\n");
+                       w.write("\t\t</OwnIdentity>\n");
+               }
+
+               w.write("\t</OwnIdentities>\n");
+               w.write("\t<Identities>\n");
+
+               ObjectSet<FMSIdentity> identities = 
config_db.queryByExample(FMSIdentity.class);
+
+               while (identities.hasNext()) {
+                       FMSIdentity id = identities.next();
+                       if (id instanceof FMSOwnIdentity)
+                               continue;
+                       w.write("\t\t<Identity>\n");
+                       w.write("\t\t\t<Nick>");
+                       XMLUtils.writeEsc(w, id.getNickName());
+                       w.write("</Nick>\n");
+                       w.write("\t\t\t<RequestURI>");
+                       w.write(id.getRequestURI());
+                       w.write("</RequestURI>\n");
+                       w.write("\t\t</Identity>\n");
+               }
+
+               w.write("\t</Identities>\n");
+               w.write("</fms-kidding>\n");
+               w.flush();
+               w.close();
+       }
+
+       public final static void importConfigDb(ObjectContainer config_db, 
String filename) throws IOException, ParserConfigurationException, SAXException 
{
+
+               File test = new File(filename).getAbsoluteFile();
+               InputStream is = new BufferedInputStream(new 
FileInputStream(test));
+               SAXParser parser = getSaxParser();
+               parser.parse(is, new ImportHandler(config_db));
+       }
+
+       private static SAXParser getSaxParser() throws 
ParserConfigurationException, SAXException {
+               if (saxParser == null) {
+                       saxParser = 
SAXParserFactory.newInstance().newSAXParser();
+               }
+               return saxParser;
+       }
+
+       public static class ImportHandler extends DefaultHandler {
+
+               boolean shouldRecord = false;
+               StringBuilder currentItem = new StringBuilder();
+               private String requestUri;
+               private String nick;
+               private String insertUri;
+               private boolean publishTL;
+               ObjectContainer config_db;
+
+               ImportHandler(ObjectContainer configdb) {
+                       config_db = configdb;
+               }
+               /*
+                * (non-Javadoc)
+                * 
+                * @see
+                * 
org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String,
+                * java.lang.String, java.lang.String, org.xml.sax.Attributes)
+                */
+               @Override
+               public void startElement(String uri, String localName, String 
name, Attributes attributes) throws SAXException {
+
+                       if ("Nick".equals(name)) {
+                               shouldRecord = true;
+                               return;
+                       }
+                       if ("RequestURI".equals(name)) {
+                               shouldRecord = true;
+                               return;
+                       }
+                       if ("InsertURI".equals(name)) {
+                               shouldRecord = true;
+                               return;
+                       }
+                       if ("PublishTrustList".equals(name)) {
+                               shouldRecord = true;
+                               return;
+                       }
+
+                       shouldRecord = false;
+                       //System.out.println("Parse: " + uri + " - " + 
localName + " - " + name);
+               }
+
+               /*
+                * (non-Javadoc)
+                * 
+                * @see org.xml.sax.helpers.DefaultHandler#characters(char[], 
int, int)
+                */
+               @Override
+               public void characters(char[] ch, int start, int length) throws 
SAXException {
+                       if (shouldRecord)
+                               currentItem.append(ch, start, length);
+               }
+
+               /*
+                * (non-Javadoc)
+                * 
+                * @see 
org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String,
+                * java.lang.String, java.lang.String)
+                */
+               @Override
+               public void endElement(String uri, String localName, String 
name) throws SAXException {
+
+                       if ("Nick".equals(name)) {
+                               nick = currentItem.toString();
+                               resetRecord();
+                               return;
+                       }
+                       if ("RequestURI".equals(name)) {
+                               requestUri = currentItem.toString();
+                               resetRecord();
+                               return;
+                       }
+                       if ("InsertURI".equals(name)) {
+                               insertUri = currentItem.toString();
+                               resetRecord();
+                               return;
+                       }
+                       if ("PublishTrustList".equals(name)) {
+                               String val = currentItem.toString();
+                               System.out.println("PTL: "+val);
+                               publishTL = "true".equals(val);
+                               resetRecord();
+                               return;
+                       }
+
+                       if ("OwnIdentity".equals(name)) {
+                               //System.out.println("OID: " + nick+" - 
"+requestUri+" - "+insertUri+" - "+publishTL);
+                               FMSOwnIdentity oid = new FMSOwnIdentity(nick, 
requestUri, insertUri, publishTL);
+                               config_db.store(oid);
+                               config_db.commit();
+                               return;
+                       }
+                       
+                       if ("Identity".equals(name)) {
+                               //System.out.println("ID: " + nick+" - 
"+requestUri);
+                               FMSIdentity id = new FMSIdentity(nick, 
requestUri);
+                               config_db.store(id);
+                               config_db.commit();
+                               return;
+                       }
+                       
+                       //System.out.println("Parse-end: " + name + " Content: 
" + currentItem.toString());
+                       shouldRecord = false;
+                       currentItem.delete(0, currentItem.length());
+               }
+
+               private void resetRecord() {
+                       shouldRecord = false;
+                       currentItem.delete(0, currentItem.length());
+               }
+
+       }
+}


Property changes on: trunk/plugins/FMSPlugin/ui/Backup.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/ui/Errors.java
===================================================================
--- trunk/plugins/FMSPlugin/ui/Errors.java                              (rev 0)
+++ trunk/plugins/FMSPlugin/ui/Errors.java      2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,73 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin.ui;
+
+import plugins.FMSPlugin.FMS;
+import plugins.FMSPlugin.FMSPlugin;
+import freenet.support.HTMLNode;
+
+public class Errors {
+       
+       public static String makeErrorPage(FMS fms, String error) {
+               return makeErrorPage(fms, "ERROR", error);
+       }
+
+       private static String makeErrorPage(FMS fms, String title, String 
error) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+               contentNode.addChild(createErrorBox(fms, title, error));
+               return pageNode.generate();
+       }
+
+       private static HTMLNode createErrorBox(FMS fms, String title, String 
errmsg) {
+               HTMLNode errorBox = fms.pm.getInfobox("infobox-alert", title);
+               errorBox.addChild("#", errmsg);
+               return errorBox;
+       }
+
+       
+       public static String makeStartStopPage(FMS fms) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+               contentNode.addChild(createImpExportBox(fms));
+               return pageNode.generate();
+       }
+       
+       public static String makeStatusPage(FMS fms) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+
+               HTMLNode stopBox = fms.pm.getInfobox("");
+               contentNode.addChild(stopBox);
+               HTMLNode stopContent = fms.pm.getContentNode(stopBox);
+               HTMLNode stopForm = fms.pr.addFormChild(stopContent, 
FMSPlugin.SELF_URI + "/startStopDealer", "dealerForm");
+               stopForm.addChild("#", "Stop Dealer. \u00a0 ");
+               stopForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "stopDealer", "Stop" });
+
+               contentNode.addChild("#", "makeStatusPage");
+               return pageNode.generate();
+       }
+
+
+       private static HTMLNode createImpExportBox(FMS fms) {
+               HTMLNode importBox = fms.pm.getInfobox("Imp & Export");
+               // contentNode.addChild(importBox);
+               HTMLNode importContent = fms.pm.getContentNode(importBox);
+               HTMLNode importForm = fms.pr.addFormChild(importContent, 
FMSPlugin.SELF_URI + "/impexport", "impexForm");
+               importForm.addChild("#", "Imp/Export xml file. \u00a0 ");
+               importForm.addChild("#", "Filename : ");
+               importForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "filename", "70", "fms-kidding.xml" 
});
+               // importForm.addChild("br");
+               importForm.addChild("#", 
"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0");
+               importForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "importall", "Import" });
+               importForm.addChild("#", 
"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0");
+               // importForm.addChild("BR");
+               // importForm.addChild("#", "Export to Wot. \u00a0 ");
+               importForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "exportall", "Export" });
+               // importForm.addChild("BR");
+               return importBox;
+       }
+
+
+}


Property changes on: trunk/plugins/FMSPlugin/ui/Errors.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/ui/IdentityEditor.java
===================================================================
--- trunk/plugins/FMSPlugin/ui/IdentityEditor.java                              
(rev 0)
+++ trunk/plugins/FMSPlugin/ui/IdentityEditor.java      2008-09-12 17:08:44 UTC 
(rev 22630)
@@ -0,0 +1,344 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin.ui;
+
+import java.util.Date;
+import java.util.List;
+
+import plugins.FMSPlugin.FMS;
+import plugins.FMSPlugin.FMSIdentity;
+import plugins.FMSPlugin.FMSOwnIdentity;
+import plugins.FMSPlugin.FMSPlugin;
+
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+
+import freenet.support.HTMLNode;
+import freenet.support.Logger;
+import freenet.support.api.HTTPRequest;
+
+public class IdentityEditor {
+               
+       /* === own identities ==================== */
+       
+       public static final String makeOwnIdentitiesPage(FMS fms, HTTPRequest 
request) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+
+               HTMLNode box = fms.pm.getInfobox("Own Identities");
+               HTMLNode boxContent = fms.pm.getContentNode(box);
+               contentNode.addChild(box);
+
+               ObjectSet<FMSOwnIdentity> ownIdentities = 
fms.db_config.queryByExample(FMSOwnIdentity.class);
+               if (ownIdentities.size() == 0) {
+                       boxContent.addChild("p", "You have no own identity yet, 
you should create one...");
+               } else {
+
+                       HTMLNode identitiesTable = boxContent.addChild("table");
+                       HTMLNode row = identitiesTable.addChild("tr");
+                       row.addChild("th", "Name");
+                       row.addChild("th", "Request URI");
+                       row.addChild("th", "Insert URI");
+                       row.addChild("th", "Publish TrustList ?");
+                       row.addChild("th", "Last update");
+                       row.addChild("th");
+
+                       while (ownIdentities.hasNext()) {
+                               FMSOwnIdentity id = ownIdentities.next();
+                               row = identitiesTable.addChild("tr");
+                               row.addChild("td", id.getNickName());
+                               row.addChild("td", new String[]{"title"}, new 
String[]{id.getRequestURI()}, id.getRequestURI().substring(0, 35)+"...");
+                               row.addChild("td", new String[]{"title"}, new 
String[]{id.getInsertURI()}, id.getInsertURI().substring(0, 15)+"...");
+                               row.addChild("td", 
id.doesPublishTrustList()?"yes":"no");
+                               HTMLNode lastUpdateCell = row.addChild("td");
+                               if (id.getLastInsert() == null) {
+                                       lastUpdateCell.addChild("p", "Insert in 
progress...");
+                               } else if (id.getLastInsert().equals(new 
Date(0))) {
+                                       lastUpdateCell.addChild("p", "Never");
+                               } else {
+                                       lastUpdateCell.addChild(new 
HTMLNode("a", "href", "/" + id.getRequestURI().toString(), 
id.getLastInsert().toString()));
+                               }
+                               HTMLNode deleteCell = row.addChild("td");
+                               HTMLNode deleteForm = 
fms.pr.addFormChild(deleteCell, FMSPlugin.SELF_URI + "/deleteOwnIdentity", 
"deleteForm");
+                               deleteForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "hidden", "identity", 
id.getRequestURI()});
+                               deleteForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "submit", "delete", "Delete" });
+                       }
+               }
+
+               contentNode.addChild(createNewOwnIdentityBox(fms));
+
+               return pageNode.generate();
+       }
+       
+       /* === new own identity ================== */
+       
+       public static final String makeNewOwnIdentityPage(FMS fms, String nick, 
String requestUri, String insertUri, boolean publish, List<String> errors) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+               contentNode.addChild(createNewOwnIdentityBox(fms, nick, 
requestUri, insertUri, publish, errors));
+               return pageNode.generate();
+       }
+
+       private static final HTMLNode createNewOwnIdentityBox(FMS fms) {
+               return createNewOwnIdentityBox(fms, "", "", "", true, null);
+       }
+
+       private static final HTMLNode createNewOwnIdentityBox(FMS fms, String 
nick, String requestUri, String insertUri, boolean publish, List<String> 
errors) {
+               HTMLNode addBox = fms.pm.getInfobox("New Identity");
+               HTMLNode addContent = fms.pm.getContentNode(addBox);
+
+               if (errors != null) {
+                       HTMLNode errorBox = fms.pm.getInfobox("infobox-alert", 
"Typo");
+                       HTMLNode errorContent = fms.pm.getContentNode(errorBox);
+                       for (String s : errors) {
+                               errorContent.addChild("#", s);
+                               errorContent.addChild("br");
+                       }
+                       addContent.addChild(errorBox);
+               }
+
+               HTMLNode addForm = fms.pr.addFormChild(addContent, 
FMSPlugin.SELF_URI + "/createownidentity", "addForm");
+
+               addForm.addChild("#", "Nick : ");
+               addForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "nick", "70", nick });
+               addForm.addChild("br");
+               addForm.addChild("#", "Request URI : ");
+               addForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "requestURI", "70", requestUri });
+               addForm.addChild("br");
+               addForm.addChild("#", "Insert URI : ");
+               addForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "insertURI", "70", insertUri });
+               addForm.addChild("br");
+               addForm.addChild("#", "Publish trust list ");
+               if (publish)
+                       addForm.addChild("input", new String[] { "type", 
"name", "value", "checked" }, new String[] { "checkbox", "publishTrustList", 
"true", "checked" });
+               else
+                       addForm.addChild("input", new String[] { "type", 
"name", "value" }, new String[] { "checkbox", "publishTrustList", "false" });
+               addForm.addChild("br");
+               addForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "create", "Create a new identity !" });
+               return addBox;
+       }
+       
+       /* === delete own identity =============== */
+       
+       public static String makeDeleteOwnIdentityPage(FMS fms, String 
requestUri, List<String> err) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+               contentNode.addChild(deleteOwnIdentityBox(fms, "nick", 
requestUri, "insertUri", false, err));
+               return pageNode.generate();
+       }
+       
+       private static final HTMLNode deleteOwnIdentityBox(FMS fms, String 
nick, String requestUri, String insertUri, boolean publish, List<String> 
errors) {
+               HTMLNode addBox = fms.pm.getInfobox("Delete Identity");
+               HTMLNode addContent = fms.pm.getContentNode(addBox);
+
+               if (errors != null) {
+                       HTMLNode errorBox = fms.pm.getInfobox("infobox-alert", 
"Typo");
+                       HTMLNode errorContent = fms.pm.getContentNode(errorBox);
+                       for (String s : errors) {
+                               errorContent.addChild("#", s);
+                               errorContent.addChild("br");
+                       }
+                       addContent.addChild(errorBox);
+               }
+
+               HTMLNode addForm = fms.pr.addFormChild(addContent, 
FMSPlugin.SELF_URI + "/deleteOwnIdentity", "deleteForm");
+               addForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "hidden", "confirmed", "true"});
+               addForm.addChild("#", "Nick : ");
+               addForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "nick", "70", nick });
+               addForm.addChild("br");
+               addForm.addChild("#", "Request URI : ");
+               addForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "identity", "70", requestUri });
+               addForm.addChild("br");
+               addForm.addChild("#", "Insert URI : ");
+               addForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "insertURI", "70", insertUri });
+               addForm.addChild("br");
+               addForm.addChild("#", "Publish trust list ");
+               if (publish)
+                       addForm.addChild("input", new String[] { "type", 
"name", "value", "checked" }, new String[] { "checkbox", "publishTrustList", 
"true", "checked" });
+               else
+                       addForm.addChild("input", new String[] { "type", 
"name", "value" }, new String[] { "checkbox", "publishTrustList", "false" });
+               addForm.addChild("br");
+               addForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "create", "Create a new identity !" });
+               return addBox;
+       }
+       
+       /* === others  identities ================ */
+       
+       public final static String makeKnownIdentitiesPage(FMS fms, HTTPRequest 
request) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+
+               HTMLNode box = fms.pm.getInfobox("Known Identities");
+               HTMLNode boxContent = fms.pm.getContentNode(box);
+               contentNode.addChild(box);
+
+               ObjectSet<FMSIdentity> identities = 
fms.db_config.queryByExample(FMSIdentity.class);
+
+               HTMLNode identitiesTable = boxContent.addChild("table", 
"border", "0");
+               HTMLNode row = identitiesTable.addChild("tr");
+               row.addChild("th", "Name");
+               row.addChild("th", "Request URI");
+               row.addChild("th");
+
+               while (identities.hasNext()) {
+                       FMSIdentity id = identities.next();
+                       if (id instanceof FMSOwnIdentity)
+                               continue;
+                       row = identitiesTable.addChild("tr");
+                       row.addChild("td", id.getNickName());
+                       row.addChild("td",  id.getRequestURI());
+                       HTMLNode deleteCell = row.addChild("td");
+                       HTMLNode deleteForm = fms.pr.addFormChild(deleteCell, 
FMSPlugin.SELF_URI + "/deleteIdentity", "deleteForm");
+                       deleteForm.addChild("input", new String[] { "type", 
"name", "value" }, new String[] { "hidden", "identity", id.getRequestURI()});
+                       deleteForm.addChild("input", new String[] { "type", 
"name", "value" }, new String[] { "submit", "delete", "Delete" });
+               }
+
+               contentNode.addChild(createNewKnownIdentityBox(fms));
+
+               return pageNode.generate();
+       }
+       
+       /* === new others identities ============= */
+       
+       public static final String makeNewKnownIdentityPage(FMS fms, String 
requestUri, List<String> errors) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+               contentNode.addChild(createNewKnownIdentityBox(fms, requestUri, 
errors));
+               contentNode.addChild("#", "makeNewIdentitiesPagecc");
+               return pageNode.generate();
+       }
+       
+       private static final HTMLNode createNewKnownIdentityBox(FMS fms) {
+               return createNewKnownIdentityBox(fms, "", null);
+       }
+
+       private static final HTMLNode createNewKnownIdentityBox(FMS fms, String 
requestUri, List<String> errors) {
+               HTMLNode addBox = fms.pm.getInfobox("New Identity");
+               HTMLNode addContent = fms.pm.getContentNode(addBox);
+
+               if (errors != null) {
+                       HTMLNode errorBox = fms.pm.getInfobox("infobox-alert", 
"Typo");
+                       HTMLNode errorContent = fms.pm.getContentNode(errorBox);
+                       for (String s : errors) {
+                               errorContent.addChild("#", s);
+                               errorContent.addChild("br");
+                       }
+                       addContent.addChild(errorBox);
+               }
+
+               HTMLNode addForm = fms.pr.addFormChild(addContent, 
FMSPlugin.SELF_URI + "/addknownidentity", "addForm");
+
+               addForm.addChild("#", "Request URI : ");
+               addForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "requestURI", "70", requestUri });
+               addForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "create", "Add identity !" });
+               return addBox;
+       }
+       
+       /* delete */
+       public static String makeDeleteKnownIdentityPage(FMS fms, String 
requestUri, List<String> err) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+               contentNode.addChild(deleteKnownIdentityBox(fms, "nick", 
requestUri, "insertUri", false, err));
+               return pageNode.generate();
+       }
+       
+       private static final HTMLNode deleteKnownIdentityBox(FMS fms, String 
nick, String requestUri, String insertUri, boolean publish, List<String> 
errors) {
+               HTMLNode addBox = fms.pm.getInfobox("Delete Identity");
+               HTMLNode addContent = fms.pm.getContentNode(addBox);
+
+               if (errors != null) {
+                       HTMLNode errorBox = fms.pm.getInfobox("infobox-alert", 
"Typo");
+                       HTMLNode errorContent = fms.pm.getContentNode(errorBox);
+                       for (String s : errors) {
+                               errorContent.addChild("#", s);
+                               errorContent.addChild("br");
+                       }
+                       addContent.addChild(errorBox);
+               }
+
+               HTMLNode addForm = fms.pr.addFormChild(addContent, 
FMSPlugin.SELF_URI + "/deleteIdentity", "deleteForm");
+               addForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "hidden", "confirmed", "true"});
+               addForm.addChild("#", "Nick : ");
+               addForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "nick", "70", nick });
+               addForm.addChild("br");
+               addForm.addChild("#", "Request URI : ");
+               addForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "identity", "70", requestUri });
+               addForm.addChild("br");
+               addForm.addChild("#", "Insert URI : ");
+               addForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "insertURI", "70", insertUri });
+               addForm.addChild("br");
+               addForm.addChild("#", "Publish trust list ");
+               if (publish)
+                       addForm.addChild("input", new String[] { "type", 
"name", "value", "checked" }, new String[] { "checkbox", "publishTrustList", 
"true", "checked" });
+               else
+                       addForm.addChild("input", new String[] { "type", 
"name", "value" }, new String[] { "checkbox", "publishTrustList", "false" });
+               addForm.addChild("br");
+               addForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "create", "Create a new identity !" });
+               return addBox;
+       }
+
+       
+       /* === utils ============================= */
+       
+       public static final void checkNick(List<String> err, String nick) {
+               if (nick.length() == 0) {
+                       err.add("Nick can not be empty.");
+               } else if (nick.length() > 128) {
+                       err.add("Nick to long. 127 chars should be enougth...");
+               }
+       }
+       
+       public static final void checkInsertURI(List<String> err, String 
insertUri) {
+               if (insertUri.length() == 0) {
+                       err.add("Insert URI is missing");
+                       return;
+               }
+       }
+       
+       public static final void checkRequestURI(List<String> err, String 
requestUri) {
+               if (requestUri.length() == 0) {
+                       err.add("Request URI is missing");
+                       return;
+               }
+       }
+       
+       public static final void addNewOwnIdentity(ObjectContainer db, 
FMSOwnIdentity identity, List<String> err) {
+               try {
+                       db.store(identity);
+                       db.commit();
+               } catch (Throwable t) {
+                       Logger.error(IdentityEditor.class, "Error while adding 
Identity: " + t.getMessage(), t);
+                       err.add("Error while adding Identity: " + 
t.getMessage());
+                       db.rollback();
+               }
+       }
+       
+       public static final void addNewKnownIdentity(ObjectContainer db, 
FMSIdentity identity, List<String> err) {
+               try {
+                       db.store(identity);
+                       db.commit();
+               } catch (Throwable t) {
+                       Logger.error(IdentityEditor.class, "Error while adding 
Identity: " + t.getMessage(), t);
+                       err.add("Error while adding Identity: " + 
t.getMessage());
+                       db.rollback();
+               }
+       }
+       
+       public static void deleteIdentity(FMS fms, String requestUri, 
List<String> err) {
+               FMSIdentity templateId = new FMSIdentity(null, requestUri);
+               
+               ObjectSet<FMSIdentity> toDelete = 
fms.db_config.queryByExample(templateId);
+               System.out.println("To delete: "+toDelete.size());
+               if (toDelete.size() > 0) {
+                       for (FMSIdentity id:toDelete) {
+                               fms.db_config.delete(id);
+                       }
+                       fms.db_config.commit();
+               } else {
+                       err.add("Identity ?"+requestUri+"? not found, nothing 
deleted");
+               }
+       }
+       //<table class="column">
+
+}


Property changes on: trunk/plugins/FMSPlugin/ui/IdentityEditor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/ui/Messages.java
===================================================================
--- trunk/plugins/FMSPlugin/ui/Messages.java                            (rev 0)
+++ trunk/plugins/FMSPlugin/ui/Messages.java    2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,20 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin.ui;
+
+import plugins.FMSPlugin.FMS;
+import freenet.support.HTMLNode;
+import freenet.support.api.HTTPRequest;
+
+public class Messages {
+       
+       public static String makeMessagesPage(FMS fms, HTTPRequest request ) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+               contentNode.addChild("#", "makeMessagesPage");
+               return pageNode.generate();
+       }
+
+
+}


Property changes on: trunk/plugins/FMSPlugin/ui/Messages.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/plugins/FMSPlugin/ui/Status.java
===================================================================
--- trunk/plugins/FMSPlugin/ui/Status.java                              (rev 0)
+++ trunk/plugins/FMSPlugin/ui/Status.java      2008-09-12 17:08:44 UTC (rev 
22630)
@@ -0,0 +1,55 @@
+/* This code is part of 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 further details of the GPL. */
+package plugins.FMSPlugin.ui;
+
+import plugins.FMSPlugin.FMS;
+import plugins.FMSPlugin.FMSPlugin;
+import freenet.support.HTMLNode;
+
+public class Status {
+       
+       public static String makeStartStopPage(FMS fms) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+               contentNode.addChild(createImpExportBox(fms));
+               return pageNode.generate();
+       }
+       
+       public static String makeStatusPage(FMS fms) {
+               HTMLNode pageNode = fms.getPageNode();
+               HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+
+               HTMLNode stopBox = fms.pm.getInfobox("");
+               contentNode.addChild(stopBox);
+               HTMLNode stopContent = fms.pm.getContentNode(stopBox);
+               HTMLNode stopForm = fms.pr.addFormChild(stopContent, 
FMSPlugin.SELF_URI + "/startStopDealer", "dealerForm");
+               stopForm.addChild("#", "Stop Dealer. \u00a0 ");
+               stopForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "stopDealer", "Stop" });
+
+               contentNode.addChild("#", "makeStatusPage");
+               return pageNode.generate();
+       }
+
+
+       private static HTMLNode createImpExportBox(FMS fms) {
+               HTMLNode importBox = fms.pm.getInfobox("Imp & Export");
+               // contentNode.addChild(importBox);
+               HTMLNode importContent = fms.pm.getContentNode(importBox);
+               HTMLNode importForm = fms.pr.addFormChild(importContent, 
FMSPlugin.SELF_URI + "/impexport", "impexForm");
+               importForm.addChild("#", "Imp/Export xml file. \u00a0 ");
+               importForm.addChild("#", "Filename : ");
+               importForm.addChild("input", new String[] { "type", "name", 
"size", "value" }, new String[] { "text", "filename", "70", "fms-kidding.xml" 
});
+               // importForm.addChild("br");
+               importForm.addChild("#", 
"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0");
+               importForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "importall", "Import" });
+               importForm.addChild("#", 
"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0");
+               // importForm.addChild("BR");
+               // importForm.addChild("#", "Export to Wot. \u00a0 ");
+               importForm.addChild("input", new String[] { "type", "name", 
"value" }, new String[] { "submit", "exportall", "Export" });
+               // importForm.addChild("BR");
+               return importBox;
+       }
+
+
+}


Property changes on: trunk/plugins/FMSPlugin/ui/Status.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain


Reply via email to