]> source.dussan.org Git - vaadin-framework.git/commitdiff
Better webbrowser impl
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Mon, 23 Jul 2007 09:18:40 +0000 (09:18 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Mon, 23 Jul 2007 09:18:40 +0000 (09:18 +0000)
svn changeset:1896/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java
src/com/itmill/toolkit/terminal/gwt/server/WebApplicationContext.java
src/com/itmill/toolkit/terminal/gwt/server/WebBrowser.java

index 66bc25e610d3febc46ad0c5f47db7668add23fbb..68d80b9fba73b04c55f8ad1b7866a1b52ca60b9c 100644 (file)
@@ -299,6 +299,11 @@ public class ApplicationServlet extends HttpServlet {
                Application application = null;
                try {
 
+                       // Update browser details
+                       WebBrowser browser = WebApplicationContext.getApplicationContext(request.getSession()).getBrowser();
+                       browser.updateBrowserProperties(request);
+                       // TODO Add screen height and width to the GWT client
+                       
                        // Gets the application
                        application = getApplication(request);
 
@@ -336,6 +341,8 @@ public class ApplicationServlet extends HttpServlet {
                                // If this is not a download request
                                if (download == null) {
 
+                                       // TODO Clean this branch
+                                       
                                        // Window renders are not cacheable
                                        response.setHeader("Cache-Control", "no-cache");
                                        response.setHeader("Pragma", "no-cache");
@@ -354,8 +361,7 @@ public class ApplicationServlet extends HttpServlet {
 
                                        // Sets terminal type for the window, if not already set
                                        if (window.getTerminal() == null) {
-                                               // TODO !!!!
-                                               window.setTerminal(new WebBrowser());
+                                               window.setTerminal(browser);
                                        }
 
                                        // Finds theme name
index fd4a56e34ae3259cc368da75151907fb8c6957a0..e414c0a0b574f85b62218e7ad4c119f7faacb5f8 100644 (file)
@@ -65,6 +65,8 @@ public class WebApplicationContext implements ApplicationContext, HttpSessionBin
        private WeakHashMap formActions = new WeakHashMap();
 
        private HashSet applications = new HashSet();
+       
+       private WebBrowser browser = new WebBrowser();
 
        /**
         * Creates a new Web Application Context.
@@ -293,4 +295,15 @@ public class WebApplicationContext implements ApplicationContext, HttpSessionBin
                        removeApplication(app);
                }
        }
+
+       /** Get the web browser associated with this application context. 
+        * 
+        * Because application context is related to the http session and server maintains one session per 
+        * browser-instance, each context has exactly one web browser associated with it. 
+        * 
+        * @return
+        */
+       public WebBrowser getBrowser() {
+               return browser;
+       }
 }
index 52db76fcfd8a71014f589b909c3c3b7cd12323cf..c065a85deb6f44961eb22cff636da63c5da53ea5 100644 (file)
@@ -1,27 +1,86 @@
 package com.itmill.toolkit.terminal.gwt.server;
 
+import java.util.Locale;
+
+import javax.servlet.http.HttpServletRequest;
+
 import com.itmill.toolkit.terminal.Terminal;
 
 public class WebBrowser implements Terminal {
 
+       private int screenHeight = 0;
+       private int screenWidth = 0;
+       private String browserApplication = null;
+       private Locale locale;
+       private String address;
+       private boolean secureConnection;
+
+       /** There is no default-theme for this terminal type.
+        * 
+        * @return Allways returns null.
+        */
        public String getDefaultTheme() {
-               // TODO Auto-generated method stub
                return null;
        }
 
+       /** Get the height of the users display in pixels.
+        * 
+        */
        public int getScreenHeight() {
-               // TODO Auto-generated method stub
-               return 0;
+               return screenHeight;
        }
 
+       /** Get the width of the users display in pixels.
+        * 
+        */
        public int getScreenWidth() {
-               // TODO Auto-generated method stub
-               return 0;
+               return screenWidth;
        }
        
+       /** Get the browser user-agent string.
+        * 
+        * @return
+        */
        public String getBrowserApplication() {
-               // TODO Auto-generated method stub
-               return "";
+               return browserApplication;
+       }
+       
+       void updateBrowserProperties(HttpServletRequest request) {
+               locale = request.getLocale();
+               address = request.getRemoteAddr();
+               secureConnection = request.isSecure();
+               
+               String agent = request.getHeader("user-agent");
+               if (agent != null) browserApplication = agent;
+
+               String sw = request.getParameter("screenWidth");
+               String sh = request.getParameter("screenHeight");
+               if (sw != null && sh != null) {
+                       try {
+                       screenHeight = Integer.parseInt(sh);
+                       screenWidth = Integer.parseInt(sw);
+                       } catch (NumberFormatException e) {
+                               screenHeight = screenWidth = 0;
+                       }
+               }
+       }
+
+       /** Get the IP-address of the web browser.
+        * 
+        * @return IP-address in 1.12.123.123 -format
+        */
+       public String getAddress() {
+               return address;
+       }
+
+       /** Get the default locate of the browser. */
+       public Locale getLocale() {
+               return locale;
+       }
+
+       /** Is the connection made using HTTPS? */
+       public boolean isSecureConnection() {
+               return secureConnection;
        }
 
 }