2 * WoTNS - ResolverPage.java - Copyright © 2011–2017 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;
23 import net.pterodactylus.util.template.Template;
24 import net.pterodactylus.util.template.TemplateContext;
25 import net.pterodactylus.wotns.main.Resolver;
26 import net.pterodactylus.wotns.web.FreenetRequest;
27 import freenet.keys.FreenetURI;
32 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 public class ResolverPage extends BasicPage {
36 private final Resolver resolver;
38 public ResolverPage(Template unknownNameTemplate, WebInterface webInterface, Resolver resolver) {
39 super(webInterface, "", "Error - Web of Trust Name Service", unknownNameTemplate);
40 this.resolver = resolver;
51 public boolean isPrefixPage() {
56 // FREENETTEMPLATEPAGE METHODS
63 protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
64 String uri = request.getUri().getPath();
65 String path = uri.substring(uri.indexOf('/', 1) + 1);
67 /* look for path after target. */
68 int firstSlash = path.indexOf('/');
69 int secondSlash = path.indexOf('/', firstSlash + 1);
71 if (secondSlash != -1) {
72 filePath = path.substring(secondSlash);
73 path = path.substring(0, secondSlash);
76 FreenetURI targetUri = resolver.resolveURI(path);
77 if (targetUri != null) {
78 throw new RedirectException("/" + targetUri.toString() + filePath);
80 } catch (MalformedURLException mue1) {
81 /* TODO - do something. */
83 templateContext.set("shortName", path);
90 public boolean isLinkExcepted(URI link) {