The client locale can be obtained through DispatchContext on the server

side
This commit is contained in:
Steffen Schaefer committed 2015-05-28 14:47:10 +02:00
1 parent 591f0aaf3c
commit 923d3b520f
6 files changed
+39 -7

No files matched your search

@@ -3,6 +3,7 @@ package com.sap.sailing.gwt.home.client.shared.dispatch;
import java.util.Date; import java.util.Date;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.LocaleInfo;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget; import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.sap.sailing.gwt.ui.client.RemoteServiceMappingConstants; import com.sap.sailing.gwt.ui.client.RemoteServiceMappingConstants;
@@ -32,7 +33,7 @@ public class SimpleDispatch implements DispatchAsync {
@Override @Override
public <R extends Result, A extends Action<R>> void execute(A action, final AsyncCallback<R> callback) { public <R extends Result, A extends Action<R>> void execute(A action, final AsyncCallback<R> callback) {
dispatchRPC.execute(new RequestWrapper<R, A>(action), new AsyncCallback<ResultWrapper<R>>() { dispatchRPC.execute(new RequestWrapper<R, A>(action, LocaleInfo.getCurrentLocale().getLocaleName()), new AsyncCallback<ResultWrapper<R>>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
@@ -28,7 +28,7 @@ public class DispatchRPCImpl extends ProxiedRemoteServiceServlet implements Disp
@Override @Override
public <R extends Result, A extends Action<R>> ResultWrapper<R> execute(RequestWrapper<R, A> request) throws DispatchException { public <R extends Result, A extends Action<R>> ResultWrapper<R> execute(RequestWrapper<R, A> request) throws DispatchException {
R executionResult = request.getAction().execute(new DispatchContextImpl(request.getCurrentClientTime(), racingEventServiceTracker.getService())); R executionResult = request.getAction().execute(new DispatchContextImpl(request.getCurrentClientTime(), racingEventServiceTracker.getService(), request.getClientLocaleName()));
return new ResultWrapper<R>(executionResult); return new ResultWrapper<R>(executionResult);
} }
@@ -1,9 +1,18 @@
package com.sap.sailing.gwt.ui.shared.dispatch; package com.sap.sailing.gwt.ui.shared.dispatch;
import java.util.Date;
import java.util.Locale;
import com.sap.sailing.server.RacingEventService; import com.sap.sailing.server.RacingEventService;
public interface DispatchContext { public interface DispatchContext {
RacingEventService getRacingEventService(); RacingEventService getRacingEventService();
String getClientLocaleName();
Locale getClientLocale();
Date getCurrentClientTime();
} }
@@ -1,6 +1,7 @@
package com.sap.sailing.gwt.ui.shared.dispatch; package com.sap.sailing.gwt.ui.shared.dispatch;
import java.util.Date; import java.util.Date;
import java.util.Locale;
import com.sap.sailing.server.RacingEventService; import com.sap.sailing.server.RacingEventService;
@@ -8,11 +9,13 @@ import com.sap.sailing.server.RacingEventService;
public class DispatchContextImpl implements DispatchContext { public class DispatchContextImpl implements DispatchContext {
private final RacingEventService racingEventService; private final RacingEventService racingEventService;
private final Date currentClientTime; private final Date currentClientTime;
private final Date currentServerTime = new Date(); // private final Date currentServerTime = new Date();
private String clientLocaleName;
public DispatchContextImpl(Date currentClientTime, RacingEventService racingEventService) { public DispatchContextImpl(Date currentClientTime, RacingEventService racingEventService, String clientLocaleName) {
this.currentClientTime = currentClientTime; this.currentClientTime = currentClientTime;
this.racingEventService = racingEventService; this.racingEventService = racingEventService;
this.clientLocaleName = clientLocaleName;
} }
@Override @Override
@@ -20,11 +23,22 @@ public class DispatchContextImpl implements DispatchContext {
return racingEventService; return racingEventService;
} }
@Override
public Date getCurrentClientTime() { public Date getCurrentClientTime() {
return currentClientTime; return currentClientTime;
} }
public Date getCurrentServerTime() { // public Date getCurrentServerTime() {
return currentServerTime; // return currentServerTime;
// }
@Override
public String getClientLocaleName() {
return clientLocaleName;
}
@Override
public Locale getClientLocale() {
return Locale.forLanguageTag(clientLocaleName);
} }
} }
@@ -8,15 +8,18 @@ public class RequestWrapper<R extends Result, A extends Action<R>> implements Is
private Date currentClientTime = new Date(); private Date currentClientTime = new Date();
private String clientLocaleName;
private A action; private A action;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private RequestWrapper() { private RequestWrapper() {
} }
public RequestWrapper(A action) { public RequestWrapper(A action, String clientLocaleName) {
super(); super();
this.action = action; this.action = action;
this.clientLocaleName = clientLocaleName;
} }
public A getAction() { public A getAction() {
@@ -26,4 +29,8 @@ public class RequestWrapper<R extends Result, A extends Action<R>> implements Is
public Date getCurrentClientTime() { public Date getCurrentClientTime() {
return currentClientTime; return currentClientTime;
} }
public String getClientLocaleName() {
return clientLocaleName;
}
} }
@@ -52,6 +52,7 @@ public class GetEventOverviewStageAction implements Action<ResultWithTTL<EventOv
Iterable<URL> videoURLs = event.getVideoURLs(); Iterable<URL> videoURLs = event.getVideoURLs();
for (int i = Util.size(videoURLs) - 1; i >= 0; i--) { for (int i = Util.size(videoURLs) - 1; i >= 0; i--) {
// TODO fmittag/pgt: implement locale specific live stream using context.getClientLocaleName() or context.getClientLocale()
String videoUrl = Util.get(videoURLs, i).toString(); String videoUrl = Util.get(videoURLs, i).toString();
MimeType type = MediaUtils.detectMimeTypeFromUrl(videoUrl); MimeType type = MediaUtils.detectMimeTypeFromUrl(videoUrl);
if (type == MimeType.youtube || type == MimeType.vimeo || type == MimeType.mp4) { if (type == MimeType.youtube || type == MimeType.vimeo || type == MimeType.mp4) {