.*?input=(\\d+).*?" // locationId
- + "(?:
|(verkehren an dieser Haltestelle keine))"//
- + "|(Eingabe kann nicht interpretiert)|(Verbindung zum Server konnte leider nicht hergestellt werden|kann vom Server derzeit leider nicht bearbeitet werden))" //
- + ".*?" //
- , Pattern.DOTALL);
- private static final Pattern P_DEPARTURES_HEAD_FINE = Pattern.compile(
- ".*?" //
- + "
(.*?)<.*?" // location
- + "\n(\\d{2}\\.\\d{2}\\.\\d{2}).*?" // date
- + "Abfahrt (\\d{1,2}:\\d{2}).*?" // time
- , Pattern.DOTALL);
- private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("(.*?) ",
- Pattern.DOTALL);
- private static final Pattern P_DEPARTURES_FINE = Pattern.compile(
- ".*?" //
- + " (\\d{1,2}:\\d{2}) \n" // plannedTime
- + "(?:
\n" //
- + "(?: |(pünktlich|\\d{1,2}:\\d{2}) )\n \n" // predictedTime
- + ")?.*?" //
- + "
]*>\\s*(.*?)\\s*\n" //
- + "
]*>" // destinationId
- + "\\s*(.*?)\\s* \n" // destination
- + ".*?" //
- + "(?:
\n(" + ParserUtils.P_PLATFORM + ").*?)?" // position
- , Pattern.DOTALL);
-
- @Override
- public QueryDeparturesResult queryDepartures(final String stationId, final @Nullable Date time,
- final int maxDepartures, final boolean equivs) throws IOException {
- checkNotNull(Strings.emptyToNull(stationId));
-
- final ResultHeader header = new ResultHeader(network, SERVER_PRODUCT);
- final QueryDeparturesResult result = new QueryDeparturesResult(header);
-
- // scrape page
- final HttpUrl.Builder url = stationBoardEndpoint.newBuilder().addPathSegment(apiLanguage);
- appendXmlStationBoardParameters(url, time, stationId, maxDepartures, false, null);
- final CharSequence page = httpClient.get(url.build());
-
- // parse page
- final Matcher mHeadCoarse = P_DEPARTURES_HEAD_COARSE.matcher(page);
- if (mHeadCoarse.matches()) {
- // messages
- if (mHeadCoarse.group(4) != null) {
- result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, stationId),
- Collections. emptyList(), null));
- return result;
- } else if (mHeadCoarse.group(5) != null)
- return new QueryDeparturesResult(header, Status.INVALID_STATION);
- else if (mHeadCoarse.group(6) != null)
- return new QueryDeparturesResult(header, Status.SERVICE_DOWN);
-
- final String locationId = mHeadCoarse.group(2);
-
- final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(mHeadCoarse.group(1));
- if (mHeadFine.matches()) {
- final String[] placeAndName = splitStationName(ParserUtils.resolveEntities(mHeadFine.group(1)));
- final Calendar currentTime = new GregorianCalendar(timeZone);
- currentTime.clear();
- ParserUtils.parseGermanDate(currentTime, mHeadFine.group(2));
- ParserUtils.parseEuropeanTime(currentTime, mHeadFine.group(3));
- final List departures = new ArrayList<>(8);
- String oldZebra = null;
-
- final Matcher mDepCoarse = P_DEPARTURES_COARSE.matcher(mHeadCoarse.group(3));
- while (mDepCoarse.find()) {
- final String zebra = mDepCoarse.group(1);
- if (oldZebra != null && zebra.equals(oldZebra))
- throw new IllegalArgumentException("missed row? last:" + zebra);
- else
- oldZebra = zebra;
-
- final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(2));
- if (mDepFine.matches()) {
- final Calendar plannedTime = new GregorianCalendar(timeZone);
- plannedTime.setTimeInMillis(currentTime.getTimeInMillis());
- ParserUtils.parseEuropeanTime(plannedTime, mDepFine.group(1));
-
- if (plannedTime.getTimeInMillis()
- - currentTime.getTimeInMillis() < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
- plannedTime.add(Calendar.DAY_OF_MONTH, 1);
-
- final Calendar predictedTime;
- final String prognosis = ParserUtils.resolveEntities(mDepFine.group(2));
- if (prognosis != null) {
- predictedTime = new GregorianCalendar(timeZone);
- if (prognosis.equals("pünktlich")) {
- predictedTime.setTimeInMillis(plannedTime.getTimeInMillis());
- } else {
- predictedTime.setTimeInMillis(currentTime.getTimeInMillis());
- ParserUtils.parseEuropeanTime(predictedTime, prognosis);
- }
- } else {
- predictedTime = null;
- }
-
- final String lineType = mDepFine.group(3);
-
- final Line line = parseLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4)), false);
-
- final String destinationId = mDepFine.group(5);
- final String destinationName = ParserUtils.resolveEntities(mDepFine.group(6));
- final Location destination;
- if (destinationId != null) {
- final String[] destinationPlaceAndName = splitStationName(destinationName);
- destination = new Location(LocationType.STATION, destinationId, destinationPlaceAndName[0],
- destinationPlaceAndName[1]);
- } else {
- destination = new Location(LocationType.ANY, null, null, destinationName);
- }
-
- final Position position = parsePosition(ParserUtils.resolveEntities(mDepFine.group(7)));
-
- final Departure dep = new Departure(plannedTime.getTime(),
- predictedTime != null ? predictedTime.getTime() : null, line, position, destination,
- null, null);
-
- if (!departures.contains(dep))
- departures.add(dep);
- } else {
- throw new IllegalArgumentException(
- "cannot parse '" + mDepCoarse.group(2) + "' on " + stationId);
- }
- }
-
- result.stationDepartures.add(new StationDepartures(
- new Location(LocationType.STATION, locationId, placeAndName[0], placeAndName[1]), departures,
- null));
- return result;
- } else {
- throw new IllegalArgumentException("cannot parse '" + mHeadCoarse.group(1) + "' on " + stationId);
- }
- } else {
- throw new IllegalArgumentException("cannot parse '" + page + "' on " + stationId);
- }
- }
-
- @Override
- public QueryTripsResult queryTrips(final Location from, final @Nullable Location via, final Location to,
- final Date date, final boolean dep, final @Nullable Set products,
- final @Nullable Optimize optimize, final @Nullable WalkSpeed walkSpeed,
- final @Nullable Accessibility accessibility, final @Nullable Set options) throws IOException {
- return queryTripsXml(from, via, to, date, dep, products, walkSpeed, accessibility, options);
- }
-
- @Override
- public QueryTripsResult queryMoreTrips(final QueryTripsContext context, final boolean later) throws IOException {
- return queryMoreTripsXml(context, later);
- }
-
- protected static final Pattern P_NORMALIZE_LINE_BUS = Pattern.compile("Bus\\s*(\\d+)");
- protected static final Pattern P_NORMALIZE_LINE_NACHTBUS = Pattern.compile("Bus\\s*N\\s*(\\d+)");
- protected static final Pattern P_NORMALIZE_LINE_BUS_S = Pattern.compile("Bus\\s*S\\s*(\\d+)");
- protected static final Pattern P_NORMALIZE_LINE_BUS_X = Pattern.compile("Bus\\s*X\\s*(\\d+)");
-
- @Override
- protected Line parseLine(final String type, final String line, final boolean wheelchairAccess) {
- if ("1".equals(type)) {
- final Matcher mBus = P_NORMALIZE_LINE_BUS.matcher(line);
- if (mBus.matches()) {
- final String label = mBus.group(1);
- return new Line(null, null, Product.BUS, label, lineStyle(null, Product.BUS, label));
- }
-
- final Matcher mNachtbus = P_NORMALIZE_LINE_NACHTBUS.matcher(line);
- if (mNachtbus.matches()) {
- final String label = "N" + mNachtbus.group(1);
- return new Line(null, null, Product.BUS, label, lineStyle(null, Product.BUS, label));
- }
-
- final Matcher mBusS = P_NORMALIZE_LINE_BUS_S.matcher(line);
- if (mBusS.matches()) {
- final String label = "S" + mBusS.group(1);
- return new Line(null, null, Product.BUS, label, lineStyle(null, Product.BUS, label));
- }
-
- final Matcher mBusX = P_NORMALIZE_LINE_BUS_X.matcher(line);
- if (mBusX.matches()) {
- final String label = "X" + mBusX.group(1);
- return new Line(null, null, Product.BUS, label, lineStyle(null, Product.BUS, label));
- }
- }
-
- return super.parseLine(type, line, wheelchairAccess);
- }
-
- @Override
- protected Product normalizeType(final String type) {
- if ("1".equals(type))
- return Product.BUS;
-
- // skip parsing of "common" lines
- throw new IllegalStateException("cannot normalize type '" + type + "'");
- }
-
private static final Map STYLES = new HashMap<>();
static {
diff --git a/enabler/src/de/schildbach/pte/util/ParserUtils.java b/enabler/src/de/schildbach/pte/util/ParserUtils.java
index 17ac549e..a663cf6a 100644
--- a/enabler/src/de/schildbach/pte/util/ParserUtils.java
+++ b/enabler/src/de/schildbach/pte/util/ParserUtils.java
@@ -289,6 +289,4 @@ public final class ParserUtils {
return null;
}
-
- public static final String P_PLATFORM = "[\\wÄÖÜäöüßáàâéèêíìîóòôúùû\\. -/]+?";
}
diff --git a/enabler/test/de/schildbach/pte/live/InvgProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/InvgProviderLiveTest.java
index ee6ed213..73693f4e 100644
--- a/enabler/test/de/schildbach/pte/live/InvgProviderLiveTest.java
+++ b/enabler/test/de/schildbach/pte/live/InvgProviderLiveTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2015 the original author or authors.
+ * Copyright 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
@@ -39,7 +39,7 @@ import de.schildbach.pte.dto.SuggestLocationsResult;
*/
public class InvgProviderLiveTest extends AbstractProviderLiveTest {
public InvgProviderLiveTest() {
- super(new InvgProvider());
+ super(new InvgProvider(secretProperty("invg.api_authorization")));
}
@Test
@@ -68,16 +68,27 @@ public class InvgProviderLiveTest extends AbstractProviderLiveTest {
@Test
public void suggestLocations() throws Exception {
- final SuggestLocationsResult result = suggestLocations("Flughafen");
+ final SuggestLocationsResult result = suggestLocations("Rathausplatz");
print(result);
}
@Test
public void shortTrip() throws Exception {
- final QueryTripsResult result = queryTrips(
- new Location(LocationType.STATION, "80302", null, "Ingolstadt, Hauptbahnhof Stadteinwärts"), null,
- new Location(LocationType.STATION, "181102", null, "Elisabethstraße"), new Date(), true, Product.ALL,
- WalkSpeed.NORMAL, Accessibility.NEUTRAL);
+ final Location from = new Location(LocationType.STATION, "60706", null, "Rathausplatz");
+ final Location to = new Location(LocationType.STATION, "146704", null, "Hochschule");
+ final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, Product.ALL, WalkSpeed.NORMAL,
+ Accessibility.NEUTRAL);
+ print(result);
+ final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
+ print(laterResult);
+ }
+
+ @Test
+ public void tripBetweenCoordinates() throws Exception {
+ final Location from = Location.coord(48744414, 11434603); // Ingolstadt Hbf
+ final Location to = Location.coord(48751558, 11426546); // Ingolstadt Nordbahnhof
+ final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, Product.ALL, WalkSpeed.NORMAL,
+ Accessibility.NEUTRAL);
print(result);
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
print(laterResult);
diff --git a/enabler/test/de/schildbach/pte/live/secrets.properties.template b/enabler/test/de/schildbach/pte/live/secrets.properties.template
index 7beaa859..80aa5912 100644
--- a/enabler/test/de/schildbach/pte/live/secrets.properties.template
+++ b/enabler/test/de/schildbach/pte/live/secrets.properties.template
@@ -4,6 +4,7 @@ bvg.api_authorization =
vbn.api_authorization =
sh.api_authorization =
vmt.api_authorization =
+invg.api_authorization =
vor.api_authorization =
ooevv.api_authorization =
svv.api_authorization =