]> source.dussan.org Git - vaadin-framework.git/commitdiff
#3413 Portlet widgetset should be loaded from servlet by default
authorHenri Sara <henri.sara@itmill.com>
Wed, 30 Sep 2009 07:12:35 +0000 (07:12 +0000)
committerHenri Sara <henri.sara@itmill.com>
Wed, 30 Sep 2009 07:12:35 +0000 (07:12 +0000)
svn changeset:8993/svn branch:6.1

src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/ApplicationPortlet.java

index 725b906f978d1b5006e443bf4f61cd7a62768977..f27bf51899c6de1a11dc1d1958d18a3c3609dcdf 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@
@@ -111,6 +111,13 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     public static final String REQUEST_WIDGETSET = ApplicationServlet.class
             .getName()
             + ".widgetset";
+    /**
+     * This request attribute indicates the shared widgetset (e.g. portal-wide
+     * default widgetset).
+     */
+    public static final String REQUEST_SHARED_WIDGETSET = ApplicationServlet.class
+            .getName()
+            + ".sharedWidgetset";
     /**
      * If set, do not load the default theme but assume that loading it is
      * handled e.g. by ApplicationPortlet.
@@ -184,7 +191,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     /**
      * 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
@@ -253,7 +260,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Gets an application property value.
-     * 
+     *
      * @param parameterName
      *            the Name or the parameter.
      * @return String value or null if not found
@@ -274,7 +281,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Gets an system property value.
-     * 
+     *
      * @param parameterName
      *            the Name or the parameter.
      * @return String value or null if not found
@@ -303,7 +310,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Gets an application or system property value.
-     * 
+     *
      * @param parameterName
      *            the Name or the parameter.
      * @param defaultValue
@@ -333,7 +340,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     /**
      * 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() {
@@ -343,7 +350,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     /**
      * 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.
@@ -507,7 +514,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * 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
@@ -569,7 +576,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * 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
@@ -634,7 +641,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     /**
      * 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
@@ -665,7 +672,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * Gets resource path using different implementations. Required to
      * supporting different servlet container implementations (application
      * servers).
-     * 
+     *
      * @param servletContext
      * @param path
      *            the resource path.
@@ -694,16 +701,16 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * 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")
@@ -784,7 +791,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * 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
@@ -825,7 +832,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Returns the theme for given request/window
-     * 
+     *
      * @param request
      * @param window
      * @return
@@ -856,7 +863,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Returns the default theme. Must never return null.
-     * 
+     *
      * @return
      */
     public static String getDefaultTheme() {
@@ -866,7 +873,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     /**
      * 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
@@ -913,7 +920,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
                  * 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.
                  */
@@ -969,7 +976,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Creates a new application for the given request.
-     * 
+     *
      * @param request
      *            the HTTP request.
      * @return A new Application instance.
@@ -980,7 +987,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Starts the application if it is not already running.
-     * 
+     *
      * @param request
      * @param application
      * @param webApplicationContext
@@ -1007,7 +1014,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * 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
@@ -1039,7 +1046,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Serve resources from VAADIN directory.
-     * 
+     *
      * @param request
      * @param response
      * @throws IOException
@@ -1149,7 +1156,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Get system messages from the current application class
-     * 
+     *
      * @return
      */
     protected SystemMessages getSystemMessages() {
@@ -1185,10 +1192,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * 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 (/).
@@ -1210,7 +1217,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     /**
      * 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
      */
@@ -1253,7 +1260,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Remove any heading or trailing "what" from the "string".
-     * 
+     *
      * @param string
      * @param what
      * @return
@@ -1272,7 +1279,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Write a redirect response to the main page of the application.
-     * 
+     *
      * @param request
      * @param response
      * @throws IOException
@@ -1302,7 +1309,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * {@link #writeAjaxPageHtmlMainDiv(BufferedWriter, String, String, String)}
      * <li> {@link #writeAjaxPageHtmlBodyEnd(BufferedWriter)}
      * </ul>
-     * 
+     *
      * @param request
      *            the HTTP request.
      * @param response
@@ -1412,6 +1419,16 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     }
 
+    /**
+     * 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
+     */
     private String getThemeUri(String themeName, HttpServletRequest request) {
         final String staticFilePath;
         if (themeName.equals(request.getAttribute(REQUEST_DEFAULT_THEME))) {
@@ -1420,8 +1437,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
             staticFilePath = getStaticFilesLocation(request);
         } else {
             /*
-             * theme is a custom theme, which does not necessary locate in
-             * portals VAADIN directory. Let default servlet conf decide
+             * theme is a custom theme, which is not necessarily located in
+             * portals VAADIN directory. Let the default servlet conf decide
              * (omitting request parameter) the location. Note that theme can
              * still be placed to portal directory with servlet parameter.
              */
@@ -1437,7 +1454,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * 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
@@ -1453,12 +1470,12 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     }
 
     /**
-     * 
+     *
      * * 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
@@ -1476,10 +1493,31 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
             String appId, HttpServletRequest request) throws ServletException,
             IOException {
 
-        String widgetset = getWidgetSet(request);
+        // request widgetset takes precedence (e.g portlet include)
+        String requestWidgetset = (String) request
+                .getAttribute(REQUEST_WIDGETSET);
+        String sharedWidgetset = (String) request
+                .getAttribute(REQUEST_SHARED_WIDGETSET);
+        if (requestWidgetset == null && sharedWidgetset == null) {
+            // Use the value from configuration or DEFAULT_WIDGETSET.
+            // If no shared widgetset is specified, the default widgetset is
+            // assumed to be in the servlet/portlet itself.
+            requestWidgetset = getApplicationOrSystemProperty(
+                    PARAMETER_WIDGETSET,
+                    DEFAULT_WIDGETSET);
+        }
 
-        final String staticFilePath = getStaticFilesLocation(request);
-        final String widgetsetFilePath = staticFilePath + "/"
+        String widgetset;
+        String widgetsetBasePath;
+        if (requestWidgetset != null) {
+            widgetset = requestWidgetset;
+            widgetsetBasePath = getWebApplicationsStaticFileLocation(request);
+        } else {
+            widgetset = sharedWidgetset;
+            widgetsetBasePath = getStaticFilesLocation(request);
+        }
+
+        final String widgetsetFilePath = widgetsetBasePath + "/"
                 + WIDGETSET_DIRECTORY_PATH + widgetset + "/" + widgetset
                 + ".nocache.js?" + new Date().getTime();
 
@@ -1579,26 +1617,15 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
                         + "//]]>\n</script>\n");
     }
 
-    private String getWidgetSet(HttpServletRequest request) {
-        // request widgetset takes precedence (e.g portlet include)
-        String widgetset = (String) request.getAttribute(REQUEST_WIDGETSET);
-        if (widgetset == null) {
-            // use the value from configuration or DEFAULT_WIDGETSET
-            widgetset = getApplicationOrSystemProperty(PARAMETER_WIDGETSET,
-                    DEFAULT_WIDGETSET);
-        }
-        return widgetset;
-    }
-
     /**
-     * 
+     *
      * 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
      */
@@ -1613,7 +1640,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * <p>
      * Override this method if you want to add some custom html to the header of
      * the page.
-     * 
+     *
      * @param page
      * @param title
      * @param themeUri
@@ -1645,7 +1672,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * <p>
      * Override this method if you want to add some custom html to the very
      * beginning of the page.
-     * 
+     *
      * @param page
      * @throws IOException
      */
@@ -1665,7 +1692,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
      * 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) {
@@ -1686,7 +1713,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Gets the current application URL from request.
-     * 
+     *
      * @param request
      *            the HTTP request.
      * @throws MalformedURLException
@@ -1726,7 +1753,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     /**
      * 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
@@ -1786,7 +1813,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Ends the application.
-     * 
+     *
      * @param request
      *            the HTTP request.
      * @param response
@@ -1817,7 +1844,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     /**
      * 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
@@ -1863,7 +1890,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
     /**
      * Returns the path info; note that this _can_ be different than
      * request.getPathInfo() (e.g application runner).
-     * 
+     *
      * @param request
      * @return
      */
@@ -1873,7 +1900,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
     /**
      * Gets relative location of a theme resource.
-     * 
+     *
      * @param theme
      *            the Theme name.
      * @param resource
@@ -1920,7 +1947,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
         /**
          * Gets the contained throwable.
-         * 
+         *
          * @see com.vaadin.terminal.Terminal.ErrorEvent#getThrowable()
          */
         public Throwable getThrowable() {
@@ -1929,7 +1956,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
         /**
          * Gets the source ParameterHandler.
-         * 
+         *
          * @see com.vaadin.terminal.ParameterHandler.ErrorEvent#getParameterHandler()
          */
         public ParameterHandler getParameterHandler() {
@@ -1949,7 +1976,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
         private final Throwable throwable;
 
         /**
-         * 
+         *
          * @param owner
          * @param throwable
          */
@@ -1960,7 +1987,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
         /**
          * Gets the contained throwable.
-         * 
+         *
          * @see com.vaadin.terminal.Terminal.ErrorEvent#getThrowable()
          */
         public Throwable getThrowable() {
@@ -1969,7 +1996,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet {
 
         /**
          * Gets the source URIHandler.
-         * 
+         *
          * @see com.vaadin.terminal.URIHandler.ErrorEvent#getURIHandler()
          */
         public URIHandler getURIHandler() {
index 24880d04ad33b85329a73aeb8127c3ebcbf9b636..f363fcfddb5ca2d24c39c1d976f5a07b3a12fb43 100644 (file)
@@ -104,12 +104,6 @@ public class ApplicationPortlet implements Portlet, Serializable {
                 String portalResourcePath = getPortalProperty(\r
                         PORTAL_PARAMETER_VAADIN_RESOURCE_PATH, portalCtx);\r
 \r
-                // by default on LifeRay, widgetset and default theme is in\r
-                // /html/VAADIN/widgetsets/...\r
-                if (isLifeRay && portalResourcePath == null) {\r
-                    portalResourcePath = "/html";\r
-                }\r
-\r
                 if (portalResourcePath != null) {\r
                     // if portalResourcePath is defined, set it as a request\r
                     // parameter which will override the default location in\r
@@ -125,20 +119,24 @@ public class ApplicationPortlet implements Portlet, Serializable {
                 // and widgetset path settings (recommended)\r
                 // - finally, default to use the default widgetset if nothing\r
                 // else is found\r
-                if (portalWidgetset != null) {\r
-                    request.setAttribute(ApplicationServlet.REQUEST_WIDGETSET,\r
-                            portalWidgetset);\r
-                } else if (portletWidgetset != null) {\r
+                if (portletWidgetset != null) {\r
                     request.setAttribute(ApplicationServlet.REQUEST_WIDGETSET,\r
                             portletWidgetset);\r
                 }\r
+                if (portalWidgetset != null) {\r
+                    request.setAttribute(\r
+                            ApplicationServlet.REQUEST_SHARED_WIDGETSET,\r
+                            portalWidgetset);\r
+                }\r
 \r
                 if (style != null) {\r
                     request.setAttribute(ApplicationServlet.REQUEST_APPSTYLE,\r
                             style);\r
                 }\r
 \r
-                if (portalTheme != null) {\r
+                // portalTheme is only used if the shared portal resource\r
+                // directory is defined\r
+                if (portalTheme != null && portalResourcePath != null) {\r
                     request.setAttribute(\r
                             ApplicationServlet.REQUEST_DEFAULT_THEME,\r
                             portalTheme);\r
@@ -183,7 +181,7 @@ public class ApplicationPortlet implements Portlet, Serializable {
                      * servlet to extend the session lifetime after each Vaadin\r
                      * request. This hack can be removed when supporting portlet\r
                      * 2.0 and resourceRequests.\r
-                     * \r
+                     *\r
                      * TODO make this configurable, this is not necessary with\r
                      * some custom session configurations.\r
                      */\r