mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-06 19:12:23 +00:00
choose complicated approach for encoding URLs, as tycho doesn't allow com.google.gwt references in common bundles
This commit is contained in:
1 parent
523ad4cc3e
commit
52fa52efce
9 files changed
+69
-43
No files matched your search
+5
-5
@@ -1,7 +1,7 @@
|
||||
package com.sap.sailing.domain.common.racelog.tracking;
|
||||
|
||||
import com.sap.sailing.domain.common.racelog.RaceLogServletConstants;
|
||||
import com.sap.sse.common.URLEncoder;
|
||||
import com.sap.sse.common.util.UrlHelper;
|
||||
|
||||
/**
|
||||
* Shared between GWT and Android. Used for creating and deciphering the URL encoded by the QRCode, which gives the
|
||||
@@ -42,8 +42,8 @@ public class DeviceMappingConstants {
|
||||
static final String APK_PATH = "/apps/com.sap.sailing.android.tracking.app.apk";
|
||||
|
||||
public static String getDeviceMappingForRegattaLogUrl(String serverUrlWithoutTrailingSlash, String eventId,
|
||||
String leaderboardName, String mappedItemType, String mappedItemId) {
|
||||
return URLEncoder.encode(serverUrlWithoutTrailingSlash + URL_BASE + "?" + URL_EVENT_ID + "=" + eventId + "&"
|
||||
String leaderboardName, String mappedItemType, String mappedItemId, UrlHelper helper) {
|
||||
return helper.encodeUrl(serverUrlWithoutTrailingSlash + URL_BASE + "?" + URL_EVENT_ID + "=" + eventId + "&"
|
||||
+ URL_LEADERBOARD_NAME + "=" + leaderboardName + "&" + mappedItemType + "="
|
||||
+ mappedItemId);
|
||||
}
|
||||
@@ -51,11 +51,11 @@ public class DeviceMappingConstants {
|
||||
@Deprecated
|
||||
public static String getDeviceMappingForRaceLogUrl(String serverUrlWithoutTrailingSlash, String leaderboardName,
|
||||
String raceColumnName, String fleetName, String mappedItemType, String mappedItemId, long fromMillis,
|
||||
long toMillis) throws QRCodeURLCreationException {
|
||||
long toMillis, UrlHelper helper) throws QRCodeURLCreationException {
|
||||
if (fromMillis > toMillis) {
|
||||
throw new QRCodeURLCreationException("from can't lie after to");
|
||||
}
|
||||
return URLEncoder.encode(serverUrlWithoutTrailingSlash + DeviceMappingConstants.APK_PATH + "?"
|
||||
return helper.encodeUrl(serverUrlWithoutTrailingSlash + DeviceMappingConstants.APK_PATH + "?"
|
||||
+ RaceLogServletConstants.PARAMS_LEADERBOARD_NAME + "=" + leaderboardName + "&"
|
||||
+ RaceLogServletConstants.PARAMS_RACE_COLUMN_NAME + "=" + raceColumnName + "&"
|
||||
+ RaceLogServletConstants.PARAMS_RACE_FLEET_NAME + "=" + fleetName + "&" + mappedItemType + "="
|
||||
|
||||
+2
-1
@@ -80,6 +80,7 @@ import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
import com.sap.sse.common.mail.MailException;
|
||||
import com.sap.sse.common.qrcode.QRCodeGenerationUtil;
|
||||
import com.sap.sse.mail.MailService;
|
||||
import com.sap.sse.util.impl.NonGwtUrlHelper;
|
||||
|
||||
public class RaceLogTrackingAdapterImpl implements RaceLogTrackingAdapter {
|
||||
private static final Logger logger = Logger.getLogger(RaceLogTrackingAdapterImpl.class.getName());
|
||||
@@ -368,7 +369,7 @@ public class RaceLogTrackingAdapterImpl implements RaceLogTrackingAdapter {
|
||||
|
||||
String url = DeviceMappingConstants.getDeviceMappingForRegattaLogUrl(serverUrlWithoutTrailingSlash,
|
||||
event.getId().toString(), leaderboardName, DeviceMappingConstants.URL_COMPETITOR_ID_AS_STRING,
|
||||
competitor.getId().toString());
|
||||
competitor.getId().toString(), NonGwtUrlHelper.INSTANCE);
|
||||
String subject = String.format("%s %s",
|
||||
RaceLogTrackingI18n.STRING_MESSAGES.get(locale, "trackingInvitationFor"), competitorName);
|
||||
|
||||
|
||||
+3
-1
@@ -22,6 +22,7 @@ import com.sap.sailing.domain.common.racelog.tracking.DeviceMappingConstants;
|
||||
import com.sap.sailing.domain.common.racelog.tracking.MappableToDevice;
|
||||
import com.sap.sailing.domain.common.racelog.tracking.QRCodeURLCreationException;
|
||||
import com.sap.sailing.gwt.ui.adminconsole.ItemToMapToDeviceSelectionPanel.SelectionChangedHandler;
|
||||
import com.sap.sailing.gwt.ui.client.GwtUrlHelper;
|
||||
import com.sap.sailing.gwt.ui.client.SailingServiceAsync;
|
||||
import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
import com.sap.sailing.gwt.ui.shared.BetterDateTimeBox;
|
||||
@@ -149,7 +150,8 @@ public class AddDeviceMappingToRaceLogDialog extends DataEntryDialog<DeviceMappi
|
||||
throw new QRCodeURLCreationException("from can't lie after to");
|
||||
}
|
||||
return DeviceMappingConstants.getDeviceMappingForRaceLogUrl(baseUrlWithoutTrailingSlash,
|
||||
leaderboardName, raceColumnName, fleetName, mappedItemType, mappedItemId, fromMillis, toMillis);
|
||||
leaderboardName, raceColumnName, fleetName, mappedItemType, mappedItemId, fromMillis, toMillis,
|
||||
GwtUrlHelper.INSTANCE);
|
||||
}
|
||||
});
|
||||
qrWidget.generateQRCode();
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@ import com.sap.sailing.domain.common.dto.CompetitorDTO;
|
||||
import com.sap.sailing.domain.common.racelog.tracking.DeviceMappingConstants;
|
||||
import com.sap.sailing.domain.common.racelog.tracking.QRCodeURLCreationException;
|
||||
import com.sap.sailing.gwt.ui.adminconsole.ItemToMapToDeviceSelectionPanel.SelectionChangedHandler;
|
||||
import com.sap.sailing.gwt.ui.client.GwtUrlHelper;
|
||||
import com.sap.sailing.gwt.ui.client.SailingServiceAsync;
|
||||
import com.sap.sailing.gwt.ui.client.StringMessages;
|
||||
import com.sap.sailing.gwt.ui.shared.EventDTO;
|
||||
@@ -98,7 +99,7 @@ public class AddDeviceMappingToRegattaLogDialog extends AbstractCancelableDialog
|
||||
}
|
||||
String eventIdAsString = events.getValue().id.toString();
|
||||
return DeviceMappingConstants.getDeviceMappingForRegattaLogUrl(baseUrlWithoutTrailingSlash, eventIdAsString,
|
||||
leaderboardName, mappedItemType, mappedItemId);
|
||||
leaderboardName, mappedItemType, mappedItemId, GwtUrlHelper.INSTANCE);
|
||||
}
|
||||
});
|
||||
qrWidget.generateQRCode();
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.sap.sailing.gwt.ui.client;
|
||||
|
||||
import com.google.gwt.core.shared.GWT;
|
||||
import com.google.gwt.http.client.URL;
|
||||
import com.sap.sse.common.util.UrlHelper;
|
||||
|
||||
/**
|
||||
* Tycho complains that {@link com.google.gwt} cannot be resolved when placing this in *common projects, where it would ideally
|
||||
* go (then we could also auto-determine if GWT context is present, e.g. through {@link GWT#isClient}).
|
||||
*
|
||||
* @author Fredrik Teschke
|
||||
*
|
||||
*/
|
||||
public enum GwtUrlHelper implements UrlHelper {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public String encodeUrl(String decodedUrlString) {
|
||||
return URL.encode(decodedUrlString);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,10 +8,11 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Export-Package: com.sap.sse.common,
|
||||
com.sap.sse.common.filter,
|
||||
com.sap.sse.common.impl,
|
||||
com.sap.sse.common.qrcode,
|
||||
com.sap.sse.common.mail,
|
||||
com.sap.sse.common.qrcode,
|
||||
com.sap.sse.common.scalablevalue,
|
||||
com.sap.sse.common.search
|
||||
com.sap.sse.common.search,
|
||||
com.sap.sse.common.util
|
||||
Require-Bundle: com.sap.sse.datamining.shared;bundle-version="1.0.0",
|
||||
org.apache.servicemix.bundles.zxing;bundle-version="3.1.0"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.sap.sse.common;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
public class URLEncoder {
|
||||
/**
|
||||
* Use different encoding strategies, depending on whether running in GWT or server context.
|
||||
*/
|
||||
public static String encode(String decodedUrlString) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName("com.google.gwt.http.client.URL");
|
||||
// GWT context
|
||||
return (String) clazz.getMethod("encode", String.class).invoke(/* object */null, decodedUrlString);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// non-GWT context (URL/URI should be fully available)
|
||||
try {
|
||||
URL url = new URL(decodedUrlString);
|
||||
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
|
||||
url.getQuery(), url.getRef());
|
||||
return uri.toString();
|
||||
} catch (MalformedURLException | URISyntaxException f) {
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
|
||||
| SecurityException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.sap.sse.common.util;
|
||||
|
||||
/**
|
||||
* Context-independent interface for dealing with URLs.
|
||||
* GWT context does not offer full implementations of URL/URI. *
|
||||
*/
|
||||
public interface UrlHelper {
|
||||
String encodeUrl(String decodedUrlString);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.sap.sse.util.impl;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import com.sap.sse.common.util.UrlHelper;
|
||||
|
||||
public enum NonGwtUrlHelper implements UrlHelper {
|
||||
INSTANCE;
|
||||
|
||||
public String encodeUrl(String decodedUrlString) {
|
||||
try {
|
||||
URL url = new URL(decodedUrlString);
|
||||
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(),
|
||||
url.getQuery(), url.getRef());
|
||||
return uri.toString();
|
||||
} catch (MalformedURLException | URISyntaxException f) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user