mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-14 08:40:29 +00:00
fixed certain autocompletes for efa based providers
This commit is contained in:
parent
89332f50e9
commit
3ad2d19f77
1 changed files with 60 additions and 35 deletions
|
@ -229,15 +229,48 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
|
||||
try
|
||||
{
|
||||
final List<Location> results = new ArrayList<Location>();
|
||||
|
||||
final JSONObject head = new JSONObject(page.toString());
|
||||
final JSONArray stops = head.getJSONArray("stopFinder");
|
||||
final JSONObject stopFinder = head.optJSONObject("stopFinder");
|
||||
final JSONArray stops;
|
||||
if (stopFinder == null)
|
||||
{
|
||||
stops = head.getJSONArray("stopFinder");
|
||||
}
|
||||
else
|
||||
{
|
||||
final JSONObject points = stopFinder.optJSONObject("points");
|
||||
if (points != null)
|
||||
{
|
||||
final JSONObject stop = points.getJSONObject("point");
|
||||
final Location location = parseJsonStop(stop);
|
||||
results.add(location);
|
||||
return results;
|
||||
}
|
||||
|
||||
stops = stopFinder.getJSONArray("points");
|
||||
}
|
||||
|
||||
final int nStops = stops.length();
|
||||
final List<Location> results = new ArrayList<Location>();
|
||||
|
||||
for (int i = 0; i < nStops; i++)
|
||||
{
|
||||
final JSONObject stop = stops.optJSONObject(i);
|
||||
final Location location = parseJsonStop(stop);
|
||||
results.add(location);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
catch (final JSONException x)
|
||||
{
|
||||
throw new RuntimeException("cannot parse: '" + page + "' on " + uri, x);
|
||||
}
|
||||
}
|
||||
|
||||
private Location parseJsonStop(final JSONObject stop) throws JSONException
|
||||
{
|
||||
String type = stop.getString("type");
|
||||
if ("any".equals(type))
|
||||
type = stop.getString("anyType");
|
||||
|
@ -262,23 +295,15 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
|||
}
|
||||
|
||||
if ("stop".equals(type))
|
||||
results.add(new Location(LocationType.STATION, stop.getInt("stateless"), lat, lon, place, name));
|
||||
return new Location(LocationType.STATION, stop.getInt("stateless"), lat, lon, place, name);
|
||||
else if ("poi".equals(type))
|
||||
results.add(new Location(LocationType.POI, 0, lat, lon, place, name));
|
||||
return new Location(LocationType.POI, 0, lat, lon, place, name);
|
||||
else if ("crossing".equals(type))
|
||||
results.add(new Location(LocationType.ADDRESS, 0, lat, lon, place, name));
|
||||
return new Location(LocationType.ADDRESS, 0, lat, lon, place, name);
|
||||
else if ("street".equals(type) || "address".equals(type) || "singlehouse".equals(type))
|
||||
results.add(new Location(LocationType.ADDRESS, 0, lat, lon, place, normalizeLocationName(stop.getString("name"))));
|
||||
return new Location(LocationType.ADDRESS, 0, lat, lon, place, normalizeLocationName(stop.getString("name")));
|
||||
else
|
||||
throw new IllegalArgumentException("unknown type: " + type + " on " + uri);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
catch (final JSONException x)
|
||||
{
|
||||
throw new RuntimeException("cannot parse: '" + page + "' on " + uri, x);
|
||||
}
|
||||
throw new JSONException("unknown type: " + type);
|
||||
}
|
||||
|
||||
protected List<Location> xmlStopfinderRequest(final Location constraint) throws IOException
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue