From 8d082b7384c169b295766bb95843f2be4c9c65fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 15 Sep 2011 17:47:48 +0200 Subject: [PATCH] Add page that lets the user edit and delete targets. --- .../pterodactylus/wotns/ui/web/EditTargetPage.java | 81 ++++++++++++++++++++++ .../pterodactylus/wotns/ui/web/WebInterface.java | 1 + src/main/resources/templates/manage.html | 5 +- 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/pterodactylus/wotns/ui/web/EditTargetPage.java diff --git a/src/main/java/net/pterodactylus/wotns/ui/web/EditTargetPage.java b/src/main/java/net/pterodactylus/wotns/ui/web/EditTargetPage.java new file mode 100644 index 0000000..3ee6715 --- /dev/null +++ b/src/main/java/net/pterodactylus/wotns/ui/web/EditTargetPage.java @@ -0,0 +1,81 @@ +/* + * WoTNS - EditTargetPage.java - Copyright © 2011 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.wotns.ui.web; + +import java.net.MalformedURLException; + +import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.web.Method; +import net.pterodactylus.wotns.freenet.wot.OwnIdentity; +import net.pterodactylus.wotns.freenet.wot.WebOfTrustException; +import net.pterodactylus.wotns.web.FreenetRequest; +import freenet.keys.FreenetURI; + +/** + * TODO + * + * @author David ‘Bombe’ Roden + */ +public class EditTargetPage extends BasicPage { + + /** + * @param webInterface + * @param path + * @param template + */ + public EditTargetPage(Template template, WebInterface webInterface) { + super(webInterface, "editTarget.html", template); + } + + /** + * {@inheritDoc} + */ + @Override + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { + super.processTemplate(request, templateContext); + if (request.getMethod() == Method.POST) { + OwnIdentity ownIdentity = getOwnIdentity(request); + String name = request.getHttpRequest().getPartAsStringFailsafe("name", 64).trim(); + String target = request.getHttpRequest().getPartAsStringFailsafe("target", 256).trim(); + if ((name.length() == 0) || (target.length() == 0)) { + /* TODO - show error. */ + return; + } + try { + new FreenetURI(target); + } catch (MalformedURLException mue1) { + /* TODO - show error. */ + return; + } + try { + if (request.getHttpRequest().getPartAsStringFailsafe("edit", 4).equals("true")) { + System.out.println("edit"); + ownIdentity.setProperty("tns." + name, target); + } else if (request.getHttpRequest().getPartAsStringFailsafe("delete", 4).equals("true")) { + System.out.println("delete"); + ownIdentity.removeProperty("tns." + name); + } + throw new RedirectException("manage.html?ownIdentity=" + ownIdentity.getId()); + } catch (WebOfTrustException wote1) { + /* TODO - show error. */ + } + } + } + +} diff --git a/src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java b/src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java index c786d94..efcdced 100644 --- a/src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java @@ -103,6 +103,7 @@ public class WebInterface { pageToadlets.add(pageToadletFactory.createPageToadlet(new ManagePage(manageTemplate, this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new EnableIdentityPage(new Template(), this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new AddTargetPage(addTargetTemplate, this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new EditTargetPage(new Template(), this))); ToadletContainer toadletContainer = wotNSPlugin.getToadletContainer(); toadletContainer.getPageMaker().addNavigationCategory("/tns/index.html", "Navigation.Menu.Name", "Navigation.Menu.Tooltip", wotNSPlugin); diff --git a/src/main/resources/templates/manage.html b/src/main/resources/templates/manage.html index b0b2be6..3f50a8c 100644 --- a/src/main/resources/templates/manage.html +++ b/src/main/resources/templates/manage.html @@ -5,11 +5,12 @@ <%/first>
+ <%target.key|html>: - - + +
<%/foreach>

Add Target

-- 2.7.4