Add title to pages.
[WoTNS.git] / src / main / java / net / pterodactylus / wotns / ui / web / EditTargetPage.java
1 /*
2  * WoTNS - EditTargetPage.java - Copyright © 2011 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.wotns.ui.web;
19
20 import java.net.MalformedURLException;
21
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;
29
30 /**
31  * TODO
32  *
33  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34  */
35 public class EditTargetPage extends BasicPage {
36
37         /**
38          * @param webInterface
39          * @param path
40          * @param template
41          */
42         public EditTargetPage(Template template, WebInterface webInterface) {
43                 super(webInterface, "editTarget.html", null, template);
44         }
45
46         /**
47          * {@inheritDoc}
48          */
49         @Override
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. */
58                                 return;
59                         }
60                         try {
61                                 new FreenetURI(target);
62                         } catch (MalformedURLException mue1) {
63                                 /* TODO - show error. */
64                                 return;
65                         }
66                         try {
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);
73                                 }
74                                 throw new RedirectException("manage.html?ownIdentity=" + ownIdentity.getId());
75                         } catch (WebOfTrustException wote1) {
76                                 /* TODO - show error. */
77                         }
78                 }
79         }
80
81 }