X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpage%2FFreenetTemplatePage.java;h=1a5b95094b6965195e2360039cc83fa8fc9a6983;hb=d35ab97a494fd187d3b8fe6b3253b65e3427a077;hp=5831a1b339a8c0bd7fced073b91b7a9e06ebcd92;hpb=ed57f849f204eee0a3074c1acb7c290ef20ada3a;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java
index 5831a1b..1a5b950 100644
--- a/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java
+++ b/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java
@@ -1,5 +1,5 @@
/*
- * Sone - FreenetTemplatePage.java - Copyright © 2010 David Roden
+ * Sone - FreenetTemplatePage.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
@@ -17,7 +17,9 @@
package net.pterodactylus.sone.web.page;
+import java.io.IOException;
import java.io.StringWriter;
+import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -26,11 +28,14 @@ import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
-import net.pterodactylus.sone.web.page.Page.Request.Method;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
import net.pterodactylus.util.template.TemplateContextFactory;
+import net.pterodactylus.util.web.Method;
+import net.pterodactylus.util.web.Page;
+import net.pterodactylus.util.web.RedirectResponse;
+import net.pterodactylus.util.web.Response;
import freenet.clients.http.LinkEnabledCallback;
import freenet.clients.http.PageMaker;
import freenet.clients.http.PageNode;
@@ -43,7 +48,7 @@ import freenet.support.HTMLNode;
*
* @author David âBombeâ Roden
*/
-public class FreenetTemplatePage implements Page, LinkEnabledCallback {
+public class FreenetTemplatePage implements FreenetPage, LinkEnabledCallback {
/** The logger. */
private static final Logger logger = Logging.getLogger(FreenetTemplatePage.class);
@@ -80,9 +85,6 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
this.invalidFormPasswordRedirectTarget = invalidFormPasswordRedirectTarget;
}
- /**
- * {@inheritDoc}
- */
@Override
public String getPath() {
return path;
@@ -95,22 +97,25 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
* The request to serve
* @return The title of the page
*/
- protected String getPageTitle(Request request) {
+ @SuppressWarnings("static-method")
+ protected String getPageTitle(FreenetRequest request) {
return null;
}
- /**
- * {@inheritDoc}
- */
@Override
- public Response handleRequest(Request request) {
+ public boolean isPrefixPage() {
+ return false;
+ }
+
+ @Override
+ public Response handleRequest(FreenetRequest request, Response response) throws IOException {
String redirectTarget = getRedirectTarget(request);
if (redirectTarget != null) {
return new RedirectResponse(redirectTarget);
}
if (isFullAccessOnly() && !request.getToadletContext().isAllowedFullAccess()) {
- return new Response(401, "Not authorized", "text/html", "Not authorized");
+ return response.setStatusCode(401).setStatusText("Not authorized").setContentType("text/html");
}
ToadletContext toadletContext = request.getToadletContext();
if (request.getMethod() == Method.POST) {
@@ -142,7 +147,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
long start = System.nanoTime();
processTemplate(request, templateContext);
long finish = System.nanoTime();
- logger.log(Level.FINEST, "Template was rendered in " + ((finish - start) / 1000) / 1000.0 + "ms.");
+ logger.log(Level.FINEST, String.format("Template was rendered in %.2fms.", ((finish - start) / 1000) / 1000.0));
} catch (RedirectException re1) {
return new RedirectResponse(re1.getTarget());
}
@@ -153,7 +158,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
postProcess(request, templateContext);
- return new Response(200, "OK", "text/html", pageNode.outer.generate());
+ return response.setStatusCode(200).setStatusText("OK").setContentType("text/html").write(pageNode.outer.generate());
}
/**
@@ -162,6 +167,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
*
* @return Additional style sheets to load
*/
+ @SuppressWarnings("static-method")
protected Collection getStyleSheets() {
return Collections.emptySet();
}
@@ -171,6 +177,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
*
* @return The URL of the shortcut icon, or {@code null} for no icon
*/
+ @SuppressWarnings("static-method")
protected String getShortcutIcon() {
return null;
}
@@ -186,16 +193,15 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
* @throws RedirectException
* if the processing page wants to redirect after processing
*/
- protected void processTemplate(Request request, TemplateContext templateContext) throws RedirectException {
+ protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
/* do nothing. */
}
/**
* This method will be called after
- * {@link #processTemplate(net.pterodactylus.sone.web.page.Page.Request, TemplateContext)}
- * has processed the template and the template was rendered. This method
- * will not be called if
- * {@link #processTemplate(net.pterodactylus.sone.web.page.Page.Request, TemplateContext)}
+ * {@link #processTemplate(FreenetRequest, TemplateContext)} has processed
+ * the template and the template was rendered. This method will not be
+ * called if {@link #processTemplate(FreenetRequest, TemplateContext)}
* throws a {@link RedirectException}!
*
* @param request
@@ -203,7 +209,7 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
* @param templateContext
* The template context that supplied the rendered data
*/
- protected void postProcess(Request request, TemplateContext templateContext) {
+ protected void postProcess(FreenetRequest request, TemplateContext templateContext) {
/* do nothing. */
}
@@ -215,7 +221,8 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
* The request that is processed
* @return The URL to redirect to, or {@code null} to not redirect
*/
- protected String getRedirectTarget(Page.Request request) {
+ @SuppressWarnings("static-method")
+ protected String getRedirectTarget(FreenetRequest request) {
return null;
}
@@ -226,7 +233,8 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback {
* The request for which to return the link nodes
* @return All link nodes that should be added to the HTML head
*/
- protected List