diff --git a/src/de/schildbach/pte/AbstractHafasProvider.java b/src/de/schildbach/pte/AbstractHafasProvider.java
index 69c3e422..2b0f266e 100644
--- a/src/de/schildbach/pte/AbstractHafasProvider.java
+++ b/src/de/schildbach/pte/AbstractHafasProvider.java
@@ -1204,6 +1204,14 @@ public abstract class AbstractHafasProvider implements NetworkProvider
return 'R';
if ("ARZ".equals(ucType)) // Auto-Reisezug Brig - Iselle di Trasquera
return 'R';
+ if ("OE".equals(ucType)) // Ostdeutsche Eisenbahn
+ return 'R';
+ if ("MR".equals(ucType)) // Märkische Regionalbahn
+ return 'R';
+ if ("PE".equals(ucType)) // Prignitzer Eisenbahn GmbH
+ return 'R';
+ if ("NE".equals(ucType)) // NEB Betriebsgesellschaft mbH
+ return 'R';
// Suburban Trains
if (ucType.equals("S")) // Generic S-Bahn
@@ -1240,12 +1248,14 @@ public abstract class AbstractHafasProvider implements NetworkProvider
return 'B';
// Ferry
+ if ("SCHIFF".equals(ucType))
+ return 'F';
+ if ("FÄHRE".equals(ucType))
+ return 'F';
if (ucType.equals("SCH")) // Schiff
return 'F';
if (ucType.equals("AS")) // SyltShuttle, eigentlich Autoreisezug
return 'F';
- if ("SCHIFF".equals(ucType))
- return 'F';
if ("KAT".equals(ucType)) // Katamaran
return 'F';
diff --git a/src/de/schildbach/pte/NetworkId.java b/src/de/schildbach/pte/NetworkId.java
index a2d05c11..de77b2ff 100644
--- a/src/de/schildbach/pte/NetworkId.java
+++ b/src/de/schildbach/pte/NetworkId.java
@@ -23,7 +23,7 @@ package de.schildbach.pte;
public enum NetworkId
{
// Germany
- DB, BVG, RMV, VRT, MVV, INVG, AVV, VMV, SH, GVH, BSVAG, BSAG, NASA, VVO, VMS, VGS, VRR, MVG, VRN, VVS, NALDO, DING, KVV, VVM, VAGFR, NVBW,
+ DB, BVG, VBB, RMV, VRT, MVV, INVG, AVV, VMV, SH, GVH, BSVAG, BSAG, NASA, VVO, VMS, VGS, VRR, MVG, VRN, VVS, NALDO, DING, KVV, VVM, VAGFR, NVBW,
// Austria
OEBB, VOR, LINZ, SVV, VVV, IVB, STV,
diff --git a/src/de/schildbach/pte/VbbProvider.java b/src/de/schildbach/pte/VbbProvider.java
new file mode 100644
index 00000000..b98f631b
--- /dev/null
+++ b/src/de/schildbach/pte/VbbProvider.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2010, 2011 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.io.IOException;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import de.schildbach.pte.dto.Location;
+import de.schildbach.pte.dto.LocationType;
+import de.schildbach.pte.dto.NearbyStationsResult;
+import de.schildbach.pte.dto.QueryDeparturesResult;
+import de.schildbach.pte.util.ParserUtils;
+
+/**
+ * @author Andreas Schildbach
+ */
+public class VbbProvider extends AbstractHafasProvider
+{
+ public static final NetworkId NETWORK_ID = NetworkId.VBB;
+ private static final String API_BASE = "http://www.vbb-fahrinfo.de/hafas/";
+
+ public VbbProvider()
+ {
+ super(API_BASE + "query.exe/dn", 7, null);
+ }
+
+ public NetworkId id()
+ {
+ return NETWORK_ID;
+ }
+
+ public boolean hasCapabilities(final Capability... capabilities)
+ {
+ for (final Capability capability : capabilities)
+ if (capability == Capability.DEPARTURES || capability == Capability.AUTOCOMPLETE_ONE_LINE || capability == Capability.CONNECTIONS)
+ return true;
+
+ return false;
+ }
+
+ private static final Pattern P_SPLIT_NAME_PAREN = Pattern.compile("(.*?) \\((.{4,}?)\\)(?: \\((U|S|S\\+U)\\))?");
+ private static final Pattern P_SPLIT_NAME_COMMA = Pattern.compile("([^,]*), ([^,]*)");
+
+ @Override
+ protected String[] splitNameAndPlace(final String name)
+ {
+ final Matcher mParen = P_SPLIT_NAME_PAREN.matcher(name);
+ if (mParen.matches())
+ {
+ final String su = mParen.group(3);
+ return new String[] { mParen.group(2), mParen.group(1) + (su != null ? " (" + su + ")" : "") };
+ }
+
+ final Matcher mComma = P_SPLIT_NAME_COMMA.matcher(name);
+ if (mComma.matches())
+ return new String[] { mComma.group(1), mComma.group(2) };
+
+ return super.splitNameAndPlace(name);
+ }
+
+ private static final String AUTOCOMPLETE_URI = API_BASE + "ajax-getstop.exe/dn?getstop=1&REQ0JourneyStopsS0A=255&S=%s?&js=true&";
+ private static final String ENCODING = "ISO-8859-1";
+
+ public List autocompleteStations(final CharSequence constraint) throws IOException
+ {
+ final String uri = String.format(AUTOCOMPLETE_URI, ParserUtils.urlEncode(constraint.toString(), ENCODING));
+
+ return jsonGetStops(uri);
+ }
+
+ public NearbyStationsResult queryNearbyStations(final Location location, final int maxDistance, final int maxStations) throws IOException
+ {
+ final StringBuilder uri = new StringBuilder(API_BASE);
+
+ if (location.hasLocation())
+ {
+ uri.append("query.exe/dny");
+ uri.append("?performLocating=2&tpl=stop2json");
+ uri.append("&look_maxno=").append(maxStations != 0 ? maxStations : 200);
+ uri.append("&look_maxdist=").append(maxDistance != 0 ? maxDistance : 5000);
+ uri.append("&look_stopclass=").append(allProductsInt());
+ uri.append("&look_x=").append(location.lon);
+ uri.append("&look_y=").append(location.lat);
+
+ return jsonNearbyStations(uri.toString());
+ }
+ else if (location.type == LocationType.STATION && location.hasId())
+ {
+ uri.append("stboard.exe/dn");
+ uri.append("?productsFilter=").append(allProductsString());
+ uri.append("&boardType=dep");
+ uri.append("&input=").append(location.id);
+ uri.append("&sTI=1&start=yes&hcount=0");
+ uri.append("&L=vs_java3");
+
+ return xmlNearbyStations(uri.toString());
+ }
+ else
+ {
+ throw new IllegalArgumentException("cannot handle: '" + location.toDebugString());
+ }
+ }
+
+ private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)");
+
+ @Override
+ protected String normalizeLine(final String line)
+ {
+ final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(line);
+ if (m.matches())
+ {
+ final String number = m.group(1).replaceAll("\\s+", " ");
+ final String type = m.group(2);
+
+ final char normalizedType = normalizeType(type);
+ if (normalizedType != 0)
+ return normalizedType + number;
+
+ throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line " + line);
+ }
+
+ throw new IllegalStateException("cannot normalize line " + line);
+ }
+
+ @Override
+ protected char normalizeType(final String type)
+ {
+ final String ucType = type.toUpperCase();
+
+ if ("D".equals(ucType)) // DB Regio AG, e.g. Berlin - Prag
+ return 'I';
+
+ final char t = normalizeCommonTypes(ucType);
+ if (t != 0)
+ return t;
+
+ return 0;
+ }
+
+ public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
+ {
+ final StringBuilder uri = new StringBuilder();
+ uri.append(API_BASE).append("stboard.exe/dn");
+ uri.append("?productsFilter=").append(allProductsString());
+ uri.append("&boardType=dep");
+ uri.append("&disableEquivs=").append(equivs ? "no" : "yes"); // don't use nearby stations
+ uri.append("&maxJourneys=50"); // ignore maxDepartures because result contains other stations
+ uri.append("&start=yes");
+ uri.append("&L=vs_java3");
+ uri.append("&input=").append(stationId);
+
+ return xmlQueryDepartures(uri.toString(), stationId);
+ }
+}
diff --git a/test/de/schildbach/pte/live/VbbProviderLiveTest.java b/test/de/schildbach/pte/live/VbbProviderLiveTest.java
new file mode 100644
index 00000000..07170d15
--- /dev/null
+++ b/test/de/schildbach/pte/live/VbbProviderLiveTest.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2010, 2011 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 java.util.Date;
+import java.util.List;
+
+import org.junit.Test;
+
+import de.schildbach.pte.NetworkProvider.WalkSpeed;
+import de.schildbach.pte.VbbProvider;
+import de.schildbach.pte.dto.Location;
+import de.schildbach.pte.dto.LocationType;
+import de.schildbach.pte.dto.NearbyStationsResult;
+import de.schildbach.pte.dto.QueryConnectionsResult;
+import de.schildbach.pte.dto.QueryDeparturesResult;
+
+/**
+ * @author Andreas Schildbach
+ */
+public class VbbProviderLiveTest
+{
+ private VbbProvider provider = new VbbProvider();
+ private static final String ALL_PRODUCTS = "IRSUTBFC";
+
+ @Test
+ public void nearbyStations() throws Exception
+ {
+ final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.STATION, 9007102), 0, 0);
+
+ System.out.println(result.stations.size() + " " + result.stations);
+ }
+
+ @Test
+ public void nearbyStationsByCoordinate() throws Exception
+ {
+ final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.ADDRESS, 52548505, 1338864), 0, 0);
+
+ System.out.println(result.stations.size() + " " + result.stations);
+ }
+
+ @Test
+ public void queryDepartures() throws Exception
+ {
+ final QueryDeparturesResult result = provider.queryDepartures(9007102, 0, false);
+
+ System.out.println(result.stationDepartures);
+ }
+
+ @Test
+ public void autocompleteIncomplete() throws Exception
+ {
+ final List autocompletes = provider.autocompleteStations("nol");
+
+ list(autocompletes);
+ }
+
+ private void list(final List autocompletes)
+ {
+ System.out.print(autocompletes.size() + " ");
+ for (final Location autocomplete : autocompletes)
+ System.out.print(autocomplete.toDebugString() + " ");
+ System.out.println();
+ }
+
+ @Test
+ public void shortConnection() throws Exception
+ {
+ final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 9056102, "Berlin", "Nollendorfplatz"),
+ null, new Location(LocationType.STATION, 9013103, "Berlin", "Prinzenstraße"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
+ System.out.println(result);
+ final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
+ System.out.println(moreResult);
+ }
+
+ @Test
+ public void shortViaConnection() throws Exception
+ {
+ final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 9056102, "Berlin", "Nollendorfplatz"),
+ new Location(LocationType.STATION, 9044202, "Berlin", "Bundesplatz"), new Location(LocationType.STATION, 9013103, "Berlin",
+ "Prinzenstraße"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
+ System.out.println(result);
+ final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
+ System.out.println(moreResult);
+ }
+
+ @Test
+ public void connectionBetweenCoordinates() throws Exception
+ {
+ final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 52501507, 13357026, null, null), null,
+ new Location(LocationType.ADDRESS, 0, 52513639, 13568648, null, null), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
+ System.out.println(result);
+ final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
+ System.out.println(moreResult);
+ }
+
+ @Test
+ public void viaConnectionBetweenCoordinates() throws Exception
+ {
+ final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 52501507, 13357026, null, null),
+ new Location(LocationType.ADDRESS, 0, 52479868, 13324247, null, null), new Location(LocationType.ADDRESS, 0, 52513639, 13568648,
+ null, null), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
+ System.out.println(result);
+ final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
+ System.out.println(moreResult);
+ }
+
+ @Test
+ public void connectionBetweenAddresses() throws Exception
+ {
+ final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null,
+ "10715 Bln Charlb.-Wilm., Weimarische Str. 7"), null, new Location(LocationType.ADDRESS, 0, null, "10178 Bln Mitte, Sophienstr. 24"),
+ new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
+ System.out.println(result);
+ final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
+ System.out.println(moreResult);
+ }
+
+ @Test
+ public void viaConnectionBetweenAddresses() throws Exception
+ {
+ final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null,
+ "10715 Bln Charlb.-Wilm., Weimarische Str. 7"), new Location(LocationType.ADDRESS, 0, null, "10115 Bln Mitte, Hannoversche Str. 20"),
+ new Location(LocationType.ADDRESS, 0, null, "10178 Bln Mitte, Sophienstr. 24"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
+ System.out.println(result);
+ final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
+ System.out.println(moreResult);
+ }
+}