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:
andreas.schildbach 2010-08-30 14:11:53 +00:00
parent 92644b5475
commit ce9a890986
9 changed files with 103 additions and 48 deletions

View file

@ -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);