From: David ‘Bombe’ Roden Date: Wed, 13 Oct 2010 05:59:11 +0000 (+0200) Subject: Add method to get the current session. X-Git-Tag: 0.1-RC1~513 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=2f68aaf6cfc4b5665436bebdd560cad472ce79d7 Add method to get the current session. --- diff --git a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java index 2b697ce..67c5293 100644 --- a/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java +++ b/src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java @@ -60,6 +60,22 @@ public class SoneTemplatePage extends TemplatePage { // /** + * Returns the current session. + * + * @param request + * The request to extract the session information from + * @return The current session, or {@code null} if there is no current + * session + */ + protected Session getCurrentSession(Request request) { + try { + return webInterface.sessionManager().useSession(request.getToadletContext()); + } catch (RedirectException re1) { + return null; + } + } + + /** * Returns the currently logged in Sone. * * @param request @@ -68,16 +84,11 @@ public class SoneTemplatePage extends TemplatePage { * currently logged in */ protected Sone getCurrentSone(Request request) { - try { - Session session = webInterface.sessionManager().useSession(request.getToadletContext()); - if (session == null) { - return null; - } - return (Sone) session.getAttribute("Sone.CurrentSone"); - } catch (RedirectException re1) { - /* okay, no current session, return null. */ + Session session = getCurrentSession(request); + if (session == null) { return null; } + return (Sone) session.getAttribute("Sone.CurrentSone"); } //