]> source.dussan.org Git - vaadin-framework.git/commitdiff
Bugfixes: pass application properties to AbstractDeploymentConfiguration constructor...
authorJohannes Dahlström <johannesd@vaadin.com>
Fri, 17 Aug 2012 13:54:35 +0000 (16:54 +0300)
committerJohannes Dahlström <johannesd@vaadin.com>
Fri, 17 Aug 2012 14:02:50 +0000 (17:02 +0300)
server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java

index 06ed54990a453277bd2be6118c4963aa7b557d26..bd39504237be62d5a60951e3589987fc386d1a59 100644 (file)
@@ -217,99 +217,13 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
     // TODO Can we close the application when the portlet is removed? Do we know
     // when the portlet is removed?
 
-    private boolean productionMode = false;
-
-    private DeploymentConfiguration deploymentConfiguration = new AbstractDeploymentConfiguration(
-            getClass()) {
-        @Override
-        public String getConfiguredWidgetset(WrappedRequest request) {
-
-            String widgetset = getApplicationOrSystemProperty(
-                    PARAMETER_WIDGETSET, null);
-
-            if (widgetset == null) {
-                // If no widgetset defined for the application, check the
-                // portal
-                // property
-                widgetset = WrappedPortletRequest.cast(request)
-                        .getPortalProperty(PORTAL_PARAMETER_VAADIN_WIDGETSET);
-            }
-
-            if (widgetset == null) {
-                // If no widgetset defined for the portal, use the default
-                widgetset = DEFAULT_WIDGETSET;
-            }
-
-            return widgetset;
-        }
-
-        @Override
-        public String getConfiguredTheme(WrappedRequest request) {
-
-            // is the default theme defined by the portal?
-            String themeName = WrappedPortletRequest.cast(request)
-                    .getPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME);
-
-            if (themeName == null) {
-                // no, using the default theme defined by Vaadin
-                themeName = DEFAULT_THEME_NAME;
-            }
-
-            return themeName;
-        }
-
-        @Override
-        public boolean isStandalone(WrappedRequest request) {
-            return false;
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see
-         * com.vaadin.terminal.DeploymentConfiguration#getStaticFileLocation
-         * (com.vaadin.terminal.WrappedRequest)
-         * 
-         * 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.
-         * 
-         * @return The location of static resources (inside which there should
-         * be a VAADIN directory). Does not end with a slash (/).
-         */
-
-        @Override
-        public String getStaticFileLocation(WrappedRequest request) {
-            String staticFileLocation = WrappedPortletRequest.cast(request)
-                    .getPortalProperty(
-                            Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH);
-            if (staticFileLocation != null) {
-                // remove trailing slash if any
-                while (staticFileLocation.endsWith(".")) {
-                    staticFileLocation = staticFileLocation.substring(0,
-                            staticFileLocation.length() - 1);
-                }
-                return staticFileLocation;
-            } else {
-                // default for Liferay
-                return "/html";
-            }
-        }
-
-        @Override
-        public String getMimeType(String resourceName) {
-            return getPortletContext().getMimeType(resourceName);
-        }
-    };
-
-    private final AddonContext addonContext = new AddonContext(
-            getDeploymentConfiguration());
+    private DeploymentConfiguration deploymentConfiguration;
+    private AddonContext addonContext;
 
     @Override
     public void init(PortletConfig config) throws PortletException {
         super.init(config);
-        Properties applicationProperties = getDeploymentConfiguration()
-                .getInitParameters();
+        Properties applicationProperties = new Properties();
 
         // Read default parameters from the context
         final PortletContext context = config.getPortletContext();
@@ -328,6 +242,93 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
                     config.getInitParameter(name));
         }
 
+        deploymentConfiguration = new AbstractDeploymentConfiguration(
+                getClass(), applicationProperties) {
+            @Override
+            public String getConfiguredWidgetset(WrappedRequest request) {
+
+                String widgetset = getApplicationOrSystemProperty(
+                        PARAMETER_WIDGETSET, null);
+
+                if (widgetset == null) {
+                    // If no widgetset defined for the application, check the
+                    // portal property
+                    widgetset = WrappedPortletRequest.cast(request)
+                            .getPortalProperty(
+                                    PORTAL_PARAMETER_VAADIN_WIDGETSET);
+                }
+
+                if (widgetset == null) {
+                    // If no widgetset defined for the portal, use the default
+                    widgetset = DEFAULT_WIDGETSET;
+                }
+
+                return widgetset;
+            }
+
+            @Override
+            public String getConfiguredTheme(WrappedRequest request) {
+
+                // is the default theme defined by the portal?
+                String themeName = WrappedPortletRequest.cast(request)
+                        .getPortalProperty(
+                                Constants.PORTAL_PARAMETER_VAADIN_THEME);
+
+                if (themeName == null) {
+                    // no, using the default theme defined by Vaadin
+                    themeName = DEFAULT_THEME_NAME;
+                }
+
+                return themeName;
+            }
+
+            @Override
+            public boolean isStandalone(WrappedRequest request) {
+                return false;
+            }
+
+            /*
+             * (non-Javadoc)
+             * 
+             * @see
+             * com.vaadin.terminal.DeploymentConfiguration#getStaticFileLocation
+             * (com.vaadin.terminal.WrappedRequest)
+             * 
+             * 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.
+             * 
+             * @return The location of static resources (inside which there
+             * should be a VAADIN directory). Does not end with a slash (/).
+             */
+
+            @Override
+            public String getStaticFileLocation(WrappedRequest request) {
+                String staticFileLocation = WrappedPortletRequest
+                        .cast(request)
+                        .getPortalProperty(
+                                Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH);
+                if (staticFileLocation != null) {
+                    // remove trailing slash if any
+                    while (staticFileLocation.endsWith(".")) {
+                        staticFileLocation = staticFileLocation.substring(0,
+                                staticFileLocation.length() - 1);
+                    }
+                    return staticFileLocation;
+                } else {
+                    // default for Liferay
+                    return "/html";
+                }
+            }
+
+            @Override
+            public String getMimeType(String resourceName) {
+                return getPortletContext().getMimeType(resourceName);
+            }
+        };
+
+        addonContext = new AddonContext(deploymentConfiguration);
         addonContext.init();
     }
 
@@ -384,13 +385,13 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
     }
 
     /**
-     * Returns true if the servlet is running in production mode. Production
+     * Returns true if the portlet 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() {
-        return productionMode;
+        return deploymentConfiguration.isProductionMode();
     }
 
     protected void handleRequest(PortletRequest request,
index 8857c0e9647c88b0c33d6a02aa08c9b1755edbc9..062ba6cdf7c93c897695e8eaf84ba78f2931697d 100644 (file)
@@ -99,43 +99,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
     private final String resourcePath = null;
 
-    private DeploymentConfiguration deploymentConfiguration = new AbstractDeploymentConfiguration(
-            getClass()) {
+    private DeploymentConfiguration deploymentConfiguration;
 
-        @Override
-        public String getStaticFileLocation(WrappedRequest request) {
-            HttpServletRequest servletRequest = WrappedHttpServletRequest
-                    .cast(request);
-            return AbstractApplicationServlet.this
-                    .getStaticFilesLocation(servletRequest);
-        }
-
-        @Override
-        public String getConfiguredWidgetset(WrappedRequest request) {
-            return getApplicationOrSystemProperty(
-                    AbstractApplicationServlet.PARAMETER_WIDGETSET,
-                    AbstractApplicationServlet.DEFAULT_WIDGETSET);
-        }
-
-        @Override
-        public String getConfiguredTheme(WrappedRequest request) {
-            // Use the default
-            return AbstractApplicationServlet.getDefaultTheme();
-        }
-
-        @Override
-        public boolean isStandalone(WrappedRequest request) {
-            return true;
-        }
-
-        @Override
-        public String getMimeType(String resourceName) {
-            return getServletContext().getMimeType(resourceName);
-        }
-    };
-
-    private final AddonContext addonContext = new AddonContext(
-            getDeploymentConfiguration());
+    private AddonContext addonContext;
 
     /**
      * Called by the servlet container to indicate to a servlet that the servlet
@@ -152,8 +118,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
     public void init(javax.servlet.ServletConfig servletConfig)
             throws javax.servlet.ServletException {
         super.init(servletConfig);
-        Properties applicationProperties = getDeploymentConfiguration()
-                .getInitParameters();
+        Properties applicationProperties = new Properties();
 
         // Read default parameters from server.xml
         final ServletContext context = servletConfig.getServletContext();
@@ -172,6 +137,42 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
                     servletConfig.getInitParameter(name));
         }
 
+        deploymentConfiguration = new AbstractDeploymentConfiguration(
+                getClass(), applicationProperties) {
+
+            @Override
+            public String getStaticFileLocation(WrappedRequest request) {
+                HttpServletRequest servletRequest = WrappedHttpServletRequest
+                        .cast(request);
+                return AbstractApplicationServlet.this
+                        .getStaticFilesLocation(servletRequest);
+            }
+
+            @Override
+            public String getConfiguredWidgetset(WrappedRequest request) {
+                return getApplicationOrSystemProperty(
+                        AbstractApplicationServlet.PARAMETER_WIDGETSET,
+                        AbstractApplicationServlet.DEFAULT_WIDGETSET);
+            }
+
+            @Override
+            public String getConfiguredTheme(WrappedRequest request) {
+                // Use the default
+                return AbstractApplicationServlet.getDefaultTheme();
+            }
+
+            @Override
+            public boolean isStandalone(WrappedRequest request) {
+                return true;
+            }
+
+            @Override
+            public String getMimeType(String resourceName) {
+                return getServletContext().getMimeType(resourceName);
+            }
+        };
+
+        addonContext = new AddonContext(deploymentConfiguration);
         addonContext.init();
     }
 
index a8e4cdfacaa2b5edfd25b38c8f87744c53147480..ad5acad5e90e52e9ab2241bb98d64ba839964a91 100644 (file)
@@ -28,14 +28,16 @@ public abstract class AbstractDeploymentConfiguration implements
         DeploymentConfiguration {
 
     private final Class<?> systemPropertyBaseClass;
-    private final Properties applicationProperties = new Properties();
+    private final Properties applicationProperties;
     private AddonContext addonContext;
     private boolean productionMode;
     private boolean xsrfProtectionEnabled;
     private int resourceCacheTime;
 
-    public AbstractDeploymentConfiguration(Class<?> systemPropertyBaseClass) {
+    public AbstractDeploymentConfiguration(Class<?> systemPropertyBaseClass,
+            Properties applicationProperties) {
         this.systemPropertyBaseClass = systemPropertyBaseClass;
+        this.applicationProperties = applicationProperties;
 
         checkProductionMode();
         checkXsrfProtection();
@@ -192,7 +194,7 @@ public abstract class AbstractDeploymentConfiguration implements
      * Log a warning if cross-site request forgery protection is disabled.
      */
     private void checkXsrfProtection() {
-        xsrfProtectionEnabled = getApplicationOrSystemProperty(
+        xsrfProtectionEnabled = !getApplicationOrSystemProperty(
                 Constants.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, "false")
                 .equals("true");
         if (!xsrfProtectionEnabled) {