diff options
author | John Ahlroos <john@vaadin.com> | 2012-09-03 14:18:16 +0300 |
---|---|---|
committer | John Ahlroos <john@vaadin.com> | 2012-09-03 14:18:16 +0300 |
commit | b6e762dc8408b607568919f518ab2e2f74df7010 (patch) | |
tree | b6ccf5b5cb1225d6744f20b0292880cd094bbcf1 /server/src | |
parent | 1bc93daa34b1094f41cf19f20342c94c4e423244 (diff) | |
parent | ae2c302f71554f49b3f57b649cec7450c652cf09 (diff) | |
download | vaadin-framework-b6e762dc8408b607568919f518ab2e2f74df7010.tar.gz vaadin-framework-b6e762dc8408b607568919f518ab2e2f74df7010.zip |
Merge branch 'master' into layoutgraph
Diffstat (limited to 'server/src')
31 files changed, 929 insertions, 580 deletions
diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index cd34fb7540..2af3c6a59f 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -48,8 +48,8 @@ import com.vaadin.data.util.converter.Converter; import com.vaadin.data.util.converter.ConverterFactory; import com.vaadin.data.util.converter.DefaultConverterFactory; import com.vaadin.event.EventRouter; -import com.vaadin.server.AbstractApplicationServlet; import com.vaadin.server.AbstractErrorMessage; +import com.vaadin.server.ApplicationContext; import com.vaadin.server.BootstrapFragmentResponse; import com.vaadin.server.BootstrapListener; import com.vaadin.server.BootstrapPageResponse; @@ -60,14 +60,14 @@ import com.vaadin.server.CombinedRequest; import com.vaadin.server.DeploymentConfiguration; import com.vaadin.server.GlobalResourceHandler; import com.vaadin.server.RequestHandler; +import com.vaadin.server.ServletApplicationContext; import com.vaadin.server.Terminal; import com.vaadin.server.UIProvider; +import com.vaadin.server.VaadinServlet; import com.vaadin.server.VariableOwner; -import com.vaadin.server.WebApplicationContext; import com.vaadin.server.WrappedRequest; import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.server.WrappedResponse; -import com.vaadin.service.ApplicationContext; import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.tools.ReflectTools; import com.vaadin.ui.AbstractComponent; @@ -463,12 +463,6 @@ public class Application implements Terminal.ErrorListener, Serializable { private String logoutURL = null; /** - * The default SystemMessages (read-only). Change by overriding - * getSystemMessages() and returning CustomizedSystemMessages - */ - private static final SystemMessages DEFAULT_SYSTEM_MESSAGES = new SystemMessages(); - - /** * Application wide error handler which is used by default if an error is * left unhandled. */ @@ -792,25 +786,6 @@ public class Application implements Terminal.ErrorListener, Serializable { } /** - * Gets the SystemMessages for this application. SystemMessages are used to - * notify the user of various critical situations that can occur, such as - * session expiration, client/server out of sync, and internal server error. - * - * You can customize the messages by "overriding" this method and returning - * {@link CustomizedSystemMessages}. To "override" this method, re-implement - * this method in your application (the class that extends - * {@link Application}). Even though overriding static methods is not - * possible in Java, Vaadin selects to call the static method from the - * subclass instead of the original {@link #getSystemMessages()} if such a - * method exists. - * - * @return the SystemMessages for this application - */ - public static SystemMessages getSystemMessages() { - return DEFAULT_SYSTEM_MESSAGES; - } - - /** * <p> * Invoked by the terminal on any exception that occurs in application and * is thrown by the <code>setVariable</code> to the terminal. The default @@ -867,8 +842,8 @@ public class Application implements Terminal.ErrorListener, Serializable { * </p> * <p> * By default, when you are deploying your application to a servlet - * container, the implementation class is {@link WebApplicationContext} - - * you can safely cast to this class and use the methods from there. When + * container, the implementation class is {@link ServletApplicationContext} + * - you can safely cast to this class and use the methods from there. When * you are deploying your application as a portlet, context implementation * is {@link PortletApplicationContext}. * </p> @@ -880,17 +855,6 @@ public class Application implements Terminal.ErrorListener, Serializable { } /** - * Override this method to return correct version number of your - * Application. Version information is delivered for example to Testing - * Tools test results. By default this returns a string "NONVERSIONED". - * - * @return version string - */ - public String getVersion() { - return "NONVERSIONED"; - } - - /** * Gets the application error handler. * * The default error handler is the application itself. @@ -1764,7 +1728,7 @@ public class Application implements Terminal.ErrorListener, Serializable { * Handles a request by passing it to each registered {@link RequestHandler} * in turn until one produces a response. This method is used for requests * that have not been handled by any specific functionality in the terminal - * implementation (e.g. {@link AbstractApplicationServlet}). + * implementation (e.g. {@link VaadinServlet}). * <p> * The request handlers are invoked in the revere order in which they were * added to the application until a response has been produced. This means diff --git a/server/src/com/vaadin/data/Validator.java b/server/src/com/vaadin/data/Validator.java index 1755a44920..421d88f574 100644 --- a/server/src/com/vaadin/data/Validator.java +++ b/server/src/com/vaadin/data/Validator.java @@ -18,7 +18,7 @@ package com.vaadin.data; import java.io.Serializable; -import com.vaadin.server.AbstractApplicationServlet; +import com.vaadin.server.VaadinServlet; /** * Interface that implements a method for validating if an {@link Object} is @@ -144,8 +144,7 @@ public interface Validator extends Serializable { * Note that this API may change in future versions. */ public String getHtmlMessage() { - return AbstractApplicationServlet - .safeEscapeForHtml(getLocalizedMessage()); + return VaadinServlet.safeEscapeForHtml(getLocalizedMessage()); } /** diff --git a/server/src/com/vaadin/navigator/Navigator.java b/server/src/com/vaadin/navigator/Navigator.java index bda422379c..2f42acb320 100644 --- a/server/src/com/vaadin/navigator/Navigator.java +++ b/server/src/com/vaadin/navigator/Navigator.java @@ -103,17 +103,22 @@ public class Navigator implements Serializable { this.page = page; this.navigator = navigator; - page.addListener(this); + page.addFragmentChangedListener(this); } @Override public String getState() { - return page.getFragment(); + String fragment = page.getFragment(); + if (fragment.startsWith("!")) { + return page.getFragment().substring(1); + } else { + return ""; + } } @Override public void setState(String state) { - page.setFragment(state, false); + page.setFragment("!" + state, false); } @Override @@ -475,7 +480,7 @@ public class Navigator implements Serializable { if (null != viewName && getStateManager() != null) { String navigationState = viewName; - if (!parameters.equals("")) { + if (!parameters.isEmpty()) { navigationState += "/" + parameters; } if (!navigationState.equals(getStateManager().getState())) { @@ -662,15 +667,6 @@ public class Navigator implements Serializable { } /** - * @deprecated Since 7.0, replaced by - * {@link #addViewChangeListener(ViewChangeListener)} - **/ - @Deprecated - public void addListener(ViewChangeListener listener) { - addViewChangeListener(listener); - } - - /** * Remove a view change listener. * * @param listener @@ -679,14 +675,4 @@ public class Navigator implements Serializable { public void removeViewChangeListener(ViewChangeListener listener) { listeners.remove(listener); } - - /** - * @deprecated Since 7.0, replaced by - * {@link #removeViewChangeListener(ViewChangeListener)} - **/ - @Deprecated - public void removeListener(ViewChangeListener listener) { - removeViewChangeListener(listener); - } - } diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index 72406e629d..2e42f51249 100644 --- a/server/src/com/vaadin/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java @@ -27,8 +27,6 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Serializable; import java.io.StringWriter; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.lang.reflect.Type; import java.net.URI; import java.net.URISyntaxException; @@ -59,7 +57,6 @@ import java.util.logging.Logger; import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; -import com.vaadin.Application.SystemMessages; import com.vaadin.annotations.JavaScript; import com.vaadin.annotations.StyleSheet; import com.vaadin.external.json.JSONArray; @@ -574,28 +571,15 @@ public abstract class AbstractCommunicationManager implements Serializable { if (!handleVariables(request, response, callback, application, uI)) { // var inconsistency; the client is probably out-of-sync - SystemMessages ci = null; - try { - Method m = application.getClass().getMethod( - "getSystemMessages", (Class[]) null); - ci = (Application.SystemMessages) m.invoke(null, - (Object[]) null); - } catch (Exception e2) { - // FIXME: Handle exception - // Not critical, but something is still wrong; print - // stacktrace - getLogger().log(Level.WARNING, - "getSystemMessages() failed - continuing", e2); - } - if (ci != null) { - String msg = ci.getOutOfSyncMessage(); - String cap = ci.getOutOfSyncCaption(); - if (msg != null || cap != null) { - callback.criticalNotification(request, response, cap, - msg, null, ci.getOutOfSyncURL()); - // will reload page after this - return; - } + SystemMessages ci = response.getDeploymentConfiguration() + .getSystemMessages(); + String msg = ci.getOutOfSyncMessage(); + String cap = ci.getOutOfSyncCaption(); + if (msg != null || cap != null) { + callback.criticalNotification(request, response, cap, msg, + null, ci.getOutOfSyncURL()); + // will reload page after this + return; } // No message to show, let's just repaint all. repaintAll = true; @@ -1028,24 +1012,8 @@ public abstract class AbstractCommunicationManager implements Serializable { } } - SystemMessages ci = null; - try { - Method m = application.getClass().getMethod("getSystemMessages", - (Class[]) null); - ci = (Application.SystemMessages) m.invoke(null, (Object[]) null); - } catch (NoSuchMethodException e) { - getLogger().log(Level.WARNING, - "getSystemMessages() failed - continuing", e); - } catch (IllegalArgumentException e) { - getLogger().log(Level.WARNING, - "getSystemMessages() failed - continuing", e); - } catch (IllegalAccessException e) { - getLogger().log(Level.WARNING, - "getSystemMessages() failed - continuing", e); - } catch (InvocationTargetException e) { - getLogger().log(Level.WARNING, - "getSystemMessages() failed - continuing", e); - } + SystemMessages ci = request.getDeploymentConfiguration() + .getSystemMessages(); // meta instruction for client to enable auto-forward to // sessionExpiredURL after timer expires. @@ -1323,8 +1291,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * response. */ private void writePerformanceData(final PrintWriter outWriter) { - AbstractWebApplicationContext ctx = (AbstractWebApplicationContext) application - .getContext(); + ApplicationContext ctx = application.getContext(); outWriter.write(String.format(", \"timings\":[%d, %d]", ctx.getTotalSessionTime(), ctx.getLastRequestTime())); } @@ -1517,7 +1484,7 @@ public abstract class AbstractCommunicationManager implements Serializable { themeName = requestThemeName; } if (themeName == null) { - themeName = AbstractApplicationServlet.getDefaultTheme(); + themeName = VaadinServlet.getDefaultTheme(); } return themeName; } @@ -1535,7 +1502,7 @@ public abstract class AbstractCommunicationManager implements Serializable { public boolean isXSRFEnabled(Application application) { return !"true" .equals(application - .getProperty(AbstractApplicationServlet.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION)); + .getProperty(VaadinServlet.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION)); } /** diff --git a/server/src/com/vaadin/server/AbstractErrorMessage.java b/server/src/com/vaadin/server/AbstractErrorMessage.java index 0928ea4bd4..4e30dff06f 100644 --- a/server/src/com/vaadin/server/AbstractErrorMessage.java +++ b/server/src/com/vaadin/server/AbstractErrorMessage.java @@ -109,12 +109,11 @@ public abstract class AbstractErrorMessage implements ErrorMessage { String result = null; switch (getMode()) { case TEXT: - result = AbstractApplicationServlet.safeEscapeForHtml(getMessage()); + result = VaadinServlet.safeEscapeForHtml(getMessage()); break; case PREFORMATTED: - result = "<pre>" - + AbstractApplicationServlet - .safeEscapeForHtml(getMessage()) + "</pre>"; + result = "<pre>" + VaadinServlet.safeEscapeForHtml(getMessage()) + + "</pre>"; break; case XHTML: result = getMessage(); diff --git a/server/src/com/vaadin/server/AbstractWebApplicationContext.java b/server/src/com/vaadin/server/ApplicationContext.java index cf983f4c80..b698ea51c8 100644 --- a/server/src/com/vaadin/server/AbstractWebApplicationContext.java +++ b/server/src/com/vaadin/server/ApplicationContext.java @@ -15,6 +15,7 @@ */ package com.vaadin.server; +import java.io.File; import java.io.PrintWriter; import java.io.Serializable; import java.io.StringWriter; @@ -31,17 +32,65 @@ import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; import com.vaadin.Application; -import com.vaadin.service.ApplicationContext; /** + * <code>ApplicationContext</code> provides information about the running + * context of the application. Each context is shared by all applications that + * are open for one user. In a web-environment this corresponds to a + * HttpSession. + * <p> * Base class for web application contexts (including portlet contexts) that * handles the common tasks. + * + * @author Vaadin Ltd. + * @since 3.1 */ -public abstract class AbstractWebApplicationContext implements - ApplicationContext, HttpSessionBindingListener, Serializable { +public abstract class ApplicationContext implements HttpSessionBindingListener, + Serializable { + + /** + * Interface for listening to transaction events. Implement this interface + * to listen to all transactions between the client and the application. + * + */ + public static interface TransactionListener extends Serializable { + + /** + * Invoked at the beginning of every transaction. + * + * The transaction is linked to the context, not the application so if + * you have multiple applications running in the same context you need + * to check that the request is associated with the application you are + * interested in. This can be done looking at the application parameter. + * + * @param application + * the Application object. + * @param transactionData + * the Data identifying the transaction. + */ + public void transactionStart(Application application, + Object transactionData); + + /** + * Invoked at the end of every transaction. + * + * The transaction is linked to the context, not the application so if + * you have multiple applications running in the same context you need + * to check that the request is associated with the application you are + * interested in. This can be done looking at the application parameter. + * + * @param applcation + * the Application object. + * @param transactionData + * the Data identifying the transaction. + */ + public void transactionEnd(Application application, + Object transactionData); + + } - protected Collection<TransactionListener> listeners = Collections - .synchronizedList(new LinkedList<TransactionListener>()); + protected Collection<ApplicationContext.TransactionListener> listeners = Collections + .synchronizedList(new LinkedList<ApplicationContext.TransactionListener>()); protected final HashSet<Application> applications = new HashSet<Application>(); @@ -53,15 +102,31 @@ public abstract class AbstractWebApplicationContext implements private long lastRequestTime = -1; - @Override - public void addTransactionListener(TransactionListener listener) { + /** + * Adds a transaction listener to this context. The transaction listener is + * called before and after each each request related to this session except + * when serving static resources. + * + * The transaction listener must not be null. + * + * @see com.vaadin.service.ApplicationContext#addTransactionListener(com.vaadin.service.ApplicationContext.TransactionListener) + */ + public void addTransactionListener( + ApplicationContext.TransactionListener listener) { if (listener != null) { listeners.add(listener); } } - @Override - public void removeTransactionListener(TransactionListener listener) { + /** + * Removes a transaction listener from this context. + * + * @param listener + * the listener to be removed. + * @see ApplicationContext.TransactionListener + */ + public void removeTransactionListener( + ApplicationContext.TransactionListener listener) { listeners.remove(listener); } @@ -74,11 +139,12 @@ public abstract class AbstractWebApplicationContext implements * the HTTP or portlet request that triggered the transaction. */ protected void startTransaction(Application application, Object request) { - ArrayList<TransactionListener> currentListeners; + ArrayList<ApplicationContext.TransactionListener> currentListeners; synchronized (listeners) { - currentListeners = new ArrayList<TransactionListener>(listeners); + currentListeners = new ArrayList<ApplicationContext.TransactionListener>( + listeners); } - for (TransactionListener listener : currentListeners) { + for (ApplicationContext.TransactionListener listener : currentListeners) { listener.transactionStart(application, request); } } @@ -94,12 +160,13 @@ public abstract class AbstractWebApplicationContext implements protected void endTransaction(Application application, Object request) { LinkedList<Exception> exceptions = null; - ArrayList<TransactionListener> currentListeners; + ArrayList<ApplicationContext.TransactionListener> currentListeners; synchronized (listeners) { - currentListeners = new ArrayList<TransactionListener>(listeners); + currentListeners = new ArrayList<ApplicationContext.TransactionListener>( + listeners); } - for (TransactionListener listener : currentListeners) { + for (ApplicationContext.TransactionListener listener : currentListeners) { try { listener.transactionEnd(application, request); } catch (final RuntimeException t) { @@ -172,7 +239,13 @@ public abstract class AbstractWebApplicationContext implements return browser; } - @Override + /** + * Returns a collection of all the applications in this context. + * + * Each application context contains all active applications for one user. + * + * @return A collection containing all the applications in this context. + */ public Collection<Application> getApplications() { return Collections.unmodifiableCollection(applications); } @@ -209,7 +282,27 @@ public abstract class AbstractWebApplicationContext implements } private Logger getLogger() { - return Logger.getLogger(AbstractWebApplicationContext.class.getName()); + return Logger.getLogger(ApplicationContext.class.getName()); } + /** + * Returns application context base directory. + * + * Typically an application is deployed in a such way that is has an + * application directory. For web applications this directory is the root + * directory of the web applications. In some cases applications might not + * have an application directory (for example web applications running + * inside a war). + * + * @return The application base directory or null if the application has no + * base directory. + */ + public abstract File getBaseDirectory(); + + /** + * Returns the time between requests, in seconds, before this context is + * invalidated. A negative time indicates the context should never timeout. + */ + public abstract int getMaxInactiveInterval(); + }
\ No newline at end of file diff --git a/server/src/com/vaadin/server/ApplicationPortlet2.java b/server/src/com/vaadin/server/ApplicationPortlet2.java deleted file mode 100644 index 3708d8fe0d..0000000000 --- a/server/src/com/vaadin/server/ApplicationPortlet2.java +++ /dev/null @@ -1,50 +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.server; - -import javax.portlet.PortletConfig; -import javax.portlet.PortletException; - -import com.vaadin.Application; -import com.vaadin.server.ServletPortletHelper.ApplicationClassException; - -/** - * TODO Write documentation, fix JavaDoc tags. - * - * @author peholmst - */ -public class ApplicationPortlet2 extends AbstractApplicationPortlet { - - private Class<? extends Application> applicationClass; - - @Override - public void init(PortletConfig config) throws PortletException { - super.init(config); - try { - applicationClass = ServletPortletHelper - .getApplicationClass(getDeploymentConfiguration()); - } catch (ApplicationClassException e) { - throw new PortletException(e); - } - } - - @Override - protected Class<? extends Application> getApplicationClass() { - return applicationClass; - } - -} diff --git a/server/src/com/vaadin/server/ApplicationServlet.java b/server/src/com/vaadin/server/ApplicationServlet.java deleted file mode 100644 index af0cebcf86..0000000000 --- a/server/src/com/vaadin/server/ApplicationServlet.java +++ /dev/null @@ -1,89 +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.server; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; - -import com.vaadin.Application; -import com.vaadin.server.ServletPortletHelper.ApplicationClassException; - -/** - * This servlet connects a Vaadin Application to Web. - * - * @author Vaadin Ltd. - * @since 5.0 - */ - -@SuppressWarnings("serial") -public class ApplicationServlet extends AbstractApplicationServlet { - - // Private fields - private Class<? extends Application> applicationClass; - - /** - * Called by the servlet container to indicate to a servlet that the servlet - * is being placed into service. - * - * @param servletConfig - * the object containing the servlet's configuration and - * initialization parameters - * @throws javax.servlet.ServletException - * if an exception has occurred that interferes with the - * servlet's normal operation. - */ - @Override - public void init(javax.servlet.ServletConfig servletConfig) - throws javax.servlet.ServletException { - super.init(servletConfig); - - // Loads the application class using the classloader defined in the - // deployment configuration - - try { - applicationClass = ServletPortletHelper - .getApplicationClass(getDeploymentConfiguration()); - } catch (ApplicationClassException e) { - throw new ServletException(e); - } - } - - @Override - protected Application getNewApplication(HttpServletRequest request) - throws ServletException { - - // Creates a new application instance - try { - final Application application = getApplicationClass().newInstance(); - application.addUIProvider(new DefaultUIProvider()); - - return application; - } catch (final IllegalAccessException e) { - throw new ServletException("getNewApplication failed", e); - } catch (final InstantiationException e) { - throw new ServletException("getNewApplication failed", e); - } catch (ClassNotFoundException e) { - throw new ServletException("getNewApplication failed", e); - } - } - - @Override - protected Class<? extends Application> getApplicationClass() - throws ClassNotFoundException { - return applicationClass; - } -} diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java index 60ac40916c..a1438312b6 100644 --- a/server/src/com/vaadin/server/BootstrapHandler.java +++ b/server/src/com/vaadin/server/BootstrapHandler.java @@ -277,7 +277,7 @@ public abstract class BootstrapHandler implements RequestHandler { .getConfiguredWidgetset(request); } - widgetset = AbstractApplicationServlet.stripSpecialChars(widgetset); + widgetset = VaadinServlet.stripSpecialChars(widgetset); return widgetset; } @@ -401,7 +401,6 @@ public abstract class BootstrapHandler implements RequestHandler { JSONObject versionInfo = new JSONObject(); versionInfo.put("vaadinVersion", Version.getFullVersion()); - versionInfo.put("applicationVersion", application.getVersion()); appConfig.put("versionInfo", versionInfo); appConfig.put("widgetset", context.getWidgetsetName()); @@ -421,10 +420,12 @@ public abstract class BootstrapHandler implements RequestHandler { WrappedRequest request = context.getRequest(); Application application = context.getApplication(); + DeploymentConfiguration deploymentConfiguration = request + .getDeploymentConfiguration(); // Get system messages - Application.SystemMessages systemMessages = AbstractApplicationServlet - .getSystemMessages(application.getClass()); + SystemMessages systemMessages = deploymentConfiguration + .getSystemMessages(); if (systemMessages != null) { // Write the CommunicationError -message to client JSONObject comErrMsg = new JSONObject(); @@ -446,12 +447,10 @@ public abstract class BootstrapHandler implements RequestHandler { defaults.put("authErrMsg", authErrMsg); } - DeploymentConfiguration deploymentConfiguration = request - .getDeploymentConfiguration(); String staticFileLocation = deploymentConfiguration .getStaticFileLocation(request); String widgetsetBase = staticFileLocation + "/" - + AbstractApplicationServlet.WIDGETSET_DIRECTORY_PATH; + + VaadinServlet.WIDGETSET_DIRECTORY_PATH; defaults.put("widgetsetBase", widgetsetBase); if (!application.isProductionMode()) { @@ -487,8 +486,8 @@ public abstract class BootstrapHandler implements RequestHandler { WrappedRequest request = context.getRequest(); final String staticFilePath = request.getDeploymentConfiguration() .getStaticFileLocation(request); - return staticFilePath + "/" - + AbstractApplicationServlet.THEME_DIRECTORY_PATH + themeName; + return staticFilePath + "/" + VaadinServlet.THEME_DIRECTORY_PATH + + themeName; } /** @@ -518,7 +517,7 @@ public abstract class BootstrapHandler implements RequestHandler { // XSS preventation, theme names shouldn't contain special chars anyway. // The servlet denies them via url parameter. - themeName = AbstractApplicationServlet.stripSpecialChars(themeName); + themeName = VaadinServlet.stripSpecialChars(themeName); return themeName; } diff --git a/server/src/com/vaadin/server/CombinedRequest.java b/server/src/com/vaadin/server/CombinedRequest.java index c186fcc87c..0577c0098a 100644 --- a/server/src/com/vaadin/server/CombinedRequest.java +++ b/server/src/com/vaadin/server/CombinedRequest.java @@ -153,8 +153,8 @@ public class CombinedRequest implements WrappedRequest { @Override public WebBrowser getWebBrowser() { - WebApplicationContext context = (WebApplicationContext) Application - .getCurrent().getContext(); + ApplicationContext context = Application.getCurrent() + .getContext(); return context.getBrowser(); } }; diff --git a/server/src/com/vaadin/server/CommunicationManager.java b/server/src/com/vaadin/server/CommunicationManager.java index 3c594eaf02..cc92023919 100644 --- a/server/src/com/vaadin/server/CommunicationManager.java +++ b/server/src/com/vaadin/server/CommunicationManager.java @@ -45,7 +45,7 @@ public class CommunicationManager extends AbstractCommunicationManager { */ @Deprecated public CommunicationManager(Application application, - AbstractApplicationServlet applicationServlet) { + VaadinServlet applicationServlet) { super(application); } @@ -100,7 +100,7 @@ public class CommunicationManager extends AbstractCommunicationManager { @Override public String getThemeName(BootstrapContext context) { String themeName = context.getRequest().getParameter( - AbstractApplicationServlet.URL_PARAMETER_THEME); + VaadinServlet.URL_PARAMETER_THEME); if (themeName == null) { themeName = super.getThemeName(context); } @@ -112,12 +112,12 @@ public class CommunicationManager extends AbstractCommunicationManager { @Override protected InputStream getThemeResourceAsStream(UI uI, String themeName, String resource) { - WebApplicationContext context = (WebApplicationContext) uI + ServletApplicationContext context = (ServletApplicationContext) uI .getApplication().getContext(); ServletContext servletContext = context.getHttpSession() .getServletContext(); return servletContext.getResourceAsStream("/" - + AbstractApplicationServlet.THEME_DIRECTORY_PATH + themeName - + "/" + resource); + + VaadinServlet.THEME_DIRECTORY_PATH + themeName + "/" + + resource); } } diff --git a/server/src/com/vaadin/server/CustomizedSystemMessages.java b/server/src/com/vaadin/server/CustomizedSystemMessages.java new file mode 100644 index 0000000000..8e3d7bf8e0 --- /dev/null +++ b/server/src/com/vaadin/server/CustomizedSystemMessages.java @@ -0,0 +1,339 @@ +/* + * 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.io.Serializable; + +/** + * Contains the system messages used to notify the user about various + * critical situations that can occur. + * <p> + * Vaadin gets the SystemMessages from your application by calling a static + * getSystemMessages() method. By default the + * Application.getSystemMessages() is used. You can customize this by + * defining a static MyApplication.getSystemMessages() and returning + * CustomizedSystemMessages. Note that getSystemMessages() is static - + * changing the system messages will by default change the message for all + * users of the application. + * </p> + * <p> + * The default behavior is to show a notification, and restart the + * application the the user clicks the message. <br/> + * Instead of restarting the application, you can set a specific URL that + * the user is taken to.<br/> + * Setting both caption and message to null will restart the application (or + * go to the specified URL) without displaying a notification. + * set*NotificationEnabled(false) will achieve the same thing. + * </p> + * <p> + * The situations are: + * <li>Session expired: the user session has expired, usually due to + * inactivity.</li> + * <li>Communication error: the client failed to contact the server, or the + * server returned and invalid response.</li> + * <li>Internal error: unhandled critical server error (e.g out of memory, + * database crash) + * <li>Out of sync: the client is not in sync with the server. E.g the user + * opens two windows showing the same application, but the application does + * not support this and uses the same Window instance. When the user makes + * changes in one of the windows - the other window is no longer in sync, + * and (for instance) pressing a button that is no longer present in the UI + * will cause a out-of-sync -situation. + * </p> + */ + +public class CustomizedSystemMessages extends SystemMessages + implements Serializable { + + /** + * Sets the URL to go to when the session has expired. + * + * @param sessionExpiredURL + * the URL to go to, or null to reload current + */ + public void setSessionExpiredURL(String sessionExpiredURL) { + this.sessionExpiredURL = sessionExpiredURL; + } + + /** + * Enables or disables the notification. If disabled, the set URL (or + * current) is loaded directly when next transaction between server and + * client happens. + * + * @param sessionExpiredNotificationEnabled + * true = enabled, false = disabled + */ + public void setSessionExpiredNotificationEnabled( + boolean sessionExpiredNotificationEnabled) { + this.sessionExpiredNotificationEnabled = sessionExpiredNotificationEnabled; + } + + /** + * Sets the caption of the notification. Set to null for no caption. If + * both caption and message are null, client automatically forwards to + * sessionExpiredUrl after timeout timer expires. Timer uses value read + * from HTTPSession.getMaxInactiveInterval() + * + * @param sessionExpiredCaption + * the caption + */ + public void setSessionExpiredCaption(String sessionExpiredCaption) { + this.sessionExpiredCaption = sessionExpiredCaption; + } + + /** + * Sets the message of the notification. Set to null for no message. If + * both caption and message are null, client automatically forwards to + * sessionExpiredUrl after timeout timer expires. Timer uses value read + * from HTTPSession.getMaxInactiveInterval() + * + * @param sessionExpiredMessage + * the message + */ + public void setSessionExpiredMessage(String sessionExpiredMessage) { + this.sessionExpiredMessage = sessionExpiredMessage; + } + + /** + * Sets the URL to go to when there is a authentication error. + * + * @param authenticationErrorURL + * the URL to go to, or null to reload current + */ + public void setAuthenticationErrorURL(String authenticationErrorURL) { + this.authenticationErrorURL = authenticationErrorURL; + } + + /** + * Enables or disables the notification. If disabled, the set URL (or + * current) is loaded directly. + * + * @param authenticationErrorNotificationEnabled + * true = enabled, false = disabled + */ + public void setAuthenticationErrorNotificationEnabled( + boolean authenticationErrorNotificationEnabled) { + this.authenticationErrorNotificationEnabled = authenticationErrorNotificationEnabled; + } + + /** + * Sets the caption of the notification. Set to null for no caption. If + * both caption and message is null, the notification is disabled; + * + * @param authenticationErrorCaption + * the caption + */ + public void setAuthenticationErrorCaption( + String authenticationErrorCaption) { + this.authenticationErrorCaption = authenticationErrorCaption; + } + + /** + * Sets the message of the notification. Set to null for no message. If + * both caption and message is null, the notification is disabled; + * + * @param authenticationErrorMessage + * the message + */ + public void setAuthenticationErrorMessage( + String authenticationErrorMessage) { + this.authenticationErrorMessage = authenticationErrorMessage; + } + + /** + * Sets the URL to go to when there is a communication error. + * + * @param communicationErrorURL + * the URL to go to, or null to reload current + */ + public void setCommunicationErrorURL(String communicationErrorURL) { + this.communicationErrorURL = communicationErrorURL; + } + + /** + * Enables or disables the notification. If disabled, the set URL (or + * current) is loaded directly. + * + * @param communicationErrorNotificationEnabled + * true = enabled, false = disabled + */ + public void setCommunicationErrorNotificationEnabled( + boolean communicationErrorNotificationEnabled) { + this.communicationErrorNotificationEnabled = communicationErrorNotificationEnabled; + } + + /** + * Sets the caption of the notification. Set to null for no caption. If + * both caption and message is null, the notification is disabled; + * + * @param communicationErrorCaption + * the caption + */ + public void setCommunicationErrorCaption( + String communicationErrorCaption) { + this.communicationErrorCaption = communicationErrorCaption; + } + + /** + * Sets the message of the notification. Set to null for no message. If + * both caption and message is null, the notification is disabled; + * + * @param communicationErrorMessage + * the message + */ + public void setCommunicationErrorMessage( + String communicationErrorMessage) { + this.communicationErrorMessage = communicationErrorMessage; + } + + /** + * Sets the URL to go to when an internal error occurs. + * + * @param internalErrorURL + * the URL to go to, or null to reload current + */ + public void setInternalErrorURL(String internalErrorURL) { + this.internalErrorURL = internalErrorURL; + } + + /** + * Enables or disables the notification. If disabled, the set URL (or + * current) is loaded directly. + * + * @param internalErrorNotificationEnabled + * true = enabled, false = disabled + */ + public void setInternalErrorNotificationEnabled( + boolean internalErrorNotificationEnabled) { + this.internalErrorNotificationEnabled = internalErrorNotificationEnabled; + } + + /** + * Sets the caption of the notification. Set to null for no caption. If + * both caption and message is null, the notification is disabled; + * + * @param internalErrorCaption + * the caption + */ + public void setInternalErrorCaption(String internalErrorCaption) { + this.internalErrorCaption = internalErrorCaption; + } + + /** + * Sets the message of the notification. Set to null for no message. If + * both caption and message is null, the notification is disabled; + * + * @param internalErrorMessage + * the message + */ + public void setInternalErrorMessage(String internalErrorMessage) { + this.internalErrorMessage = internalErrorMessage; + } + + /** + * Sets the URL to go to when the client is out-of-sync. + * + * @param outOfSyncURL + * the URL to go to, or null to reload current + */ + public void setOutOfSyncURL(String outOfSyncURL) { + this.outOfSyncURL = outOfSyncURL; + } + + /** + * Enables or disables the notification. If disabled, the set URL (or + * current) is loaded directly. + * + * @param outOfSyncNotificationEnabled + * true = enabled, false = disabled + */ + public void setOutOfSyncNotificationEnabled( + boolean outOfSyncNotificationEnabled) { + this.outOfSyncNotificationEnabled = outOfSyncNotificationEnabled; + } + + /** + * Sets the caption of the notification. Set to null for no caption. If + * both caption and message is null, the notification is disabled; + * + * @param outOfSyncCaption + * the caption + */ + public void setOutOfSyncCaption(String outOfSyncCaption) { + this.outOfSyncCaption = outOfSyncCaption; + } + + /** + * Sets the message of the notification. Set to null for no message. If + * both caption and message is null, the notification is disabled; + * + * @param outOfSyncMessage + * the message + */ + public void setOutOfSyncMessage(String outOfSyncMessage) { + this.outOfSyncMessage = outOfSyncMessage; + } + + /** + * Sets the URL to redirect to when the browser has cookies disabled. + * + * @param cookiesDisabledURL + * the URL to redirect to, or null to reload the current URL + */ + public void setCookiesDisabledURL(String cookiesDisabledURL) { + this.cookiesDisabledURL = cookiesDisabledURL; + } + + /** + * Enables or disables the notification for "cookies disabled" messages. + * If disabled, the URL returned by {@link #getCookiesDisabledURL()} is + * loaded directly. + * + * @param cookiesDisabledNotificationEnabled + * true to enable "cookies disabled" messages, false + * otherwise + */ + public void setCookiesDisabledNotificationEnabled( + boolean cookiesDisabledNotificationEnabled) { + this.cookiesDisabledNotificationEnabled = cookiesDisabledNotificationEnabled; + } + + /** + * Sets the caption of the "cookies disabled" notification. Set to null + * for no caption. If both caption and message is null, the notification + * is disabled. + * + * @param cookiesDisabledCaption + * the caption for the "cookies disabled" notification + */ + public void setCookiesDisabledCaption(String cookiesDisabledCaption) { + this.cookiesDisabledCaption = cookiesDisabledCaption; + } + + /** + * Sets the message of the "cookies disabled" notification. Set to null + * for no message. If both caption and message is null, the notification + * is disabled. + * + * @param cookiesDisabledMessage + * the message for the "cookies disabled" notification + */ + public void setCookiesDisabledMessage(String cookiesDisabledMessage) { + this.cookiesDisabledMessage = cookiesDisabledMessage; + } + +}
\ No newline at end of file diff --git a/server/src/com/vaadin/server/DeploymentConfiguration.java b/server/src/com/vaadin/server/DeploymentConfiguration.java index d1cbdfc499..acfba405e6 100644 --- a/server/src/com/vaadin/server/DeploymentConfiguration.java +++ b/server/src/com/vaadin/server/DeploymentConfiguration.java @@ -23,8 +23,6 @@ import java.util.Properties; import javax.portlet.PortletContext; import javax.servlet.ServletContext; -import com.vaadin.service.ApplicationContext; - /** * Provide deployment specific settings that are required outside terminal * specific code. @@ -183,4 +181,11 @@ public interface DeploymentConfiguration extends Serializable { * indefinitely. */ public boolean isIdleUICleanupEnabled(); + + /** + * Gets the system messages object + * + * @return the system messages object + */ + public SystemMessages getSystemMessages(); } diff --git a/server/src/com/vaadin/server/GAEApplicationServlet.java b/server/src/com/vaadin/server/GAEVaadinServlet.java index 16345edead..642737f73b 100644 --- a/server/src/com/vaadin/server/GAEApplicationServlet.java +++ b/server/src/com/vaadin/server/GAEVaadinServlet.java @@ -47,7 +47,6 @@ import com.google.appengine.api.memcache.Expiration; import com.google.appengine.api.memcache.MemcacheService; import com.google.appengine.api.memcache.MemcacheServiceFactory; import com.google.apphosting.api.DeadlineExceededException; -import com.vaadin.service.ApplicationContext; /** * ApplicationServlet to be used when deploying to Google App Engine, in @@ -104,7 +103,7 @@ import com.vaadin.service.ApplicationContext; * possible. * </ul> */ -public class GAEApplicationServlet extends ApplicationServlet { +public class GAEVaadinServlet extends VaadinServlet { // memcache mutex is MUTEX_BASE + sessio id private static final String MUTEX_BASE = "_vmutex"; @@ -323,7 +322,7 @@ public class GAEApplicationServlet extends ApplicationServlet { ois = new ObjectInputStream(bais); ApplicationContext applicationContext = (ApplicationContext) ois .readObject(); - session.setAttribute(WebApplicationContext.class.getName(), + session.setAttribute(ServletApplicationContext.class.getName(), applicationContext); } catch (IOException e) { getLogger().log( @@ -361,7 +360,7 @@ public class GAEApplicationServlet extends ApplicationServlet { private void cleanSession(HttpServletRequest request) { HttpSession session = request.getSession(false); if (session != null) { - session.removeAttribute(WebApplicationContext.class.getName()); + session.removeAttribute(ServletApplicationContext.class.getName()); } } @@ -424,6 +423,6 @@ public class GAEApplicationServlet extends ApplicationServlet { } private static final Logger getLogger() { - return Logger.getLogger(GAEApplicationServlet.class.getName()); + return Logger.getLogger(GAEVaadinServlet.class.getName()); } } diff --git a/server/src/com/vaadin/server/HttpServletRequestListener.java b/server/src/com/vaadin/server/HttpServletRequestListener.java index 1f9f633c17..e871dca05d 100644 --- a/server/src/com/vaadin/server/HttpServletRequestListener.java +++ b/server/src/com/vaadin/server/HttpServletRequestListener.java @@ -23,7 +23,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; -import com.vaadin.service.ApplicationContext.TransactionListener; /** * {@link Application} that implements this interface gets notified of request @@ -37,7 +36,7 @@ import com.vaadin.service.ApplicationContext.TransactionListener; * </ul> * <p> * Alternatives for implementing similar features are are Servlet {@link Filter} - * s and {@link TransactionListener}s in Vaadin. + * s and {@link ApplicationContext.TransactionListener}s in Vaadin. * * @since 6.2 * @see PortletRequestListener diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index b8fdae6cfb..da172ed837 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -391,8 +391,7 @@ public class Page implements Serializable { } public WebBrowser getWebBrowser() { - return ((WebApplicationContext) uI.getApplication().getContext()) - .getBrowser(); + return uI.getApplication().getContext().getBrowser(); } public void setBrowserWindowSize(int width, int height) { diff --git a/server/src/com/vaadin/server/PortletApplicationContext2.java b/server/src/com/vaadin/server/PortletApplicationContext2.java index aca80f9c17..cea97bc939 100644 --- a/server/src/com/vaadin/server/PortletApplicationContext2.java +++ b/server/src/com/vaadin/server/PortletApplicationContext2.java @@ -56,7 +56,7 @@ import com.vaadin.ui.UI; * @author peholmst */ @SuppressWarnings("serial") -public class PortletApplicationContext2 extends AbstractWebApplicationContext { +public class PortletApplicationContext2 extends ApplicationContext { protected Map<Application, Set<PortletListener>> portletListeners = new HashMap<Application, Set<PortletListener>>(); @@ -254,7 +254,7 @@ public class PortletApplicationContext2 extends AbstractWebApplicationContext { } /** - * This is for use by {@link AbstractApplicationPortlet} only. + * This is for use by {@link VaadinPortlet} only. * * TODO cleaner implementation, now "semi-static"! * diff --git a/server/src/com/vaadin/server/PortletCommunicationManager.java b/server/src/com/vaadin/server/PortletCommunicationManager.java index 697095d691..cb3a8eab80 100644 --- a/server/src/com/vaadin/server/PortletCommunicationManager.java +++ b/server/src/com/vaadin/server/PortletCommunicationManager.java @@ -97,8 +97,7 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { ResourceURL portletResourceUrl = getRenderResponse(context) .createResourceURL(); - portletResourceUrl - .setResourceID(AbstractApplicationPortlet.RESOURCE_URL_ID); + portletResourceUrl.setResourceID(VaadinPortlet.RESOURCE_URL_ID); defaults.put(ApplicationConstants.PORTLET_RESOUCE_URL_BASE, portletResourceUrl.toString()); @@ -113,10 +112,9 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { throws JSONException, IOException { // fixed base theme to use - all portal pages with Vaadin // applications will load this exactly once - String portalTheme = WrappedPortletRequest - .cast(context.getRequest()) - .getPortalProperty( - AbstractApplicationPortlet.PORTAL_PARAMETER_VAADIN_THEME); + String portalTheme = WrappedPortletRequest.cast( + context.getRequest()).getPortalProperty( + VaadinPortlet.PORTAL_PARAMETER_VAADIN_THEME); if (portalTheme != null && !portalTheme.equals(context.getThemeName())) { String portalThemeUri = getThemeUri(context, portalTheme); @@ -133,8 +131,7 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { DeploymentConfiguration deploymentConfiguration = context .getRequest().getDeploymentConfiguration(); return deploymentConfiguration.getApplicationOrSystemProperty( - AbstractApplicationPortlet.PORTLET_PARAMETER_STYLE, - null); + VaadinPortlet.PORTLET_PARAMETER_STYLE, null); } @Override @@ -164,8 +161,8 @@ public class PortletCommunicationManager extends AbstractCommunicationManager { PortletContext portletContext = context.getPortletSession() .getPortletContext(); return portletContext.getResourceAsStream("/" - + AbstractApplicationPortlet.THEME_DIRECTORY_PATH + themeName - + "/" + resource); + + VaadinPortlet.THEME_DIRECTORY_PATH + themeName + "/" + + resource); } } diff --git a/server/src/com/vaadin/server/PortletRequestListener.java b/server/src/com/vaadin/server/PortletRequestListener.java index 35f2a946c5..4562ddf7b9 100644 --- a/server/src/com/vaadin/server/PortletRequestListener.java +++ b/server/src/com/vaadin/server/PortletRequestListener.java @@ -22,7 +22,6 @@ import javax.portlet.PortletResponse; import javax.servlet.Filter; import com.vaadin.Application; -import com.vaadin.service.ApplicationContext.TransactionListener; /** * An {@link Application} that implements this interface gets notified of @@ -41,7 +40,7 @@ import com.vaadin.service.ApplicationContext.TransactionListener; * </ul> * <p> * Alternatives for implementing similar features are are Servlet {@link Filter} - * s and {@link TransactionListener}s in Vaadin. + * s and {@link ApplicationContext.TransactionListener}s in Vaadin. * * @since 6.2 * @see HttpServletRequestListener diff --git a/server/src/com/vaadin/server/RequestTimer.java b/server/src/com/vaadin/server/RequestTimer.java index 1dfe24f23b..470677e331 100644 --- a/server/src/com/vaadin/server/RequestTimer.java +++ b/server/src/com/vaadin/server/RequestTimer.java @@ -18,6 +18,7 @@ package com.vaadin.server; import java.io.Serializable; + /** * Times the handling of requests and stores the information as an attribute in * the request. The timing info is later passed on to the client in the UIDL and @@ -43,7 +44,7 @@ public class RequestTimer implements Serializable { * * @param context */ - public void stop(AbstractWebApplicationContext context) { + public void stop(ApplicationContext context) { // Measure and store the total handling time. This data can be // used in TestBench 3 tests. long time = (System.nanoTime() - requestStartTime) / 1000000; diff --git a/server/src/com/vaadin/server/WebApplicationContext.java b/server/src/com/vaadin/server/ServletApplicationContext.java index 7059a04682..a38c523254 100644 --- a/server/src/com/vaadin/server/WebApplicationContext.java +++ b/server/src/com/vaadin/server/ServletApplicationContext.java @@ -37,7 +37,7 @@ import com.vaadin.Application; * @since 3.1 */ @SuppressWarnings("serial") -public class WebApplicationContext extends AbstractWebApplicationContext { +public class ServletApplicationContext extends ApplicationContext { protected transient HttpSession session; private transient boolean reinitializingSession = false; @@ -51,7 +51,7 @@ public class WebApplicationContext extends AbstractWebApplicationContext { * Creates a new Web Application Context. * */ - protected WebApplicationContext() { + protected ServletApplicationContext() { } @@ -119,11 +119,11 @@ public class WebApplicationContext extends AbstractWebApplicationContext { /** * Gets the application context base directory. * - * @see com.vaadin.service.ApplicationContext#getBaseDirectory() + * @see com.vaadin.server.ApplicationContext#getBaseDirectory() */ @Override public File getBaseDirectory() { - final String realPath = ApplicationServlet.getResourcePath( + final String realPath = VaadinServlet.getResourcePath( session.getServletContext(), "/"); if (realPath == null) { return null; @@ -147,13 +147,13 @@ public class WebApplicationContext extends AbstractWebApplicationContext { * the HTTP session. * @return the application context for HttpSession. */ - static public WebApplicationContext getApplicationContext( + static public ServletApplicationContext getApplicationContext( HttpSession session) { - WebApplicationContext cx = (WebApplicationContext) session - .getAttribute(WebApplicationContext.class.getName()); + ServletApplicationContext cx = (ServletApplicationContext) session + .getAttribute(ServletApplicationContext.class.getName()); if (cx == null) { - cx = new WebApplicationContext(); - session.setAttribute(WebApplicationContext.class.getName(), cx); + cx = new ServletApplicationContext(); + session.setAttribute(ServletApplicationContext.class.getName(), cx); } if (cx.session == null) { cx.session = session; @@ -175,7 +175,7 @@ public class WebApplicationContext extends AbstractWebApplicationContext { * @return CommunicationManager */ public CommunicationManager getApplicationManager(Application application, - AbstractApplicationServlet servlet) { + VaadinServlet servlet) { CommunicationManager mgr = (CommunicationManager) applicationToAjaxAppMgrMap .get(application); diff --git a/server/src/com/vaadin/server/ServletPortletHelper.java b/server/src/com/vaadin/server/ServletPortletHelper.java index cce98ab925..f9ca55b50e 100644 --- a/server/src/com/vaadin/server/ServletPortletHelper.java +++ b/server/src/com/vaadin/server/ServletPortletHelper.java @@ -24,6 +24,10 @@ import com.vaadin.ui.UI; class ServletPortletHelper implements Serializable { public static final String UPLOAD_URL_PREFIX = "APP/UPLOAD/"; + /** + * The default SystemMessages (read-only). + */ + static final SystemMessages DEFAULT_SYSTEM_MESSAGES = new SystemMessages(); public static class ApplicationClassException extends Exception { diff --git a/server/src/com/vaadin/server/SystemError.java b/server/src/com/vaadin/server/SystemError.java index 5d1426e87c..aa9ffcaf52 100644 --- a/server/src/com/vaadin/server/SystemError.java +++ b/server/src/com/vaadin/server/SystemError.java @@ -80,8 +80,7 @@ public class SystemError extends AbstractErrorMessage { StringBuilder sb = new StringBuilder(); if (getMessage() != null) { sb.append("<h2>"); - sb.append(AbstractApplicationServlet - .safeEscapeForHtml(getMessage())); + sb.append(VaadinServlet.safeEscapeForHtml(getMessage())); sb.append("</h2>"); } return sb.toString(); diff --git a/server/src/com/vaadin/server/SystemMessages.java b/server/src/com/vaadin/server/SystemMessages.java new file mode 100644 index 0000000000..17aed0003e --- /dev/null +++ b/server/src/com/vaadin/server/SystemMessages.java @@ -0,0 +1,310 @@ +/* + * 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.io.Serializable; + +import com.vaadin.Application; + + +/** + * Contains the system messages used to notify the user about various + * critical situations that can occur. + * <p> + * Customize by overriding the static + * {@link Application#getSystemMessages()} and returning + * {@link CustomizedSystemMessages}. + * </p> + * <p> + * The defaults defined in this class are: + * <ul> + * <li><b>sessionExpiredURL</b> = null</li> + * <li><b>sessionExpiredNotificationEnabled</b> = true</li> + * <li><b>sessionExpiredCaption</b> = ""</li> + * <li><b>sessionExpiredMessage</b> = + * "Take note of any unsaved data, and <u>click here</u> to continue."</li> + * <li><b>communicationErrorURL</b> = null</li> + * <li><b>communicationErrorNotificationEnabled</b> = true</li> + * <li><b>communicationErrorCaption</b> = "Communication problem"</li> + * <li><b>communicationErrorMessage</b> = + * "Take note of any unsaved data, and <u>click here</u> to continue."</li> + * <li><b>internalErrorURL</b> = null</li> + * <li><b>internalErrorNotificationEnabled</b> = true</li> + * <li><b>internalErrorCaption</b> = "Internal error"</li> + * <li><b>internalErrorMessage</b> = "Please notify the administrator.<br/> + * Take note of any unsaved data, and <u>click here</u> to continue."</li> + * <li><b>outOfSyncURL</b> = null</li> + * <li><b>outOfSyncNotificationEnabled</b> = true</li> + * <li><b>outOfSyncCaption</b> = "Out of sync"</li> + * <li><b>outOfSyncMessage</b> = "Something has caused us to be out of sync + * with the server.<br/> + * Take note of any unsaved data, and <u>click here</u> to re-sync."</li> + * <li><b>cookiesDisabledURL</b> = null</li> + * <li><b>cookiesDisabledNotificationEnabled</b> = true</li> + * <li><b>cookiesDisabledCaption</b> = "Cookies disabled"</li> + * <li><b>cookiesDisabledMessage</b> = "This application requires cookies to + * function.<br/> + * Please enable cookies in your browser and <u>click here</u> to try again. + * </li> + * </ul> + * </p> + * + */ +public class SystemMessages implements Serializable { + protected String sessionExpiredURL = null; + protected boolean sessionExpiredNotificationEnabled = true; + protected String sessionExpiredCaption = "Session Expired"; + protected String sessionExpiredMessage = "Take note of any unsaved data, and <u>click here</u> to continue."; + + protected String communicationErrorURL = null; + protected boolean communicationErrorNotificationEnabled = true; + protected String communicationErrorCaption = "Communication problem"; + protected String communicationErrorMessage = "Take note of any unsaved data, and <u>click here</u> to continue."; + + protected String authenticationErrorURL = null; + protected boolean authenticationErrorNotificationEnabled = true; + protected String authenticationErrorCaption = "Authentication problem"; + protected String authenticationErrorMessage = "Take note of any unsaved data, and <u>click here</u> to continue."; + + protected String internalErrorURL = null; + protected boolean internalErrorNotificationEnabled = true; + protected String internalErrorCaption = "Internal error"; + protected String internalErrorMessage = "Please notify the administrator.<br/>Take note of any unsaved data, and <u>click here</u> to continue."; + + protected String outOfSyncURL = null; + protected boolean outOfSyncNotificationEnabled = true; + protected String outOfSyncCaption = "Out of sync"; + protected String outOfSyncMessage = "Something has caused us to be out of sync with the server.<br/>Take note of any unsaved data, and <u>click here</u> to re-sync."; + + protected String cookiesDisabledURL = null; + protected boolean cookiesDisabledNotificationEnabled = true; + protected String cookiesDisabledCaption = "Cookies disabled"; + protected String cookiesDisabledMessage = "This application requires cookies to function.<br/>Please enable cookies in your browser and <u>click here</u> to try again."; + + /** + * Use {@link CustomizedSystemMessages} to customize + */ + SystemMessages() { + + } + + /** + * @return null to indicate that the application will be restarted after + * session expired message has been shown. + */ + public String getSessionExpiredURL() { + return sessionExpiredURL; + } + + /** + * @return true to show session expiration message. + */ + public boolean isSessionExpiredNotificationEnabled() { + return sessionExpiredNotificationEnabled; + } + + /** + * @return "" to show no caption. + */ + public String getSessionExpiredCaption() { + return (sessionExpiredNotificationEnabled ? sessionExpiredCaption + : null); + } + + /** + * @return + * "Take note of any unsaved data, and <u>click here</u> to continue." + */ + public String getSessionExpiredMessage() { + return (sessionExpiredNotificationEnabled ? sessionExpiredMessage + : null); + } + + /** + * @return null to reload the application after communication error + * message. + */ + public String getCommunicationErrorURL() { + return communicationErrorURL; + } + + /** + * @return true to show the communication error message. + */ + public boolean isCommunicationErrorNotificationEnabled() { + return communicationErrorNotificationEnabled; + } + + /** + * @return "Communication problem" + */ + public String getCommunicationErrorCaption() { + return (communicationErrorNotificationEnabled ? communicationErrorCaption + : null); + } + + /** + * @return + * "Take note of any unsaved data, and <u>click here</u> to continue." + */ + public String getCommunicationErrorMessage() { + return (communicationErrorNotificationEnabled ? communicationErrorMessage + : null); + } + + /** + * @return null to reload the application after authentication error + * message. + */ + public String getAuthenticationErrorURL() { + return authenticationErrorURL; + } + + /** + * @return true to show the authentication error message. + */ + public boolean isAuthenticationErrorNotificationEnabled() { + return authenticationErrorNotificationEnabled; + } + + /** + * @return "Authentication problem" + */ + public String getAuthenticationErrorCaption() { + return (authenticationErrorNotificationEnabled ? authenticationErrorCaption + : null); + } + + /** + * @return + * "Take note of any unsaved data, and <u>click here</u> to continue." + */ + public String getAuthenticationErrorMessage() { + return (authenticationErrorNotificationEnabled ? authenticationErrorMessage + : null); + } + + /** + * @return null to reload the current URL after internal error message + * has been shown. + */ + public String getInternalErrorURL() { + return internalErrorURL; + } + + /** + * @return true to enable showing of internal error message. + */ + public boolean isInternalErrorNotificationEnabled() { + return internalErrorNotificationEnabled; + } + + /** + * @return "Internal error" + */ + public String getInternalErrorCaption() { + return (internalErrorNotificationEnabled ? internalErrorCaption + : null); + } + + /** + * @return "Please notify the administrator.<br/> + * Take note of any unsaved data, and <u>click here</u> to + * continue." + */ + public String getInternalErrorMessage() { + return (internalErrorNotificationEnabled ? internalErrorMessage + : null); + } + + /** + * @return null to reload the application after out of sync message. + */ + public String getOutOfSyncURL() { + return outOfSyncURL; + } + + /** + * @return true to enable showing out of sync message + */ + public boolean isOutOfSyncNotificationEnabled() { + return outOfSyncNotificationEnabled; + } + + /** + * @return "Out of sync" + */ + public String getOutOfSyncCaption() { + return (outOfSyncNotificationEnabled ? outOfSyncCaption : null); + } + + /** + * @return "Something has caused us to be out of sync with the server.<br/> + * Take note of any unsaved data, and <u>click here</u> to + * re-sync." + */ + public String getOutOfSyncMessage() { + return (outOfSyncNotificationEnabled ? outOfSyncMessage : null); + } + + /** + * Returns the URL the user should be redirected to after dismissing the + * "you have to enable your cookies" message. Typically null. + * + * @return A URL the user should be redirected to after dismissing the + * message or null to reload the current URL. + */ + public String getCookiesDisabledURL() { + return cookiesDisabledURL; + } + + /** + * Determines if "cookies disabled" messages should be shown to the end + * user or not. If the notification is disabled the user will be + * immediately redirected to the URL returned by + * {@link #getCookiesDisabledURL()}. + * + * @return true to show "cookies disabled" messages to the end user, + * false to redirect to the given URL directly + */ + public boolean isCookiesDisabledNotificationEnabled() { + return cookiesDisabledNotificationEnabled; + } + + /** + * Returns the caption of the message shown to the user when cookies are + * disabled in the browser. + * + * @return The caption of the "cookies disabled" message + */ + public String getCookiesDisabledCaption() { + return (cookiesDisabledNotificationEnabled ? cookiesDisabledCaption + : null); + } + + /** + * Returns the message shown to the user when cookies are disabled in + * the browser. + * + * @return The "cookies disabled" message + */ + public String getCookiesDisabledMessage() { + return (cookiesDisabledNotificationEnabled ? cookiesDisabledMessage + : null); + } + +}
\ No newline at end of file diff --git a/server/src/com/vaadin/server/AbstractApplicationPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index e8151462aa..25512e9237 100644 --- a/server/src/com/vaadin/server/AbstractApplicationPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -22,7 +22,6 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.security.GeneralSecurityException; @@ -55,8 +54,8 @@ import com.liferay.portal.kernel.util.PortalClassInvoker; import com.liferay.portal.kernel.util.PropsUtil; import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; -import com.vaadin.Application.SystemMessages; import com.vaadin.server.AbstractCommunicationManager.Callback; +import com.vaadin.server.ServletPortletHelper.ApplicationClassException; import com.vaadin.ui.UI; /** @@ -67,8 +66,8 @@ import com.vaadin.ui.UI; * * @author peholmst */ -public abstract class AbstractApplicationPortlet extends GenericPortlet - implements Constants { +public class VaadinPortlet extends GenericPortlet implements + Constants { public static final String RESOURCE_URL_ID = "APP"; @@ -176,10 +175,10 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet public static class AbstractApplicationPortletWrapper implements Callback { - private final AbstractApplicationPortlet portlet; + private final VaadinPortlet portlet; public AbstractApplicationPortletWrapper( - AbstractApplicationPortlet portlet) { + VaadinPortlet portlet) { this.portlet = portlet; } @@ -321,6 +320,11 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet public String getMimeType(String resourceName) { return getPortletContext().getMimeType(resourceName); } + + @Override + public SystemMessages getSystemMessages() { + return VaadinPortlet.this.getSystemMessages(); + } }; addonContext = new AddonContext(deploymentConfiguration); @@ -889,8 +893,11 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet return null; } - protected abstract Class<? extends Application> getApplicationClass() - throws ClassNotFoundException; + protected Class<? extends Application> getApplicationClass() + throws ApplicationClassException { + return ServletPortletHelper + .getApplicationClass(getDeploymentConfiguration()); + } protected Application getNewApplication(PortletRequest request) throws PortletException { @@ -901,7 +908,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet throw new PortletException("getNewApplication failed", e); } catch (final InstantiationException e) { throw new PortletException("getNewApplication failed", e); - } catch (final ClassNotFoundException e) { + } catch (final ApplicationClassException e) { throw new PortletException("getNewApplication failed", e); } } @@ -912,29 +919,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet * @return */ protected SystemMessages getSystemMessages() { - try { - Class<? extends Application> appCls = getApplicationClass(); - Method m = appCls.getMethod("getSystemMessages", (Class[]) null); - return (Application.SystemMessages) m.invoke(null, (Object[]) null); - } catch (ClassNotFoundException e) { - // This should never happen - throw new SystemMessageException(e); - } catch (SecurityException e) { - throw new SystemMessageException( - "Application.getSystemMessage() should be static public", e); - } catch (NoSuchMethodException e) { - // This is completely ok and should be silently ignored - } catch (IllegalArgumentException e) { - // This should never happen - throw new SystemMessageException(e); - } catch (IllegalAccessException e) { - throw new SystemMessageException( - "Application.getSystemMessage() should be static public", e); - } catch (InvocationTargetException e) { - // This should never happen - throw new SystemMessageException(e); - } - return Application.getSystemMessages(); + return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES; } private void handleServiceException(WrappedPortletRequest request, @@ -945,7 +930,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet // if this was an UIDL request, response UIDL back to client if (getRequestType(request) == RequestType.UIDL) { - Application.SystemMessages ci = getSystemMessages(); + SystemMessages ci = getSystemMessages(); criticalNotification(request, response, ci.getInternalErrorCaption(), ci.getInternalErrorMessage(), null, ci.getInternalErrorURL()); @@ -1054,7 +1039,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet } private static final Logger getLogger() { - return Logger.getLogger(AbstractApplicationPortlet.class.getName()); + return Logger.getLogger(VaadinPortlet.class.getName()); } } diff --git a/server/src/com/vaadin/server/AbstractApplicationServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 2f0dad7079..0766d46e93 100644 --- a/server/src/com/vaadin/server/AbstractApplicationServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -22,8 +22,6 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -48,33 +46,19 @@ import javax.servlet.http.HttpSession; import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; -import com.vaadin.Application.SystemMessages; import com.vaadin.server.AbstractCommunicationManager.Callback; +import com.vaadin.server.ServletPortletHelper.ApplicationClassException; import com.vaadin.shared.ApplicationConstants; import com.vaadin.ui.UI; -/** - * Abstract implementation of the ApplicationServlet which handles all - * communication between the client and the server. - * - * It is possible to extend this class to provide own functionality but in most - * cases this is unnecessary. - * - * - * @author Vaadin Ltd. - * @since 6.0 - */ - @SuppressWarnings("serial") -public abstract class AbstractApplicationServlet extends HttpServlet implements - Constants { +public class VaadinServlet extends HttpServlet implements Constants { private static class AbstractApplicationServletWrapper implements Callback { - private final AbstractApplicationServlet servlet; + private final VaadinServlet servlet; - public AbstractApplicationServletWrapper( - AbstractApplicationServlet servlet) { + public AbstractApplicationServletWrapper(VaadinServlet servlet) { this.servlet = servlet; } @@ -139,21 +123,21 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements public String getStaticFileLocation(WrappedRequest request) { HttpServletRequest servletRequest = WrappedHttpServletRequest .cast(request); - return AbstractApplicationServlet.this + return VaadinServlet.this .getStaticFilesLocation(servletRequest); } @Override public String getConfiguredWidgetset(WrappedRequest request) { return getApplicationOrSystemProperty( - AbstractApplicationServlet.PARAMETER_WIDGETSET, - AbstractApplicationServlet.DEFAULT_WIDGETSET); + VaadinServlet.PARAMETER_WIDGETSET, + VaadinServlet.DEFAULT_WIDGETSET); } @Override public String getConfiguredTheme(WrappedRequest request) { // Use the default - return AbstractApplicationServlet.getDefaultTheme(); + return VaadinServlet.getDefaultTheme(); } @Override @@ -165,6 +149,11 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements public String getMimeType(String resourceName) { return getServletContext().getMimeType(resourceName); } + + @Override + public SystemMessages getSystemMessages() { + return VaadinServlet.this.getSystemMessages(); + } }; addonContext = new AddonContext(deploymentConfiguration); @@ -275,7 +264,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements * Get or create a WebApplicationContext and an ApplicationManager * for the session */ - WebApplicationContext webApplicationContext = getApplicationContext(request + ServletApplicationContext webApplicationContext = getApplicationContext(request .getSession()); CommunicationManager applicationManager = webApplicationContext .getApplicationManager(application, this); @@ -363,7 +352,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements // Notifies transaction end try { if (transactionStarted) { - ((WebApplicationContext) application.getContext()) + ((ServletApplicationContext) application.getContext()) .endTransaction(application, request); } @@ -694,7 +683,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements throws ServletException, MalformedURLException { Application newApplication = getNewApplication(request); - final WebApplicationContext context = getApplicationContext(request + final ServletApplicationContext context = getApplicationContext(request .getSession()); context.addApplication(newApplication); @@ -706,7 +695,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements Throwable e) throws IOException, ServletException { // if this was an UIDL request, response UIDL back to client if (getRequestType(request) == RequestType.UIDL) { - Application.SystemMessages ci = getSystemMessages(); + SystemMessages ci = getSystemMessages(); criticalNotification(request, response, ci.getInternalErrorCaption(), ci.getInternalErrorMessage(), null, ci.getInternalErrorURL()); @@ -769,7 +758,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } try { - Application.SystemMessages ci = getSystemMessages(); + SystemMessages ci = getSystemMessages(); if (getRequestType(request) != RequestType.UIDL) { // 'plain' http req - e.g. browser reload; // just go ahead redirect the browser @@ -811,7 +800,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } try { - Application.SystemMessages ci = getSystemMessages(); + SystemMessages ci = getSystemMessages(); if (getRequestType(request) != RequestType.UIDL) { // 'plain' http req - e.g. browser reload; // just go ahead redirect the browser @@ -843,8 +832,26 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements * @return A new Application instance. * @throws ServletException */ - protected abstract Application getNewApplication(HttpServletRequest request) - throws ServletException; + protected Application getNewApplication(HttpServletRequest request) + throws ServletException { + + // Creates a new application instance + try { + Class<? extends Application> applicationClass = ServletPortletHelper + .getApplicationClass(getDeploymentConfiguration()); + + final Application application = applicationClass.newInstance(); + application.addUIProvider(new DefaultUIProvider()); + + return application; + } catch (final IllegalAccessException e) { + throw new ServletException("getNewApplication failed", e); + } catch (final InstantiationException e) { + throw new ServletException("getNewApplication failed", e); + } catch (ApplicationClassException e) { + throw new ServletException("getNewApplication failed", e); + } + } /** * Starts the application if it is not already running. @@ -856,7 +863,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements * @throws MalformedURLException */ private void startApplication(HttpServletRequest request, - Application application, WebApplicationContext webApplicationContext) + Application application, + ServletApplicationContext webApplicationContext) throws ServletException, MalformedURLException { if (!application.isRunning()) { @@ -1177,51 +1185,14 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } /** - * Get system messages from the current application class + * Get system messages * * @return */ protected SystemMessages getSystemMessages() { - Class<? extends Application> appCls = null; - try { - appCls = getApplicationClass(); - } catch (ClassNotFoundException e) { - // Previous comment claimed that this should never happen - throw new SystemMessageException(e); - } - return getSystemMessages(appCls); - } - - public static SystemMessages getSystemMessages( - Class<? extends Application> appCls) { - try { - if (appCls != null) { - Method m = appCls - .getMethod("getSystemMessages", (Class[]) null); - return (Application.SystemMessages) m.invoke(null, - (Object[]) null); - } - } catch (SecurityException e) { - throw new SystemMessageException( - "Application.getSystemMessage() should be static public", e); - } catch (NoSuchMethodException e) { - // This is completely ok and should be silently ignored - } catch (IllegalArgumentException e) { - // This should never happen - throw new SystemMessageException(e); - } catch (IllegalAccessException e) { - throw new SystemMessageException( - "Application.getSystemMessage() should be static public", e); - } catch (InvocationTargetException e) { - // This should never happen - throw new SystemMessageException(e); - } - return Application.getSystemMessages(); + return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES; } - protected abstract Class<? extends Application> getApplicationClass() - throws ClassNotFoundException; - /** * 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 @@ -1385,7 +1356,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements throw new SessionExpiredException(); } - WebApplicationContext context = getApplicationContext(session); + ServletApplicationContext context = getApplicationContext(session); // Gets application list for the session. final Collection<Application> applications = context.getApplications(); @@ -1491,7 +1462,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements application.close(); if (session != null) { - WebApplicationContext context = getApplicationContext(session); + ServletApplicationContext context = getApplicationContext(session); context.removeApplication(application); } } @@ -1506,13 +1477,14 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements * the HTTP session. * @return the application context for HttpSession. */ - protected WebApplicationContext getApplicationContext(HttpSession session) { + protected ServletApplicationContext getApplicationContext( + HttpSession session) { /* * TODO the ApplicationContext.getApplicationContext() should be removed * and logic moved here. Now overriding context type is possible, but * the whole creation logic should be here. MT 1101 */ - return WebApplicationContext.getApplicationContext(session); + return ServletApplicationContext.getApplicationContext(session); } public class RequestError implements Terminal.ErrorEvent, Serializable { @@ -1535,11 +1507,11 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements * mananger implementation. * * @deprecated Instead of overriding this method, override - * {@link WebApplicationContext} implementation via - * {@link AbstractApplicationServlet#getApplicationContext(HttpSession)} + * {@link ServletApplicationContext} implementation via + * {@link VaadinServlet#getApplicationContext(HttpSession)} * method and in that customized implementation return your * CommunicationManager in - * {@link WebApplicationContext#getApplicationManager(Application, AbstractApplicationServlet)} + * {@link ServletApplicationContext#getApplicationManager(Application, VaadinServlet)} * method. * * @param application @@ -1587,6 +1559,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } private static final Logger getLogger() { - return Logger.getLogger(AbstractApplicationServlet.class.getName()); + return Logger.getLogger(VaadinServlet.class.getName()); } } diff --git a/server/src/com/vaadin/server/WebBrowser.java b/server/src/com/vaadin/server/WebBrowser.java index 92090da14a..96cab99e40 100644 --- a/server/src/com/vaadin/server/WebBrowser.java +++ b/server/src/com/vaadin/server/WebBrowser.java @@ -335,9 +335,8 @@ public class WebBrowser { } /** - * For internal use by AbstractApplicationServlet/AbstractApplicationPortlet - * only. Updates all properties in the class according to the given - * information. + * For internal use by VaadinServlet/VaadinPortlet only. Updates all + * properties in the class according to the given information. * * @param sw * Screen width @@ -406,9 +405,8 @@ public class WebBrowser { } /** - * For internal use by AbstractApplicationServlet/AbstractApplicationPortlet - * only. Updates all properties in the class according to the given - * information. + * For internal use by VaadinServlet/VaadinPortlet only. Updates all + * properties in the class according to the given information. * * @param request * the wrapped request to read the information from diff --git a/server/src/com/vaadin/server/WrappedHttpServletRequest.java b/server/src/com/vaadin/server/WrappedHttpServletRequest.java index cb8a9e8c5f..b069235843 100644 --- a/server/src/com/vaadin/server/WrappedHttpServletRequest.java +++ b/server/src/com/vaadin/server/WrappedHttpServletRequest.java @@ -99,8 +99,8 @@ public class WrappedHttpServletRequest extends HttpServletRequestWrapper @Override public WebBrowser getWebBrowser() { - WebApplicationContext context = (WebApplicationContext) Application - .getCurrent().getContext(); + ApplicationContext context = Application.getCurrent() + .getContext(); return context.getBrowser(); } }; diff --git a/server/src/com/vaadin/server/WrappedPortletRequest.java b/server/src/com/vaadin/server/WrappedPortletRequest.java index 40a5c5f509..47a8e2c358 100644 --- a/server/src/com/vaadin/server/WrappedPortletRequest.java +++ b/server/src/com/vaadin/server/WrappedPortletRequest.java @@ -101,7 +101,7 @@ public class WrappedPortletRequest implements WrappedRequest { if (request instanceof ResourceRequest) { ResourceRequest resourceRequest = (ResourceRequest) request; String resourceID = resourceRequest.getResourceID(); - if (AbstractApplicationPortlet.RESOURCE_URL_ID.equals(resourceID)) { + if (VaadinPortlet.RESOURCE_URL_ID.equals(resourceID)) { String resourcePath = resourceRequest .getParameter(ApplicationConstants.V_RESOURCE_PATH); return resourcePath; diff --git a/server/src/com/vaadin/service/ApplicationContext.java b/server/src/com/vaadin/service/ApplicationContext.java deleted file mode 100644 index 591704764f..0000000000 --- a/server/src/com/vaadin/service/ApplicationContext.java +++ /dev/null @@ -1,125 +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.service; - -import java.io.File; -import java.io.Serializable; -import java.util.Collection; - -import com.vaadin.Application; - -/** - * <code>ApplicationContext</code> provides information about the running - * context of the application. Each context is shared by all applications that - * are open for one user. In a web-environment this corresponds to a - * HttpSession. - * - * @author Vaadin Ltd. - * @since 3.1 - */ -public interface ApplicationContext extends Serializable { - - /** - * Returns application context base directory. - * - * Typically an application is deployed in a such way that is has an - * application directory. For web applications this directory is the root - * directory of the web applications. In some cases applications might not - * have an application directory (for example web applications running - * inside a war). - * - * @return The application base directory or null if the application has no - * base directory. - */ - public File getBaseDirectory(); - - /** - * Returns a collection of all the applications in this context. - * - * Each application context contains all active applications for one user. - * - * @return A collection containing all the applications in this context. - */ - public Collection<Application> getApplications(); - - /** - * Adds a transaction listener to this context. The transaction listener is - * called before and after each each request related to this session except - * when serving static resources. - * - * The transaction listener must not be null. - * - * @see com.vaadin.service.ApplicationContext#addTransactionListener(com.vaadin.service.ApplicationContext.TransactionListener) - */ - public void addTransactionListener(TransactionListener listener); - - /** - * Removes a transaction listener from this context. - * - * @param listener - * the listener to be removed. - * @see TransactionListener - */ - public void removeTransactionListener(TransactionListener listener); - - /** - * Returns the time between requests, in seconds, before this context is - * invalidated. A negative time indicates the context should never timeout. - */ - public int getMaxInactiveInterval(); - - /** - * Interface for listening to transaction events. Implement this interface - * to listen to all transactions between the client and the application. - * - */ - public interface TransactionListener extends Serializable { - - /** - * Invoked at the beginning of every transaction. - * - * The transaction is linked to the context, not the application so if - * you have multiple applications running in the same context you need - * to check that the request is associated with the application you are - * interested in. This can be done looking at the application parameter. - * - * @param application - * the Application object. - * @param transactionData - * the Data identifying the transaction. - */ - public void transactionStart(Application application, - Object transactionData); - - /** - * Invoked at the end of every transaction. - * - * The transaction is linked to the context, not the application so if - * you have multiple applications running in the same context you need - * to check that the request is associated with the application you are - * interested in. This can be done looking at the application parameter. - * - * @param applcation - * the Application object. - * @param transactionData - * the Data identifying the transaction. - */ - public void transactionEnd(Application application, - Object transactionData); - - } -} diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index d1ccaacde3..0f914d3947 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -33,7 +33,6 @@ import com.vaadin.event.Action.Handler; import com.vaadin.event.ActionManager; import com.vaadin.event.MouseEvents.ClickEvent; import com.vaadin.event.MouseEvents.ClickListener; -import com.vaadin.server.AbstractApplicationServlet; import com.vaadin.server.LegacyComponent; import com.vaadin.server.Page; import com.vaadin.server.Page.BrowserWindowResizeEvent; @@ -41,6 +40,7 @@ import com.vaadin.server.Page.BrowserWindowResizeListener; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; +import com.vaadin.server.VaadinServlet; import com.vaadin.server.WrappedRequest; import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.shared.EventId; @@ -63,7 +63,7 @@ import com.vaadin.tools.ReflectTools; * </p> * <p> * When a new UI instance is needed, typically because the user opens a URL in a - * browser window which points to {@link AbstractApplicationServlet}, + * browser window which points to {@link VaadinServlet}, * {@link Application#getUIForRequest(WrappedRequest)} is invoked to get a UI. * That method does by default create a UI according to the * {@value Application#UI_PARAMETER} parameter from web.xml. |