fixed own station parsing

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@240 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-10-05 11:23:51 +00:00
parent 6ca75b99e9
commit 89da3a9bba

View file

@ -117,20 +117,25 @@ public abstract class AbstractEfaProvider implements NetworkProvider
{ {
final List<Station> stations = new ArrayList<Station>(); final List<Station> stations = new ArrayList<Station>();
Station ownStation = null;
XmlPullUtil.jumpToStartTag(pp, null, "odvNameElem"); XmlPullUtil.jumpToStartTag(pp, null, "odvNameElem");
final String parsedOwnLocationIdStr = pp.getAttributeValue(null, "stopID"); String parsedOwnLocationIdStr = pp.getAttributeValue(null, "stopID");
if (parsedOwnLocationIdStr == null)
parsedOwnLocationIdStr = pp.getAttributeValue(null, "id");
if (parsedOwnLocationIdStr != null) if (parsedOwnLocationIdStr != null)
{ {
final int parsedOwnLocationId = Integer.parseInt(parsedOwnLocationIdStr); final int parsedOwnLocationId = Integer.parseInt(parsedOwnLocationIdStr);
final String parsedOwnMapName = pp.getAttributeValue(null, "mapName"); int parsedOwnLat = 0, parsedOwnLon = 0;
if (parsedOwnMapName != null) final String mapName = pp.getAttributeValue(null, "mapName");
if (mapName != null)
{ {
if (!"WGS84".equals(parsedOwnMapName)) if (!"WGS84".equals(mapName))
throw new IllegalStateException("unknown mapName: " + parsedOwnMapName); throw new IllegalStateException("unknown mapName: " + mapName);
final int parsedOwnLon = Integer.parseInt(pp.getAttributeValue(null, "x")); parsedOwnLon = Integer.parseInt(pp.getAttributeValue(null, "x"));
final int parsedOwnLat = Integer.parseInt(pp.getAttributeValue(null, "y")); parsedOwnLat = Integer.parseInt(pp.getAttributeValue(null, "y"));
stations.add(new Station(parsedOwnLocationId, null, parsedOwnLat, parsedOwnLon, 0, null, null));
} }
final String parsedOwnLocation = normalizeLocationName(pp.nextText()); // FIXME evtl. nur optional?
ownStation = new Station(parsedOwnLocationId, parsedOwnLocation, parsedOwnLat, parsedOwnLon, 0, null, null);
} }
if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops")) if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops"))
@ -150,13 +155,18 @@ public abstract class AbstractEfaProvider implements NetworkProvider
final String parsedDistStr = pp.getAttributeValue(null, "distance"); final String parsedDistStr = pp.getAttributeValue(null, "distance");
final int parsedDist = parsedDistStr != null ? Integer.parseInt(parsedDistStr) : 0; final int parsedDist = parsedDistStr != null ? Integer.parseInt(parsedDistStr) : 0;
stations.add(new Station(parsedLocationId, parsedName, parsedLat, parsedLon, parsedDist, null, null)); final Station newStation = new Station(parsedLocationId, parsedName, parsedLat, parsedLon, parsedDist, null, null);
if (!stations.contains(newStation))
stations.add(newStation);
XmlPullUtil.skipRestOfTree(pp); XmlPullUtil.skipRestOfTree(pp);
} }
} }
} }
if (ownStation != null && !stations.contains(ownStation))
stations.add(ownStation);
if (maxStations == 0 || maxStations >= stations.size()) if (maxStations == 0 || maxStations >= stations.size())
return new NearbyStationsResult(uri, stations); return new NearbyStationsResult(uri, stations);
else else