From 00863079b2fda73b5737de747fb10a4570dd9557 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 6 Nov 2012 18:11:50 +0200 Subject: Moved classes from com.vaadin to com.vaadin.server (#10145) Change-Id: Ica48f1d5edbefde0ef8afca0c2774fe122a6c8ad --- .../com/vaadin/DefaultDeploymentConfiguration.java | 246 ------------------ server/src/com/vaadin/LegacyApplication.java | 283 --------------------- .../server/DefaultDeploymentConfiguration.java | 244 ++++++++++++++++++ .../src/com/vaadin/server/LegacyApplication.java | 281 ++++++++++++++++++++ .../vaadin/server/LegacyApplicationUIProvider.java | 1 - .../src/com/vaadin/server/LegacyVaadinPortlet.java | 1 - .../src/com/vaadin/server/LegacyVaadinServlet.java | 1 - .../com/vaadin/server/ServletPortletHelper.java | 1 - server/src/com/vaadin/server/VaadinPortlet.java | 1 - server/src/com/vaadin/server/VaadinService.java | 1 - .../com/vaadin/server/VaadinServiceSession.java | 1 - server/src/com/vaadin/server/VaadinServlet.java | 1 - server/src/com/vaadin/ui/LegacyWindow.java | 4 +- ...tractApplicationServletStaticFilesLocation.java | 1 - .../server/component/ui/CustomUIClassLoader.java | 2 +- .../component/window/AddRemoveSubWindow.java | 2 +- 16 files changed, 529 insertions(+), 542 deletions(-) delete mode 100644 server/src/com/vaadin/DefaultDeploymentConfiguration.java delete mode 100644 server/src/com/vaadin/LegacyApplication.java create mode 100644 server/src/com/vaadin/server/DefaultDeploymentConfiguration.java create mode 100644 server/src/com/vaadin/server/LegacyApplication.java (limited to 'server') diff --git a/server/src/com/vaadin/DefaultDeploymentConfiguration.java b/server/src/com/vaadin/DefaultDeploymentConfiguration.java deleted file mode 100644 index 1d804c99aa..0000000000 --- a/server/src/com/vaadin/DefaultDeploymentConfiguration.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * 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.Constants; -import com.vaadin.server.DeploymentConfiguration; - -/** - * The default implementation of {@link DeploymentConfiguration} based on a base - * class for resolving system properties and a set of init parameters. - * - * @author Vaadin Ltd - * @since 7.0.0 - */ -public class DefaultDeploymentConfiguration implements DeploymentConfiguration { - private final Properties initParameters; - private boolean productionMode; - private boolean xsrfProtectionEnabled; - private int resourceCacheTime; - private int heartbeatInterval; - private boolean idleRootCleanupEnabled; - private final Class systemPropertyBaseClass; - - /** - * Create a new deployment configuration instance. - * - * @param systemPropertyBaseClass - * the class that should be used as a basis when reading system - * properties - * @param initParameters - * the init parameters that should make up the foundation for - * this configuration - */ - public DefaultDeploymentConfiguration(Class systemPropertyBaseClass, - Properties initParameters) { - this.initParameters = initParameters; - 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 = initParameters.getProperty(parameterName); - if (val != null) { - return val; - } - - // Try lower case application properties for backward compatibility with - // 3.0.2 and earlier - val = initParameters.getProperty(parameterName.toLowerCase()); - - return val; - } - - /** - * {@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_INTERVAL, - "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 initParameters; - } - -} diff --git a/server/src/com/vaadin/LegacyApplication.java b/server/src/com/vaadin/LegacyApplication.java deleted file mode 100644 index c28482e2a5..0000000000 --- a/server/src/com/vaadin/LegacyApplication.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * 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.net.URL; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import com.vaadin.server.DefaultErrorListener; -import com.vaadin.server.Terminal.ErrorEvent; -import com.vaadin.server.Terminal.ErrorListener; -import com.vaadin.server.VaadinServiceSession; -import com.vaadin.ui.LegacyWindow; -import com.vaadin.ui.UI; - -/** - * A special application designed to help migrating applications from Vaadin 6 - * to Vaadin 7. The legacy application supports setting a main window, adding - * additional browser level windows and defining the theme for the entire - * application. - * - * @deprecated This class is only intended to ease migration and should not be - * used for new projects. - * - * @since 7.0 - */ -@Deprecated -public abstract class LegacyApplication implements ErrorListener { - private LegacyWindow mainWindow; - private String theme; - - private Map legacyUINames = new HashMap(); - - private boolean isRunning = true; - - /** - * URL where the user is redirected to on application close, or null if - * application is just closed without redirection. - */ - private String logoutURL = null; - private URL url; - - /** - * Sets the main window of this application. Setting window as a main window - * of this application also adds the window to this application. - * - * @param mainWindow - * the UI to set as the default window - */ - public void setMainWindow(LegacyWindow mainWindow) { - if (this.mainWindow != null) { - throw new IllegalStateException("mainWindow has already been set"); - } - if (mainWindow.getSession() != null) { - throw new IllegalStateException( - "mainWindow is attached to another application"); - } - if (UI.getCurrent() == null) { - // Assume setting a main window from Application.init if there's - // no current UI -> set the main window as the current UI - UI.setCurrent(mainWindow); - } - addWindow(mainWindow); - this.mainWindow = mainWindow; - } - - public void doInit(URL url) { - this.url = url; - VaadinServiceSession.getCurrent().setErrorHandler(this); - init(); - } - - protected abstract void init(); - - /** - * Gets the mainWindow of the application. - * - *

- * The main window is the window attached to the application URL ( - * {@link #getURL()}) and thus which is show by default to the user. - *

- *

- * Note that each application must have at least one main window. - *

- * - * @return the UI used as the default window - */ - public LegacyWindow getMainWindow() { - return mainWindow; - } - - /** - * Sets the application's theme. - *

- * Note that this theme can be overridden for a specific UI with - * {@link VaadinServiceSession#getThemeForUI(UI)}. Setting theme to be - * null selects the default theme. For the available theme - * names, see the contents of the VAADIN/themes directory. - *

- * - * @param theme - * the new theme for this application. - */ - public void setTheme(String theme) { - this.theme = theme; - } - - /** - * Gets the application's theme. The application's theme is the default - * theme used by all the uIs for which a theme is not explicitly defined. If - * the application theme is not explicitly set, null is - * returned. - * - * @return the name of the application's theme. - */ - public String getTheme() { - return theme; - } - - /** - *

- * Gets a UI by name. Returns null if the application is not - * running or it does not contain a window corresponding to the name. - *

- * - * @param name - * the name of the requested window - * @return a UI corresponding to the name, or null to use the - * default window - */ - public LegacyWindow getWindow(String name) { - return legacyUINames.get(name); - } - - /** - * Counter to get unique names for windows with no explicit name - */ - private int namelessUIIndex = 0; - - /** - * Adds a new browser level window to this application. Please note that UI - * doesn't have a name that is used in the URL - to add a named window you - * should instead use {@link #addWindow(UI, String)} - * - * @param uI - * the UI window to add to the application - * @return returns the name that has been assigned to the window - * - * @see #addWindow(UI, String) - */ - public void addWindow(LegacyWindow uI) { - if (uI.getName() == null) { - String name = Integer.toString(namelessUIIndex++); - uI.setName(name); - } - - uI.setApplication(this); - - legacyUINames.put(uI.getName(), uI); - uI.setSession(VaadinServiceSession.getCurrent()); - } - - /** - * Removes the specified window from the application. This also removes all - * name mappings for the window (see {@link #addWindow(UI, String) and - * #getWindowName(UI)}. - * - *

- * Note that removing window from the application does not close the browser - * window - the window is only removed from the server-side. - *

- * - * @param uI - * the UI to remove - */ - public void removeWindow(LegacyWindow uI) { - for (Entry entry : legacyUINames.entrySet()) { - if (entry.getValue() == uI) { - legacyUINames.remove(entry.getKey()); - } - } - } - - /** - * Gets the set of windows contained by the application. - * - *

- * Note that the returned set of windows can not be modified. - *

- * - * @return the unmodifiable collection of windows. - */ - public Collection getWindows() { - return Collections.unmodifiableCollection(legacyUINames.values()); - } - - @Override - public void terminalError(ErrorEvent event) { - DefaultErrorListener.doDefault(event); - } - - public VaadinServiceSession getContext() { - return VaadinServiceSession.getCurrent(); - } - - public void close() { - isRunning = false; - Collection windows = getWindows(); - for (LegacyWindow legacyWindow : windows) { - String logoutUrl = getLogoutURL(); - if (logoutUrl == null) { - URL url = getURL(); - if (url != null) { - logoutUrl = url.toString(); - } - } - if (logoutUrl != null) { - legacyWindow.getPage().setLocation(logoutUrl); - } - legacyWindow.getSession().cleanupUI(legacyWindow); - } - } - - public boolean isRunning() { - return isRunning; - } - - public URL getURL() { - return url; - } - - /** - * Returns the URL user is redirected to on application close. If the URL is - * null, the application is closed normally as defined by the - * application running environment. - *

- * Desktop application just closes the application window and - * web-application redirects the browser to application main URL. - *

- * - * @return the URL. - * - * @deprecated might be refactored or removed before 7.0.0 - */ - @Deprecated - public String getLogoutURL() { - return logoutURL; - } - - /** - * Sets the URL user is redirected to on application close. If the URL is - * null, the application is closed normally as defined by the - * application running environment: Desktop application just closes the - * application window and web-application redirects the browser to - * application main URL. - * - * @param logoutURL - * the logoutURL to set. - * - * @deprecated might be refactored or removed before 7.0.0 - */ - @Deprecated - public void setLogoutURL(String logoutURL) { - this.logoutURL = logoutURL; - } -} \ No newline at end of file diff --git a/server/src/com/vaadin/server/DefaultDeploymentConfiguration.java b/server/src/com/vaadin/server/DefaultDeploymentConfiguration.java new file mode 100644 index 0000000000..07a810c64c --- /dev/null +++ b/server/src/com/vaadin/server/DefaultDeploymentConfiguration.java @@ -0,0 +1,244 @@ +/* + * 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; +import java.util.logging.Logger; + + +/** + * The default implementation of {@link DeploymentConfiguration} based on a base + * class for resolving system properties and a set of init parameters. + * + * @author Vaadin Ltd + * @since 7.0.0 + */ +public class DefaultDeploymentConfiguration implements DeploymentConfiguration { + private final Properties initParameters; + private boolean productionMode; + private boolean xsrfProtectionEnabled; + private int resourceCacheTime; + private int heartbeatInterval; + private boolean idleRootCleanupEnabled; + private final Class systemPropertyBaseClass; + + /** + * Create a new deployment configuration instance. + * + * @param systemPropertyBaseClass + * the class that should be used as a basis when reading system + * properties + * @param initParameters + * the init parameters that should make up the foundation for + * this configuration + */ + public DefaultDeploymentConfiguration(Class systemPropertyBaseClass, + Properties initParameters) { + this.initParameters = initParameters; + 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 = initParameters.getProperty(parameterName); + if (val != null) { + return val; + } + + // Try lower case application properties for backward compatibility with + // 3.0.2 and earlier + val = initParameters.getProperty(parameterName.toLowerCase()); + + return val; + } + + /** + * {@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_INTERVAL, + "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 initParameters; + } + +} diff --git a/server/src/com/vaadin/server/LegacyApplication.java b/server/src/com/vaadin/server/LegacyApplication.java new file mode 100644 index 0000000000..6ac7ad2e0c --- /dev/null +++ b/server/src/com/vaadin/server/LegacyApplication.java @@ -0,0 +1,281 @@ +/* + * 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.net.URL; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.vaadin.server.Terminal.ErrorEvent; +import com.vaadin.server.Terminal.ErrorListener; +import com.vaadin.ui.LegacyWindow; +import com.vaadin.ui.UI; + +/** + * A special application designed to help migrating applications from Vaadin 6 + * to Vaadin 7. The legacy application supports setting a main window, adding + * additional browser level windows and defining the theme for the entire + * application. + * + * @deprecated This class is only intended to ease migration and should not be + * used for new projects. + * + * @since 7.0 + */ +@Deprecated +public abstract class LegacyApplication implements ErrorListener { + private LegacyWindow mainWindow; + private String theme; + + private Map legacyUINames = new HashMap(); + + private boolean isRunning = true; + + /** + * URL where the user is redirected to on application close, or null if + * application is just closed without redirection. + */ + private String logoutURL = null; + private URL url; + + /** + * Sets the main window of this application. Setting window as a main window + * of this application also adds the window to this application. + * + * @param mainWindow + * the UI to set as the default window + */ + public void setMainWindow(LegacyWindow mainWindow) { + if (this.mainWindow != null) { + throw new IllegalStateException("mainWindow has already been set"); + } + if (mainWindow.getSession() != null) { + throw new IllegalStateException( + "mainWindow is attached to another application"); + } + if (UI.getCurrent() == null) { + // Assume setting a main window from Application.init if there's + // no current UI -> set the main window as the current UI + UI.setCurrent(mainWindow); + } + addWindow(mainWindow); + this.mainWindow = mainWindow; + } + + public void doInit(URL url) { + this.url = url; + VaadinServiceSession.getCurrent().setErrorHandler(this); + init(); + } + + protected abstract void init(); + + /** + * Gets the mainWindow of the application. + * + *

+ * The main window is the window attached to the application URL ( + * {@link #getURL()}) and thus which is show by default to the user. + *

+ *

+ * Note that each application must have at least one main window. + *

+ * + * @return the UI used as the default window + */ + public LegacyWindow getMainWindow() { + return mainWindow; + } + + /** + * Sets the application's theme. + *

+ * Note that this theme can be overridden for a specific UI with + * {@link VaadinServiceSession#getThemeForUI(UI)}. Setting theme to be + * null selects the default theme. For the available theme + * names, see the contents of the VAADIN/themes directory. + *

+ * + * @param theme + * the new theme for this application. + */ + public void setTheme(String theme) { + this.theme = theme; + } + + /** + * Gets the application's theme. The application's theme is the default + * theme used by all the uIs for which a theme is not explicitly defined. If + * the application theme is not explicitly set, null is + * returned. + * + * @return the name of the application's theme. + */ + public String getTheme() { + return theme; + } + + /** + *

+ * Gets a UI by name. Returns null if the application is not + * running or it does not contain a window corresponding to the name. + *

+ * + * @param name + * the name of the requested window + * @return a UI corresponding to the name, or null to use the + * default window + */ + public LegacyWindow getWindow(String name) { + return legacyUINames.get(name); + } + + /** + * Counter to get unique names for windows with no explicit name + */ + private int namelessUIIndex = 0; + + /** + * Adds a new browser level window to this application. Please note that UI + * doesn't have a name that is used in the URL - to add a named window you + * should instead use {@link #addWindow(UI, String)} + * + * @param uI + * the UI window to add to the application + * @return returns the name that has been assigned to the window + * + * @see #addWindow(UI, String) + */ + public void addWindow(LegacyWindow uI) { + if (uI.getName() == null) { + String name = Integer.toString(namelessUIIndex++); + uI.setName(name); + } + + uI.setApplication(this); + + legacyUINames.put(uI.getName(), uI); + uI.setSession(VaadinServiceSession.getCurrent()); + } + + /** + * Removes the specified window from the application. This also removes all + * name mappings for the window (see {@link #addWindow(UI, String) and + * #getWindowName(UI)}. + * + *

+ * Note that removing window from the application does not close the browser + * window - the window is only removed from the server-side. + *

+ * + * @param uI + * the UI to remove + */ + public void removeWindow(LegacyWindow uI) { + for (Entry entry : legacyUINames.entrySet()) { + if (entry.getValue() == uI) { + legacyUINames.remove(entry.getKey()); + } + } + } + + /** + * Gets the set of windows contained by the application. + * + *

+ * Note that the returned set of windows can not be modified. + *

+ * + * @return the unmodifiable collection of windows. + */ + public Collection getWindows() { + return Collections.unmodifiableCollection(legacyUINames.values()); + } + + @Override + public void terminalError(ErrorEvent event) { + DefaultErrorListener.doDefault(event); + } + + public VaadinServiceSession getContext() { + return VaadinServiceSession.getCurrent(); + } + + public void close() { + isRunning = false; + Collection windows = getWindows(); + for (LegacyWindow legacyWindow : windows) { + String logoutUrl = getLogoutURL(); + if (logoutUrl == null) { + URL url = getURL(); + if (url != null) { + logoutUrl = url.toString(); + } + } + if (logoutUrl != null) { + legacyWindow.getPage().setLocation(logoutUrl); + } + legacyWindow.getSession().cleanupUI(legacyWindow); + } + } + + public boolean isRunning() { + return isRunning; + } + + public URL getURL() { + return url; + } + + /** + * Returns the URL user is redirected to on application close. If the URL is + * null, the application is closed normally as defined by the + * application running environment. + *

+ * Desktop application just closes the application window and + * web-application redirects the browser to application main URL. + *

+ * + * @return the URL. + * + * @deprecated might be refactored or removed before 7.0.0 + */ + @Deprecated + public String getLogoutURL() { + return logoutURL; + } + + /** + * Sets the URL user is redirected to on application close. If the URL is + * null, the application is closed normally as defined by the + * application running environment: Desktop application just closes the + * application window and web-application redirects the browser to + * application main URL. + * + * @param logoutURL + * the logoutURL to set. + * + * @deprecated might be refactored or removed before 7.0.0 + */ + @Deprecated + public void setLogoutURL(String logoutURL) { + this.logoutURL = logoutURL; + } +} \ No newline at end of file diff --git a/server/src/com/vaadin/server/LegacyApplicationUIProvider.java b/server/src/com/vaadin/server/LegacyApplicationUIProvider.java index e2a58ba1bc..467e1c4a5e 100644 --- a/server/src/com/vaadin/server/LegacyApplicationUIProvider.java +++ b/server/src/com/vaadin/server/LegacyApplicationUIProvider.java @@ -21,7 +21,6 @@ import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.vaadin.LegacyApplication; import com.vaadin.ui.LegacyWindow; import com.vaadin.ui.UI; diff --git a/server/src/com/vaadin/server/LegacyVaadinPortlet.java b/server/src/com/vaadin/server/LegacyVaadinPortlet.java index f186971f7c..92079653c7 100644 --- a/server/src/com/vaadin/server/LegacyVaadinPortlet.java +++ b/server/src/com/vaadin/server/LegacyVaadinPortlet.java @@ -20,7 +20,6 @@ import javax.portlet.PortletConfig; import javax.portlet.PortletException; import javax.portlet.PortletRequest; -import com.vaadin.LegacyApplication; public class LegacyVaadinPortlet extends VaadinPortlet { diff --git a/server/src/com/vaadin/server/LegacyVaadinServlet.java b/server/src/com/vaadin/server/LegacyVaadinServlet.java index d2f55211e5..8ee10f5176 100644 --- a/server/src/com/vaadin/server/LegacyVaadinServlet.java +++ b/server/src/com/vaadin/server/LegacyVaadinServlet.java @@ -20,7 +20,6 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; -import com.vaadin.LegacyApplication; public class LegacyVaadinServlet extends VaadinServlet { diff --git a/server/src/com/vaadin/server/ServletPortletHelper.java b/server/src/com/vaadin/server/ServletPortletHelper.java index 15c3e18959..1bcfdf8692 100644 --- a/server/src/com/vaadin/server/ServletPortletHelper.java +++ b/server/src/com/vaadin/server/ServletPortletHelper.java @@ -4,7 +4,6 @@ import java.io.Serializable; import java.util.Locale; import java.util.Properties; -import com.vaadin.LegacyApplication; import com.vaadin.shared.ApplicationConstants; import com.vaadin.ui.Component; import com.vaadin.ui.UI; diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index b18eff2f09..818cde2879 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -50,7 +50,6 @@ import javax.servlet.http.HttpServletResponse; import com.liferay.portal.kernel.util.PortalClassInvoker; import com.liferay.portal.kernel.util.PropsUtil; -import com.vaadin.DefaultDeploymentConfiguration; import com.vaadin.server.AbstractCommunicationManager.Callback; import com.vaadin.ui.UI; import com.vaadin.util.CurrentInstance; diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java index 05e79500bb..d79210206b 100644 --- a/server/src/com/vaadin/server/VaadinService.java +++ b/server/src/com/vaadin/server/VaadinService.java @@ -32,7 +32,6 @@ import javax.portlet.PortletContext; import javax.servlet.ServletContext; import javax.servlet.ServletException; -import com.vaadin.LegacyApplication; import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.event.EventRouter; import com.vaadin.shared.ui.ui.UIConstants; diff --git a/server/src/com/vaadin/server/VaadinServiceSession.java b/server/src/com/vaadin/server/VaadinServiceSession.java index de5accbfd0..37eebe3a4c 100644 --- a/server/src/com/vaadin/server/VaadinServiceSession.java +++ b/server/src/com/vaadin/server/VaadinServiceSession.java @@ -36,7 +36,6 @@ import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; -import com.vaadin.LegacyApplication; import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.data.util.converter.Converter; import com.vaadin.data.util.converter.ConverterFactory; diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 67f3691855..eb84e54d85 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -41,7 +41,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import com.vaadin.DefaultDeploymentConfiguration; import com.vaadin.sass.ScssStylesheet; import com.vaadin.server.AbstractCommunicationManager.Callback; import com.vaadin.shared.ApplicationConstants; diff --git a/server/src/com/vaadin/ui/LegacyWindow.java b/server/src/com/vaadin/ui/LegacyWindow.java index 572d3f8490..88559af0b5 100644 --- a/server/src/com/vaadin/ui/LegacyWindow.java +++ b/server/src/com/vaadin/ui/LegacyWindow.java @@ -7,7 +7,7 @@ package com.vaadin.ui; import java.net.MalformedURLException; import java.net.URL; -import com.vaadin.LegacyApplication; +import com.vaadin.server.LegacyApplication; import com.vaadin.server.Page; import com.vaadin.server.Resource; import com.vaadin.server.VaadinRequest; @@ -18,7 +18,7 @@ import com.vaadin.shared.ui.BorderStyle; /** * Helper class to emulate the main window from Vaadin 6 using UIs. This * class should be used in the same way as Window used as a browser level - * window in Vaadin 6 with {@link com.vaadin.LegacyApplication} + * window in Vaadin 6 with {@link com.vaadin.server.LegacyApplication} */ @Deprecated public class LegacyWindow extends UI { diff --git a/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java b/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java index cd64622392..5f9269c6e3 100644 --- a/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java +++ b/server/tests/src/com/vaadin/server/TestAbstractApplicationServletStaticFilesLocation.java @@ -13,7 +13,6 @@ import javax.servlet.http.HttpServletRequest; import junit.framework.TestCase; -import com.vaadin.DefaultDeploymentConfiguration; public class TestAbstractApplicationServletStaticFilesLocation extends TestCase { diff --git a/server/tests/src/com/vaadin/tests/server/component/ui/CustomUIClassLoader.java b/server/tests/src/com/vaadin/tests/server/component/ui/CustomUIClassLoader.java index 82b9944371..71749ed964 100644 --- a/server/tests/src/com/vaadin/tests/server/component/ui/CustomUIClassLoader.java +++ b/server/tests/src/com/vaadin/tests/server/component/ui/CustomUIClassLoader.java @@ -8,7 +8,7 @@ import junit.framework.TestCase; import org.easymock.EasyMock; -import com.vaadin.DefaultDeploymentConfiguration; +import com.vaadin.server.DefaultDeploymentConfiguration; import com.vaadin.server.DefaultUIProvider; import com.vaadin.server.DeploymentConfiguration; import com.vaadin.server.UIClassSelectionEvent; diff --git a/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java b/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java index 0ba1ce0859..031b332ee7 100644 --- a/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java +++ b/server/tests/src/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; -import com.vaadin.LegacyApplication; +import com.vaadin.server.LegacyApplication; import com.vaadin.server.VaadinServiceSession; import com.vaadin.ui.LegacyWindow; import com.vaadin.ui.UI; -- cgit v1.2.3