mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 17:10:30 +00:00
fixed parsing of ambiguous list
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@557 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
3e66509efc
commit
a4e394be26
1 changed files with 30 additions and 22 deletions
|
@ -303,9 +303,9 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
throw new IllegalArgumentException(type.toString());
|
throw new IllegalArgumentException(type.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern P_CHECK_ADDRESS = Pattern.compile("<option[^>]*>\\s*(.*?)\\s*</option>", Pattern.DOTALL);
|
private static final Pattern P_PRE_ADDRESS = Pattern.compile(
|
||||||
private static final Pattern P_CHECK_FROM = Pattern.compile("Von:");
|
"<select[^>]*name=\"(REQ0JourneyStopsS0K|REQ0JourneyStopsZ0K|REQ0JourneyStops1\\.0K)\"[^>]*>\n(.*?)</select>", Pattern.DOTALL);
|
||||||
private static final Pattern P_CHECK_TO = Pattern.compile("Nach:");
|
private static final Pattern P_ADDRESSES = Pattern.compile("<option[^>]*>\\s*(.*?)\\s*</option>", Pattern.DOTALL);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryConnectionsResult queryConnections(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
public QueryConnectionsResult queryConnections(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
||||||
|
@ -314,31 +314,39 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
final String uri = connectionsQueryUri(from, via, to, date, dep, products);
|
final String uri = connectionsQueryUri(from, via, to, date, dep, products);
|
||||||
final CharSequence page = ParserUtils.scrape(uri);
|
final CharSequence page = ParserUtils.scrape(uri);
|
||||||
|
|
||||||
final Matcher mAddress = P_CHECK_ADDRESS.matcher(page);
|
List<Location> fromAddresses = null;
|
||||||
|
List<Location> viaAddresses = null;
|
||||||
|
List<Location> toAddresses = null;
|
||||||
|
|
||||||
final List<Location> addresses = new ArrayList<Location>();
|
final Matcher mPreAddress = P_PRE_ADDRESS.matcher(page);
|
||||||
while (mAddress.find())
|
while (mPreAddress.find())
|
||||||
{
|
{
|
||||||
final String address = ParserUtils.resolveEntities(mAddress.group(1));
|
final String type = mPreAddress.group(1);
|
||||||
if (!addresses.contains(address))
|
final String options = mPreAddress.group(2);
|
||||||
addresses.add(new Location(LocationType.ANY, 0, null, address + "!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addresses.isEmpty())
|
final Matcher mAddresses = P_ADDRESSES.matcher(options);
|
||||||
{
|
final List<Location> addresses = new ArrayList<Location>();
|
||||||
return queryConnections(uri, page);
|
while (mAddresses.find())
|
||||||
}
|
{
|
||||||
else if (P_CHECK_FROM.matcher(page).find())
|
final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim();
|
||||||
{
|
if (!addresses.contains(address))
|
||||||
if (P_CHECK_TO.matcher(page).find())
|
addresses.add(new Location(LocationType.ANY, 0, null, address + "!"));
|
||||||
return new QueryConnectionsResult(null, addresses, null);
|
}
|
||||||
|
|
||||||
|
if (type.equals("REQ0JourneyStopsS0K"))
|
||||||
|
fromAddresses = addresses;
|
||||||
|
else if (type.equals("REQ0JourneyStopsZ0K"))
|
||||||
|
toAddresses = addresses;
|
||||||
|
else if (type.equals("REQ0JourneyStops1.0K"))
|
||||||
|
viaAddresses = addresses;
|
||||||
else
|
else
|
||||||
return new QueryConnectionsResult(null, null, addresses);
|
throw new IllegalStateException(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fromAddresses != null || viaAddresses != null || toAddresses != null)
|
||||||
|
return new QueryConnectionsResult(fromAddresses, viaAddresses, toAddresses);
|
||||||
else
|
else
|
||||||
{
|
return queryConnections(uri, page);
|
||||||
return new QueryConnectionsResult(addresses, null, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue