VBB can determine location of station

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@43 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-08-06 18:36:52 +00:00
parent 6af2a24deb
commit 7edf771289
2 changed files with 66 additions and 1 deletions

View file

@ -98,9 +98,55 @@ public final class VbbProvider implements NetworkProvider
throw new UnsupportedOperationException();
}
private static Pattern P_STATION_LOCATION = Pattern.compile("<Station name=\"(.*?)\" x=\"(\\d+)\" y=\"(\\d+)\" type=\"WGS84\"");
private static Pattern P_STATION_LOCATION_ERROR = Pattern.compile("(No trains in result)|(No Response from Server)");
public StationLocationResult stationLocation(final String stationId) throws IOException
{
throw new UnsupportedOperationException();
final boolean live = stationId.length() == 6;
if (live)
throw new UnsupportedOperationException();
final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
final Date now = new Date();
final String request = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><ReqC lang=\"DE\" prod=\"testsystem\" ver=\"1.1\" accessId=\"VBB-STD\"><STBReq boardType='DEP'><Time>"
+ TIME_FORMAT.format(now)
+ "</Time><Period><DateBegin>"
+ DATE_FORMAT.format(now)
+ "</DateBegin><DateEnd>"
+ DATE_FORMAT.format(now) + "</DateEnd></Period><TableStation externalId='" + stationId + "'/></STBReq></ReqC>";
final String uri = "http://www.vbb-fahrinfo.de/hafas/extxml/extxml.exe/dn";
final CharSequence page = ParserUtils.scrape(uri, request);
final Matcher mError = P_STATION_LOCATION_ERROR.matcher(page);
if (mError.find())
{
if (mError.group(1) != null)
return null;
if (mError.group(2) != null)
throw new RuntimeException("timeout error");
}
final Matcher m = P_STATION_LOCATION.matcher(page);
if (m.find())
{
final String name = ParserUtils.resolveEntities(m.group(1));
final double lon = latLonToDouble(Integer.parseInt(m.group(2)));
final double lat = latLonToDouble(Integer.parseInt(m.group(3)));
return new StationLocationResult(lat, lon, name);
}
else
{
throw new IllegalArgumentException("cannot parse '" + page + "' on " + uri);
}
}
private static double latLonToDouble(int value)
{
return (double) value / 1000000;
}
public static final String STATION_URL_CONNECTION = "http://mobil.bvg.de/Fahrinfo/bin/query.bin/dox";
@ -534,6 +580,8 @@ public final class VbbProvider implements NetworkProvider
return "RDNZ" + (number.equals("DNZ") ? "" : number);
if (type.equals("KBS")) // Kursbuchstrecke
return "RKBS" + number;
if (type.equals("BKB")) // Buckower Kleinbahn
return "RBKB" + number;
if (type.equals("S"))
return "SS" + number;
if (type.equals("U"))