mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-17 22:19:50 +00:00
improved handling of addresses
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@117 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
92644b5475
commit
ce9a890986
9 changed files with 103 additions and 48 deletions
|
@ -122,7 +122,8 @@ public final class BahnProvider implements NetworkProvider
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private String connectionsQueryUri(final String from, final String via, final String to, final Date date, final boolean dep)
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, 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");
|
||||
|
@ -131,20 +132,14 @@ public final class BahnProvider implements NetworkProvider
|
|||
uri.append("http://mobile.bahn.de/bin/mobil/query.exe/dox");
|
||||
uri.append("?REQ0HafasOptimize1=0:1");
|
||||
uri.append("&REQ0JourneyStopsS0G=").append(ParserUtils.urlEncode(from));
|
||||
uri.append("&REQ0JourneyStopsS0A=1");
|
||||
uri.append("&REQ0JourneyStopsS0ALocation=1");
|
||||
uri.append("&REQ0JourneyStopsS0AAddress=1");
|
||||
uri.append("&REQ0JourneyStopsS0A=").append(locationType(fromType));
|
||||
if (via != null)
|
||||
{
|
||||
uri.append("&REQ0JourneyStops1.0G=").append(ParserUtils.urlEncode(via));
|
||||
uri.append("&REQ0JourneyStops1.0A=1");
|
||||
uri.append("&REQ0JourneyStops1.0ALocation=1");
|
||||
uri.append("&REQ0JourneyStops1.0AAddress=1");
|
||||
uri.append("&REQ0JourneyStops1.0A=255");
|
||||
}
|
||||
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
|
||||
uri.append("&REQ0JourneyStopsZ0A=1");
|
||||
uri.append("&REQ0JourneyStopsZ0ALocation=1");
|
||||
uri.append("&REQ0JourneyStopsZ0AAddress=1");
|
||||
uri.append("&REQ0JourneyStopsZ0A=").append(locationType(toType));
|
||||
uri.append("&REQ0HafasSearchForw=").append(dep ? "1" : "0");
|
||||
uri.append("&REQ0JourneyDate=").append(ParserUtils.urlEncode(DATE_FORMAT.format(date)));
|
||||
uri.append("&REQ0JourneyTime=").append(ParserUtils.urlEncode(TIME_FORMAT.format(date)));
|
||||
|
@ -158,6 +153,15 @@ public final class BahnProvider implements NetworkProvider
|
|||
return uri.toString();
|
||||
}
|
||||
|
||||
private static int locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return 2;
|
||||
if (locationType == LocationType.ANY)
|
||||
return 255;
|
||||
throw new IllegalArgumentException(locationType.toString());
|
||||
}
|
||||
|
||||
private static final Pattern P_PRE_ADDRESS = Pattern.compile(
|
||||
"<select name=\"(REQ0JourneyStopsS0K|REQ0JourneyStopsZ0K|REQ0JourneyStops1\\.0K)\" class=\"nofullwidth\">(.*?)</select>", Pattern.DOTALL);
|
||||
private static final Pattern P_ADDRESSES = Pattern.compile("<option.*?>\\s*(.*?)\\s*</option>", Pattern.DOTALL);
|
||||
|
@ -167,7 +171,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(from, via, to, date, dep);
|
||||
final String uri = connectionsQueryUri(fromType, from, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
|
@ -35,7 +35,7 @@ public interface NetworkProvider
|
|||
|
||||
public enum LocationType
|
||||
{
|
||||
ANY, WGS84
|
||||
ANY, WGS84, ADDRESS
|
||||
}
|
||||
|
||||
boolean hasCapabilities(Capability... capabilities);
|
||||
|
|
|
@ -66,7 +66,8 @@ public class OebbProvider implements NetworkProvider
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private String connectionsQueryUri(final String from, final String via, final String to, final Date date, final boolean dep)
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, 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");
|
||||
|
@ -76,7 +77,7 @@ public class OebbProvider implements NetworkProvider
|
|||
uri.append("&REQ0HafasSearchForw=").append(dep ? "1" : "0");
|
||||
uri.append("&REQ0JourneyDate=").append(ParserUtils.urlEncode(DATE_FORMAT.format(date)));
|
||||
uri.append("&REQ0JourneyStopsS0G=").append(ParserUtils.urlEncode(from));
|
||||
uri.append("&REQ0JourneyStopsS0A=255"); // 1=station, 2=city/street, 255=any
|
||||
uri.append("&REQ0JourneyStopsS0A=").append(locationType(fromType));
|
||||
uri.append("&REQ0JourneyStopsS0ID="); // "tupel"?
|
||||
if (via != null)
|
||||
{
|
||||
|
@ -85,7 +86,7 @@ public class OebbProvider implements NetworkProvider
|
|||
uri.append("&REQ0JourneyStops1.0ID=");
|
||||
}
|
||||
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
|
||||
uri.append("&REQ0JourneyStopsZ0A=255"); // 1=station, 2=city/street, 255=any
|
||||
uri.append("&REQ0JourneyStopsZ0A=").append(locationType(toType));
|
||||
uri.append("&REQ0JourneyStopsZ0ID=");
|
||||
uri.append("&REQ0JourneyTime=").append(ParserUtils.urlEncode(TIME_FORMAT.format(date)));
|
||||
uri.append("&REQ0JourneyProduct_list=0:1111111111010000-000000");
|
||||
|
@ -97,6 +98,15 @@ public class OebbProvider implements NetworkProvider
|
|||
return uri.toString();
|
||||
}
|
||||
|
||||
private static int locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return 2;
|
||||
if (locationType == LocationType.ANY)
|
||||
return 255;
|
||||
throw new IllegalArgumentException(locationType.toString());
|
||||
}
|
||||
|
||||
private static final Pattern P_PRE_ADDRESS = Pattern.compile(
|
||||
"<select.*? name=\"(REQ0JourneyStopsS0K|REQ0JourneyStopsZ0K|REQ0JourneyStops1\\.0K)\".*?>(.*?)</select>", Pattern.DOTALL);
|
||||
private static final Pattern P_ADDRESSES = Pattern.compile("<option.*?>\\s*(.*?)\\s*</option>", Pattern.DOTALL);
|
||||
|
@ -105,7 +115,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(from, via, to, date, dep);
|
||||
final String uri = connectionsQueryUri(fromType, from, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
@ -565,7 +575,7 @@ public class OebbProvider implements NetworkProvider
|
|||
|
||||
if (ucType.equals("R"))
|
||||
return 'R';
|
||||
if (ucType.equals("REX"))
|
||||
if (ucType.equals("REX")) // RegionalExpress
|
||||
return 'R';
|
||||
if (ucType.equals("ZUG"))
|
||||
return 'R';
|
||||
|
|
|
@ -134,7 +134,8 @@ public class RmvProvider implements NetworkProvider
|
|||
return (double) value / 1000000;
|
||||
}
|
||||
|
||||
private String connectionsQueryUri(final String from, final String via, final String to, final Date date, final boolean dep)
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, 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");
|
||||
|
@ -146,9 +147,9 @@ public class RmvProvider implements NetworkProvider
|
|||
uri.append("&REQ0JourneyDate=").append(ParserUtils.urlEncode(DATE_FORMAT.format(date)));
|
||||
uri.append("&REQ0JourneyTime=").append(ParserUtils.urlEncode(TIME_FORMAT.format(date)));
|
||||
uri.append("&REQ0JourneyStopsS0G=").append(ParserUtils.urlEncode(from));
|
||||
uri.append("&REQ0JourneyStopsS0A=255");
|
||||
uri.append("&REQ0JourneyStopsS0A=").append(locationType(fromType));
|
||||
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
|
||||
uri.append("&REQ0JourneyStopsZ0A=255");
|
||||
uri.append("&REQ0JourneyStopsZ0A=").append(locationType(toType));
|
||||
if (via != null)
|
||||
{
|
||||
uri.append("&REQ0JourneyStops1.0G=").append(ParserUtils.urlEncode(via));
|
||||
|
@ -159,6 +160,15 @@ public class RmvProvider implements NetworkProvider
|
|||
return uri.toString();
|
||||
}
|
||||
|
||||
private static int locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return 2;
|
||||
if (locationType == LocationType.ANY)
|
||||
return 255;
|
||||
throw new IllegalArgumentException(locationType.toString());
|
||||
}
|
||||
|
||||
public QueryConnectionsResult queryMoreConnections(final String uri) throws IOException
|
||||
{
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
@ -176,7 +186,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(from, via, to, date, dep);
|
||||
final String uri = connectionsQueryUri(fromType, from, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
|
@ -89,7 +89,8 @@ public class SbbProvider implements NetworkProvider
|
|||
// final String uri = "http://fahrplan.sbb.ch/bin/extxml.exe/dn";
|
||||
}
|
||||
|
||||
private String connectionsQueryUri(final String from, final String via, final String to, final Date date, final boolean dep)
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, 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");
|
||||
|
@ -103,7 +104,7 @@ public class SbbProvider implements NetworkProvider
|
|||
uri.append("&REQ0HafasSkipLongChanges=1");
|
||||
uri.append("&REQ0JourneyDate=").append(ParserUtils.urlEncode(DATE_FORMAT.format(date)));
|
||||
uri.append("&REQ0JourneyStopsS0G=").append(ParserUtils.urlEncode(from));
|
||||
uri.append("&REQ0JourneyStopsS0A=7"); // any
|
||||
uri.append("&REQ0JourneyStopsS0A=").append(locationType(fromType));
|
||||
uri.append("&REQ0JourneyStopsS0ID=");
|
||||
if (via != null)
|
||||
{
|
||||
|
@ -112,14 +113,24 @@ public class SbbProvider implements NetworkProvider
|
|||
uri.append("&REQ0JourneyStops1.0ID=");
|
||||
}
|
||||
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
|
||||
uri.append("&REQ0JourneyStopsZ0A=7"); // any
|
||||
uri.append("&REQ0JourneyStopsZ0A=").append(locationType(toType));
|
||||
uri.append("&REQ0JourneyStopsZ0ID=");
|
||||
uri.append("&REQ0JourneyTime=").append(ParserUtils.urlEncode(TIME_FORMAT.format(date)));
|
||||
uri.append("&queryPageDisplayed=yes");
|
||||
uri.append("&start=Suchen");
|
||||
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
private static int locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return 2;
|
||||
if (locationType == LocationType.ANY)
|
||||
return 7;
|
||||
throw new IllegalArgumentException(locationType.toString());
|
||||
}
|
||||
|
||||
private static final Pattern P_PRE_ADDRESS = Pattern.compile(
|
||||
"<select name=\"(REQ0JourneyStopsS0K|REQ0JourneyStopsZ0K|REQ0JourneyStops1\\.0K)\" accesskey=\"f\".*?>(.*?)</select>", Pattern.DOTALL);
|
||||
private static final Pattern P_ADDRESSES = Pattern.compile("<option.*?>\\s*(.*?)\\s*</option>", Pattern.DOTALL);
|
||||
|
@ -128,7 +139,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(from, via, to, date, dep);
|
||||
final String uri = connectionsQueryUri(fromType, from, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
|
@ -164,46 +164,47 @@ public final class VbbProvider implements NetworkProvider
|
|||
uri.append("?REQ0HafasInitialSelection=0");
|
||||
|
||||
// from
|
||||
if (fromType == LocationType.ANY)
|
||||
{
|
||||
uri.append("&REQ0JourneyStopsS0A=255");
|
||||
uri.append("&REQ0JourneyStopsS0G=").append(ParserUtils.urlEncode(from));
|
||||
}
|
||||
else
|
||||
if (fromType == LocationType.WGS84)
|
||||
{
|
||||
final String[] parts = from.split(",\\s*", 2);
|
||||
final double lat = Double.parseDouble(parts[0]);
|
||||
final double lon = Double.parseDouble(parts[1]);
|
||||
uri.append("&SID=").append(ParserUtils.urlEncode("A=16@X=" + latLonToInt(lon) + "@Y=" + latLonToInt(lat)));
|
||||
}
|
||||
else
|
||||
{
|
||||
uri.append("&REQ0JourneyStopsS0A=").append(locationType(fromType));
|
||||
uri.append("&REQ0JourneyStopsS0G=").append(ParserUtils.urlEncode(from));
|
||||
}
|
||||
|
||||
// via
|
||||
if (via != null)
|
||||
{
|
||||
if (fromType == LocationType.ANY)
|
||||
if (fromType == LocationType.WGS84)
|
||||
{
|
||||
uri.append("&REQ0JourneyStops1A=1");
|
||||
uri.append("&REQ0JourneyStops1G=").append(ParserUtils.urlEncode(via));
|
||||
// FIXME
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME
|
||||
uri.append("&REQ0JourneyStops1A=255");
|
||||
uri.append("&REQ0JourneyStops1G=").append(ParserUtils.urlEncode(via));
|
||||
}
|
||||
}
|
||||
|
||||
// to
|
||||
if (toType == LocationType.ANY)
|
||||
{
|
||||
uri.append("&REQ0JourneyStopsZ0A=255");
|
||||
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
|
||||
}
|
||||
else
|
||||
if (toType == LocationType.WGS84)
|
||||
{
|
||||
final String[] parts = to.split(",\\s*", 2);
|
||||
final double lat = Double.parseDouble(parts[0]);
|
||||
final double lon = Double.parseDouble(parts[1]);
|
||||
uri.append("&ZID=").append(ParserUtils.urlEncode("A=16@X=" + latLonToInt(lon) + "@Y=" + latLonToInt(lat)));
|
||||
}
|
||||
else
|
||||
{
|
||||
uri.append("&REQ0JourneyStopsZ0A=").append(locationType(toType));
|
||||
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
|
||||
}
|
||||
|
||||
uri.append("&REQ0HafasSearchForw=").append(dep ? "1" : "0");
|
||||
uri.append("&REQ0JourneyDate=").append(ParserUtils.urlEncode(DATE_FORMAT.format(date)));
|
||||
|
@ -213,7 +214,16 @@ public final class VbbProvider implements NetworkProvider
|
|||
return uri.toString();
|
||||
}
|
||||
|
||||
private static int latLonToInt(double value)
|
||||
private static int locationType(final LocationType locationType)
|
||||
{
|
||||
if (locationType == LocationType.ADDRESS)
|
||||
return 2;
|
||||
if (locationType == LocationType.ANY)
|
||||
return 255;
|
||||
throw new IllegalArgumentException(locationType.toString());
|
||||
}
|
||||
|
||||
private static int latLonToInt(final double value)
|
||||
{
|
||||
return (int) (value * 1000000);
|
||||
}
|
||||
|
|
|
@ -71,4 +71,14 @@ public class MvvProviderLiveTest
|
|||
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater);
|
||||
System.out.println(moreResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionBetweenAddresses() throws Exception
|
||||
{
|
||||
final QueryConnectionsResult result = provider.queryConnections(LocationType.ADDRESS, "München, Maximilianstr. 1", null, null,
|
||||
LocationType.ADDRESS, "Starnberg, Jahnstraße 50", new Date(), true);
|
||||
System.out.println(result);
|
||||
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater);
|
||||
System.out.println(moreResult);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public class OebbProviderLiveTest
|
|||
@Test
|
||||
public void slowConnection() throws Exception
|
||||
{
|
||||
final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Ufhusen, Zollhus", null, null, LocationType.ANY, "Azuga",
|
||||
final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Ramsen, Zoll", null, null, LocationType.ANY, "Azuga",
|
||||
new Date(), true);
|
||||
System.out.println(result);
|
||||
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater);
|
||||
|
@ -55,8 +55,8 @@ public class OebbProviderLiveTest
|
|||
@Test
|
||||
public void connectionWithFootway() throws Exception
|
||||
{
|
||||
final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Graz, Haselweg", null, null, LocationType.ANY,
|
||||
"Innsbruck, Gumppstraße 69!", new Date(), true);
|
||||
final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Graz, Haselweg", null, null, LocationType.ADDRESS,
|
||||
"Innsbruck, Gumppstraße 69", new Date(), true);
|
||||
System.out.println(result);
|
||||
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater);
|
||||
System.out.println(moreResult);
|
||||
|
@ -66,7 +66,7 @@ public class OebbProviderLiveTest
|
|||
public void connectionWithFootway2() throws Exception
|
||||
{
|
||||
final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Wien, Krottenbachstraße 110!", null, null,
|
||||
LocationType.ANY, "Wien, Meidlinger Hauptstraße 1!", new Date(), true);
|
||||
LocationType.ADDRESS, "Wien, Meidlinger Hauptstraße 1", new Date(), true);
|
||||
System.out.println(result);
|
||||
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater);
|
||||
System.out.println(moreResult);
|
||||
|
|
|
@ -55,8 +55,8 @@ public class SbbProviderLiveTest
|
|||
@Test
|
||||
public void connectionWithFootway() throws Exception
|
||||
{
|
||||
final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Spiez, Seestraße 62", null, null, LocationType.ANY,
|
||||
"Einsiedeln, Erlenmoosweg 24", new Date(), true);
|
||||
final QueryConnectionsResult result = provider.queryConnections(LocationType.ADDRESS, "Spiez, Seestraße 62", null, null,
|
||||
LocationType.ADDRESS, "Einsiedeln, Erlenmoosweg 24", new Date(), true);
|
||||
System.out.println(result);
|
||||
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater);
|
||||
System.out.println(moreResult);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue