diff options
Diffstat (limited to 'server/src/com/vaadin/server/AbstractDeploymentConfiguration.java')
-rw-r--r-- | server/src/com/vaadin/server/AbstractDeploymentConfiguration.java | 208 |
1 files changed, 8 insertions, 200 deletions
diff --git a/server/src/com/vaadin/server/AbstractDeploymentConfiguration.java b/server/src/com/vaadin/server/AbstractDeploymentConfiguration.java index d1280d29ce..3d7efa6711 100644 --- a/server/src/com/vaadin/server/AbstractDeploymentConfiguration.java +++ b/server/src/com/vaadin/server/AbstractDeploymentConfiguration.java @@ -18,87 +18,28 @@ package com.vaadin.server; import java.lang.reflect.Constructor; import java.util.Iterator; -import java.util.Properties; import java.util.ServiceLoader; -import java.util.logging.Logger; public abstract class AbstractDeploymentConfiguration implements DeploymentConfiguration { - private final Class<?> systemPropertyBaseClass; - private final Properties applicationProperties; private AddonContext addonContext; - private boolean productionMode; - private boolean xsrfProtectionEnabled; - private int resourceCacheTime; - private int heartbeatInterval; - private boolean idleRootCleanupEnabled; + private final ApplicationConfiguration applicationConfiguration; - public AbstractDeploymentConfiguration(Class<?> systemPropertyBaseClass, - Properties applicationProperties) { - this.systemPropertyBaseClass = systemPropertyBaseClass; - this.applicationProperties = applicationProperties; - - checkProductionMode(); - checkXsrfProtection(); - checkResourceCacheTime(); - checkHeartbeatInterval(); - checkIdleUICleanup(); + public AbstractDeploymentConfiguration( + ApplicationConfiguration applicationConfiguration) { + this.applicationConfiguration = applicationConfiguration; } @Override - public String getApplicationOrSystemProperty(String propertyName, - String defaultValue) { - String val = null; - - // Try application properties - val = getApplicationProperty(propertyName); - if (val != null) { - return val; - } - - // Try system properties - val = getSystemProperty(propertyName); - if (val != null) { - return val; - } - - return defaultValue; - } - - /** - * Gets an system property value. - * - * @param parameterName - * the Name or the parameter. - * @return String value or null if not found - */ - protected String getSystemProperty(String parameterName) { - String val = null; - - String pkgName; - final Package pkg = systemPropertyBaseClass.getPackage(); - if (pkg != null) { - pkgName = pkg.getName(); - } else { - final String className = systemPropertyBaseClass.getName(); - pkgName = new String(className.toCharArray(), 0, - className.lastIndexOf('.')); - } - val = System.getProperty(pkgName + "." + parameterName); - if (val != null) { - return val; - } - - // Try lowercased system properties - val = System.getProperty(pkgName + "." + parameterName.toLowerCase()); - return val; + public ApplicationConfiguration getApplicationConfiguration() { + return applicationConfiguration; } @Override public ClassLoader getClassLoader() { - final String classLoaderName = getApplicationOrSystemProperty( - "ClassLoader", null); + final String classLoaderName = getApplicationConfiguration() + .getApplicationOrSystemProperty("ClassLoader", null); ClassLoader classLoader; if (classLoaderName == null) { classLoader = getClass().getClassLoader(); @@ -119,32 +60,6 @@ public abstract class AbstractDeploymentConfiguration implements return classLoader; } - /** - * Gets an application property value. - * - * @param parameterName - * the Name or the parameter. - * @return String value or null if not found - */ - protected String getApplicationProperty(String parameterName) { - - String val = applicationProperties.getProperty(parameterName); - if (val != null) { - return val; - } - - // Try lower case application properties for backward compatibility with - // 3.0.2 and earlier - val = applicationProperties.getProperty(parameterName.toLowerCase()); - - return val; - } - - @Override - public Properties getInitParameters() { - return applicationProperties; - } - @Override public Iterator<AddonContextListener> getAddonContextListeners() { // Called once for init and then no more, so there's no point in caching @@ -163,111 +78,4 @@ public abstract class AbstractDeploymentConfiguration implements public AddonContext getAddonContext() { return addonContext; } - - /** - * {@inheritDoc} - * - * The default is false. - */ - @Override - public boolean isProductionMode() { - return productionMode; - } - - /** - * {@inheritDoc} - * - * The default is true. - */ - @Override - public boolean isXsrfProtectionEnabled() { - return xsrfProtectionEnabled; - } - - /** - * {@inheritDoc} - * - * The default interval is 3600 seconds (1 hour). - */ - @Override - public int getResourceCacheTime() { - return resourceCacheTime; - } - - /** - * {@inheritDoc} - * - * The default interval is 300 seconds (5 minutes). - */ - @Override - public int getHeartbeatInterval() { - return heartbeatInterval; - } - - @Override - public boolean isIdleUICleanupEnabled() { - return idleRootCleanupEnabled; - } - - /** - * Log a warning if Vaadin is not running in production mode. - */ - private void checkProductionMode() { - productionMode = getApplicationOrSystemProperty( - Constants.SERVLET_PARAMETER_PRODUCTION_MODE, "false").equals( - "true"); - if (!productionMode) { - getLogger().warning(Constants.NOT_PRODUCTION_MODE_INFO); - } - } - - /** - * Log a warning if cross-site request forgery protection is disabled. - */ - private void checkXsrfProtection() { - xsrfProtectionEnabled = !getApplicationOrSystemProperty( - Constants.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, "false") - .equals("true"); - if (!xsrfProtectionEnabled) { - getLogger().warning(Constants.WARNING_XSRF_PROTECTION_DISABLED); - } - } - - /** - * Log a warning if resource cache time is set but is not an integer. - */ - private void checkResourceCacheTime() { - try { - resourceCacheTime = Integer - .parseInt(getApplicationOrSystemProperty( - Constants.SERVLET_PARAMETER_RESOURCE_CACHE_TIME, - "3600")); - } catch (NumberFormatException e) { - getLogger().warning( - Constants.WARNING_RESOURCE_CACHING_TIME_NOT_NUMERIC); - resourceCacheTime = 3600; - } - } - - private void checkHeartbeatInterval() { - try { - heartbeatInterval = Integer - .parseInt(getApplicationOrSystemProperty( - Constants.SERVLET_PARAMETER_HEARTBEAT_RATE, "300")); - } catch (NumberFormatException e) { - getLogger().warning( - Constants.WARNING_HEARTBEAT_INTERVAL_NOT_NUMERIC); - heartbeatInterval = 300; - } - } - - private void checkIdleUICleanup() { - idleRootCleanupEnabled = getApplicationOrSystemProperty( - Constants.SERVLET_PARAMETER_CLOSE_IDLE_UIS, "false").equals( - "true"); - } - - private Logger getLogger() { - return Logger.getLogger(getClass().getName()); - } } |