Author: dbkr
Date: 2006-04-13 16:52:18 +0000 (Thu, 13 Apr 2006)
New Revision: 8539
Modified:
trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
trunk/freenet/src/freenet/clients/http/staticfiles/themes/aqua/theme.css
trunk/freenet/src/freenet/clients/http/staticfiles/themes/clean/theme.css
trunk/freenet/src/freenet/node/UserAlertManager.java
trunk/freenet/src/freenet/node/Version.java
Log:
644: Bookmark editing support. Also some HTML / CSS cleanups with UserAlerts,
and don't listen on the fproxy port if fproxy is disabled!
Modified: trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
2006-04-13 15:44:44 UTC (rev 8538)
+++ trunk/freenet/src/freenet/clients/http/SimpleToadletServer.java
2006-04-13 16:52:18 UTC (rev 8539)
@@ -132,14 +132,15 @@
if(cssName.indexOf(':') != -1 || cssName.indexOf('/') != -1)
throw new InvalidConfigValueException("CSS name must
not contain slashes or colons!");
- this.sock = new ServerSocket(port, 0,
InetAddress.getByName(this.bindTo));
toadlets = new LinkedList();
-
node.setToadletContainer(this); // even if not enabled, because
of config
if(!enabled) {
Logger.normal(node, "Not starting Fproxy as it's
disabled");
+ this.sock = null;
} else {
+ this.sock = new ServerSocket(port, 0,
InetAddress.getByName(this.bindTo));
+
myThread = new Thread(this, "SimpleToadletServer");
myThread.setDaemon(true);
myThread.start();
Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2006-04-13
15:44:44 UTC (rev 8538)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2006-04-13
16:52:18 UTC (rev 8539)
@@ -23,6 +23,8 @@
private static final String[] DEFAULT_DARKNET_BOOKMARKS = {
"USK at
PFeLTa1si2Ml5sDeUy7eDhPso6TPdmw-2gWfQ4Jg02w,3ocfrqgUMVWA2PeorZx40TW0c-FiIOL-TWKQHoDbVdE,AQABAAE/Index/-1/=Darknet
Index"
};
+ private final static int MODE_ADD = 1;
+ private final static int MODE_EDIT = 2;
Node node;
SubConfig config;
BookmarkManager bookmarks;
@@ -48,7 +50,7 @@
public void handlePost(URI uri, Bucket data, ToadletContext ctx) throws
ToadletContextClosedException, IOException {
if(data.size() > 1024*1024) {
- this.writeReply(ctx, 400, "text/plain", "Too big", "Too
much data, config servlet limited to 1MB");
+ this.writeReply(ctx, 400, "text/plain", "Too big",
"Data exceeds 1MB limit");
return;
}
byte[] d = BucketTools.toByteArray(data);
@@ -91,11 +93,11 @@
buf.append("</form>\n");
ctx.getPageMaker().makeTail(buf);
writeReply(ctx, 200, "text/html", "OK", buf.toString());
- } else if (request.getParam("newbookmark").length() > 0) {
+ } else if (request.isParameterSet("addbookmark")) {
try {
- bookmarks.addBookmark(new
Bookmark(request.getParam("newbookmark"), request.getParam("name")));
+ bookmarks.addBookmark(new
Bookmark(request.getParam("key"), request.getParam("name")));
} catch (MalformedURLException mue) {
- this.sendErrorPage(ctx, 200, "Invalid freenet
key", "Could not add the given item as a bookmark since it was not possible to
interpret it as a freenet key. Please <a href=\"/\">Try Again</a>");
+ this.sendBookmarkEditPage(ctx, MODE_ADD, null,
request.getParam("key"), request.getParam("name"), "Given key does not appear
to be a valid Freenet key.");
return;
}
@@ -111,6 +113,24 @@
if
(request.isParameterSet("delete_"+b.hashCode())) {
bookmarks.removeBookmark(b);
+ } else if
(request.isParameterSet("edit_"+b.hashCode())) {
+ this.sendBookmarkEditPage(ctx, b);
+ return;
+ } else if
(request.isParameterSet("update_"+b.hashCode())) {
+ // removing it and adding means that
any USK subscriptions are updated properly
+ try {
+ Bookmark newbkmk = new
Bookmark(request.getParam("key"), request.getParam("name"));
+ bookmarks.removeBookmark(b);
+ bookmarks.addBookmark(newbkmk);
+ } catch (MalformedURLException mue) {
+ this.sendBookmarkEditPage(ctx,
MODE_EDIT, b, request.getParam("key"), request.getParam("name"), "Given key
does not appear to be a valid freenet key.");
+ return;
+ }
+ try {
+ this.handleGet(new
URI("/welcome/?managebookmarks"), ctx);
+ } catch (URISyntaxException ex) {
+
+ }
}
}
try {
@@ -137,8 +157,8 @@
buf.append("To your bookmarks, and enter the
description that you would prefer:<br />\n");
buf.append("Description:\n");
buf.append("<input type=\"text\" name=\"name\"
value=\""+HTMLEncoder.encode(request.getParam("desc"))+"\" style=\"width: 100%;
\" />\n");
- buf.append("<input type=\"hidden\" name=\"newbookmark\"
value=\""+HTMLEncoder.encode(request.getParam("newbookmark"))+"\" />\n");
- buf.append("<input type=\"submit\" value=\"Add
Bookmark\" />\n");
+ buf.append("<input type=\"hidden\" name=\"key\"
value=\""+HTMLEncoder.encode(request.getParam("newbookmark"))+"\" />\n");
+ buf.append("<input type=\"submit\" name=\"addbookmark\"
value=\"Add Bookmark\" />\n");
buf.append("</div>\n");
buf.append("</form>\n");
@@ -165,6 +185,7 @@
buf.append(HTMLEncoder.encode(b.getDesc()));
buf.append("</a>\n");
buf.append("<input type=\"submit\"
name=\"delete_"+b.hashCode()+"\" value=\"Delete\" style=\"float: right; \"
/>\n");
+ buf.append("<input type=\"submit\"
name=\"edit_"+b.hashCode()+"\" value=\"Edit\" style=\"float: right; \" />\n");
buf.append("</li>\n");
}
buf.append("</ul>\n");
@@ -174,16 +195,7 @@
buf.append("</form>\n");
// new bookmark
- buf.append("<form action=\".\" method=\"post\">\n");
- buf.append("<div class=\"infobox\">\n");
- buf.append("<h2>New Bookmark</h2>\n");
- buf.append("Key: \n");
- buf.append("<input type=\"text\" name=\"newbookmark\"
style=\"width: 100%; \"/>\n");
- buf.append("Description: \n");
- buf.append("<input type=\"text\" name=\"name\"
style=\"width: 100%; \"/>\n");
- buf.append("<input type=\"submit\" value=\"Add
Bookmark\"/>\n");
- buf.append("</div>\n");
- buf.append("</form>\n");
+ this.makeBookmarkEditForm(buf, MODE_ADD, null, "", "",
null);
ctx.getPageMaker().makeTail(buf);
@@ -265,6 +277,65 @@
this.writeReply(ctx, 200, "text/html", "OK", buf.toString());
}
+ private void sendBookmarkEditPage(ToadletContext ctx, Bookmark b)
throws ToadletContextClosedException, IOException {
+ this.sendBookmarkEditPage(ctx, MODE_EDIT, b, b.getKey(),
b.getDesc(), null);
+ }
+
+ private void sendBookmarkEditPage(ToadletContext ctx, int mode,
Bookmark b, String origKey, String origDesc, String message) throws
ToadletContextClosedException, IOException {
+ StringBuffer buf = new StringBuffer();
+
+ if (mode == MODE_ADD) {
+ ctx.getPageMaker().makeHead(buf, "Add a Bookmark");
+ } else {
+ ctx.getPageMaker().makeHead(buf, "Edit a Bookmark");
+ }
+
+ if (message != null) {
+ buf.append("<div class=\"infobox\">\n");
+ buf.append(message);
+ buf.append("</div>\n");
+ }
+
+ this.makeBookmarkEditForm(buf, mode, b, origKey, origDesc,
message);
+
+ ctx.getPageMaker().makeTail(buf);
+ this.writeReply(ctx, 200, "text/html", "OK", buf.toString());
+ }
+
+ private void makeBookmarkEditForm(StringBuffer buf, int mode, Bookmark
b, String origKey, String origDesc, String message) {
+ buf.append("<form action=\".\" method=\"post\">\n");
+ buf.append("<div class=\"infobox\">\n");
+ if (mode == MODE_ADD) {
+ buf.append("<h2>New Bookmark</h2>\n");
+ } else {
+ buf.append("<h2>Update Bookmark</h2>\n");
+ }
+ buf.append("<div style=\"text-align: right; \">\n");
+ buf.append("Key: \n");
+ buf.append("<input type=\"text\" name=\"key\"
value=\""+origKey+"\" size=\"80\" />\n");
+ buf.append("<br />\n");
+
+ buf.append("Description: \n");
+ buf.append("<input type=\"text\" name=\"name\"
value=\""+origDesc+"\" size=\"80\" />\n");
+ buf.append("<br />\n");
+
+ if (mode == MODE_ADD) {
+ buf.append("<input type=\"submit\" name=\"addbookmark\"
value=\"Add Bookmark\" class=\"confirm\" />\n");
+ } else {
+ buf.append("<input type=\"submit\"
name=\"update_"+b.hashCode()+"\" value=\"Update Bookmark\" class=\"confirm\"
/>\n");
+ }
+
+ buf.append("<input type=\"submit\" value=\"Cancel\"
class=\"cancel\" />\n");
+
+ buf.append("<br style=\"clear: all;\" />\n");
+
+ buf.append("<input type=\"hidden\" name=\"managebookmarks\"
value=\"yes\" />\n");
+
+ buf.append("</div>\n");
+ buf.append("</div>\n");
+ buf.append("</form>\n");
+ }
+
public String supportedMethods() {
return "GET, POST";
}
Modified:
trunk/freenet/src/freenet/clients/http/staticfiles/themes/aqua/theme.css
===================================================================
--- trunk/freenet/src/freenet/clients/http/staticfiles/themes/aqua/theme.css
2006-04-13 15:44:44 UTC (rev 8538)
+++ trunk/freenet/src/freenet/clients/http/staticfiles/themes/aqua/theme.css
2006-04-13 16:52:18 UTC (rev 8539)
@@ -119,3 +119,16 @@
.peer_disconnected {
color: black;
}
+
+.alert-error {
+ color: darkred;
+}
+
+.alert-warning {
+ color: blue;
+}
+
+.alert-minor {
+ color: green;
+}
+
Modified:
trunk/freenet/src/freenet/clients/http/staticfiles/themes/clean/theme.css
===================================================================
--- trunk/freenet/src/freenet/clients/http/staticfiles/themes/clean/theme.css
2006-04-13 15:44:44 UTC (rev 8538)
+++ trunk/freenet/src/freenet/clients/http/staticfiles/themes/clean/theme.css
2006-04-13 16:52:18 UTC (rev 8539)
@@ -103,6 +103,20 @@
color: #ff0000;
}
+/* alerts */
+
+.alert-error {
+ color: darkred;
+}
+
+.alert-warning {
+ color: blue;
+}
+
+.alert-minor {
+ color: green;
+}
+
/* content */
#content {
@@ -211,3 +225,4 @@
table.darknet_connections span.peer_disconnected {
color: #d0d0d0;
}
+
Modified: trunk/freenet/src/freenet/node/UserAlertManager.java
===================================================================
--- trunk/freenet/src/freenet/node/UserAlertManager.java 2006-04-13
15:44:44 UTC (rev 8538)
+++ trunk/freenet/src/freenet/node/UserAlertManager.java 2006-04-13
16:52:18 UTC (rev 8539)
@@ -49,23 +49,22 @@
UserAlert alert = a[i];
synchronized(alert) {
if(!alert.isValid()) return;
- // FIXME should have separate CSS styles for
each type of alert
buf.append("<p><b>");
short level = a[i].getPriorityClass();
if(level <= UserAlert.CRITICAL_ERROR)
- buf.append("<font color=\"darkred\">");
+ buf.append("<span color=\"darkred\">");
else if(level <= UserAlert.ERROR)
- buf.append("<font color=\"red\">");
+ buf.append("<span
class=\"alert-error\">");
else if(level <= UserAlert.WARNING)
- buf.append("<font color=\"blue\">");
+ buf.append("<span
class=\"alert-warning\">");
else if(level <= UserAlert.MINOR)
- buf.append("<font color=\"green\">");
+ buf.append("<span
class=\"alert-minor\">");
buf.append(a[i].getTitle());
if(level <= UserAlert.MINOR)
- buf.append("</font>");
- buf.append("</b><br>\n");
+ buf.append("</span>");
+ buf.append("</b><br />\n");
buf.append(a[i].getText());
- buf.append("<p>\n");
+ buf.append("</p>\n");
}
}
}
Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-04-13 15:44:44 UTC (rev
8538)
+++ trunk/freenet/src/freenet/node/Version.java 2006-04-13 16:52:18 UTC (rev
8539)
@@ -20,7 +20,7 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- private static final int buildNumber = 643;
+ private static final int buildNumber = 644;
/** Oldest build of Fred we will talk to */
private static final int lastGoodBuild = 591;