import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Enumeration;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Iterator;
import com.vaadin.event.EventRouter;
import com.vaadin.server.AbstractErrorMessage;
import com.vaadin.server.AbstractUIProvider;
+import com.vaadin.server.ApplicationConfiguration;
import com.vaadin.server.ApplicationContext;
import com.vaadin.server.BootstrapFragmentResponse;
import com.vaadin.server.BootstrapListener;
public static class ApplicationStartEvent implements Serializable {
private final URL applicationUrl;
- private final DeploymentConfiguration configuration;
+ private final ApplicationConfiguration configuration;
private final ApplicationContext context;
* @param applicationUrl
* the URL the application should respond to.
* @param configuration
- * the deployment configuration for the application.
+ * the application configuration for the application.
* @param context
* the context application will be running in.
*/
public ApplicationStartEvent(URL applicationUrl,
- DeploymentConfiguration configuration,
+ ApplicationConfiguration configuration,
ApplicationContext context) {
this.applicationUrl = applicationUrl;
this.configuration = configuration;
}
/**
- * Returns the deployment configuration used by this application.
+ * Returns the application configuration used by this application.
*
* @return the deployment configuration.
*/
- public DeploymentConfiguration getConfiguration() {
+ public ApplicationConfiguration getConfiguration() {
return configuration;
}
private ApplicationContext context;
/**
- * Deployment configuration for the application.
+ * Configuration for the application.
*/
- private DeploymentConfiguration configuration;
+ private ApplicationConfiguration configuration;
/**
* The application's URL.
}
/**
- * Returns the properties of this application as specified in the deployment
- * configuration.
+ * Gets the configuration for this application
*
- * @return Application properties
+ * @return the application configuration
*/
- protected Properties getProperties() {
- return configuration.getInitParameters();
- }
-
- /**
- * Returns an enumeration of all the names in this application.
- *
- * <p>
- * See {@link #start(URL, Properties, ApplicationContext)} how properties
- * are defined.
- * </p>
- *
- * @return an enumeration of all the keys in this property list, including
- * the keys in the default property list.
- *
- */
- public Enumeration<?> getPropertyNames() {
- return getProperties().propertyNames();
- }
-
- /**
- * Searches for the property with the specified name in this application.
- * This method returns <code>null</code> if the property is not found.
- *
- * See {@link #start(URL, Properties, ApplicationContext)} how properties
- * are defined.
- *
- * @param name
- * the name of the property.
- * @return the value in this property list with the specified key value.
- */
- public String getProperty(String name) {
- return getProperties().getProperty(name);
+ public ApplicationConfiguration getConfiguration() {
+ return configuration;
}
/**
--- /dev/null
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin;
+
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import com.vaadin.server.ApplicationConfiguration;
+import com.vaadin.server.Constants;
+
+public class DefaultApplicationConfiguration implements
+ ApplicationConfiguration {
+ private final Properties applicationProperties;
+ private boolean productionMode;
+ private boolean xsrfProtectionEnabled;
+ private int resourceCacheTime;
+ private int heartbeatInterval;
+ private boolean idleRootCleanupEnabled;
+ private final Class<?> systemPropertyBaseClass;
+
+ public DefaultApplicationConfiguration(Class<?> systemPropertyBaseClass,
+ Properties applicationProperties) {
+ this.applicationProperties = applicationProperties;
+ this.systemPropertyBaseClass = systemPropertyBaseClass;
+
+ checkProductionMode();
+ checkXsrfProtection();
+ checkResourceCacheTime();
+ checkHeartbeatInterval();
+ checkIdleUICleanup();
+ }
+
+ @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;
+ }
+
+ /**
+ * Gets an application property value.
+ *
+ * @param parameterName
+ * the Name or the parameter.
+ * @return String value or null if not found
+ */
+ public 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;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * The default is false.
+ */
+ @Override
+ public boolean isProductionMode() {
+ return productionMode;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * The default is true.
+ */
+ @Override
+ public boolean isXsrfProtectionEnabled() {
+ return xsrfProtectionEnabled;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * The default interval is 3600 seconds (1 hour).
+ */
+ @Override
+ public int getResourceCacheTime() {
+ return resourceCacheTime;
+ }
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * 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());
+ }
+
+ @Override
+ public Properties getInitParameters() {
+ return applicationProperties;
+ }
+
+}
* @return false if the XSRF is turned off, true otherwise
*/
public boolean isXSRFEnabled(Application application) {
- return !"true"
- .equals(application
- .getProperty(VaadinServlet.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION));
+ return application.getConfiguration().isXsrfProtectionEnabled();
}
/**
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();
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
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());
- }
}
--- /dev/null
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.server;
+
+import java.util.Properties;
+
+
+/**
+ * A collection of properties configured for all applications as well as a way
+ * of accessing third party properties not explicitely supported by this class.
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public interface ApplicationConfiguration {
+ /**
+ * Returns whether Vaadin is in production mode.
+ *
+ * @return true if in production mode, false otherwise.
+ */
+ public boolean isProductionMode();
+
+ /**
+ * Returns whether cross-site request forgery protection is enabled.
+ *
+ * @return true if XSRF protection is enabled, false otherwise.
+ */
+ public boolean isXsrfProtectionEnabled();
+
+ /**
+ * Returns the time resources can be cached in the browsers, in seconds.
+ *
+ * @return The resource cache time.
+ */
+ public int getResourceCacheTime();
+
+ /**
+ * Returns the number of seconds between heartbeat requests of a UI, or a
+ * non-positive number if heartbeat is disabled.
+ *
+ * @return The time between heartbeats.
+ */
+ public int getHeartbeatInterval();
+
+ /**
+ * Returns whether UIs that have no other activity than heartbeat requests
+ * should be closed after they have been idle the maximum inactivity time
+ * enforced by the session.
+ *
+ * @see ApplicationContext#getMaxInactiveInterval()
+ *
+ * @since 7.0.0
+ *
+ * @return True if UIs receiving only heartbeat requests are eventually
+ * closed; false if heartbeat requests extend UI lifetime
+ * indefinitely.
+ */
+ public boolean isIdleUICleanupEnabled();
+
+ /**
+ * Gets the properties configured for the deployment, e.g. as init
+ * parameters to the servlet or portlet.
+ *
+ * @return properties for the application.
+ */
+ public Properties getInitParameters();
+
+ /**
+ * Gets a configured property. The properties are typically read from e.g.
+ * web.xml or from system properties of the JVM.
+ *
+ * @param propertyName
+ * The simple of the property, in some contexts, lookup might be
+ * performed using variations of the provided name.
+ * @param defaultValue
+ * the default value that should be used if no value has been
+ * defined
+ * @return the property value, or the passed default value if no property
+ * value is found
+ */
+ public String getApplicationOrSystemProperty(String propertyName,
+ String defaultValue);
+
+}
defaults.put("standalone", true);
}
- defaults.put("heartbeatInterval",
- deploymentConfiguration.getHeartbeatInterval());
+ defaults.put("heartbeatInterval", deploymentConfiguration
+ .getApplicationConfiguration().getHeartbeatInterval());
defaults.put("appUri", getAppUri(context));
@Override
public Class<? extends UI> getUIClass(Application application,
WrappedRequest request) {
- Object uiClassNameObj = application
- .getProperty(Application.UI_PARAMETER);
+ Object uiClassNameObj = application.getConfiguration()
+ .getInitParameters().getProperty(Application.UI_PARAMETER);
if (uiClassNameObj instanceof String) {
String uiClassName = uiClassNameObj.toString();
import java.io.Serializable;
import java.util.Iterator;
-import java.util.Properties;
import javax.portlet.PortletContext;
import javax.servlet.ServletContext;
*/
public boolean isStandalone(WrappedRequest request);
- /**
- * Gets a configured property. The properties are typically read from e.g.
- * web.xml or from system properties of the JVM.
- *
- * @param propertyName
- * The simple of the property, in some contexts, lookup might be
- * performed using variations of the provided name.
- * @param defaultValue
- * the default value that should be used if no value has been
- * defined
- * @return the property value, or the passed default value if no property
- * value is found
- */
- public String getApplicationOrSystemProperty(String propertyName,
- String defaultValue);
-
/**
* Get the class loader to use for loading classes loaded by name, e.g.
* custom UI classes. <code>null</code> indicates that the default class
public String getMimeType(String resourceName);
/**
- * Gets the properties configured for the deployment, e.g. as init
- * parameters to the servlet or portlet.
+ * Gets the application configuration.
*
- * @return properties for the application.
+ * @return the application configuration
*/
- public Properties getInitParameters();
+ public ApplicationConfiguration getApplicationConfiguration();
public Iterator<AddonContextListener> getAddonContextListeners();
public void setAddonContext(AddonContext vaadinContext);
- /**
- * Returns whether Vaadin is in production mode.
- *
- * @since 7.0.0
- *
- * @return true if in production mode, false otherwise.
- */
- public boolean isProductionMode();
-
- /**
- * Returns whether cross-site request forgery protection is enabled.
- *
- * @since 7.0.0
- *
- * @return true if XSRF protection is enabled, false otherwise.
- */
- public boolean isXsrfProtectionEnabled();
-
- /**
- * Returns the time resources can be cached in the browsers, in seconds.
- *
- * @since 7.0.0
- *
- * @return The resource cache time.
- */
- public int getResourceCacheTime();
-
- /**
- * Returns the number of seconds between heartbeat requests of a UI, or a
- * non-positive number if heartbeat is disabled.
- *
- * @since 7.0.0
- *
- * @return The time between heartbeats.
- */
- public int getHeartbeatInterval();
-
- /**
- * Returns whether UIs that have no other activity than heartbeat requests
- * should be closed after they have been idle the maximum inactivity time
- * enforced by the session.
- *
- * @see ApplicationContext#getMaxInactiveInterval()
- *
- * @since 7.0.0
- *
- * @return True if UIs receiving only heartbeat requests are eventually
- * closed; false if heartbeat requests extend UI lifetime
- * indefinitely.
- */
- public boolean isIdleUICleanupEnabled();
-
/**
* Gets the system messages object
*
protected String getMainDivStyle(BootstrapContext context) {
DeploymentConfiguration deploymentConfiguration = context
.getRequest().getDeploymentConfiguration();
- return deploymentConfiguration.getApplicationOrSystemProperty(
- VaadinPortlet.PORTLET_PARAMETER_STYLE, null);
+ return deploymentConfiguration.getApplicationConfiguration()
+ .getApplicationOrSystemProperty(
+ VaadinPortlet.PORTLET_PARAMETER_STYLE, null);
}
@Override
package com.vaadin.server;
import java.io.Serializable;
+import java.util.Properties;
import com.vaadin.Application;
import com.vaadin.shared.ApplicationConstants;
static Class<? extends Application> getApplicationClass(
DeploymentConfiguration deploymentConfiguration)
throws ApplicationClassException {
- String applicationParameter = deploymentConfiguration
- .getInitParameters().getProperty("application");
- String uiParameter = deploymentConfiguration.getInitParameters()
+ Properties initParameters = deploymentConfiguration
+ .getApplicationConfiguration().getInitParameters();
+ String applicationParameter = initParameters.getProperty("application");
+ String uiParameter = initParameters
.getProperty(Application.UI_PARAMETER);
ClassLoader classLoader = deploymentConfiguration.getClassLoader();
import com.liferay.portal.kernel.util.PropsUtil;
import com.vaadin.Application;
import com.vaadin.Application.ApplicationStartEvent;
+import com.vaadin.DefaultApplicationConfiguration;
import com.vaadin.server.AbstractCommunicationManager.Callback;
import com.vaadin.server.ServletPortletHelper.ApplicationClassException;
import com.vaadin.ui.UI;
private final VaadinPortlet portlet;
public PortletDeploymentConfiguration(VaadinPortlet portlet,
- Properties applicationProperties) {
- super(portlet.getClass(), applicationProperties);
+ ApplicationConfiguration applicationConfiguration) {
+ super(applicationConfiguration);
this.portlet = portlet;
}
@Override
public String getConfiguredWidgetset(WrappedRequest request) {
- String widgetset = getApplicationOrSystemProperty(
- PARAMETER_WIDGETSET, null);
+ String widgetset = getApplicationConfiguration()
+ .getApplicationOrSystemProperty(PARAMETER_WIDGETSET, null);
if (widgetset == null) {
// If no widgetset defined for the application, check the
config.getInitParameter(name));
}
- deploymentConfiguration = createDeploymentConfiguration(applicationProperties);
+ ApplicationConfiguration applicationConfiguration = createApplicationConfiguration(applicationProperties);
+ deploymentConfiguration = createDeploymentConfiguration(applicationConfiguration);
addonContext = new AddonContext(deploymentConfiguration);
addonContext.init();
}
- protected PortletDeploymentConfiguration createDeploymentConfiguration(
+ protected ApplicationConfiguration createApplicationConfiguration(
Properties applicationProperties) {
- return new PortletDeploymentConfiguration(this, applicationProperties);
+ return new DefaultApplicationConfiguration(getClass(),
+ applicationProperties);
+ }
+
+ protected PortletDeploymentConfiguration createDeploymentConfiguration(
+ ApplicationConfiguration applicationConfiguration) {
+ return new PortletDeploymentConfiguration(this,
+ applicationConfiguration);
}
@Override
&& request.getResourceID().equals("DUMMY");
}
- /**
- * 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 deploymentConfiguration.isProductionMode();
- }
-
protected void handleRequest(PortletRequest request,
PortletResponse response) throws PortletException, IOException {
RequestTimer requestTimer = new RequestTimer();
application.setLocale(locale);
// No application URL when running inside a portlet
application.start(new ApplicationStartEvent(null,
- getDeploymentConfiguration(), context));
+ getDeploymentConfiguration().getApplicationConfiguration(),
+ context));
addonContext.fireApplicationStarted(application);
}
}
import com.vaadin.Application;
import com.vaadin.Application.ApplicationStartEvent;
+import com.vaadin.DefaultApplicationConfiguration;
import com.vaadin.server.AbstractCommunicationManager.Callback;
import com.vaadin.server.ServletPortletHelper.ApplicationClassException;
import com.vaadin.shared.ApplicationConstants;
private final VaadinServlet servlet;
public ServletDeploymentConfiguration(VaadinServlet servlet,
- Properties applicationProperties) {
- super(servlet.getClass(), applicationProperties);
+ ApplicationConfiguration applicationProperties) {
+ super(applicationProperties);
this.servlet = servlet;
}
.cast(request);
String staticFileLocation;
// if property is defined in configurations, use that
- staticFileLocation = getApplicationOrSystemProperty(
- PARAMETER_VAADIN_RESOURCES, null);
+ staticFileLocation = getApplicationConfiguration()
+ .getApplicationOrSystemProperty(PARAMETER_VAADIN_RESOURCES,
+ null);
if (staticFileLocation != null) {
return staticFileLocation;
}
@Override
public String getConfiguredWidgetset(WrappedRequest request) {
- return getApplicationOrSystemProperty(
- VaadinServlet.PARAMETER_WIDGETSET,
- VaadinServlet.DEFAULT_WIDGETSET);
+ return getApplicationConfiguration()
+ .getApplicationOrSystemProperty(
+ VaadinServlet.PARAMETER_WIDGETSET,
+ VaadinServlet.DEFAULT_WIDGETSET);
}
@Override
servletConfig.getInitParameter(name));
}
- deploymentConfiguration = createDeploymentConfiguration(applicationProperties);
+ ApplicationConfiguration applicationConfiguration = createApplicationConfiguration(applicationProperties);
+ deploymentConfiguration = createDeploymentConfiguration(applicationConfiguration);
addonContext = new AddonContext(deploymentConfiguration);
addonContext.init();
}
- protected ServletDeploymentConfiguration createDeploymentConfiguration(
+ protected ApplicationConfiguration createApplicationConfiguration(
Properties applicationProperties) {
- return new ServletDeploymentConfiguration(this, applicationProperties);
+ return new DefaultApplicationConfiguration(getClass(),
+ applicationProperties);
+ }
+
+ protected ServletDeploymentConfiguration createDeploymentConfiguration(
+ ApplicationConfiguration applicationConfiguration) {
+ return new ServletDeploymentConfiguration(this,
+ applicationConfiguration);
}
@Override
addonContext.destroy();
}
- /**
- * 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() {
- return getDeploymentConfiguration().isProductionMode();
- }
-
- /**
- * Returns the number of seconds the browser should cache a file. Default is
- * 1 hour (3600 s).
- *
- * @return The number of seconds files are cached in the browser
- */
- public int getResourceCacheTime() {
- return getDeploymentConfiguration().getResourceCacheTime();
- }
-
/**
* Receives standard HTTP requests from the public service method and
* dispatches them.
Locale locale = request.getLocale();
application.setLocale(locale);
application.start(new ApplicationStartEvent(applicationUrl,
- getDeploymentConfiguration(), webApplicationContext));
+ getDeploymentConfiguration().getApplicationConfiguration(),
+ webApplicationContext));
addonContext.fireApplicationStarted(application);
}
}
* cache timeout can be configured by setting the resourceCacheTime
* parameter in web.xml
*/
+ int resourceCacheTime = getDeploymentConfiguration()
+ .getApplicationConfiguration().getResourceCacheTime();
response.setHeader("Cache-Control",
- "max-age= " + String.valueOf(getResourceCacheTime()));
+ "max-age= " + String.valueOf(resourceCacheTime));
}
// Write the resource to the client.
import junit.framework.TestCase;
+import com.vaadin.DefaultApplicationConfiguration;
import com.vaadin.server.VaadinServlet.ServletDeploymentConfiguration;
public class TestAbstractApplicationServletStaticFilesLocation extends TestCase {
.getDeclaredField("deploymentConfiguration");
f.setAccessible(true);
f.set(servlet, new ServletDeploymentConfiguration(servlet,
- new Properties()));
+ new DefaultApplicationConfiguration(servlet.getClass(),
+ new Properties())));
}
import com.vaadin.Application;
import com.vaadin.Application.ApplicationStartEvent;
+import com.vaadin.DefaultApplicationConfiguration;
+import com.vaadin.server.ApplicationConfiguration;
import com.vaadin.server.DefaultUIProvider;
import com.vaadin.server.DeploymentConfiguration;
import com.vaadin.server.WrappedRequest;
assertEquals(MyUI.class, uiClass);
}
- private static DeploymentConfiguration createConfigurationMock() {
- DeploymentConfiguration configurationMock = EasyMock
- .createMock(DeploymentConfiguration.class);
- EasyMock.expect(configurationMock.isProductionMode()).andReturn(false);
- EasyMock.expect(configurationMock.getInitParameters()).andReturn(
- new Properties());
-
- EasyMock.replay(configurationMock);
- return configurationMock;
+ private static ApplicationConfiguration createConfigurationMock() {
+ Properties properties = new Properties();
+ properties.put(Application.UI_PARAMETER, MyUI.class.getName());
+ return new DefaultApplicationConfiguration(CustomUIClassLoader.class,
+ properties);
}
private static WrappedRequest createRequestMock(ClassLoader classloader) {
private Application createStubApplication() {
return new Application() {
@Override
- public String getProperty(String name) {
- if (name.equals(UI_PARAMETER)) {
- return MyUI.class.getName();
- } else {
- return super.getProperty(name);
- }
+ public ApplicationConfiguration getConfiguration() {
+ return createConfigurationMock();
}
};
}
import java.net.URL;
import java.util.Collections;
import java.util.LinkedHashSet;
-import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.vaadin.Application;
import com.vaadin.server.AbstractUIProvider;
+import com.vaadin.server.ApplicationConfiguration;
import com.vaadin.server.VaadinServlet;
import com.vaadin.server.WrappedHttpServletRequest;
import com.vaadin.server.WrappedRequest;
@Override
protected ServletDeploymentConfiguration createDeploymentConfiguration(
- Properties applicationProperties) {
- return new ServletDeploymentConfiguration(this, applicationProperties) {
+ ApplicationConfiguration applicationConfiguration) {
+ return new ServletDeploymentConfiguration(this,
+ applicationConfiguration) {
@Override
public String getStaticFileLocation(WrappedRequest request) {
URIS uris = getApplicationRunnerURIs(WrappedHttpServletRequest
// cannot access example directory, possible security issue with
// Application Server or Servlet Container
// Try to read sample directory from web.xml parameter
- if (application.getProperty("sampleDirectory") != null) {
- file = new File(application.getProperty("sampleDirectory"));
+ String sampleDirProperty = application.getConfiguration()
+ .getInitParameters().getProperty("sampleDirectory");
+ if (sampleDirProperty != null) {
+ file = new File(sampleDirProperty);
if ((file != null) && (file.canRead())
&& (file.getAbsolutePath() != null)) {
// Success using property
}
// Failure using property
errorMessage += "Failed also to access sample directory <b>["
- + application.getProperty("sampleDirectory")
+ + sampleDirProperty
+ "]</b> defined in <b>sampleDirectory property</b>.";
} else {
// Failure using application context base dir, no property set