mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-18 00:09:55 +00:00
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:
parent
7a077f56c7
commit
7ca487c632
5 changed files with 57 additions and 26 deletions
|
@ -240,15 +240,29 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
|
|
||||||
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"dm".equals(pp.getAttributeValue(null, "usage")))
|
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"dm".equals(pp.getAttributeValue(null, "usage")))
|
||||||
throw new IllegalStateException("cannot find <itdOdv usage=\"dm\" />");
|
throw new IllegalStateException("cannot find <itdOdv usage=\"dm\" />");
|
||||||
if (!XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvName"))
|
XmlPullUtil.enter(pp, "itdOdv");
|
||||||
throw new IllegalStateException("cannot find <itdOdvName />");
|
|
||||||
|
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");
|
final String nameState = pp.getAttributeValue(null, "state");
|
||||||
|
XmlPullUtil.enter(pp, "itdOdvName");
|
||||||
if ("identified".equals(nameState))
|
if ("identified".equals(nameState))
|
||||||
{
|
{
|
||||||
final List<Station> stations = new ArrayList<Station>();
|
final List<Station> stations = new ArrayList<Station>();
|
||||||
|
|
||||||
Station ownStation = null;
|
Station ownStation = null;
|
||||||
XmlPullUtil.jumpToStartTag(pp, null, "odvNameElem");
|
XmlPullUtil.require(pp, "odvNameElem");
|
||||||
String parsedOwnLocationIdStr = pp.getAttributeValue(null, "stopID");
|
String parsedOwnLocationIdStr = pp.getAttributeValue(null, "stopID");
|
||||||
if (parsedOwnLocationIdStr == null)
|
if (parsedOwnLocationIdStr == null)
|
||||||
parsedOwnLocationIdStr = pp.getAttributeValue(null, "id");
|
parsedOwnLocationIdStr = pp.getAttributeValue(null, "id");
|
||||||
|
@ -264,32 +278,41 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
parsedOwnLon = Integer.parseInt(pp.getAttributeValue(null, "x"));
|
parsedOwnLon = Integer.parseInt(pp.getAttributeValue(null, "x"));
|
||||||
parsedOwnLat = Integer.parseInt(pp.getAttributeValue(null, "y"));
|
parsedOwnLat = Integer.parseInt(pp.getAttributeValue(null, "y"));
|
||||||
}
|
}
|
||||||
final String parsedOwnLocation = normalizeLocationName(pp.nextText()); // FIXME evtl. nur optional?
|
final String parsedOwnLocation = normalizeLocationName(pp.nextText());
|
||||||
ownStation = new Station(parsedOwnLocationId, parsedOwnLocation, parsedOwnLat, parsedOwnLon, 0, null, null);
|
ownStation = new Station(parsedOwnLocationId, place, parsedOwnLocation, null, parsedOwnLat, parsedOwnLon, 0, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops"))
|
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");
|
final String parsedMapName = pp.getAttributeValue(null, "mapName");
|
||||||
if (parsedMapName != null)
|
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))
|
if (!"WGS84".equals(parsedMapName))
|
||||||
throw new IllegalStateException("unknown mapName: " + parsedMapName);
|
throw new IllegalStateException("unknown mapName: " + parsedMapName);
|
||||||
|
|
||||||
final int parsedLocationId = Integer.parseInt(pp.getAttributeValue(null, "stopID"));
|
final Station newStation = new Station(parsedLocationId, parsedPlace, parsedName, parsedLongName, parsedLat, parsedLon,
|
||||||
final String parsedName = normalizeLocationName(pp.getAttributeValue(null, "nameWithPlace"));
|
parsedDist, null, null);
|
||||||
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);
|
|
||||||
if (!stations.contains(newStation))
|
if (!stations.contains(newStation))
|
||||||
stations.add(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))
|
else if ("list".equals(nameState))
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "itdOdvName");
|
|
||||||
final List<Station> stations = new ArrayList<Station>();
|
final List<Station> stations = new ArrayList<Station>();
|
||||||
|
|
||||||
if (XmlPullUtil.test(pp, "itdMessage"))
|
if (XmlPullUtil.test(pp, "itdMessage"))
|
||||||
|
@ -314,7 +336,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
final Location location = processOdvNameElem(pp);
|
final Location location = processOdvNameElem(pp);
|
||||||
if (location.type == LocationType.STATION)
|
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))
|
if (!stations.contains(newStation))
|
||||||
stations.add(newStation);
|
stations.add(newStation);
|
||||||
}
|
}
|
||||||
|
@ -330,6 +352,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
{
|
{
|
||||||
throw new RuntimeException("unknown nameState '" + nameState + "' on " + uri);
|
throw new RuntimeException("unknown nameState '" + nameState + "' on " + uri);
|
||||||
}
|
}
|
||||||
|
// XmlPullUtil.exit(pp, "itdOdvName");
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
|
|
|
@ -766,7 +766,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
parsedLat = Integer.parseInt(mFineCoords.group(2));
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -126,7 +126,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
final int sDist = Integer.parseInt(m.group(4));
|
final int sDist = Integer.parseInt(m.group(4));
|
||||||
final String sName = ParserUtils.resolveEntities(m.group(5).trim());
|
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);
|
stations.add(station);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
final int parsedLon = (int) (Float.parseFloat(mOwn.group(2)) * 1E6);
|
final int parsedLon = (int) (Float.parseFloat(mOwn.group(2)) * 1E6);
|
||||||
final int parsedLat = (int) (Float.parseFloat(mOwn.group(3)) * 1E6);
|
final int parsedLat = (int) (Float.parseFloat(mOwn.group(3)) * 1E6);
|
||||||
final String parsedName = ParserUtils.urlDecode(mOwn.group(4), "ISO-8859-1");
|
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);
|
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 int parsedId = Integer.parseInt(mFineLocation.group(1));
|
||||||
final String parsedName = ParserUtils.resolveEntities(mFineLocation.group(2));
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,17 +24,21 @@ public final class Station
|
||||||
{
|
{
|
||||||
// data
|
// data
|
||||||
public final int id;
|
public final int id;
|
||||||
|
public final String place;
|
||||||
public final String name;
|
public final String name;
|
||||||
|
public final String longName;
|
||||||
public final int latitude, longitude;
|
public final int latitude, longitude;
|
||||||
public float distance;
|
public float distance;
|
||||||
public final String[] lines;
|
public final String[] lines;
|
||||||
public final int[][] lineColors;
|
public final int[][] lineColors;
|
||||||
|
|
||||||
public Station(final int id, final String name, final int latitude, final int longitude, final float distance, final String[] lines,
|
public Station(final int id, final String place, final String name, final String longName, final int latitude, final int longitude, final float distance,
|
||||||
final int[][] lineColors)
|
final String[] lines, final int[][] lineColors)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.place = place;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.longName = longName;
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
this.distance = distance;
|
this.distance = distance;
|
||||||
|
@ -47,9 +51,13 @@ public final class Station
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder("Station(");
|
StringBuilder builder = new StringBuilder("Station(");
|
||||||
builder.append(id);
|
builder.append(id);
|
||||||
builder.append(",");
|
builder.append("|");
|
||||||
|
builder.append(place);
|
||||||
|
builder.append("|");
|
||||||
builder.append(name);
|
builder.append(name);
|
||||||
builder.append(",");
|
builder.append("|");
|
||||||
|
builder.append(longName);
|
||||||
|
builder.append("|");
|
||||||
builder.append(latitude);
|
builder.append(latitude);
|
||||||
builder.append(",");
|
builder.append(",");
|
||||||
builder.append(longitude);
|
builder.append(longitude);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue