diff --git a/enabler/src/de/schildbach/pte/NetworkId.java b/enabler/src/de/schildbach/pte/NetworkId.java
index a4a706e9..f41f3bfc 100644
--- a/enabler/src/de/schildbach/pte/NetworkId.java
+++ b/enabler/src/de/schildbach/pte/NetworkId.java
@@ -26,7 +26,7 @@ public enum NetworkId
RT,
// Germany
- DB, BVG, VBB, NVV, BAYERN, MVV, INVG, AVV, VGN, VVM, VMV, HVV, SH, GVH, VSN, BSVAG, VBN, NASA, VVO, VMS, VGS, VRR, VRS, MVG, NPH, VRN, VRT, VVS, NALDO, DING, KVV, VAGFR, NVBW, VVV,
+ DB, BVG, VBB, NVV, BAYERN, MVV, INVG, AVV, VGN, VVM, VMV, RSAG, HVV, SH, GVH, VSN, BSVAG, VBN, NASA, VVO, VMS, VGS, VRR, VRS, MVG, NPH, VRN, VRT, VVS, NALDO, DING, KVV, VAGFR, NVBW, VVV,
// Austria
OEBB, VOR, WIEN, LINZ, SVV, VVT, VMOBIL, IVB, STV,
diff --git a/enabler/src/de/schildbach/pte/RsagProvider.java b/enabler/src/de/schildbach/pte/RsagProvider.java
new file mode 100644
index 00000000..8eb8684d
--- /dev/null
+++ b/enabler/src/de/schildbach/pte/RsagProvider.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package de.schildbach.pte;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import de.schildbach.pte.dto.Product;
+import de.schildbach.pte.dto.Style;
+import de.schildbach.pte.dto.Style.Shape;
+
+/**
+ * @author Andreas Schildbach
+ */
+public class RsagProvider extends AbstractHafasProvider
+{
+ public static final NetworkId NETWORK_ID = NetworkId.RSAG;
+ private static final String API_BASE = "http://fahrplan.rsag-online.de/hafas/";
+
+ public RsagProvider()
+ {
+ super(API_BASE + "stboard.exe/dn", API_BASE + "ajax-getstop.exe/dn", API_BASE + "query.exe/dn", 10, UTF_8);
+
+ setStyles(STYLES);
+ }
+
+ public NetworkId id()
+ {
+ return NETWORK_ID;
+ }
+
+ public boolean hasCapabilities(final Capability... capabilities)
+ {
+ for (final Capability capability : capabilities)
+ if (capability == Capability.SUGGEST_LOCATIONS || capability == Capability.DEPARTURES || capability == Capability.TRIPS)
+ return true;
+
+ return false;
+ }
+
+ @Override
+ protected char intToProduct(final int value)
+ {
+ if (value == 1)
+ return 'I';
+ if (value == 2)
+ return 'I';
+ if (value == 4)
+ return 'I';
+ if (value == 8)
+ return 'R';
+ if (value == 16)
+ return 'S';
+ if (value == 32)
+ return 'B';
+ if (value == 64)
+ return 'F';
+ if (value == 128)
+ return 'U';
+ if (value == 256)
+ return 'T';
+ if (value == 512)
+ return 'P';
+
+ throw new IllegalArgumentException("cannot handle: " + value);
+ }
+
+ @Override
+ protected void setProductBits(final StringBuilder productBits, final Product product)
+ {
+ if (product == Product.HIGH_SPEED_TRAIN)
+ {
+ productBits.setCharAt(0, '1'); // ICE, TGV, Thalys, etc.
+ productBits.setCharAt(1, '1'); // IC/EC
+ productBits.setCharAt(2, '1'); // sonstiger Schnellzug
+ }
+ else if (product == Product.REGIONAL_TRAIN)
+ {
+ productBits.setCharAt(3, '1'); // Regionalzug
+ }
+ else if (product == Product.SUBURBAN_TRAIN)
+ {
+ productBits.setCharAt(4, '1'); // S-Bahn
+ }
+ else if (product == Product.SUBWAY)
+ {
+ productBits.setCharAt(7, '1'); // U-Bahn
+ }
+ else if (product == Product.TRAM)
+ {
+ productBits.setCharAt(8, '1'); // Straßenbahn
+ }
+ else if (product == Product.BUS)
+ {
+ productBits.setCharAt(5, '1'); // Bus
+ }
+ else if (product == Product.ON_DEMAND)
+ {
+ productBits.setCharAt(9, '1'); // Anrufverkehre
+ }
+ else if (product == Product.FERRY)
+ {
+ productBits.setCharAt(6, '1'); // Fähre
+ }
+ else if (product == Product.CABLECAR)
+ {
+ }
+ else
+ {
+ throw new IllegalArgumentException("cannot handle: " + product);
+ }
+ }
+
+ private static final String[] PLACES = { "Rostock", "Warnemünde" };
+
+ @Override
+ protected String[] splitPlaceAndName(final String name)
+ {
+ for (final String place : PLACES)
+ {
+ if (name.startsWith(place + " ") || name.startsWith(place + "-"))
+ return new String[] { place, name.substring(place.length() + 1) };
+ }
+
+ return super.splitPlaceAndName(name);
+ }
+
+ @Override
+ public Collection defaultProducts()
+ {
+ return Product.ALL;
+ }
+
+ @Override
+ protected void appendJsonGetStopsParameters(final StringBuilder uri, final CharSequence constraint, final int maxStops)
+ {
+ super.appendJsonGetStopsParameters(uri, constraint, maxStops);
+
+ uri.append("&REQ0JourneyStopsS0B=5");
+ uri.append("&REQ0JourneyStopsS0F=distinguishPerimeterFilter;12140548;54126457;50");
+ }
+
+ private static final Map STYLES = new HashMap();
+
+ static
+ {
+ // Rostock
+ STYLES.put("SS1", new Style(Shape.CIRCLE, Style.parseColor("#108449"), Style.WHITE));
+ STYLES.put("SS2", new Style(Shape.CIRCLE, Style.parseColor("#66a933"), Style.WHITE));
+ STYLES.put("SS3", new Style(Shape.CIRCLE, Style.parseColor("#00a063"), Style.WHITE));
+
+ STYLES.put("T1", new Style(Shape.RECT, Style.parseColor("#712090"), Style.WHITE));
+ STYLES.put("T2", new Style(Shape.RECT, Style.parseColor("#d136a3"), Style.WHITE));
+ STYLES.put("T3", new Style(Shape.RECT, Style.parseColor("#870e12"), Style.WHITE));
+ STYLES.put("T4", new Style(Shape.RECT, Style.parseColor("#f47216"), Style.WHITE));
+ STYLES.put("T5", new Style(Shape.RECT, Style.parseColor("#ed1c24"), Style.WHITE));
+ STYLES.put("T6", new Style(Shape.RECT, Style.parseColor("#fab20b"), Style.WHITE));
+
+ STYLES.put("B15", new Style(Style.parseColor("#008dc6"), Style.WHITE));
+ STYLES.put("B16", new Style(Style.parseColor("#1d3c85"), Style.WHITE));
+ STYLES.put("B17", new Style(Style.parseColor("#5784cc"), Style.WHITE));
+ STYLES.put("B18", new Style(Style.parseColor("#0887c9"), Style.WHITE));
+ STYLES.put("B19", new Style(Style.parseColor("#202267"), Style.WHITE));
+ STYLES.put("PALT19A", new Style(Style.WHITE, Style.parseColor("#202267")));
+ STYLES.put("PALT20A", new Style(Style.WHITE, Style.parseColor("#1959a6")));
+ STYLES.put("B22", new Style(Style.parseColor("#3871c1"), Style.WHITE));
+ STYLES.put("B23", new Style(Style.parseColor("#009ddb"), Style.WHITE));
+ STYLES.put("B25", new Style(Style.parseColor("#0994dc"), Style.WHITE));
+ STYLES.put("B26", new Style(Style.parseColor("#0994dc"), Style.WHITE));
+ STYLES.put("B27", new Style(Style.parseColor("#6e87cd"), Style.WHITE));
+ STYLES.put("B28", new Style(Style.parseColor("#4fc6f4"), Style.WHITE));
+ STYLES.put("PALT30A", new Style(Style.WHITE, Style.parseColor("#1082ce")));
+ STYLES.put("B31", new Style(Style.parseColor("#3a9fdf"), Style.WHITE));
+ STYLES.put("B33", new Style(Style.parseColor("#21518d"), Style.WHITE));
+ STYLES.put("B35", new Style(Style.parseColor("#1969bc"), Style.WHITE));
+ STYLES.put("PALT35A", new Style(Style.WHITE, Style.parseColor("#1969bc")));
+ STYLES.put("B36", new Style(Style.parseColor("#2c6d8b"), Style.WHITE));
+ STYLES.put("B37", new Style(Style.parseColor("#36aee8"), Style.WHITE));
+ STYLES.put("B38", new Style(Style.parseColor("#173e7d"), Style.WHITE));
+ STYLES.put("B45", new Style(Style.parseColor("#66cef5"), Style.WHITE));
+ STYLES.put("PALT45A", new Style(Style.WHITE, Style.parseColor("#66cef5")));
+ STYLES.put("B49", new Style(Style.parseColor("#166ab8"), Style.WHITE));
+ STYLES.put("BF1", new Style(Style.parseColor("#656263"), Style.WHITE));
+ STYLES.put("PALTF1A", new Style(Style.WHITE, Style.parseColor("#656263")));
+ STYLES.put("BF2", new Style(Style.parseColor("#9c9a9b"), Style.WHITE));
+
+ STYLES.put("F", new Style(Shape.CIRCLE, Style.parseColor("#00adef"), Style.WHITE));
+ }
+}
diff --git a/enabler/test/de/schildbach/pte/live/RsagProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/RsagProviderLiveTest.java
new file mode 100644
index 00000000..4cfc233d
--- /dev/null
+++ b/enabler/test/de/schildbach/pte/live/RsagProviderLiveTest.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package de.schildbach.pte.live;
+
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import java.util.Date;
+
+import org.junit.Test;
+
+import de.schildbach.pte.NetworkProvider.Accessibility;
+import de.schildbach.pte.NetworkProvider.WalkSpeed;
+import de.schildbach.pte.RsagProvider;
+import de.schildbach.pte.dto.Location;
+import de.schildbach.pte.dto.LocationType;
+import de.schildbach.pte.dto.NearbyStationsResult;
+import de.schildbach.pte.dto.Product;
+import de.schildbach.pte.dto.QueryDeparturesResult;
+import de.schildbach.pte.dto.QueryTripsResult;
+import de.schildbach.pte.dto.SuggestLocationsResult;
+
+/**
+ * @author Andreas Schildbach
+ */
+public class RsagProviderLiveTest extends AbstractProviderLiveTest
+{
+ public RsagProviderLiveTest()
+ {
+ super(new RsagProvider());
+ }
+
+ @Test
+ public void nearbyStations() throws Exception
+ {
+ final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.STATION, "8010304"), 0, 0);
+
+ print(result);
+ }
+
+ @Test
+ public void nearbyStationsByCoordinate() throws Exception
+ {
+ final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.ADDRESS, 54078314, 12131715), 0, 0);
+
+ print(result);
+ }
+
+ @Test
+ public void queryDepartures() throws Exception
+ {
+ final QueryDeparturesResult result = provider.queryDepartures("8010304", 0, false);
+
+ print(result);
+ }
+
+ @Test
+ public void queryDeparturesInvalidStation() throws Exception
+ {
+ final QueryDeparturesResult result = provider.queryDepartures("999999", 0, false);
+
+ assertEquals(QueryDeparturesResult.Status.INVALID_STATION, result.status);
+ }
+
+ @Test
+ public void suggestLocations() throws Exception
+ {
+ final SuggestLocationsResult result = provider.suggestLocations("Rostock");
+
+ print(result);
+ }
+
+ @Test
+ public void suggestLocationsUmlaut() throws Exception
+ {
+ final SuggestLocationsResult result = provider.suggestLocations("Lütten Klein");
+
+ print(result);
+
+ assertEquals("Lütten Klein", result.getLocations().get(0).name);
+ }
+
+ @Test
+ public void suggestLocationsCoverage() throws Exception
+ {
+ final SuggestLocationsResult rostockResult = provider.suggestLocations("Rostock");
+ print(rostockResult);
+ assertThat(rostockResult.getLocations(), hasItem(new Location(LocationType.STATION, "8010304")));
+
+ final SuggestLocationsResult warnemuendeResult = provider.suggestLocations("Warnemünde");
+ print(warnemuendeResult);
+ assertThat(warnemuendeResult.getLocations(), hasItem(new Location(LocationType.STATION, "8013236")));
+ }
+
+ @Test
+ public void suggestLocationsLocality() throws Exception
+ {
+ final SuggestLocationsResult result = provider.suggestLocations("lange");
+ assertEquals("Rostock", result.getLocations().get(0).place);
+ assertEquals("Lange Straße", result.getLocations().get(0).name);
+ }
+
+ @Test
+ public void shortTrip() throws Exception
+ {
+ final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "8096109", null, "Oldenburg"), null, new Location(
+ LocationType.STATION, "625398", null, "Bremerhaven"), new Date(), true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
+ assertEquals(QueryTripsResult.Status.OK, result.status);
+ print(result);
+ final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
+ print(laterResult);
+ }
+
+ @Test
+ public void tripDateOutsideTimetablePeriod() throws Exception
+ {
+ final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "8096109", null, "Oldenburg"), null, new Location(
+ LocationType.STATION, "625398", null, "Bremerhaven"), new Date(1155822689759l), true, Product.ALL, WalkSpeed.NORMAL,
+ Accessibility.NEUTRAL);
+ assertEquals(QueryTripsResult.Status.INVALID_DATE, result.status);
+ }
+}