summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-11-19 20:19:47 +0200
committerArtur Signell <artur@vaadin.com>2012-11-19 20:31:46 +0200
commit1aceeea98320b5c5f6fd71055ef718f1c305e44e (patch)
treeb0ea821b1949655684f76b038053b864a9950391 /server
parent02a808548472a8aa66631fdbf5ee119b24061a92 (diff)
downloadvaadin-framework-1aceeea98320b5c5f6fd71055ef718f1c305e44e.tar.gz
vaadin-framework-1aceeea98320b5c5f6fd71055ef718f1c305e44e.zip
Changed SystemMessagesProvider parameter into object (#10226)
Change-Id: I7ba22460ae5105e29b88b17bc3e3ac664e9ca980
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/AbstractCommunicationManager.java4
-rw-r--r--server/src/com/vaadin/server/BootstrapHandler.java3
-rw-r--r--server/src/com/vaadin/server/DefaultSystemMessagesProvider.java4
-rw-r--r--server/src/com/vaadin/server/SystemMessages.java4
-rw-r--r--server/src/com/vaadin/server/SystemMessagesInfo.java53
-rw-r--r--server/src/com/vaadin/server/SystemMessagesProvider.java19
-rw-r--r--server/src/com/vaadin/server/VaadinPortlet.java2
-rw-r--r--server/src/com/vaadin/server/VaadinService.java10
-rw-r--r--server/src/com/vaadin/server/VaadinServlet.java10
9 files changed, 85 insertions, 24 deletions
diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java
index 1481085247..834d7d8a17 100644
--- a/server/src/com/vaadin/server/AbstractCommunicationManager.java
+++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java
@@ -590,7 +590,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
// var inconsistency; the client is probably out-of-sync
SystemMessages ci = response.getService().getSystemMessages(
- uI.getLocale());
+ uI.getLocale(), request);
String msg = ci.getOutOfSyncMessage();
String cap = ci.getOutOfSyncCaption();
if (msg != null || cap != null) {
@@ -1042,7 +1042,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
}
SystemMessages ci = request.getService().getSystemMessages(
- ui.getLocale());
+ ui.getLocale(), request);
// meta instruction for client to enable auto-forward to
// sessionExpiredURL after timer expires.
diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java
index d0e87d5e08..36a09253d9 100644
--- a/server/src/com/vaadin/server/BootstrapHandler.java
+++ b/server/src/com/vaadin/server/BootstrapHandler.java
@@ -413,7 +413,8 @@ public abstract class BootstrapHandler implements RequestHandler {
Locale locale = ServletPortletHelper.findLocale(null,
context.getSession(), context.getRequest());
// Get system messages
- SystemMessages systemMessages = vaadinService.getSystemMessages(locale);
+ SystemMessages systemMessages = vaadinService.getSystemMessages(locale,
+ request);
if (systemMessages != null) {
// Write the CommunicationError -message to client
JSONObject comErrMsg = new JSONObject();
diff --git a/server/src/com/vaadin/server/DefaultSystemMessagesProvider.java b/server/src/com/vaadin/server/DefaultSystemMessagesProvider.java
index 08042d3848..7111a8bbbb 100644
--- a/server/src/com/vaadin/server/DefaultSystemMessagesProvider.java
+++ b/server/src/com/vaadin/server/DefaultSystemMessagesProvider.java
@@ -16,7 +16,6 @@
package com.vaadin.server;
-import java.util.Locale;
/**
* System messages provider using the built-in default system messages. This
@@ -34,7 +33,8 @@ public class DefaultSystemMessagesProvider implements SystemMessagesProvider {
}
@Override
- public SystemMessages getSystemMessages(Locale locale) {
+ public SystemMessages getSystemMessages(
+ SystemMessagesInfo systemMessagesInfo) {
return ServletPortletHelper.DEFAULT_SYSTEM_MESSAGES;
}
diff --git a/server/src/com/vaadin/server/SystemMessages.java b/server/src/com/vaadin/server/SystemMessages.java
index 647266d8e3..f36a8e8570 100644
--- a/server/src/com/vaadin/server/SystemMessages.java
+++ b/server/src/com/vaadin/server/SystemMessages.java
@@ -22,8 +22,8 @@ import java.io.Serializable;
* Contains the system messages used to notify the user about various critical
* situations that can occur.
* <p>
- * Customize by overriding the static {@link VaadinSession#getSystemMessages()}
- * and returning {@link CustomizedSystemMessages}.
+ * Use {@link VaadinService#setSystemMessagesProvider(SystemMessagesProvider)}
+ * to customize.
* </p>
* <p>
* The defaults defined in this class are:
diff --git a/server/src/com/vaadin/server/SystemMessagesInfo.java b/server/src/com/vaadin/server/SystemMessagesInfo.java
new file mode 100644
index 0000000000..30a6e82a90
--- /dev/null
+++ b/server/src/com/vaadin/server/SystemMessagesInfo.java
@@ -0,0 +1,53 @@
+package com.vaadin.server;
+
+import java.io.Serializable;
+import java.util.Locale;
+
+public class SystemMessagesInfo implements Serializable {
+
+ private Locale locale;
+ private VaadinRequest request;
+ private VaadinService service;
+
+ /**
+ * The locale of the UI related to the {@link SystemMessages} request.
+ *
+ * @return The Locale or null if the locale is not known
+ */
+ public Locale getLocale() {
+ return locale;
+ }
+
+ public void setLocale(Locale locale) {
+ this.locale = locale;
+ }
+
+ /**
+ * Gets the request currently in progress.
+ *
+ * @return The request currently in progress or null if no request is in
+ * progress.
+ */
+ public VaadinRequest getRequest() {
+ return request;
+ }
+
+ public void setRequest(VaadinRequest request) {
+ this.request = request;
+ }
+
+ /**
+ * Returns the service this SystemMessages request comes from.
+ *
+ * @return The service which triggered this request or null of not triggered
+ * from a service.
+ */
+ public VaadinService getService() {
+ return service;
+ }
+
+ public void setService(VaadinService service) {
+ this.service = service;
+ }
+
+}
diff --git a/server/src/com/vaadin/server/SystemMessagesProvider.java b/server/src/com/vaadin/server/SystemMessagesProvider.java
index 21263a2950..caef8de420 100644
--- a/server/src/com/vaadin/server/SystemMessagesProvider.java
+++ b/server/src/com/vaadin/server/SystemMessagesProvider.java
@@ -17,7 +17,6 @@
package com.vaadin.server;
import java.io.Serializable;
-import java.util.Locale;
import com.vaadin.ui.UI;
@@ -30,16 +29,16 @@ import com.vaadin.ui.UI;
*/
public interface SystemMessagesProvider extends Serializable {
/**
- * Gets the system messages to use in the given context. Locale is the only
- * piece of information guaranteed to be available, but in most cases some
- * or all of {@link VaadinService#getCurrent()},
- * {@link VaadinService#getCurrentRequest()},
- * {@link VaadinSession#getCurrent()} and {@link UI#getCurrent()} can also
- * be used to find more information to help the decision.
+ * Gets the system messages to use in the given context. The
+ * {@link SystemMessagesInfo} object contains available information but in
+ * most cases some or both of {@link VaadinSession#getCurrent()} and
+ * {@link UI#getCurrent()} can also be used to find more information to help
+ * the decision.
*
- * @param locale
- * the desired locale of the system messages
+ * @param systemMessagesInfo
+ * Locale, current request and other information available.
* @return a system messages object
*/
- public SystemMessages getSystemMessages(Locale locale);
+ public SystemMessages getSystemMessages(
+ SystemMessagesInfo systemMessagesInfo);
}
diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java
index 51a71f1cd6..b1843ce9e5 100644
--- a/server/src/com/vaadin/server/VaadinPortlet.java
+++ b/server/src/com/vaadin/server/VaadinPortlet.java
@@ -628,7 +628,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants {
if (getRequestType(request) == RequestType.UIDL) {
SystemMessages ci = getService().getSystemMessages(
ServletPortletHelper.findLocale(null, vaadinSession,
- request));
+ request), request);
criticalNotification(request, response,
ci.getInternalErrorCaption(), ci.getInternalErrorMessage(),
null, ci.getInternalErrorURL());
diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java
index 2a3c04c49e..a4caf6cdd6 100644
--- a/server/src/com/vaadin/server/VaadinService.java
+++ b/server/src/com/vaadin/server/VaadinService.java
@@ -250,10 +250,16 @@ public abstract class VaadinService implements Serializable {
*
* @param locale
* the desired locale for the system messages
+ * @param request
* @return the system messages to use
*/
- public SystemMessages getSystemMessages(Locale locale) {
- return getSystemMessagesProvider().getSystemMessages(locale);
+ public SystemMessages getSystemMessages(Locale locale, VaadinRequest request) {
+ SystemMessagesInfo systemMessagesInfo = new SystemMessagesInfo();
+ systemMessagesInfo.setLocale(locale);
+ systemMessagesInfo.setService(this);
+ systemMessagesInfo.setRequest(request);
+ return getSystemMessagesProvider()
+ .getSystemMessages(systemMessagesInfo);
}
/**
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java
index 48e5304cc7..2ef9550823 100644
--- a/server/src/com/vaadin/server/VaadinServlet.java
+++ b/server/src/com/vaadin/server/VaadinServlet.java
@@ -418,7 +418,8 @@ public class VaadinServlet extends HttpServlet implements Constants {
if (request.getRequestedSessionId() == null) {
// User has cookies disabled
SystemMessages systemMessages = getService().getSystemMessages(
- ServletPortletHelper.findLocale(null, null, request));
+ ServletPortletHelper.findLocale(null, null, request),
+ request);
criticalNotification(request, response,
systemMessages.getCookiesDisabledCaption(),
systemMessages.getCookiesDisabledMessage(), null,
@@ -576,7 +577,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
if (getRequestType(request) == RequestType.UIDL) {
SystemMessages ci = getService().getSystemMessages(
ServletPortletHelper.findLocale(null, vaadinSession,
- request));
+ request), request);
criticalNotification(request, response,
ci.getInternalErrorCaption(), ci.getInternalErrorMessage(),
null, ci.getInternalErrorURL());
@@ -652,7 +653,8 @@ public class VaadinServlet extends HttpServlet implements Constants {
try {
SystemMessages ci = getService().getSystemMessages(
- ServletPortletHelper.findLocale(null, null, request));
+ ServletPortletHelper.findLocale(null, null, request),
+ request);
RequestType requestType = getRequestType(request);
if (requestType == RequestType.UIDL) {
/*
@@ -702,7 +704,7 @@ public class VaadinServlet extends HttpServlet implements Constants {
* this case so just use the info provided in the request.
*/
SystemMessages ci = getService().getSystemMessages(
- request.getLocale());
+ request.getLocale(), request);
RequestType requestType = getRequestType(request);
if (requestType == RequestType.UIDL) {
// send uidl redirect