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

michi at wyona.com michi at wyona.com
Mon Sep 12 13:51:12 CEST 2011


Author: michi
Date: 2011-09-12 13:51:11 +0200 (Mon, 12 Sep 2011)
New Revision: 60641

Modified:
   public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java
Log:
get view id centralized and is mobile view improved accordingly

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-09-12 11:49:34 UTC (rev 60640)
+++ public/yanel/trunk/src/impl/java/org/wyona/yanel/impl/resources/BasicXMLResource.java	2011-09-12 11:51:11 UTC (rev 60641)
@@ -118,6 +118,8 @@
 
     protected HashMap<String, ViewDescriptor> viewDescriptors;
 
+    private static final String VIEW_ID_PARAM_NAME = "yanel.resource.viewid";
+
     /**
      * Get view descriptor for a particular view id
      * @param viewId View id
@@ -254,7 +256,10 @@
             } else {
                 viewId = DEFAULT_VIEW_ID;
             }
+        } else {
+            log.warn("DEBUG: View already set (probably via query string or session attribute): " + viewId);
         }
+
         ConfigurableViewDescriptor viewDescriptor = (ConfigurableViewDescriptor)getViewDescriptor(viewId);
         String mimeType = getMimeType(viewId);
         view.setMimeType(mimeType);
@@ -484,7 +489,7 @@
         }
 
         // INFO: Set whether mobile view should be set to true
-        String queryStringViewId = getEnvironment().getRequest().getParameter("yanel.resource.viewid");
+        String queryStringViewId = getViewID();
         if (queryStringViewId != null) {
             if (queryStringViewId.equals(MOBILE_VIEW_ID)) {
                 if (getViewDescriptor(MOBILE_VIEW_ID) == null) {
@@ -573,6 +578,12 @@
             if (isMobileViewParamValue != null && isMobileViewParamValue.equals("false")) { // INFO: In some cases one wants to disable the mobile view completely (including mobile CSS, if applicable)
                 return false;
             }
+
+            String viewIdFromSession = (String) request.getSession(true).getAttribute(VIEW_ID_PARAM_NAME);
+            if (viewIdFromSession != null && !viewIdFromSession.equals("mobile")) {
+                log.warn("It seems like the view id is set inside session, but not set to mobile: " + viewIdFromSession);
+                return false;
+            }
         } catch(Exception e) {
             log.error(e, e);
         }
@@ -691,4 +702,28 @@
         }
         return userAgent;
     }
+
+    /**
+     * Determine view ID
+     */
+    private String getViewID() {
+        String viewId = null;
+
+        String viewIdFromSession = (String) getEnvironment().getRequest().getAttribute(VIEW_ID_PARAM_NAME);
+        if (viewIdFromSession != null) {
+            log.warn("It seems like the view id is set inside session: " + viewIdFromSession);
+            viewId = viewIdFromSession;
+        }
+
+        viewId = getEnvironment().getRequest().getParameter(VIEW_ID_PARAM_NAME);
+
+/*
+        if (request.getParameter("yanel.format") != null) { // backwards compatible
+            viewId = request.getParameter("yanel.format");
+            log.warn("For backwards compatibility reasons also consider parameter 'yanel.format', but which is deprecated. Please use '" + VIEW_ID_PARAM_NAME + "' instead.");
+        }
+*/
+
+        return viewId;
+    }
 }



More information about the Yanel-commits mailing list