mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-16 09:29:49 +00:00
auto-complete station name
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@100 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
dc9ff11c09
commit
235573a11f
1 changed files with 22 additions and 1 deletions
|
@ -28,9 +28,30 @@ public class OebbProvider implements NetworkProvider
|
|||
return true;
|
||||
}
|
||||
|
||||
private static final String NAME_URL = "http://fahrplan.oebb.at/bin/stboard.exe/dn?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);
|
||||
|
||||
public List<String> autoCompleteStationName(final CharSequence constraint) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
final CharSequence page = ParserUtils.scrape(NAME_URL + ParserUtils.urlEncode(constraint.toString()));
|
||||
|
||||
final List<String> names = new ArrayList<String>();
|
||||
|
||||
final Matcher mSingle = P_SINGLE_NAME.matcher(page);
|
||||
if (mSingle.matches())
|
||||
{
|
||||
names.add(ParserUtils.resolveEntities(mSingle.group(1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
final Matcher mMulti = P_MULTI_NAME.matcher(page);
|
||||
while (mMulti.find())
|
||||
names.add(ParserUtils.resolveEntities(mMulti.group(2)));
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
public List<Station> nearbyStations(final double lat, final double lon, final int maxDistance, final int maxStations) throws IOException
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue