/*
- * shortener - TemplatePage.java - Copyright © 2010 David Roden
+ * Sone - FreenetTemplatePage.java - Copyright © 2010 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
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;
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
return new RedirectResponse(redirectTarget);
}
+ if (isFullAccessOnly() && !request.getToadletContext().isAllowedFullAccess()) {
+ return new Response(401, "Not authorized", "text/html", "Not authorized");
+ }
ToadletContext toadletContext = request.getToadletContext();
if (request.getMethod() == Method.POST) {
/* require form password. */
for (String styleSheet : getStyleSheets()) {
pageNode.addCustomStyleSheet(styleSheet);
}
+ for (Map<String, String> linkNodeParameters : getAdditionalLinkNodes(request)) {
+ HTMLNode linkNode = pageNode.headNode.addChild("link");
+ for (Entry<String, String> parameter : linkNodeParameters.entrySet()) {
+ linkNode.addAttribute(parameter.getKey(), parameter.getValue());
+ }
+ }
String shortcutIcon = getShortcutIcon();
if (shortcutIcon != null) {
pageNode.addForwardLink("icon", shortcutIcon);
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<Map<String, String>> getAdditionalLinkNodes(Request request) {
+ return Collections.emptyList();
+ }
+
+ /**
+ * Returns whether this page should only be allowed for requests from hosts
+ * with full access.
+ *
+ * @return {@code true} if this page should only be allowed for hosts with
+ * full access, {@code false} to allow this page for any host
+ */
+ protected boolean isFullAccessOnly() {
+ return false;
+ }
+
//
// INTERFACE LinkEnabledCallback
//
*/
@Override
public boolean isEnabled(ToadletContext toadletContext) {
- return true;
+ return !isFullAccessOnly();
}
/**