Author: saces
Date: 2008-09-13 19:58:00 +0000 (Sat, 13 Sep 2008)
New Revision: 22645
Added:
trunk/plugins/FMSPlugin/ui/Service.java
trunk/plugins/FMSPlugin/ui/Welcome.java
Modified:
trunk/plugins/FMSPlugin/FMSPlugin.java
trunk/plugins/FMSPlugin/ui/Backup.java
trunk/plugins/FMSPlugin/ui/Errors.java
trunk/plugins/FMSPlugin/ui/Status.java
Log:
db backup/import goes through browser now
ui fixes
code cleanup
Modified: trunk/plugins/FMSPlugin/FMSPlugin.java
===================================================================
--- trunk/plugins/FMSPlugin/FMSPlugin.java 2008-09-13 19:42:52 UTC (rev
22644)
+++ trunk/plugins/FMSPlugin/FMSPlugin.java 2008-09-13 19:58:00 UTC (rev
22645)
@@ -4,6 +4,7 @@
package plugins.FMSPlugin;
import java.io.IOException;
+import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
@@ -11,7 +12,9 @@
import plugins.FMSPlugin.ui.Errors;
import plugins.FMSPlugin.ui.IdentityEditor;
import plugins.FMSPlugin.ui.Messages;
+import plugins.FMSPlugin.ui.Service;
import plugins.FMSPlugin.ui.Status;
+import plugins.FMSPlugin.ui.Welcome;
import com.db4o.Db4o;
import com.db4o.ObjectContainer;
@@ -23,6 +26,7 @@
import freenet.clients.http.PageMaker.THEME;
import freenet.keys.FreenetURI;
import freenet.l10n.L10n.LANGUAGE;
+import freenet.pluginmanager.DownloadPluginHTTPException;
import freenet.pluginmanager.FredPlugin;
import freenet.pluginmanager.FredPluginFCP;
import freenet.pluginmanager.FredPluginHTTP;
@@ -39,6 +43,7 @@
import freenet.support.SimpleFieldSet;
import freenet.support.api.Bucket;
import freenet.support.api.HTTPRequest;
+import freenet.support.api.HTTPUploadedFile;
/**
* @author saces
@@ -104,7 +109,6 @@
dealer = new FMSDealer(pr.getNode().executor);
fms = new FMS(pr.getNode().clientCore.tempBucketFactory, pm,
pr, db_config, db_cache);
-
}
public void terminate() {
@@ -124,11 +128,15 @@
String page = request.getPath().substring(SELF_URI.length());
if ((page.length() < 1) || ("/".equals(page)))
- return Status.makeStartStopPage(fms);
+ return Welcome.makeWelcomePage(fms);
if ("/status".equals(page)) {
return Status.makeStatusPage(fms);
}
+
+ if ("/service".equals(page)) {
+ return Service.makeServicePage(fms);
+ }
if ("/ownidentities".equals(page))
return IdentityEditor.makeOwnIdentitiesPage(fms,
request);
@@ -162,34 +170,32 @@
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");
+ if (page.equals("/exportDB")) {
+ StringWriter sw = new StringWriter();
+ try {
+ Backup.exportConfigDb(db_config, sw);
+ } catch (IOException e) {
+ Logger.error(this, "Error While exporting
database!", e);
+ return Errors.makeErrorPage(fms, "Server
BuhBuh! " + e.getMessage());
}
- 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);
+ throw new
DownloadPluginHTTPException(sw.toString().getBytes(), "fms-kidding.xml",
"fms-clone/db-backup");
+ }
+
+ if (page.equals("/importDB")) {
+ HTTPUploadedFile file =
request.getUploadedFile("filename");
+ if (file == null || file.getFilename().trim().length()
== 0) {
+ return Errors.makeErrorPage(fms, "No file to
import selected!");
}
- 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);
+ try {
+ Backup.importConfigDb(db_config,
file.getData().getInputStream());
+ } catch (Exception e) {
+ Logger.error(this, "Error While importing db
from: " + file.getFilename(), e);
+ return Errors.makeErrorPage(fms, "Error While
importing db from: " + file.getFilename() + e.getMessage());
}
- return Errors.makeErrorPage(fms, "Invalid Request on
?ownIdentities?");
+ throw new RedirectPluginHTTPException("", SELF_URI);
}
+
if (page.equals("/createownidentity")) {
List<String> err = new ArrayList<String>();
String nick = request.getPartAsString("nick",
1024).trim();
@@ -302,11 +308,12 @@
}
public void setLanguage(LANGUAGE newLanguage) {
- Logger.error(this, "Set LANGUAGE to: " + newLanguage.isoCode);
language = newLanguage;
+ Logger.error(this, "Set LANGUAGE to: " + language.isoCode);
}
public void setTheme(THEME newTheme) {
theme= newTheme;
+ Logger.error(this, "Set THEME to: " + theme.code);
}
}
Modified: trunk/plugins/FMSPlugin/ui/Backup.java
===================================================================
--- trunk/plugins/FMSPlugin/ui/Backup.java 2008-09-13 19:42:52 UTC (rev
22644)
+++ trunk/plugins/FMSPlugin/ui/Backup.java 2008-09-13 19:58:00 UTC (rev
22645)
@@ -7,7 +7,6 @@
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;
@@ -35,10 +34,9 @@
private static SAXParser saxParser;
- public final static void exportConfigDb(ObjectContainer config_db,
String filename) throws IOException {
+ public final static void exportConfigDb(ObjectContainer config_db,
Writer ow) throws IOException {
- File test = new File(filename).getAbsoluteFile();
- Writer w = new BufferedWriter(new FileWriter(test));
+ Writer w = new BufferedWriter(ow);
w.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
w.write("<fms-kidding>\n");
@@ -88,12 +86,10 @@
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));
+ public final static void importConfigDb(ObjectContainer config_db,
InputStream is) throws IOException, ParserConfigurationException, SAXException {
+ InputStream i = new BufferedInputStream(is);
SAXParser parser = getSaxParser();
- parser.parse(is, new ImportHandler(config_db));
+ parser.parse(i, new ImportHandler(config_db));
}
private static SAXParser getSaxParser() throws
ParserConfigurationException, SAXException {
@@ -144,7 +140,6 @@
}
shouldRecord = false;
- //System.out.println("Parse: " + uri + " - " +
localName + " - " + name);
}
/*
@@ -191,7 +186,6 @@
}
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();
@@ -199,14 +193,11 @@
}
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());
}
Modified: trunk/plugins/FMSPlugin/ui/Errors.java
===================================================================
--- trunk/plugins/FMSPlugin/ui/Errors.java 2008-09-13 19:42:52 UTC (rev
22644)
+++ trunk/plugins/FMSPlugin/ui/Errors.java 2008-09-13 19:58:00 UTC (rev
22645)
@@ -4,7 +4,6 @@
package plugins.FMSPlugin.ui;
import plugins.FMSPlugin.FMS;
-import plugins.FMSPlugin.FMSPlugin;
import freenet.support.HTMLNode;
public class Errors {
@@ -25,49 +24,4 @@
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;
- }
-
-
}
Added: trunk/plugins/FMSPlugin/ui/Service.java
===================================================================
--- trunk/plugins/FMSPlugin/ui/Service.java (rev 0)
+++ trunk/plugins/FMSPlugin/ui/Service.java 2008-09-13 19:58:00 UTC (rev
22645)
@@ -0,0 +1,43 @@
+/* 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 Service {
+
+ public static String makeServicePage(FMS fms) {
+ HTMLNode pageNode = fms.getPageNode();
+ HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+ contentNode.addChild(createExportBox(fms));
+ contentNode.addChild(createImportBox(fms));
+ return pageNode.generate();
+ }
+
+ private static HTMLNode createExportBox(FMS fms) {
+ HTMLNode exportBox = fms.pm.getInfobox("Export");
+ HTMLNode exportContent = fms.pm.getContentNode(exportBox);
+ HTMLNode exportForm = fms.pr.addFormChild(exportContent,
FMSPlugin.SELF_URI + "/exportDB", "exportForm");
+ exportForm.addChild("#", "Export the database (Identities etc
pp) to xml file. \u00a0 ");
+ exportForm.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "export", "Export" });
+ exportForm.addChild("br");
+ exportForm.addChild("#", "Store the backup at a safe place. You
can reimport it at any node and continue flaming...");
+ return exportBox;
+ }
+
+ private static HTMLNode createImportBox(FMS fms) {
+ HTMLNode importBox = fms.pm.getInfobox("Import");
+ HTMLNode importContent = fms.pm.getContentNode(importBox);
+ HTMLNode importForm = fms.pr.addFormChild(importContent,
FMSPlugin.SELF_URI + "/importDB", "importForm");
+ importForm.addChild("#", "Choose xml file to import.\u00a0");
+ importForm.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "file", "filename", "" });
+ importForm.addChild("#", "\u00a0");
+ importForm.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "import", "Import" });
+ importForm.addChild("br");
+ importForm.addChild("#", "You should only try to import files
that was exported with the function above.");
+ return importBox;
+ }
+}
Property changes on: trunk/plugins/FMSPlugin/ui/Service.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/plugins/FMSPlugin/ui/Status.java
===================================================================
--- trunk/plugins/FMSPlugin/ui/Status.java 2008-09-13 19:42:52 UTC (rev
22644)
+++ trunk/plugins/FMSPlugin/ui/Status.java 2008-09-13 19:58:00 UTC (rev
22645)
@@ -4,52 +4,14 @@
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;
- }
-
-
}
Added: trunk/plugins/FMSPlugin/ui/Welcome.java
===================================================================
--- trunk/plugins/FMSPlugin/ui/Welcome.java (rev 0)
+++ trunk/plugins/FMSPlugin/ui/Welcome.java 2008-09-13 19:58:00 UTC (rev
22645)
@@ -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.ui;
+
+import plugins.FMSPlugin.FMS;
+import plugins.FMSPlugin.FMSPlugin;
+import freenet.support.HTMLNode;
+
+public class Welcome {
+
+ public static String makeWelcomePage(FMS fms) {
+ HTMLNode pageNode = fms.getPageNode();
+ HTMLNode contentNode = fms.pm.getContentNode(pageNode);
+ contentNode.addChild(createWelcomeBox(fms));
+ contentNode.addChild(createBackupHintBox(fms));
+ return pageNode.generate();
+ }
+
+ private static HTMLNode createWelcomeBox(FMS fms) {
+ HTMLNode welcomeBox = fms.pm.getInfobox("Welcome");
+ HTMLNode welcomeContent = fms.pm.getContentNode(welcomeBox);
+ welcomeContent.addChild("P", "Welcome to GenTec Labs. This is
our last experiment: cloning FMS.");
+ welcomeContent.addChild("P", "Things happens you didn't expect?
Call 0800-GordonFreeman for rescue");
+ return welcomeBox;
+ }
+
+ private static HTMLNode createBackupHintBox(FMS fms) {
+ HTMLNode bhBox = fms.pm.getInfobox("The boring backup
reminder");
+ HTMLNode bhContent = fms.pm.getContentNode(bhBox);
+ bhContent.addChild("P", "You can not turn me off, because I'm
boring. :P");
+ bhContent.addChild("P", "Don't forget to backup your data. You
find the buttons at the service page.");
+ bhContent.addChild(new HTMLNode("a", "href", FMSPlugin.SELF_URI
+ "/service", "Service Page"));
+ return bhBox;
+ }
+}
Property changes on: trunk/plugins/FMSPlugin/ui/Welcome.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain