autocomplete parses stationid where possible

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@129 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-09-04 22:58:15 +00:00
parent d0162ed846
commit c632118a6e
6 changed files with 36 additions and 19 deletions

View file

@ -51,9 +51,9 @@ public final class BahnProvider implements NetworkProvider
}
private static final String NAME_URL = "http://mobile.bahn.de/bin/mobil/bhftafel.exe/dox?input=";
private static final Pattern P_SINGLE_NAME = Pattern
.compile(".*<input type=\"hidden\" name=\"input\" value=\"(.+?)#\\d+?\" />.*", Pattern.DOTALL);
private static final Pattern P_MULTI_NAME = Pattern.compile("<option value=\".+?#\\d+?\">(.+?)</option>", Pattern.DOTALL);
private static final Pattern P_SINGLE_NAME = Pattern.compile(".*<input type=\"hidden\" name=\"input\" value=\"(.+?)#(\\d+)\" />.*",
Pattern.DOTALL);
private static final Pattern P_MULTI_NAME = Pattern.compile("<option value=\".+?#(\\d+)\">(.+?)</option>", Pattern.DOTALL);
public List<Autocomplete> autocompleteStations(final CharSequence constraint) throws IOException
{
@ -64,13 +64,13 @@ public final class BahnProvider implements NetworkProvider
final Matcher mSingle = P_SINGLE_NAME.matcher(page);
if (mSingle.matches())
{
results.add(new Autocomplete(0, ParserUtils.resolveEntities(mSingle.group(1))));
results.add(new Autocomplete(Integer.parseInt(mSingle.group(2)), ParserUtils.resolveEntities(mSingle.group(1))));
}
else
{
final Matcher mMulti = P_MULTI_NAME.matcher(page);
while (mMulti.find())
results.add(new Autocomplete(0, ParserUtils.resolveEntities(mMulti.group(1))));
results.add(new Autocomplete(Integer.parseInt(mMulti.group(1)), ParserUtils.resolveEntities(mMulti.group(2))));
}
return results;