X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FSoneTemplatePage.java;h=fa2798e762adf37462bf5a813ea13debd6328899;hb=53a71d1d6b91e4d56af49a06f2e06bc4d11bf3eb;hp=4ef434fe2d8469194e0041432cf4633fd2014a68;hpb=a47643aed43d118ca68044f95451bb5374cdb332;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index 4ef434f..fa2798e 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -1,5 +1,5 @@ /* - * Sone - SoneTemplatePage.java - Copyright © 2010–2012 David Roden + * Sone - SoneTemplatePage.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 @@ -30,13 +30,14 @@ import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.sone.notify.ListNotificationFilters; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.sone.web.page.FreenetTemplatePage; -import net.pterodactylus.util.collection.ListBuilder; -import net.pterodactylus.util.collection.MapBuilder; import net.pterodactylus.util.notify.Notification; -import net.pterodactylus.util.object.HashCode; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; -import freenet.clients.http.SessionManager.Session; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + import freenet.clients.http.ToadletContext; import freenet.support.api.HTTPRequest; @@ -130,35 +131,6 @@ public class SoneTemplatePage extends FreenetTemplatePage { // /** - * Returns the current session, creating a new session if there is no - * current session. - * - * @param toadletContenxt - * The toadlet context - * @return The current session, or {@code null} if there is no current - * session - */ - protected Session getCurrentSession(ToadletContext toadletContenxt) { - return webInterface.getCurrentSession(toadletContenxt); - } - - /** - * Returns the current session, creating a new session if there is no - * current session and {@code create} is {@code true}. - * - * @param toadletContenxt - * The toadlet context - * @param create - * {@code true} to create a new session if there is no current - * session, {@code false} otherwise - * @return The current session, or {@code null} if there is no current - * session - */ - protected Session getCurrentSession(ToadletContext toadletContenxt, boolean create) { - return webInterface.getCurrentSession(toadletContenxt, create); - } - - /** * Returns the currently logged in Sone. * * @param toadletContext @@ -166,7 +138,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { * @return The currently logged in Sone, or {@code null} if no Sone is * currently logged in */ - protected Sone getCurrentSone(ToadletContext toadletContext) { + protected Optional getCurrentSone(ToadletContext toadletContext) { return webInterface.getCurrentSone(toadletContext); } @@ -181,7 +153,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { * @return The currently logged in Sone, or {@code null} if no Sone is * currently logged in */ - protected Sone getCurrentSone(ToadletContext toadletContext, boolean create) { + protected Optional getCurrentSone(ToadletContext toadletContext, boolean create) { return webInterface.getCurrentSone(toadletContext, create); } @@ -217,7 +189,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { */ @Override protected List> getAdditionalLinkNodes(FreenetRequest request) { - return new ListBuilder>().add(new MapBuilder().put("rel", "search").put("type", "application/opensearchdescription+xml").put("title", "Sone").put("href", "http://" + request.getHttpRequest().getHeader("host") + "/Sone/OpenSearch.xml").get()).get(); + return ImmutableList.> builder().add(ImmutableMap. builder().put("rel", "search").put("type", "application/opensearchdescription+xml").put("title", "Sone").put("href", "http://" + request.getHttpRequest().getHeader("host") + "/Sone/OpenSearch.xml").build()).build(); } /** @@ -252,9 +224,9 @@ public class SoneTemplatePage extends FreenetTemplatePage { @Override protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); - Sone currentSone = getCurrentSone(request.getToadletContext(), false); + Optional currentSone = getCurrentSone(request.getToadletContext(), false); templateContext.set("core", webInterface.getCore()); - templateContext.set("currentSone", currentSone); + templateContext.set("currentSone", currentSone.orNull()); templateContext.set("localSones", webInterface.getCore().getLocalSones()); templateContext.set("request", request); templateContext.set("currentVersion", SonePlugin.VERSION); @@ -262,10 +234,10 @@ public class SoneTemplatePage extends FreenetTemplatePage { templateContext.set("latestEdition", webInterface.getCore().getUpdateChecker().getLatestEdition()); templateContext.set("latestVersion", webInterface.getCore().getUpdateChecker().getLatestVersion()); templateContext.set("latestVersionTime", webInterface.getCore().getUpdateChecker().getLatestVersionDate()); - List notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone); + List notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone.orNull()); Collections.sort(notifications, Notification.CREATED_TIME_SORTER); templateContext.set("notifications", notifications); - templateContext.set("notificationHash", HashCode.hashCode(notifications)); + templateContext.set("notificationHash", notifications.hashCode()); } /** @@ -273,7 +245,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { */ @Override protected String getRedirectTarget(FreenetRequest request) { - if (requiresLogin() && (getCurrentSone(request.getToadletContext(), false) == null)) { + if (requiresLogin() && !getCurrentSone(request.getToadletContext(), false).isPresent()) { HTTPRequest httpRequest = request.getHttpRequest(); String originalUrl = httpRequest.getPath(); if (httpRequest.hasParameters()) { @@ -315,7 +287,7 @@ public class SoneTemplatePage extends FreenetTemplatePage { return false; } if (requiresLogin()) { - return getCurrentSone(toadletContext, false) != null; + return getCurrentSone(toadletContext, false).isPresent(); } return true; }