parse place and nameWithPlace for efa based providers

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@439 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-01-08 17:03:43 +00:00
parent 7a077f56c7
commit 7ca487c632
5 changed files with 57 additions and 26 deletions

View file

@ -240,15 +240,29 @@ public abstract class AbstractEfaProvider implements NetworkProvider
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"dm".equals(pp.getAttributeValue(null, "usage")))
throw new IllegalStateException("cannot find <itdOdv usage=\"dm\" />");
if (!XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvName"))
throw new IllegalStateException("cannot find <itdOdvName />");
XmlPullUtil.enter(pp, "itdOdv");
String place = null;
XmlPullUtil.require(pp, "itdOdvPlace");
final String placeState = pp.getAttributeValue(null, "state");
XmlPullUtil.enter(pp, "itdOdvPlace");
if ("identified".equals(placeState))
{
XmlPullUtil.enter(pp, "odvPlaceElem");
place = normalizeLocationName(pp.getText());
XmlPullUtil.exit(pp, "odvPlaceElem");
}
XmlPullUtil.exit(pp, "itdOdvPlace");
XmlPullUtil.require(pp, "itdOdvName");
final String nameState = pp.getAttributeValue(null, "state");
XmlPullUtil.enter(pp, "itdOdvName");
if ("identified".equals(nameState))
{
final List<Station> stations = new ArrayList<Station>();
Station ownStation = null;
XmlPullUtil.jumpToStartTag(pp, null, "odvNameElem");
XmlPullUtil.require(pp, "odvNameElem");
String parsedOwnLocationIdStr = pp.getAttributeValue(null, "stopID");
if (parsedOwnLocationIdStr == null)
parsedOwnLocationIdStr = pp.getAttributeValue(null, "id");
@ -264,32 +278,41 @@ public abstract class AbstractEfaProvider implements NetworkProvider
parsedOwnLon = Integer.parseInt(pp.getAttributeValue(null, "x"));
parsedOwnLat = Integer.parseInt(pp.getAttributeValue(null, "y"));
}
final String parsedOwnLocation = normalizeLocationName(pp.nextText()); // FIXME evtl. nur optional?
ownStation = new Station(parsedOwnLocationId, parsedOwnLocation, parsedOwnLat, parsedOwnLon, 0, null, null);
final String parsedOwnLocation = normalizeLocationName(pp.nextText());
ownStation = new Station(parsedOwnLocationId, place, parsedOwnLocation, null, parsedOwnLat, parsedOwnLon, 0, null, null);
}
if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops"))
{
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvAssignedStop"))
XmlPullUtil.enter(pp, "itdOdvAssignedStops");
while (XmlPullUtil.test(pp, "itdOdvAssignedStop"))
{
final String parsedMapName = pp.getAttributeValue(null, "mapName");
if (parsedMapName != null)
{
final int parsedLocationId = XmlPullUtil.intAttr(pp, "stopID");
final String parsedLongName = normalizeLocationName(XmlPullUtil.attr(pp, "nameWithPlace"));
final String parsedPlace = normalizeLocationName(XmlPullUtil.attr(pp, "place"));
final int parsedLon = XmlPullUtil.intAttr(pp, "x");
final int parsedLat = XmlPullUtil.intAttr(pp, "y");
final String parsedDistStr = pp.getAttributeValue(null, "distance");
final int parsedDist = parsedDistStr != null ? Integer.parseInt(parsedDistStr) : 0;
XmlPullUtil.enter(pp, "itdOdvAssignedStop");
final String parsedName = normalizeLocationName(pp.getText());
XmlPullUtil.exit(pp, "itdOdvAssignedStop");
if (!"WGS84".equals(parsedMapName))
throw new IllegalStateException("unknown mapName: " + parsedMapName);
final int parsedLocationId = Integer.parseInt(pp.getAttributeValue(null, "stopID"));
final String parsedName = normalizeLocationName(pp.getAttributeValue(null, "nameWithPlace"));
final int parsedLon = Integer.parseInt(pp.getAttributeValue(null, "x"));
final int parsedLat = Integer.parseInt(pp.getAttributeValue(null, "y"));
final String parsedDistStr = pp.getAttributeValue(null, "distance");
final int parsedDist = parsedDistStr != null ? Integer.parseInt(parsedDistStr) : 0;
final Station newStation = new Station(parsedLocationId, parsedName, parsedLat, parsedLon, parsedDist, null, null);
final Station newStation = new Station(parsedLocationId, parsedPlace, parsedName, parsedLongName, parsedLat, parsedLon,
parsedDist, null, null);
if (!stations.contains(newStation))
stations.add(newStation);
XmlPullUtil.skipRestOfTree(pp);
}
else
{
XmlPullUtil.enter(pp, "itdOdvAssignedStop");
XmlPullUtil.exit(pp, "itdOdvAssignedStop");
}
}
}
@ -304,7 +327,6 @@ public abstract class AbstractEfaProvider implements NetworkProvider
}
else if ("list".equals(nameState))
{
XmlPullUtil.enter(pp, "itdOdvName");
final List<Station> stations = new ArrayList<Station>();
if (XmlPullUtil.test(pp, "itdMessage"))
@ -314,7 +336,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
final Location location = processOdvNameElem(pp);
if (location.type == LocationType.STATION)
{
final Station newStation = new Station(location.id, location.name, location.lat, location.lon, 0, null, null);
final Station newStation = new Station(location.id, null, location.name, null, location.lat, location.lon, 0, null, null);
if (!stations.contains(newStation))
stations.add(newStation);
}
@ -330,6 +352,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
{
throw new RuntimeException("unknown nameState '" + nameState + "' on " + uri);
}
// XmlPullUtil.exit(pp, "itdOdvName");
}
catch (final XmlPullParserException x)
{

View file

@ -766,7 +766,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
parsedLat = Integer.parseInt(mFineCoords.group(2));
}
stations.add(new Station(parsedId, parsedName, parsedLat, parsedLon, 0, null, null));
stations.add(new Station(parsedId, null, parsedName, null, parsedLat, parsedLon, 0, null, null));
}
else
{

View file

@ -126,7 +126,7 @@ public final class BahnProvider extends AbstractHafasProvider
final int sDist = Integer.parseInt(m.group(4));
final String sName = ParserUtils.resolveEntities(m.group(5).trim());
final Station station = new Station(sId, sName, sLat, sLon, sDist, null, null);
final Station station = new Station(sId, null, sName, null, sLat, sLon, sDist, null, null);
stations.add(station);
}

View file

@ -146,7 +146,7 @@ public final class BvgProvider extends AbstractHafasProvider
final int parsedLon = (int) (Float.parseFloat(mOwn.group(2)) * 1E6);
final int parsedLat = (int) (Float.parseFloat(mOwn.group(3)) * 1E6);
final String parsedName = ParserUtils.urlDecode(mOwn.group(4), "ISO-8859-1");
stations.add(new Station(parsedId, parsedName, parsedLat, parsedLon, 0, null, null));
stations.add(new Station(parsedId, null, parsedName, null, parsedLat, parsedLon, 0, null, null));
}
final Matcher mPage = P_NEARBY_PAGE.matcher(page);
@ -162,7 +162,7 @@ public final class BvgProvider extends AbstractHafasProvider
{
final int parsedId = Integer.parseInt(mFineLocation.group(1));
final String parsedName = ParserUtils.resolveEntities(mFineLocation.group(2));
stations.add(new Station(parsedId, parsedName, 0, 0, 0, null, null));
stations.add(new Station(parsedId, null, parsedName, null, 0, 0, 0, null, null));
}
else
{

View file

@ -24,17 +24,21 @@ public final class Station
{
// data
public final int id;
public final String place;
public final String name;
public final String longName;
public final int latitude, longitude;
public float distance;
public final String[] lines;
public final int[][] lineColors;
public Station(final int id, final String name, final int latitude, final int longitude, final float distance, final String[] lines,
final int[][] lineColors)
public Station(final int id, final String place, final String name, final String longName, final int latitude, final int longitude, final float distance,
final String[] lines, final int[][] lineColors)
{
this.id = id;
this.place = place;
this.name = name;
this.longName = longName;
this.latitude = latitude;
this.longitude = longitude;
this.distance = distance;
@ -47,9 +51,13 @@ public final class Station
{
StringBuilder builder = new StringBuilder("Station(");
builder.append(id);
builder.append(",");
builder.append("|");
builder.append(place);
builder.append("|");
builder.append(name);
builder.append(",");
builder.append("|");
builder.append(longName);
builder.append("|");
builder.append(latitude);
builder.append(",");
builder.append(longitude);