From 2f68aaf6cfc4b5665436bebdd560cad472ce79d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 13 Oct 2010 07:59:11 +0200 Subject: [PATCH] Add method to get the current session. --- .../pterodactylus/sone/web/SoneTemplatePage.java | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) 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"); } // -- 2.7.4