mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 09:00:36 +00:00
handle stations by id if possible
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@124 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
197202e275
commit
e3b8e3e02e
7 changed files with 63 additions and 34 deletions
|
@ -122,8 +122,8 @@ public final class BahnProvider implements NetworkProvider
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final String via, final LocationType toType, final String to,
|
||||
final Date date, final boolean dep)
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep)
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
||||
|
@ -136,7 +136,7 @@ public final class BahnProvider implements NetworkProvider
|
|||
if (via != null)
|
||||
{
|
||||
uri.append("&REQ0JourneyStops1.0G=").append(ParserUtils.urlEncode(via));
|
||||
uri.append("&REQ0JourneyStops1.0A=255");
|
||||
uri.append("&REQ0JourneyStops1.0A=").append(locationType(viaType));
|
||||
}
|
||||
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
|
||||
uri.append("&REQ0JourneyStopsZ0A=").append(locationType(toType));
|
||||
|
@ -155,6 +155,8 @@ public final class BahnProvider implements NetworkProvider
|
|||
|
||||
private static int locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.STATION)
|
||||
return 1;
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return 2;
|
||||
if (locationType == LocationType.ANY)
|
||||
|
@ -171,7 +173,7 @@ public final class BahnProvider implements NetworkProvider
|
|||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep) throws IOException
|
||||
{
|
||||
final String uri = connectionsQueryUri(fromType, from, via, toType, to, date, dep);
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
|
@ -44,6 +44,7 @@ public class MvvProvider implements NetworkProvider
|
|||
|
||||
public boolean hasCapabilities(final Capability... capabilities)
|
||||
{
|
||||
// TODO remove
|
||||
for (final Capability capability : capabilities)
|
||||
if (capability == Capability.NEARBY_STATIONS)
|
||||
return false;
|
||||
|
@ -192,7 +193,7 @@ public class MvvProvider implements NetworkProvider
|
|||
uri.append("&reducedAnyWithoutAddressObjFilter_origin=102");
|
||||
uri.append("&reducedAnyPostcodeObjFilter_origin=64");
|
||||
uri.append("&reducedAnyTooManyObjFilter_origin=2");
|
||||
uri.append("&type_origin=stop"); // any|stop|poi|address
|
||||
uri.append("&type_origin=").append(locationType(fromType));
|
||||
uri.append("&name_origin=").append(ParserUtils.urlEncode(from, ENCODING)); // fine-grained location
|
||||
}
|
||||
|
||||
|
@ -216,7 +217,7 @@ public class MvvProvider implements NetworkProvider
|
|||
uri.append("&reducedAnyWithoutAddressObjFilter_destination=102");
|
||||
uri.append("&reducedAnyPostcodeObjFilter_destination=64");
|
||||
uri.append("&reducedAnyTooManyObjFilter_destination=2");
|
||||
uri.append("&type_destination=stop"); // any|stop|poi|address
|
||||
uri.append("&type_destination=").append(locationType(toType));
|
||||
uri.append("&name_destination=").append(ParserUtils.urlEncode(to, ENCODING)); // fine-grained location
|
||||
}
|
||||
|
||||
|
@ -242,7 +243,7 @@ public class MvvProvider implements NetworkProvider
|
|||
uri.append("&reducedAnyWithoutAddressObjFilter_via=102");
|
||||
uri.append("&reducedAnyPostcodeObjFilter_via=64");
|
||||
uri.append("&reducedAnyTooManyObjFilter_via=2");
|
||||
uri.append("&type_via=stop");
|
||||
uri.append("&type_via=").append(locationType(viaType));
|
||||
uri.append("&name_via=").append(ParserUtils.urlEncode(via, ENCODING));
|
||||
}
|
||||
}
|
||||
|
@ -255,6 +256,18 @@ public class MvvProvider implements NetworkProvider
|
|||
return uri.toString();
|
||||
}
|
||||
|
||||
private static String locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.STATION)
|
||||
return "stop";
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return "address";
|
||||
if (locationType == LocationType.ANY)
|
||||
return "any";
|
||||
// TODO poi
|
||||
throw new IllegalArgumentException(locationType.toString());
|
||||
}
|
||||
|
||||
private static final Pattern P_PRE_ADDRESS = Pattern.compile("<select name=\"(name_origin|name_destination|name_via)\".*?>(.*?)</select>",
|
||||
Pattern.DOTALL);
|
||||
private static final Pattern P_ADDRESSES = Pattern.compile("<option.*?>\\s*(.*?)\\s*</option>", Pattern.DOTALL);
|
||||
|
|
|
@ -30,12 +30,12 @@ public interface NetworkProvider
|
|||
{
|
||||
public enum Capability
|
||||
{
|
||||
NEARBY_STATIONS, DEPARTURES, CONNECTIONS, LOCATION_WGS84
|
||||
NEARBY_STATIONS, DEPARTURES, CONNECTIONS, LOCATION_WGS84, LOCATION_STATION_ID
|
||||
}
|
||||
|
||||
public enum LocationType
|
||||
{
|
||||
ANY, WGS84, ADDRESS
|
||||
ANY, STATION, WGS84, ADDRESS
|
||||
}
|
||||
|
||||
boolean hasCapabilities(Capability... capabilities);
|
||||
|
|
|
@ -24,7 +24,7 @@ public class OebbProvider implements NetworkProvider
|
|||
public boolean hasCapabilities(final Capability... capabilities)
|
||||
{
|
||||
for (final Capability capability : capabilities)
|
||||
if (capability == Capability.DEPARTURES || capability == Capability.CONNECTIONS)
|
||||
if (capability == Capability.DEPARTURES || capability == Capability.CONNECTIONS || capability == Capability.LOCATION_STATION_ID)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -66,8 +66,8 @@ public class OebbProvider implements NetworkProvider
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final String via, final LocationType toType, final String to,
|
||||
final Date date, final boolean dep)
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep)
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
||||
|
@ -82,7 +82,7 @@ public class OebbProvider implements NetworkProvider
|
|||
if (via != null)
|
||||
{
|
||||
uri.append("&REQ0JourneyStops1.0G=").append(ParserUtils.urlEncode(via));
|
||||
uri.append("&REQ0JourneyStops1.0A=255"); // 1=station, 2=city/street, 255=any
|
||||
uri.append("&REQ0JourneyStops1.0A=").append(locationType(viaType));
|
||||
uri.append("&REQ0JourneyStops1.0ID=");
|
||||
}
|
||||
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
|
||||
|
@ -100,6 +100,8 @@ public class OebbProvider implements NetworkProvider
|
|||
|
||||
private static int locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.STATION)
|
||||
return 1;
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return 2;
|
||||
if (locationType == LocationType.ANY)
|
||||
|
@ -115,7 +117,7 @@ public class OebbProvider implements NetworkProvider
|
|||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep) throws IOException
|
||||
{
|
||||
final String uri = connectionsQueryUri(fromType, from, via, toType, to, date, dep);
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
|
@ -134,7 +134,7 @@ public class RmvProvider implements NetworkProvider
|
|||
return (double) value / 1000000;
|
||||
}
|
||||
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final String via, final LocationType toType, final String to,
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via, final LocationType toType, final String to,
|
||||
final Date date, final boolean dep)
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||
|
@ -153,7 +153,7 @@ public class RmvProvider implements NetworkProvider
|
|||
if (via != null)
|
||||
{
|
||||
uri.append("&REQ0JourneyStops1.0G=").append(ParserUtils.urlEncode(via));
|
||||
uri.append("&REQ0JourneyStops1.0A=255");
|
||||
uri.append("&REQ0JourneyStops1.0A=").append(locationType(viaType));
|
||||
}
|
||||
uri.append("&start=Suchen");
|
||||
|
||||
|
@ -162,6 +162,8 @@ public class RmvProvider implements NetworkProvider
|
|||
|
||||
private static int locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.STATION)
|
||||
return 1;
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return 2;
|
||||
if (locationType == LocationType.ANY)
|
||||
|
@ -169,13 +171,6 @@ public class RmvProvider implements NetworkProvider
|
|||
throw new IllegalArgumentException(locationType.toString());
|
||||
}
|
||||
|
||||
public QueryConnectionsResult queryMoreConnections(final String uri) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
return queryConnections(uri, page);
|
||||
}
|
||||
|
||||
private static final Pattern P_PRE_ADDRESS = Pattern.compile("(?:Geben Sie einen (Startort|Zielort) an.*?)?Bitte wählen Sie aus der Liste",
|
||||
Pattern.DOTALL);
|
||||
private static final Pattern P_ADDRESSES = Pattern.compile(
|
||||
|
@ -186,7 +181,7 @@ public class RmvProvider implements NetworkProvider
|
|||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep) throws IOException
|
||||
{
|
||||
final String uri = connectionsQueryUri(fromType, from, via, toType, to, date, dep);
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
@ -246,6 +241,13 @@ public class RmvProvider implements NetworkProvider
|
|||
+ "(?: (.+?))?" //
|
||||
, Pattern.DOTALL);
|
||||
|
||||
public QueryConnectionsResult queryMoreConnections(final String uri) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
return queryConnections(uri, page);
|
||||
}
|
||||
|
||||
private QueryConnectionsResult queryConnections(final String uri, final CharSequence page) throws IOException
|
||||
{
|
||||
final Matcher mHead = P_CONNECTIONS_HEAD.matcher(page);
|
||||
|
|
|
@ -89,8 +89,8 @@ public class SbbProvider implements NetworkProvider
|
|||
// final String uri = "http://fahrplan.sbb.ch/bin/extxml.exe/dn";
|
||||
}
|
||||
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final String via, final LocationType toType, final String to,
|
||||
final Date date, final boolean dep)
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep)
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
||||
|
@ -109,7 +109,7 @@ public class SbbProvider implements NetworkProvider
|
|||
if (via != null)
|
||||
{
|
||||
uri.append("&REQ0JourneyStops1.0G=").append(ParserUtils.urlEncode(via));
|
||||
uri.append("&REQ0JourneyStops1.0A=7"); // any
|
||||
uri.append("&REQ0JourneyStops1.0A=").append(locationType(viaType));
|
||||
uri.append("&REQ0JourneyStops1.0ID=");
|
||||
}
|
||||
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
|
||||
|
@ -124,6 +124,8 @@ public class SbbProvider implements NetworkProvider
|
|||
|
||||
private static int locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.STATION)
|
||||
return 1;
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return 2;
|
||||
if (locationType == LocationType.ANY)
|
||||
|
@ -139,7 +141,7 @@ public class SbbProvider implements NetworkProvider
|
|||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep) throws IOException
|
||||
{
|
||||
final String uri = connectionsQueryUri(fromType, from, via, toType, to, date, dep);
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
|
@ -48,7 +48,7 @@ public final class VbbProvider implements NetworkProvider
|
|||
public boolean hasCapabilities(final Capability... capabilities)
|
||||
{
|
||||
for (final Capability capability : capabilities)
|
||||
if (capability == Capability.NEARBY_STATIONS)
|
||||
if (capability == Capability.NEARBY_STATIONS || capability == Capability.LOCATION_STATION_ID)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@ -153,8 +153,8 @@ public final class VbbProvider implements NetworkProvider
|
|||
|
||||
public static final String STATION_URL_CONNECTION = "http://mobil.bvg.de/Fahrinfo/bin/query.bin/dox";
|
||||
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final String via, final LocationType toType, final String to,
|
||||
final Date date, final boolean dep)
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep)
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
||||
|
@ -175,20 +175,24 @@ public final class VbbProvider implements NetworkProvider
|
|||
{
|
||||
uri.append("&REQ0JourneyStopsS0A=").append(locationType(fromType));
|
||||
uri.append("&REQ0JourneyStopsS0G=").append(ParserUtils.urlEncode(from));
|
||||
if (fromType == LocationType.STATION)
|
||||
uri.append(ParserUtils.urlEncode("!"));
|
||||
}
|
||||
|
||||
// via
|
||||
if (via != null)
|
||||
{
|
||||
if (fromType == LocationType.WGS84)
|
||||
if (viaType == LocationType.WGS84)
|
||||
{
|
||||
// FIXME
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
else
|
||||
{
|
||||
uri.append("&REQ0JourneyStops1A=255");
|
||||
uri.append("&REQ0JourneyStops1A=").append(locationType(viaType));
|
||||
uri.append("&REQ0JourneyStops1G=").append(ParserUtils.urlEncode(via));
|
||||
if (viaType == LocationType.STATION)
|
||||
uri.append(ParserUtils.urlEncode("!"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,6 +208,8 @@ public final class VbbProvider implements NetworkProvider
|
|||
{
|
||||
uri.append("&REQ0JourneyStopsZ0A=").append(locationType(toType));
|
||||
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
|
||||
if (toType == LocationType.STATION)
|
||||
uri.append(ParserUtils.urlEncode("!"));
|
||||
}
|
||||
|
||||
uri.append("&REQ0HafasSearchForw=").append(dep ? "1" : "0");
|
||||
|
@ -216,6 +222,8 @@ public final class VbbProvider implements NetworkProvider
|
|||
|
||||
private static int locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.STATION)
|
||||
return 1;
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return 2;
|
||||
if (locationType == LocationType.ANY)
|
||||
|
@ -236,7 +244,7 @@ public final class VbbProvider implements NetworkProvider
|
|||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep) throws IOException
|
||||
{
|
||||
final String uri = connectionsQueryUri(fromType, from, via, toType, to, date, dep);
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue