X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpage%2FPageToadlet.java;h=d919bd75f5cef68805cefb1562961db9805c4d51;hb=7708df5b6f4d1cf1416a8202b825a4f6f78f289e;hp=2d1f35aa2344902c011dfb44cb17c8bed86ddc24;hpb=38cb6c5ec82298ee351d0eb15ddd8331db273af2;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..d919bd7 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â2013 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,14 +18,17 @@
package net.pterodactylus.sone.web.page;
import java.io.IOException;
+import java.io.OutputStream;
import java.net.URI;
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.Toadlet;
import freenet.clients.http.ToadletContext;
import freenet.clients.http.ToadletContextClosedException;
@@ -39,7 +42,7 @@ import freenet.support.io.Closer;
*
* @author David âBombeâ Roden
*/
-public class PageToadlet extends Toadlet implements LinkEnabledCallback {
+public class PageToadlet extends Toadlet implements LinkEnabledCallback, LinkFilterExceptedToadlet {
/** The name of the menu item. */
private final String menuName;
@@ -79,9 +82,6 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
return menuName;
}
- /**
- * {@inheritDoc}
- */
@Override
public String path() {
return pathPrefix + page.getPath();
@@ -123,9 +123,6 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
handleRequest(new FreenetRequest(uri, Method.POST, httpRequest, toadletContext));
}
- /**
- * {@inheritDoc}
- */
@Override
public String toString() {
return getClass().getName() + "[path=" + path() + ",page=" + page + "]";
@@ -143,29 +140,33 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
*/
private void handleRequest(FreenetRequest pageRequest) throws IOException, ToadletContextClosedException {
Bucket pageBucket = null;
+ OutputStream pageBucketOutputStream = null;
+ Response pageResponse;
try {
pageBucket = pageRequest.getToadletContext().getBucketFactory().makeBucket(-1);
- Response pageResponse = new Response(pageBucket.getOutputStream());
- pageResponse = page.handleRequest(pageRequest, pageResponse);
- MultiValueTable headers = new MultiValueTable();
- if (pageResponse.getHeaders() != null) {
- for (Header header : pageResponse.getHeaders()) {
- for (String value : header) {
- headers.put(header.getName(), value);
- }
+ pageBucketOutputStream = pageBucket.getOutputStream();
+ pageResponse = page.handleRequest(pageRequest, new Response(pageBucketOutputStream));
+ } catch (IOException ioe1) {
+ Closer.close(pageBucket);
+ throw ioe1;
+ } finally {
+ Closer.close(pageBucketOutputStream);
+ }
+ MultiValueTable headers = new MultiValueTable();
+ if (pageResponse.getHeaders() != null) {
+ for (Header header : pageResponse.getHeaders()) {
+ for (String value : header) {
+ headers.put(header.getName(), value);
}
}
+ }
+ try {
writeReply(pageRequest.getToadletContext(), pageResponse.getStatusCode(), pageResponse.getContentType(), pageResponse.getStatusText(), headers, pageBucket);
- } catch (Throwable t1) {
- writeInternalError(t1, pageRequest.getToadletContext());
} finally {
Closer.close(pageBucket);
}
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean isEnabled(ToadletContext toadletContext) {
if (page instanceof LinkEnabledCallback) {
@@ -174,4 +175,13 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
return true;
}
+ //
+ // LINKFILTEREXCEPTEDTOADLET METHODS
+ //
+
+ @Override
+ public boolean isLinkExcepted(URI link) {
+ return (page instanceof FreenetPage) ? ((FreenetPage) page).isLinkExcepted(link) : false;
+ }
+
}