From: Leif Åstrand Date: Mon, 3 Sep 2012 07:38:11 +0000 (+0300) Subject: Move SystemMessages to DeploymentConfiguration (#9402) X-Git-Tag: 7.0.0.beta1~206^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3dd5a4824cda3dd7842c937a618feebc2b1a0f27;p=vaadin-framework.git Move SystemMessages to DeploymentConfiguration (#9402) --- diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index f8ff812c94..8a043154d7 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -462,12 +462,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. @@ -791,25 +785,6 @@ public class Application implements Terminal.ErrorListener, Serializable { this.logoutURL = logoutURL; } - /** - * 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; - } - /** *

* Invoked by the terminal on any exception that occurs in application and diff --git a/server/src/com/vaadin/server/AbstractApplicationPortlet.java b/server/src/com/vaadin/server/AbstractApplicationPortlet.java index e8151462aa..7fc69b05f7 100644 --- a/server/src/com/vaadin/server/AbstractApplicationPortlet.java +++ b/server/src/com/vaadin/server/AbstractApplicationPortlet.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,7 +54,6 @@ 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.ui.UI; @@ -321,6 +319,11 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet public String getMimeType(String resourceName) { return getPortletContext().getMimeType(resourceName); } + + @Override + public SystemMessages getSystemMessages() { + return AbstractApplicationPortlet.this.getSystemMessages(); + } }; addonContext = new AddonContext(deploymentConfiguration); @@ -912,29 +915,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet * @return */ protected SystemMessages getSystemMessages() { - try { - Class 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 +926,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()); diff --git a/server/src/com/vaadin/server/AbstractApplicationServlet.java b/server/src/com/vaadin/server/AbstractApplicationServlet.java index 87d36da255..8b3103b794 100644 --- a/server/src/com/vaadin/server/AbstractApplicationServlet.java +++ b/server/src/com/vaadin/server/AbstractApplicationServlet.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,7 +46,6 @@ 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.shared.ApplicationConstants; import com.vaadin.ui.UI; @@ -165,6 +162,11 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements public String getMimeType(String resourceName) { return getServletContext().getMimeType(resourceName); } + + @Override + public SystemMessages getSystemMessages() { + return AbstractApplicationServlet.this.getSystemMessages(); + } }; addonContext = new AddonContext(deploymentConfiguration); @@ -706,7 +708,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 +771,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 +813,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 @@ -1177,51 +1179,14 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } /** - * Get system messages from the current application class + * Get system messages * * @return */ protected SystemMessages getSystemMessages() { - Class appCls = null; - try { - appCls = getApplicationClass(); - } catch (ClassNotFoundException e) { - // Previous comment claimed that this should never happen - throw new SystemMessageException(e); - } - return getSystemMessages(appCls); + return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES; } - public static SystemMessages getSystemMessages( - Class 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(); - } - - protected abstract Class 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 diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index 526d18fd34..740ecf843b 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. diff --git a/server/src/com/vaadin/server/ApplicationServlet.java b/server/src/com/vaadin/server/ApplicationServlet.java index af0cebcf86..905b48d62f 100644 --- a/server/src/com/vaadin/server/ApplicationServlet.java +++ b/server/src/com/vaadin/server/ApplicationServlet.java @@ -76,14 +76,10 @@ public class ApplicationServlet extends AbstractApplicationServlet { 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 getApplicationClass() - throws ClassNotFoundException { + protected Class getApplicationClass() { return applicationClass; } } diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java index df46bb12ee..98ed1071de 100644 --- a/server/src/com/vaadin/server/BootstrapHandler.java +++ b/server/src/com/vaadin/server/BootstrapHandler.java @@ -420,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(); @@ -445,8 +447,6 @@ public abstract class BootstrapHandler implements RequestHandler { defaults.put("authErrMsg", authErrMsg); } - DeploymentConfiguration deploymentConfiguration = request - .getDeploymentConfiguration(); String staticFileLocation = deploymentConfiguration .getStaticFileLocation(request); String widgetsetBase = staticFileLocation + "/" 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. + *

+ * 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. + *

+ *

+ * The default behavior is to show a notification, and restart the + * application the the user clicks the message.
+ * Instead of restarting the application, you can set a specific URL that + * the user is taken to.
+ * 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. + *

+ *

+ * The situations are: + *

  • Session expired: the user session has expired, usually due to + * inactivity.
  • + *
  • Communication error: the client failed to contact the server, or the + * server returned and invalid response.
  • + *
  • Internal error: unhandled critical server error (e.g out of memory, + * database crash) + *
  • 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. + *

    + */ + +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 d61d03f4d9..acfba405e6 100644 --- a/server/src/com/vaadin/server/DeploymentConfiguration.java +++ b/server/src/com/vaadin/server/DeploymentConfiguration.java @@ -181,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/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/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. + *

    + * Customize by overriding the static + * {@link Application#getSystemMessages()} and returning + * {@link CustomizedSystemMessages}. + *

    + *

    + * The defaults defined in this class are: + *

    + *

    + * + */ +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 click here 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 click here 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 click here to continue."; + + protected String internalErrorURL = null; + protected boolean internalErrorNotificationEnabled = true; + protected String internalErrorCaption = "Internal error"; + protected String internalErrorMessage = "Please notify the administrator.
    Take note of any unsaved data, and click here 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.
    Take note of any unsaved data, and click here 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.
    Please enable cookies in your browser and click here 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 click here 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 click here 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 click here 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.
    + * Take note of any unsaved data, and click here 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.
    + * Take note of any unsaved data, and click here 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/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java index bceecaf35a..e2fe5df4c7 100644 --- a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java +++ b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java @@ -209,20 +209,6 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { return uris; } - @Override - protected Class getApplicationClass() - throws ClassNotFoundException { - Class classToRun = getClassToRun(); - if (UI.class.isAssignableFrom(classToRun)) { - return Application.class; - } else if (Application.class.isAssignableFrom(classToRun)) { - return classToRun.asSubclass(Application.class); - } else { - throw new ClassCastException(classToRun.getCanonicalName() - + " is not an Application nor a UI"); - } - } - private Class getClassToRun() throws ClassNotFoundException { // TODO use getClassLoader() ? diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket1673.java b/uitest/src/com/vaadin/tests/tickets/Ticket1673.java index 99f213541a..bf95001464 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket1673.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket1673.java @@ -1,6 +1,7 @@ package com.vaadin.tests.tickets; -import com.vaadin.Application; +import com.vaadin.server.CustomizedSystemMessages; +import com.vaadin.server.SystemMessages; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.UI.LegacyWindow; @@ -22,8 +23,8 @@ public class Ticket1673 extends com.vaadin.Application.LegacyApplication { } - public static Application.SystemMessages getSystemMessages() { - Application.CustomizedSystemMessages msgs = new Application.CustomizedSystemMessages(); + public static SystemMessages getSystemMessages() { + CustomizedSystemMessages msgs = new CustomizedSystemMessages(); msgs.setSessionExpiredURL("http://www.vaadin.com/"); msgs.setSessionExpiredCaption("Foo"); diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket2106.java b/uitest/src/com/vaadin/tests/tickets/Ticket2106.java index 9d6e198f03..a57a20cdc3 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket2106.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket2106.java @@ -3,6 +3,8 @@ package com.vaadin.tests.tickets; import java.util.Date; import com.vaadin.Application; +import com.vaadin.server.CustomizedSystemMessages; +import com.vaadin.server.SystemMessages; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Label; @@ -10,7 +12,7 @@ import com.vaadin.ui.UI.LegacyWindow; public class Ticket2106 extends Application.LegacyApplication { - private static CustomizedSystemMessages msgs = new Application.CustomizedSystemMessages(); + private static CustomizedSystemMessages msgs = new CustomizedSystemMessages(); static { // We will forward the user to www.vaadin.com when the session expires msgs.setSessionExpiredURL("http://www.vaadin.com"); @@ -18,7 +20,7 @@ public class Ticket2106 extends Application.LegacyApplication { msgs.setSessionExpiredCaption(null); } - public static Application.SystemMessages getSystemMessages() { + public static SystemMessages getSystemMessages() { return msgs; }