X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpage%2FPageToadlet.java;h=2b223777b66992fbdd908769d965c5a55079645d;hb=9b102d5ff09775e3867ad8709f22baf0ad608d30;hp=2d1f35aa2344902c011dfb44cb17c8bed86ddc24;hpb=0df5e91852f737d760c5a9f54c5667309fbadcc2;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java b/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java
index 2d1f35a..2b22377 100644
--- a/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java
+++ b/src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java
@@ -1,5 +1,5 @@
/*
- * Sone - PageToadlet.java - Copyright © 2010 David Roden
+ * Sone - PageToadlet.java - Copyright © 2010â2019 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
@@ -18,28 +18,32 @@
package net.pterodactylus.sone.web.page;
import java.io.IOException;
+import java.io.OutputStream;
import java.net.URI;
+import net.pterodactylus.sone.utils.AutoCloseableBucket;
import net.pterodactylus.util.web.Header;
import net.pterodactylus.util.web.Method;
import net.pterodactylus.util.web.Page;
import net.pterodactylus.util.web.Response;
+
import freenet.client.HighLevelSimpleClient;
import freenet.clients.http.LinkEnabledCallback;
+import freenet.clients.http.LinkFilterExceptedToadlet;
+import freenet.clients.http.SessionManager;
import freenet.clients.http.Toadlet;
import freenet.clients.http.ToadletContext;
import freenet.clients.http.ToadletContextClosedException;
+import freenet.l10n.NodeL10n;
import freenet.support.MultiValueTable;
-import freenet.support.api.Bucket;
import freenet.support.api.HTTPRequest;
-import freenet.support.io.Closer;
/**
* {@link Toadlet} implementation that is wrapped around a {@link Page}.
- *
- * @author David âBombeâ Roden
*/
-public class PageToadlet extends Toadlet implements LinkEnabledCallback {
+public class PageToadlet extends Toadlet implements LinkEnabledCallback, LinkFilterExceptedToadlet {
+
+ private final SessionManager sessionManager;
/** The name of the menu item. */
private final String menuName;
@@ -63,8 +67,9 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
* Prefix that is prepended to all {@link Page#getPath()} return
* values
*/
- protected PageToadlet(HighLevelSimpleClient highLevelSimpleClient, String menuName, Page page, String pathPrefix) {
+ protected PageToadlet(HighLevelSimpleClient highLevelSimpleClient, SessionManager sessionManager, String menuName, Page page, String pathPrefix) {
super(highLevelSimpleClient);
+ this.sessionManager = sessionManager;
this.menuName = menuName;
this.page = page;
this.pathPrefix = pathPrefix;
@@ -102,7 +107,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
* if the toadlet context is closed
*/
public void handleMethodGET(URI uri, HTTPRequest httpRequest, ToadletContext toadletContext) throws IOException, ToadletContextClosedException {
- handleRequest(new FreenetRequest(uri, Method.GET, httpRequest, toadletContext));
+ handleRequest(new FreenetRequest(uri, Method.GET, httpRequest, toadletContext, NodeL10n.getBase(), sessionManager));
}
/**
@@ -120,7 +125,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
* if the toadlet context is closed
*/
public void handleMethodPOST(URI uri, HTTPRequest httpRequest, ToadletContext toadletContext) throws IOException, ToadletContextClosedException {
- handleRequest(new FreenetRequest(uri, Method.POST, httpRequest, toadletContext));
+ handleRequest(new FreenetRequest(uri, Method.POST, httpRequest, toadletContext, NodeL10n.getBase(), sessionManager));
}
/**
@@ -142,12 +147,10 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
* if the toadlet context is closed
*/
private void handleRequest(FreenetRequest pageRequest) throws IOException, ToadletContextClosedException {
- Bucket pageBucket = null;
- try {
- pageBucket = pageRequest.getToadletContext().getBucketFactory().makeBucket(-1);
- Response pageResponse = new Response(pageBucket.getOutputStream());
- pageResponse = page.handleRequest(pageRequest, pageResponse);
- MultiValueTable headers = new MultiValueTable();
+ try (AutoCloseableBucket pageBucket = new AutoCloseableBucket(pageRequest.getToadletContext().getBucketFactory().makeBucket(-1));
+ OutputStream pageBucketOutputStream = pageBucket.getBucket().getOutputStream()) {
+ Response pageResponse = page.handleRequest(pageRequest, new Response(pageBucketOutputStream));
+ MultiValueTable headers = new MultiValueTable<>();
if (pageResponse.getHeaders() != null) {
for (Header header : pageResponse.getHeaders()) {
for (String value : header) {
@@ -155,11 +158,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
}
}
}
- writeReply(pageRequest.getToadletContext(), pageResponse.getStatusCode(), pageResponse.getContentType(), pageResponse.getStatusText(), headers, pageBucket);
- } catch (Throwable t1) {
- writeInternalError(t1, pageRequest.getToadletContext());
- } finally {
- Closer.close(pageBucket);
+ writeReply(pageRequest.getToadletContext(), pageResponse.getStatusCode(), pageResponse.getContentType(), pageResponse.getStatusText(), headers, pageBucket.getBucket());
}
}
@@ -174,4 +173,16 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
return true;
}
+ //
+ // LINKFILTEREXCEPTEDTOADLET METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isLinkExcepted(URI link) {
+ return (page instanceof FreenetPage) && ((FreenetPage) page).isLinkExcepted(link);
+ }
+
}