Add method to get the current session.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Oct 2010 05:59:11 +0000 (07:59 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Oct 2010 05:59:11 +0000 (07:59 +0200)
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java

index 2b697ce..67c5293 100644 (file)
@@ -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");
        }
 
        //