2 * WoTNS - EditTargetPage.java - Copyright © 2011 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.wotns.ui.web;
20 import java.net.MalformedURLException;
22 import net.pterodactylus.util.template.Template;
23 import net.pterodactylus.util.template.TemplateContext;
24 import net.pterodactylus.util.web.Method;
25 import net.pterodactylus.wotns.freenet.wot.OwnIdentity;
26 import net.pterodactylus.wotns.freenet.wot.WebOfTrustException;
27 import net.pterodactylus.wotns.web.FreenetRequest;
28 import freenet.keys.FreenetURI;
33 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
35 public class EditTargetPage extends BasicPage {
42 public EditTargetPage(Template template, WebInterface webInterface) {
43 super(webInterface, "editTarget.html", null, template);
50 protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
51 super.processTemplate(request, templateContext);
52 if (request.getMethod() == Method.POST) {
53 OwnIdentity ownIdentity = getOwnIdentity(request);
54 String name = request.getHttpRequest().getPartAsStringFailsafe("name", 64).trim();
55 String target = request.getHttpRequest().getPartAsStringFailsafe("target", 256).trim();
56 if ((name.length() == 0) || (target.length() == 0)) {
57 /* TODO - show error. */
61 new FreenetURI(target);
62 } catch (MalformedURLException mue1) {
63 /* TODO - show error. */
67 if (request.getHttpRequest().getPartAsStringFailsafe("edit", 4).equals("true")) {
68 System.out.println("edit");
69 ownIdentity.setProperty("tns." + name, target);
70 } else if (request.getHttpRequest().getPartAsStringFailsafe("delete", 4).equals("true")) {
71 System.out.println("delete");
72 ownIdentity.removeProperty("tns." + name);
74 throw new RedirectException("manage.html?ownIdentity=" + ownIdentity.getId());
75 } catch (WebOfTrustException wote1) {
76 /* TODO - show error. */