From 6f9e59e862cb1929162348019688462cc088ecf3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 2 Apr 2011 16:56:13 +0200 Subject: [PATCH] Allow FreenetTemplatePages to set arbitrary nodes in the result HTML. --- .../sone/web/page/FreenetTemplatePage.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 97c8bf3..0668154 100644 --- a/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/page/FreenetTemplatePage.java @@ -20,6 +20,9 @@ package net.pterodactylus.sone.web.page; import java.io.StringWriter; import java.util.Collection; import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; @@ -32,6 +35,7 @@ import freenet.clients.http.LinkEnabledCallback; import freenet.clients.http.PageMaker; import freenet.clients.http.PageNode; import freenet.clients.http.ToadletContext; +import freenet.support.HTMLNode; /** * Base class for all {@link Page}s that are rendered with {@link Template}s and @@ -118,6 +122,12 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback { for (String styleSheet : getStyleSheets()) { pageNode.addCustomStyleSheet(styleSheet); } + for (Map linkNodeParameters : getAdditionalLinkNodes(request)) { + HTMLNode linkNode = pageNode.headNode.addChild("link"); + for (Entry parameter : linkNodeParameters.entrySet()) { + linkNode.addAttribute(parameter.getKey(), parameter.getValue()); + } + } String shortcutIcon = getShortcutIcon(); if (shortcutIcon != null) { pageNode.addForwardLink("icon", shortcutIcon); @@ -206,6 +216,17 @@ public class FreenetTemplatePage implements Page, LinkEnabledCallback { return null; } + /** + * Returns additional <link> nodes for the HTML’s <head> node. + * + * @param request + * The request for which to return the link nodes + * @return All link nodes that should be added to the HTML head + */ + protected List> getAdditionalLinkNodes(Request request) { + return Collections.emptyList(); + } + // // INTERFACE LinkEnabledCallback // -- 2.7.4