[Yanel-commits] rev 59468 - public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources

michi at wyona.com michi at wyona.com
Tue Jul 19 11:15:40 CEST 2011


Author: michi
Date: 2011-07-19 11:15:40 +0200 (Tue, 19 Jul 2011)
New Revision: 59468

Modified:
   public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java
Log:
catch various null pointers when using the command line

Modified: public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java
===================================================================
--- public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java	2011-07-19 09:14:41 UTC (rev 59467)
+++ public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java	2011-07-19 09:15:40 UTC (rev 59468)
@@ -516,11 +516,17 @@
      * Check whether user agent is a mobile device
      */
     protected boolean isMobileDevice() {
-        String mobileDevice = (String) getEnvironment().getRequest().getSession(true).getAttribute("yanel.mobile");
-        //TODO: String mobileDevice = (String) getEnvironment().getRequest().getSession(true).getAttribute(org.wyona.yanel.servlet.YanelServlet.MOBILE_KEY);
-        if (mobileDevice != null && !mobileDevice.equals("false")) {
-            return true;
+        javax.servlet.http.HttpSession session = getEnvironment().getRequest().getSession(true);
+        if (session != null) {
+            String mobileDevice = (String) session.getAttribute("yanel.mobile");
+            //TODO: String mobileDevice = (String) getEnvironment().getRequest().getSession(true).getAttribute(org.wyona.yanel.servlet.YanelServlet.MOBILE_KEY);
+            if (mobileDevice != null && !mobileDevice.equals("false")) {
+                return true;
+            } else {
+                return false;
+            }
         } else {
+            log.warn("No HTTP session available (maybe because Yanel is used via the command line)!");
             return false;
         }
     }
@@ -580,11 +586,16 @@
      */
     protected String getToolbarStatus() {
         org.wyona.yanel.core.ToolbarState ts = getEnvironment().getToolbarState();
-        switch(ts) {
-            case ON: return "on";
-            case SUPPRESSED: return "on"; // Strictly backwards compatible
-            //case SUPPRESSED: return "suppressed";
-            default: return "off";
+        if (ts != null) {
+            switch(ts) {
+                case ON: return "on";
+                case SUPPRESSED: return "on"; // Strictly backwards compatible
+                //case SUPPRESSED: return "suppressed";
+                default: return "off";
+            }
+        } else {
+            log.warn("No toolbar state, hence return 'off'!");
+            return "off";
         }
 
 /*



More information about the Yanel-commits mailing list