]> source.dussan.org Git - vaadin-framework.git/commitdiff
#3762 removed dependency on PortletRequest
authorHenri Sara <henri.sara@itmill.com>
Wed, 25 Nov 2009 11:26:11 +0000 (11:26 +0000)
committerHenri Sara <henri.sara@itmill.com>
Wed, 25 Nov 2009 11:26:11 +0000 (11:26 +0000)
svn changeset:10009/svn branch:6.2

src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/WebBrowser.java

index 6f5528a6b30f335f038d3032fb474618f5ab8176..de25fcece33be71bff5137cbd3153af86d04444d 100644 (file)
@@ -52,7 +52,7 @@ import com.vaadin.ui.Window;
 
 /**
  * TODO Document me!
- * 
+ *
  * @author peholmst
  */
 public abstract class AbstractApplicationPortlet extends GenericPortlet
@@ -183,7 +183,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
 
     /**
      * Gets an application property value.
-     * 
+     *
      * @param parameterName
      *            the Name or the parameter.
      * @return String value or null if not found
@@ -204,7 +204,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
 
     /**
      * Gets an system property value.
-     * 
+     *
      * @param parameterName
      *            the Name or the parameter.
      * @return String value or null if not found
@@ -233,7 +233,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
 
     /**
      * Gets an application or system property value.
-     * 
+     *
      * @param parameterName
      *            the Name or the parameter.
      * @param defaultValue
@@ -309,7 +309,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
     /**
      * Returns true if the servlet is running in production mode. Production
      * mode disables all debug facilities.
-     * 
+     *
      * @return true if in production mode, false if in debug mode
      */
     public boolean isProductionMode() {
@@ -385,8 +385,8 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
                 }
 
                 /* Update browser information from request */
-                applicationContext.getBrowser()
-                        .updateBrowserProperties(request);
+                updateBrowserProperties(applicationContext.getBrowser(),
+                        request);
 
                 /* Start the newly created application */
                 startApplication(request, application, applicationContext);
@@ -496,6 +496,13 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
         }
     }
 
+    private void updateBrowserProperties(WebBrowser browser,
+            PortletRequest request) {
+        browser.updateBrowserProperties(request.getLocale(), null, request
+                .isSecure(), request.getProperty("user-agent"), request
+                .getParameter("sw"), request.getParameter("sh"));
+    }
+
     @Override
     public void processEvent(EventRequest request, EventResponse response)
             throws PortletException, IOException {
@@ -788,7 +795,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
             throws IOException, MalformedURLException, PortletException {
 
         System.out.println("writeAjaxPage");
-        
+
         response.setContentType("text/html");
         final BufferedWriter page = new BufferedWriter(new OutputStreamWriter(
                 response.getPortletOutputStream(), "UTF-8"));
@@ -815,7 +822,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
 
         String widgetsetURL = getWidgetsetURL(widgetset, request);
         String themeURI = getThemeURI(themeName, request);
-        
+
         //System.out.println("themeName : " + themeName);
         //System.out.println("widgetsetURL : " + widgetsetURL);
         //System.out.println("themeURI : " + themeURI);
@@ -854,7 +861,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
 
         /*
          * We need this in order to get uploads to work.
-         * 
+         *
          * TODO This may cause weird side effects on other places where appUri
          * is used!
          */
@@ -902,7 +909,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
         }
 
 //        System.out.println("Printing default portal theme " + portalTheme);
-        
+
         page.write("if(!vaadin.themesLoaded['" + portalTheme + "']) {\n");
         page.write("var defaultStylesheet = document.createElement('link');\n");
         page.write("defaultStylesheet.setAttribute('rel', 'stylesheet');\n");
@@ -924,7 +931,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
                     .write("document.getElementsByTagName('head')[0].appendChild(stylesheet);\n");
             page.write("vaadin.themesLoaded['" + themeName + "'] = true;\n}\n");
         }
-        
+
         page.write("</script>\n");
 
         // TODO Warn if widgetset has not been loaded after 15 seconds
@@ -957,7 +964,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
 
     /**
      * Returns the theme for given request/window
-     * 
+     *
      * @param request
      * @param window
      * @return
@@ -1011,7 +1018,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
 
     /**
      * Get system messages from the current application class
-     * 
+     *
      * @return
      */
     protected SystemMessages getSystemMessages() {
@@ -1084,7 +1091,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
      * Send notification to client's application. Used to notify client of
      * critical errors and session expiration due to long inactivity. Server has
      * no knowledge of what application client refers to.
-     * 
+     *
      * @param request
      *            the Portlet request instance.
      * @param response
index 0e98041a5090ef86ea168af4c2d4aff94e3a1079..e5ef272af97831ed7e40ba77fe91057a91315342 100644 (file)
@@ -45,11 +45,11 @@ import com.vaadin.ui.Window;
 /**
  * Abstract implementation of the ApplicationServlet which handles all
  * communication between the client and the server.
- * 
+ *
  * It is possible to extend this class to provide own functionality but in most
  * cases this is unnecessary.
- * 
- * 
+ *
+ *
  * @author IT Mill Ltd.
  * @version
  * @VERSION@
@@ -58,7 +58,7 @@ import com.vaadin.ui.Window;
 
 @SuppressWarnings("serial")
 public abstract class AbstractApplicationServlet extends HttpServlet implements Constants {
-    
+
     // TODO Move some (all?) of the constants to a separate interface (shared with portlet)
 
     /**
@@ -159,7 +159,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     /**
      * Called by the servlet container to indicate to a servlet that the servlet
      * is being placed into service.
-     * 
+     *
      * @param servletConfig
      *            the object containing the servlet's configuration and
      *            initialization parameters
@@ -228,7 +228,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Gets an application property value.
-     * 
+     *
      * @param parameterName
      *            the Name or the parameter.
      * @return String value or null if not found
@@ -249,7 +249,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Gets an system property value.
-     * 
+     *
      * @param parameterName
      *            the Name or the parameter.
      * @return String value or null if not found
@@ -278,7 +278,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Gets an application or system property value.
-     * 
+     *
      * @param parameterName
      *            the Name or the parameter.
      * @param defaultValue
@@ -308,7 +308,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     /**
      * Returns true if the servlet is running in production mode. Production
      * mode disables all debug facilities.
-     * 
+     *
      * @return true if in production mode, false if in debug mode
      */
     public boolean isProductionMode() {
@@ -318,7 +318,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     /**
      * Receives standard HTTP requests from the public service method and
      * dispatches them.
-     * 
+     *
      * @param request
      *            the object that contains the request the client made of the
      *            servlet.
@@ -380,7 +380,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
                     .getApplicationManager(application, this);
 
             /* Update browser information from the request */
-            webApplicationContext.getBrowser().updateBrowserProperties(request);
+            updateBrowserProperties(webApplicationContext.getBrowser(), request);
 
             // Start the newly created application
             startApplication(request, application, webApplicationContext);
@@ -454,6 +454,14 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
         }
     }
 
+    private void updateBrowserProperties(WebBrowser browser,
+            HttpServletRequest request) {
+        browser.updateBrowserProperties(request.getLocale(), request
+                .getRemoteAddr(), request.isSecure(), request
+                .getHeader("user-agent"), request.getParameter("sw"), request
+                .getParameter("sh"));
+    }
+
     protected ClassLoader getClassLoader() throws ServletException {
         // Gets custom class loader
         final String classLoaderName = getApplicationOrSystemProperty(
@@ -482,7 +490,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * Send notification to client's application. Used to notify client of
      * critical errors and session expiration due to long inactivity. Server has
      * no knowledge of what application client refers to.
-     * 
+     *
      * @param request
      *            the HTTP request instance.
      * @param response
@@ -544,7 +552,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * Returns the application instance to be used for the request. If an
      * existing instance is not found a new one is created or null is returned
      * to indicate that the application is not available.
-     * 
+     *
      * @param request
      * @param requestType
      * @return
@@ -609,7 +617,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     /**
      * Check if the request should create an application if an existing
      * application is not found.
-     * 
+     *
      * @param request
      * @param requestType
      * @return true if an application should be created, false otherwise
@@ -640,7 +648,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * Gets resource path using different implementations. Required to
      * supporting different servlet container implementations (application
      * servers).
-     * 
+     *
      * @param servletContext
      * @param path
      *            the resource path.
@@ -669,16 +677,16 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * processing, when a certain URI is requested. The handlers are invoked
      * before any windows URIs are processed and if a DownloadStream is returned
      * it is sent to the client.
-     * 
+     *
      * @param stream
      *            the download stream.
-     * 
+     *
      * @param request
      *            the HTTP request instance.
      * @param response
      *            the HTTP response to write to.
      * @throws IOException
-     * 
+     *
      * @see com.vaadin.terminal.URIHandler
      */
     @SuppressWarnings("unchecked")
@@ -759,7 +767,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * Creates a new application and registers it into WebApplicationContext
      * (aka session). This is not meant to be overridden. Override
      * getNewApplication to create the application instance in a custom way.
-     * 
+     *
      * @param request
      * @return
      * @throws ServletException
@@ -800,7 +808,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Returns the theme for given request/window
-     * 
+     *
      * @param request
      * @param window
      * @return
@@ -831,7 +839,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Returns the default theme. Must never return null.
-     * 
+     *
      * @return
      */
     public static String getDefaultTheme() {
@@ -841,7 +849,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     /**
      * Calls URI handlers for the request. If an URI handler returns a
      * DownloadStream the stream is passed to the client for downloading.
-     * 
+     *
      * @param applicationManager
      * @param window
      * @param request
@@ -888,7 +896,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
                  * Invalidate session (weird to have session if we're saying
                  * that it's expired, and worse: portal integration will fail
                  * since the session is not created by the portal.
-                 * 
+                 *
                  * Session must be invalidated before criticalNotification as it
                  * commits the response.
                  */
@@ -944,7 +952,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Creates a new application for the given request.
-     * 
+     *
      * @param request
      *            the HTTP request.
      * @return A new Application instance.
@@ -955,7 +963,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Starts the application if it is not already running.
-     * 
+     *
      * @param request
      * @param application
      * @param webApplicationContext
@@ -982,7 +990,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * Check if this is a request for a static resource and, if it is, serve the
      * resource to the client. Returns true if a file was served and the request
      * has been handled, false otherwise.
-     * 
+     *
      * @param request
      * @param response
      * @return
@@ -1014,7 +1022,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Serve resources from VAADIN directory.
-     * 
+     *
      * @param request
      * @param response
      * @throws IOException
@@ -1124,7 +1132,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Get system messages from the current application class
-     * 
+     *
      * @return
      */
     protected SystemMessages getSystemMessages() {
@@ -1160,10 +1168,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * Return the URL from where static files, e.g. the widgetset and the theme,
      * are served. In a standard configuration the VAADIN folder inside the
      * returned folder is what is used for widgetsets and themes.
-     * 
+     *
      * The returned folder is usually the same as the context path and
      * independent of the application.
-     * 
+     *
      * @param request
      * @return The location of static resources (should contain the VAADIN
      *         directory). Never ends with a slash (/).
@@ -1185,7 +1193,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     /**
      * The default method to fetch static files location. This method does not
      * check for request attribute {@value #REQUEST_VAADIN_STATIC_FILE_PATH}.
-     * 
+     *
      * @param request
      * @return
      */
@@ -1228,7 +1236,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Remove any heading or trailing "what" from the "string".
-     * 
+     *
      * @param string
      * @param what
      * @return
@@ -1247,7 +1255,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Write a redirect response to the main page of the application.
-     * 
+     *
      * @param request
      * @param response
      * @throws IOException
@@ -1277,7 +1285,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * {@link #writeAjaxPageHtmlMainDiv(BufferedWriter, String, String, String)}
      * <li> {@link #writeAjaxPageHtmlBodyEnd(BufferedWriter)}
      * </ul>
-     * 
+     *
      * @param request
      *            the HTTP request.
      * @param response
@@ -1386,9 +1394,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * Returns the application class identifier for use in the application CSS
      * class name in the root DIV. The application CSS class name is of form
      * "v-app-"+getApplicationCSSClassName().
-     * 
+     *
      * This method should normally not be overridden.
-     * 
+     *
      * @return The CSS class name to use in combination with "v-app-".
      */
     protected String getApplicationCSSClassName() {
@@ -1402,10 +1410,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Get the URI for the application theme.
-     * 
+     *
      * A portal-wide default theme is fetched from the portal shared resource
      * directory (if any), other themes from the portlet.
-     * 
+     *
      * @param themeName
      * @param request
      * @return
@@ -1435,7 +1443,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * Override this method if you want to add some custom html around around
      * the div element into which the actual vaadin application will be
      * rendered.
-     * 
+     *
      * @param page
      * @param appId
      * @param classNames
@@ -1451,12 +1459,12 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     }
 
     /**
-     * 
+     *
      * * Method to write the script part of the page which loads needed vaadin
      * scripts and themes.
      * <p>
      * Override this method if you want to add some custom html around scripts.
-     * 
+     *
      * @param window
      * @param themeName
      * @param application
@@ -1598,14 +1606,14 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     }
 
     /**
-     * 
+     *
      * Method to open the body tag of the html kickstart page.
      * <p>
      * This method is responsible for closing the head tag and opening the body
      * tag.
      * <p>
      * Override this method if you want to add some custom html to the page.
-     * 
+     *
      * @param page
      * @throws IOException
      */
@@ -1620,7 +1628,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * <p>
      * Override this method if you want to add some custom html to the header of
      * the page.
-     * 
+     *
      * @param page
      * @param title
      * @param themeUri
@@ -1652,7 +1660,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * <p>
      * Override this method if you want to add some custom html to the very
      * beginning of the page.
-     * 
+     *
      * @param page
      * @throws IOException
      */
@@ -1672,7 +1680,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
      * Method to set http request headers for the Vaadin kickstart page.
      * <p>
      * Override this method if you need to customize http headers of the page.
-     * 
+     *
      * @param response
      */
     protected void setAjaxPageHeaders(HttpServletResponse response) {
@@ -1693,7 +1701,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Gets the current application URL from request.
-     * 
+     *
      * @param request
      *            the HTTP request.
      * @throws MalformedURLException
@@ -1733,7 +1741,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     /**
      * Gets the existing application for given request. Looks for application
      * instance for given request based on the requested URL.
-     * 
+     *
      * @param request
      *            the HTTP request.
      * @param allowSessionCreation
@@ -1793,7 +1801,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Ends the application.
-     * 
+     *
      * @param request
      *            the HTTP request.
      * @param response
@@ -1824,7 +1832,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     /**
      * Gets the existing application or create a new one. Get a window within an
      * application based on the requested URI.
-     * 
+     *
      * @param request
      *            the HTTP Request.
      * @param application
@@ -1870,7 +1878,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     /**
      * Returns the path info; note that this _can_ be different than
      * request.getPathInfo() (e.g application runner).
-     * 
+     *
      * @param request
      * @return
      */
@@ -1880,7 +1888,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     /**
      * Gets relative location of a theme resource.
-     * 
+     *
      * @param theme
      *            the Theme name.
      * @param resource
@@ -1925,7 +1933,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
         /**
          * Gets the contained throwable.
-         * 
+         *
          * @see com.vaadin.terminal.Terminal.ErrorEvent#getThrowable()
          */
         public Throwable getThrowable() {
@@ -1934,7 +1942,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
         /**
          * Gets the source ParameterHandler.
-         * 
+         *
          * @see com.vaadin.terminal.ParameterHandler.ErrorEvent#getParameterHandler()
          */
         public ParameterHandler getParameterHandler() {
@@ -1954,7 +1962,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
         private final Throwable throwable;
 
         /**
-         * 
+         *
          * @param owner
          * @param throwable
          */
@@ -1965,7 +1973,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
         /**
          * Gets the contained throwable.
-         * 
+         *
          * @see com.vaadin.terminal.Terminal.ErrorEvent#getThrowable()
          */
         public Throwable getThrowable() {
@@ -1974,7 +1982,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
         /**
          * Gets the source URIHandler.
-         * 
+         *
          * @see com.vaadin.terminal.URIHandler.ErrorEvent#getURIHandler()
          */
         public URIHandler getURIHandler() {
index 9f8e6c99fd1b490b741e5256179ae96ece77f05a..a3fcfafb1fc4ed742fcb3aeb8a2c9d93a777f2d8 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
 @ITMillApache2LicenseForJavaFiles@
  */
 
@@ -6,9 +6,6 @@ package com.vaadin.terminal.gwt.server;
 
 import java.util.Locale;
 
-import javax.portlet.PortletRequest;
-import javax.servlet.http.HttpServletRequest;
-
 import com.vaadin.terminal.Terminal;
 
 @SuppressWarnings("serial")
@@ -23,7 +20,7 @@ public class WebBrowser implements Terminal {
 
     /**
      * There is no default-theme for this terminal type.
-     * 
+     *
      * @return Allways returns null.
      */
     public String getDefaultTheme() {
@@ -32,7 +29,7 @@ public class WebBrowser implements Terminal {
 
     /**
      * Get the height of the users display in pixels.
-     * 
+     *
      */
     public int getScreenHeight() {
         return screenHeight;
@@ -40,7 +37,7 @@ public class WebBrowser implements Terminal {
 
     /**
      * Get the width of the users display in pixels.
-     * 
+     *
      */
     public int getScreenWidth() {
         return screenWidth;
@@ -48,53 +45,27 @@ public class WebBrowser implements Terminal {
 
     /**
      * Get the browser user-agent string.
-     * 
+     *
      * @return
      */
     public String getBrowserApplication() {
         return browserApplication;
     }
 
-    void updateBrowserProperties(HttpServletRequest request) {
-        locale = request.getLocale();
-        address = request.getRemoteAddr();
-        secureConnection = request.isSecure();
-
-        final String agent = request.getHeader("user-agent");
-        if (agent != null) {
-            browserApplication = agent;
-        }
-
-        final String sw = request.getParameter("sw");
-        if (sw != null) {
-            final String sh = request.getParameter("sh");
-            try {
-                screenHeight = Integer.parseInt(sh);
-                screenWidth = Integer.parseInt(sw);
-            } catch (final NumberFormatException e) {
-                screenHeight = screenWidth = 0;
-            }
-        }
-    }
-
-    /*
-     * TODO: This method depends on the Portlet API, although this should not be
-     * a problem as the portlet API will only be required if the method is
-     * invoked.
+    /**
+     * For internal use by AbstractApplicationServlet/AbstractApplicationPortlet
+     * only.
      */
-    void updateBrowserProperties(PortletRequest request) {
-        locale = request.getLocale();
-        address = null;
-        secureConnection = request.isSecure();
-
-        final String agent = request.getProperty("user-agent");
+    void updateBrowserProperties(Locale locale, String address,
+            boolean secureConnection, String agent, String sw, String sh) {
+        this.locale = locale;
+        this.address = address;
+        this.secureConnection = secureConnection;
         if (agent != null) {
             browserApplication = agent;
         }
 
-        final String sw = request.getParameter("sw");
         if (sw != null) {
-            final String sh = request.getParameter("sh");
             try {
                 screenHeight = Integer.parseInt(sh);
                 screenWidth = Integer.parseInt(sw);
@@ -107,7 +78,7 @@ public class WebBrowser implements Terminal {
     /**
      * Get the IP-address of the web browser. If the application is running
      * inside a portlet, this method will return null.
-     * 
+     *
      * @return IP-address in 1.12.123.123 -format
      */
     public String getAddress() {