--- /dev/null
+/*
+ * Copyright 2000-2014 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;
+
+/**
+ * An abstract base class for DeploymentConfiguration implementations. This
+ * class provides default implementation for common config properties.
+ *
+ * @author Vaadin Ltd
+ */
+public abstract class AbstractDeploymentConfiguration implements
+ DeploymentConfiguration {
+
+ @Override
+ public String getUIClassName() {
+ return getApplicationOrSystemProperty(VaadinSession.UI_PARAMETER, null);
+ }
+
+ @Override
+ public String getUIProviderClassName() {
+ return getApplicationOrSystemProperty(
+ Constants.SERVLET_PARAMETER_UI_PROVIDER, null);
+ }
+
+ @Override
+ public String getWidgetset(String defaultValue) {
+ return getApplicationOrSystemProperty(Constants.PARAMETER_WIDGETSET,
+ defaultValue);
+ }
+
+ @Override
+ public String getResourcesPath() {
+ return getApplicationOrSystemProperty(
+ Constants.PARAMETER_VAADIN_RESOURCES, null);
+ }
+
+ @Override
+ public String getClassLoaderName() {
+ return getApplicationOrSystemProperty("ClassLoader", null);
+ }
+}
* @author Vaadin Ltd
* @since 7.0.0
*/
-public class DefaultDeploymentConfiguration implements DeploymentConfiguration {
+public class DefaultDeploymentConfiguration extends
+ AbstractDeploymentConfiguration {
/**
* Default value for {@link #getResourceCacheTime()} = {@value} .
*/
public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
VaadinRequest request = event.getRequest();
- Object uiClassNameObj = request
- .getService()
- .getDeploymentConfiguration()
- .getApplicationOrSystemProperty(VaadinSession.UI_PARAMETER,
- null);
-
- if (uiClassNameObj instanceof String) {
- String uiClassName = uiClassNameObj.toString();
-
+ String uiClassName = request.getService().getDeploymentConfiguration()
+ .getUIClassName();
+ if (uiClassName != null) {
ClassLoader classLoader = request.getService().getClassLoader();
try {
Class<? extends UI> uiClass = Class.forName(uiClassName, true,
public String getApplicationOrSystemProperty(String propertyName,
String defaultValue);
+ /**
+ * Gets UI class configuration option value.
+ *
+ * @return UI class name
+ */
+ public String getUIClassName();
+
+ /**
+ * Gets UI provider class configuration option value.
+ *
+ * @return UI class name
+ */
+ public String getUIProviderClassName();
+
+ /**
+ * Gets Widgetset configuration option value. {@code defaultValue} is
+ * returned if widgetset parameter is not configured.
+ *
+ * @return UI class name
+ */
+ public String getWidgetset(String defaultValue);
+
+ /**
+ * Gets resources path configuration option value.
+ */
+ public String getResourcesPath();
+
+ /**
+ * Gets class loader configuration option value.
+ */
+ public String getClassLoaderName();
+
/**
* Returns to legacy Property.toString() mode used. See
* {@link AbstractProperty#isLegacyToStringEnabled()} for more information.
public static void initDefaultUIProvider(VaadinSession session,
VaadinService vaadinService) throws ServiceException {
String uiProperty = vaadinService.getDeploymentConfiguration()
- .getApplicationOrSystemProperty(VaadinSession.UI_PARAMETER,
- null);
+ .getUIClassName();
// Add provider for UI parameter first to give it lower priority
// (providers are FILO)
}
String uiProviderProperty = vaadinService.getDeploymentConfiguration()
- .getApplicationOrSystemProperty(
- Constants.SERVLET_PARAMETER_UI_PROVIDER, null);
+ .getUIProviderClassName();
// Then add custom UI provider if defined
if (uiProviderProperty != null) {
UIProvider uiProvider = getUIProvider(uiProviderProperty,
@Override
public String getConfiguredWidgetset(VaadinRequest request) {
- String widgetset = getDeploymentConfiguration()
- .getApplicationOrSystemProperty(
- VaadinPortlet.PARAMETER_WIDGETSET, null);
+ String widgetset = getDeploymentConfiguration().getWidgetset(null);
if (widgetset == null) {
widgetset = getParameter(request,
this.deploymentConfiguration = deploymentConfiguration;
final String classLoaderName = getDeploymentConfiguration()
- .getApplicationOrSystemProperty("ClassLoader", null);
+ .getClassLoaderName();
if (classLoaderName != null) {
try {
final Class<?> classLoaderClass = getClass().getClassLoader()
VaadinServletRequest servletRequest = (VaadinServletRequest) request;
String staticFileLocation;
// if property is defined in configurations, use that
- staticFileLocation = getDeploymentConfiguration()
- .getApplicationOrSystemProperty(
- VaadinServlet.PARAMETER_VAADIN_RESOURCES, null);
+ staticFileLocation = getDeploymentConfiguration().getResourcesPath();
if (staticFileLocation != null) {
return staticFileLocation;
}
@Override
public String getConfiguredWidgetset(VaadinRequest request) {
- return getDeploymentConfiguration().getApplicationOrSystemProperty(
- VaadinServlet.PARAMETER_WIDGETSET,
+ return getDeploymentConfiguration().getWidgetset(
VaadinServlet.DEFAULT_WIDGETSET);
}
--- /dev/null
+/*
+ * Copyright 2000-2014 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;
+import java.util.UUID;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.shared.communication.PushMode;
+
+/**
+ * Test for {@link AbstractDeploymentConfiguration}
+ *
+ * @author Vaadin Ltd
+ */
+public class AbstractDeploymentConfigurationTest {
+
+ @Test
+ public void getUIClass_returnsUIParameterPropertyValue() {
+ String ui = UUID.randomUUID().toString();
+ DeploymentConfiguration config = getConfig(VaadinSession.UI_PARAMETER,
+ ui);
+ Assert.assertEquals("Unexpected UI class configuration option value",
+ ui, config.getUIClassName());
+ }
+
+ @Test
+ public void getUIProviderClass_returnsUIProviderPropertyValue() {
+ String uiProvider = UUID.randomUUID().toString();
+ DeploymentConfiguration config = getConfig(
+ Constants.SERVLET_PARAMETER_UI_PROVIDER, uiProvider);
+ Assert.assertEquals(
+ "Unexpected UI providerclass configuration option value",
+ uiProvider, config.getUIProviderClassName());
+ }
+
+ @Test
+ public void getWidgetset_returnsWidgetsetProviderPropertyValue() {
+ String widgetset = UUID.randomUUID().toString();
+ DeploymentConfiguration config = getConfig(
+ Constants.PARAMETER_WIDGETSET, widgetset);
+ Assert.assertEquals("Unexpected widgetset configuration option value",
+ widgetset, config.getWidgetset(null));
+ }
+
+ @Test
+ public void getWidgetset_noWidgetsetPropertyValue_returnsProvidedDefaultValue() {
+ DeploymentConfiguration config = getConfig(null, null);
+ String widgetset = UUID.randomUUID().toString();
+ Assert.assertEquals("Unexpected widgetset configuration option value",
+ widgetset, config.getWidgetset(widgetset));
+ }
+
+ @Test
+ public void getResourcesPath_returnsResourcesPathPropertyValue() {
+ String resources = UUID.randomUUID().toString();
+ DeploymentConfiguration config = getConfig(
+ Constants.PARAMETER_VAADIN_RESOURCES, resources);
+ Assert.assertEquals(
+ "Unexpected resources path configuration option value",
+ resources, config.getResourcesPath());
+ }
+
+ @Test
+ public void getClassLoader_returnsClassloaderPropertyValue() {
+ String classLoader = UUID.randomUUID().toString();
+ DeploymentConfiguration config = getConfig("ClassLoader", classLoader);
+ Assert.assertEquals(
+ "Unexpected classLoader configuration option value",
+ classLoader, config.getClassLoaderName());
+ }
+
+ private DeploymentConfiguration getConfig(String property, String value) {
+ Properties props = new Properties();
+ if (property != null) {
+ props.put(property, value);
+ }
+ return new DeploymentConfigImpl(props);
+ }
+
+ private static class DeploymentConfigImpl extends
+ AbstractDeploymentConfiguration {
+
+ private Properties properties;
+
+ DeploymentConfigImpl(Properties props) {
+ properties = props;
+ }
+
+ @Override
+ public boolean isProductionMode() {
+ return false;
+ }
+
+ @Override
+ public boolean isXsrfProtectionEnabled() {
+ return false;
+ }
+
+ @Override
+ public boolean isSyncIdCheckEnabled() {
+ return false;
+ }
+
+ @Override
+ public int getResourceCacheTime() {
+ return 0;
+ }
+
+ @Override
+ public int getHeartbeatInterval() {
+ return 0;
+ }
+
+ @Override
+ public boolean isCloseIdleSessions() {
+ return false;
+ }
+
+ @Override
+ public PushMode getPushMode() {
+ return null;
+ }
+
+ @Override
+ public Properties getInitParameters() {
+ return null;
+ }
+
+ @Override
+ public String getApplicationOrSystemProperty(String propertyName,
+ String defaultValue) {
+ return properties.getProperty(propertyName, defaultValue);
+ }
+
+ @Override
+ public LegacyProperyToStringMode getLegacyPropertyToStringMode() {
+ return null;
+ }
+
+ }
+}
}
private void mockWidgetsetConfiguration(String widgetset) {
- when(
- conf.getApplicationOrSystemProperty(
- Constants.PARAMETER_WIDGETSET, null)).thenReturn(
- widgetset);
+ when(conf.getWidgetset(null)).thenReturn(widgetset);
}
@Test
import java.util.Map;
import java.util.Properties;
-import com.vaadin.server.DeploymentConfiguration;
+import com.vaadin.server.AbstractDeploymentConfiguration;
import com.vaadin.shared.communication.PushMode;
-public class MockDeploymentConfiguration implements DeploymentConfiguration {
+public class MockDeploymentConfiguration extends
+ AbstractDeploymentConfiguration {
private boolean productionMode = false;
private boolean xsrfProtectionEnabled = true;