throws ToadletContextClosedException, IOException {
if(!ctx.checkFullAccess(this))
return;
PageMaker pageMaker = ctx.getPageMaker();
BookmarkManager bookmarkManager = ctx.getBookmarkManager();
String editorTitle = NodeL10n.getBase().getString("BookmarkEditorToadlet.title");
String error = NodeL10n.getBase().getString("BookmarkEditorToadlet.error");
PageNode page = pageMaker.getPageNode(editorTitle, ctx);
HTMLNode pageNode = page.outer;
HTMLNode content = page.content;
String originalBookmark = req.getParam("bookmark");
if(req.getParam("action").length() > 0 && originalBookmark.length() > 0) {
String action = req.getParam("action");
String bookmarkPath;
try {
bookmarkPath = URLDecoder.decode(originalBookmark, false);
} catch(URLEncodedFormatException e) {
pageMaker.getInfobox("infobox-error", error, content, "bookmark-url-decode-error", false).
addChild("#", NodeL10n.getBase().getString("BookmarkEditorToadlet.urlDecodeError"));
writeHTMLReply(ctx, 200, "OK", pageNode.generate());
return;
}
Bookmark bookmark;
if(bookmarkPath.endsWith("/"))
bookmark = bookmarkManager.getCategoryByPath(bookmarkPath);
else
bookmark = bookmarkManager.getItemByPath(bookmarkPath);
if(bookmark == null) {
pageMaker.getInfobox("infobox-error", error, content, "bookmark-does-not-exist", false).
addChild("#", NodeL10n.getBase().getString("BookmarkEditorToadlet.bookmarkDoesNotExist", new String[]{"bookmark"}, new String[]{bookmarkPath}));
this.writeHTMLReply(ctx, 200, "OK", pageNode.generate());
return;
} else
if("del".equals(action)) {
String[] bm = new String[]{"bookmark"};
String[] path = new String[]{bookmarkPath};
String queryTitle = NodeL10n.getBase().getString("BookmarkEditorToadlet." + ((bookmark instanceof BookmarkItem) ? "deleteBookmark" : "deleteCategory"));
HTMLNode infoBoxContent = pageMaker.getInfobox("infobox-query", queryTitle, content, "bookmark-delete", false);
String query = NodeL10n.getBase().getString("BookmarkEditorToadlet." + ((bookmark instanceof BookmarkItem) ? "deleteBookmarkConfirm" : "deleteCategoryConfirm"), bm, path);
infoBoxContent.addChild("p").addChild("#", query);
HTMLNode confirmForm = ctx.addFormChild(infoBoxContent, "", "confirmDeleteForm");
confirmForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"hidden", "bookmark", bookmarkPath});
confirmForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"submit", "cancel", NodeL10n.getBase().getString("Toadlet.cancel")});
confirmForm.addChild("input", new String[]{"type", "name", "value"}, new String[]{"submit", "confirmdelete", NodeL10n.getBase().getString("BookmarkEditorToadlet.confirmDelete")});
} else if("cut".equals(action))
cutedPath = bookmarkPath;
else if("paste".equals(action) && cutedPath != null) {
bookmarkManager.moveBookmark(cutedPath, bookmarkPath);
bookmarkManager.storeBookmarks();
cutedPath = null;
} else if("edit".equals(action) || "addItem".equals(action) || "addCat".equals(action) || "share".equals(action)) {
boolean isNew = "addItem".equals(action) || "addCat".equals(action);
String header;
if("edit".equals(action))
header = NodeL10n.getBase().getString("BookmarkEditorToadlet.edit" + ((bookmark instanceof BookmarkItem) ? "Bookmark" : "Category") + "Title");
else if("addItem".equals(action))
header = NodeL10n.getBase().getString("BookmarkEditorToadlet.addNewBookmark");
else if("share".equals(action))
header = NodeL10n.getBase().getString("BookmarkEditorToadlet.share");
else
header = NodeL10n.getBase().getString("BookmarkEditorToadlet.addNewCategory");
HTMLNode actionBoxContent = pageMaker.getInfobox("infobox-query", header, content, "bookmark-action", false);
HTMLNode form = ctx.addFormChild(actionBoxContent, "", "editBookmarkForm");
form.addChild("label", "for", "name", (NodeL10n.getBase().getString("BookmarkEditorToadlet.nameLabel") + ' '));
form.addChild("input", new String[]{"type", "id", "name", "size", "value"}, new String[]{"text", "name", "name", "20", !isNew ? bookmark.getVisibleName() : ""});
form.addChild("br");
if(("edit".equals(action) && bookmark instanceof BookmarkItem) || "addItem".equals(action) || "share".equals(action)) {
BookmarkItem item = isNew ? null : (BookmarkItem) bookmark;
String key = !isNew ? item.getKey() : "";
form.addChild("label", "for", "key", (NodeL10n.getBase().getString("BookmarkEditorToadlet.keyLabel") + ' '));
form.addChild("input", new String[] {"type", "id", "name", "size", "value"}, new String[] {"text", "key", "key", "50", key});
form.addChild("br");
if("edit".equals(action) || "addItem".equals(action)) {
form.addChild("label", "for", "descB", (NodeL10n.getBase().getString("BookmarkEditorToadlet.descLabel") + ' '));
form.addChild("br");
form.addChild("textarea", new String[]{"id", "name", "row", "cols"}, new String[]{"descB", "descB", "3", "70"}, (isNew ? "" : item.getDescription()));
form.addChild("br");
form.addChild("label", "for", "descB", (NodeL10n.getBase().getString("BookmarkEditorToadlet.explainLabel") + ' '));
form.addChild("br");
form.addChild("textarea", new String[]{"id", "name", "row", "cols"}, new String[]{"explain", "explain", "3", "70"}, (isNew ? "" : item.getShortDescription()));
form.addChild("br");
}
form.addChild("label", "for", "hasAnActivelink", (NodeL10n.getBase().getString("BookmarkEditorToadlet.hasAnActivelinkLabel") + ' '));
if(!isNew && item.hasAnActivelink())
form.addChild("input", new String[]{"type", "id", "name", "checked"}, new String[]{"checkbox", "hasAnActivelink", "hasAnActivelink", String.valueOf(item.hasAnActivelink())});
else
form.addChild("input", new String[]{"type", "id", "name"}, new String[]{"checkbox", "hasAnActivelink", "hasAnActivelink"});
if(core.node.getDarknetConnections().length > 0 && ("addItem".equals(action) || "share".equals(action))) {
form.addChild("br");
form.addChild("br");
HTMLNode peerTable = form.addChild("table", "class", "darknet_connections");
peerTable.addChild("th", "colspan", "2", NodeL10n.getBase().getString("QueueToadlet.recommendToFriends"));
for(DarknetPeerNode peer : core.node.getDarknetConnections()) {
HTMLNode peerRow = peerTable.addChild("tr", "class", "darknet_connections_normal");
peerRow.addChild("td", "class", "peer-marker").addChild("input", new String[] { "type", "name" }, new String[] { "checkbox", "node_" + peer.hashCode() });
peerRow.addChild("td", "class", "peer-name").addChild("#", peer.getName());
}
form.addChild("label", "for", "descB", (NodeL10n.getBase().getString("BookmarkEditorToadlet.publicDescLabel") + ' '));
form.addChild("br");
form.addChild("textarea", new String[]{"id", "name", "row", "cols"}, new String[]{"descB", "publicDescB", "3", "70"}, (isNew ? "" : item.getDescription()));
form.addChild("br");
}
}
form.addChild("input", new String[]{"type", "name", "value"}, new String[]{"hidden", "bookmark", bookmarkPath});
form.addChild("input", new String[]{"type", "name", "value"}, new String[]{"hidden", "action", req.getParam("action")});
form.addChild("input", new String[]{"type", "value"}, new String[]{"submit", "share".equals(action) ? NodeL10n.getBase().getString("BookmarkEditorToadlet.share") : NodeL10n.getBase().getString("BookmarkEditorToadlet.save")});
} else if("up".equals(action))
bookmarkManager.moveBookmarkUp(bookmarkPath, true);
else if("down".equals(action))
bookmarkManager.moveBookmarkDown(bookmarkPath, true);
}
if(cutedPath != null) {
HTMLNode infoBoxContent =
pageMaker.getInfobox("infobox-normal", NodeL10n.getBase().getString("BookmarkEditorToadlet.pasteTitle"), content, null, false);