diff --git a/src/de/schildbach/pte/AbstractEfaProvider.java b/src/de/schildbach/pte/AbstractEfaProvider.java index b5d07281..2967e587 100644 --- a/src/de/schildbach/pte/AbstractEfaProvider.java +++ b/src/de/schildbach/pte/AbstractEfaProvider.java @@ -34,10 +34,10 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; -import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.Connection; import de.schildbach.pte.dto.Departure; import de.schildbach.pte.dto.GetConnectionDetailsResult; +import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.LocationType; import de.schildbach.pte.dto.NearbyStationsResult; import de.schildbach.pte.dto.QueryConnectionsResult; @@ -76,19 +76,17 @@ public abstract class AbstractEfaProvider implements NetworkProvider XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvName"); final String nameState = pp.getAttributeValue(null, "state"); if ("list".equals(nameState)) - processOdvNameElem(results, pp); + while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem")) + results.add(processOdvNameElem(pp)); // parse assigned stops if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops")) { while (XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvAssignedStop")) { - final int id = Integer.parseInt(pp.getAttributeValue(null, "stopID")); - final String name = normalizeLocationName(pp.getAttributeValue(null, "nameWithPlace")); - - final Location autocomplete = new Location(LocationType.STATION, id, name); - if (!results.contains(autocomplete)) - results.add(autocomplete); + final Location location = processItdOdvAssignedStop(pp); + if (!results.contains(location)) + results.add(location); XmlPullUtil.skipRestOfTree(pp); } @@ -102,17 +100,33 @@ public abstract class AbstractEfaProvider implements NetworkProvider } } - private void processOdvNameElem(final List results, final XmlPullParser pp) throws XmlPullParserException, IOException + private Location processOdvNameElem(final XmlPullParser pp) throws XmlPullParserException, IOException { - while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem")) + final String type = pp.getAttributeValue(null, "anyType"); + int id = Integer.parseInt(pp.getAttributeValue(null, "id")); + if (id < 0) + id = 0; + int lat = 0, lon = 0; + if ("WGS84".equals(pp.getAttributeValue(null, "mapName"))) { - final String type = pp.getAttributeValue(null, "anyType"); - int id = Integer.parseInt(pp.getAttributeValue(null, "id")); - if (id < 0) - id = 0; - final String name = normalizeLocationName(pp.nextText()); - results.add(new Location(type(type), id, name)); + lat = Integer.parseInt(pp.getAttributeValue(null, "y")); + lon = Integer.parseInt(pp.getAttributeValue(null, "x")); } + final String name = normalizeLocationName(pp.nextText()); + return new Location(type(type), id, lat, lon, name); + } + + private Location processItdOdvAssignedStop(final XmlPullParser pp) + { + final int id = Integer.parseInt(pp.getAttributeValue(null, "stopID")); + int lat = 0, lon = 0; + if ("WGS84".equals(pp.getAttributeValue(null, "mapName"))) + { + lat = Integer.parseInt(pp.getAttributeValue(null, "y")); + lon = Integer.parseInt(pp.getAttributeValue(null, "x")); + } + final String name = normalizeLocationName(pp.getAttributeValue(null, "nameWithPlace")); + return new Location(LocationType.STATION, id, lat, lon, name); } private static LocationType type(final String type) @@ -651,7 +665,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider if ("list".equals(originState)) { ambiguousFrom = new ArrayList(); - processOdvNameElem(ambiguousFrom, pp); + while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem")) + ambiguousFrom.add(processOdvNameElem(pp)); } else if ("identified".equals(originState)) { @@ -667,7 +682,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider if ("list".equals(destinationState)) { ambiguousTo = new ArrayList(); - processOdvNameElem(ambiguousTo, pp); + while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem")) + ambiguousTo.add(processOdvNameElem(pp)); } else if ("identified".equals(destinationState)) { @@ -683,7 +699,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider if ("list".equals(viaState)) { ambiguousVia = new ArrayList(); - processOdvNameElem(ambiguousVia, pp); + while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem")) + ambiguousVia.add(processOdvNameElem(pp)); } else if ("identified".equals(viaState)) { diff --git a/src/de/schildbach/pte/BahnProvider.java b/src/de/schildbach/pte/BahnProvider.java index 771ca409..c9a8bf2c 100644 --- a/src/de/schildbach/pte/BahnProvider.java +++ b/src/de/schildbach/pte/BahnProvider.java @@ -75,13 +75,14 @@ public final class BahnProvider implements NetworkProvider final Matcher mSingle = P_SINGLE_NAME.matcher(page); if (mSingle.matches()) { - results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), ParserUtils.resolveEntities(mSingle.group(1)))); + results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), 0, 0, ParserUtils.resolveEntities(mSingle.group(1)))); } else { final Matcher mMulti = P_MULTI_NAME.matcher(page); while (mMulti.find()) - results.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), ParserUtils.resolveEntities(mMulti.group(2)))); + results + .add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), 0, 0, ParserUtils.resolveEntities(mMulti.group(2)))); } return results; @@ -204,7 +205,7 @@ public final class BahnProvider implements NetworkProvider { final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim(); if (!addresses.contains(address)) - addresses.add(new Location(LocationType.ANY, 0, address)); + addresses.add(new Location(LocationType.ANY, 0, 0, 0, address)); } if (type.equals("REQ0JourneyStopsS0K")) diff --git a/src/de/schildbach/pte/MvvProvider.java b/src/de/schildbach/pte/MvvProvider.java index 1b164578..e7c8f710 100644 --- a/src/de/schildbach/pte/MvvProvider.java +++ b/src/de/schildbach/pte/MvvProvider.java @@ -93,13 +93,13 @@ public class MvvProvider extends AbstractEfaProvider final int locationId = Integer.parseInt(mAutocompleteFine.group(3)); if (type.equals("stop")) - results.add(new Location(LocationType.STATION, locationId, location)); + results.add(new Location(LocationType.STATION, locationId, 0, 0, location)); else if (type.equals("street")) - results.add(new Location(LocationType.ADDRESS, 0, location)); + results.add(new Location(LocationType.ADDRESS, 0, 0, 0, location)); else if (type.equals("singlehouse")) - results.add(new Location(LocationType.ADDRESS, 0, location)); + results.add(new Location(LocationType.ADDRESS, 0, 0, 0, location)); else if (type.equals("poi")) - results.add(new Location(LocationType.POI, 0, location)); + results.add(new Location(LocationType.POI, 0, 0, 0, location)); else throw new IllegalStateException("unknown type " + type + " on " + uri); } @@ -364,7 +364,7 @@ public class MvvProvider extends AbstractEfaProvider { final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim(); if (!addresses.contains(address)) - addresses.add(new Location(LocationType.ANY, 0, address)); + addresses.add(new Location(LocationType.ANY, 0, 0, 0, address)); } if (type.equals("name_origin")) diff --git a/src/de/schildbach/pte/OebbProvider.java b/src/de/schildbach/pte/OebbProvider.java index 76e76f4e..d0e33769 100644 --- a/src/de/schildbach/pte/OebbProvider.java +++ b/src/de/schildbach/pte/OebbProvider.java @@ -94,7 +94,7 @@ public class OebbProvider extends AbstractHafasProvider if (m.matches()) { final int localId = Integer.parseInt(m.group(1)); - results.add(new Location(LocationType.STATION, localId, value)); + results.add(new Location(LocationType.STATION, localId, 0, 0, value)); } else { @@ -103,11 +103,11 @@ public class OebbProvider extends AbstractHafasProvider } else if (type == 2) // address { - results.add(new Location(LocationType.ADDRESS, 0, value)); + results.add(new Location(LocationType.ADDRESS, 0, 0, 0, value)); } else if (type == 4) // poi { - results.add(new Location(LocationType.ANY, 0, value)); + results.add(new Location(LocationType.ANY, 0, 0, 0, value)); } else { @@ -264,7 +264,7 @@ public class OebbProvider extends AbstractHafasProvider { final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim(); if (!addresses.contains(address)) - addresses.add(new Location(LocationType.ANY, 0, address)); + addresses.add(new Location(LocationType.ANY, 0, 0, 0, address)); } if (type.equals("REQ0JourneyStopsS0K")) diff --git a/src/de/schildbach/pte/RmvProvider.java b/src/de/schildbach/pte/RmvProvider.java index 19cb2ef3..82d6ef06 100644 --- a/src/de/schildbach/pte/RmvProvider.java +++ b/src/de/schildbach/pte/RmvProvider.java @@ -75,13 +75,14 @@ public class RmvProvider extends AbstractHafasProvider final Matcher mSingle = P_SINGLE_NAME.matcher(page); if (mSingle.matches()) { - results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), ParserUtils.resolveEntities(mSingle.group(1)))); + results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), 0, 0, ParserUtils.resolveEntities(mSingle.group(1)))); } else { final Matcher mMulti = P_MULTI_NAME.matcher(page); while (mMulti.find()) - results.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), ParserUtils.resolveEntities(mMulti.group(2)))); + results + .add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), 0, 0, ParserUtils.resolveEntities(mMulti.group(2)))); } return results; @@ -202,7 +203,7 @@ public class RmvProvider extends AbstractHafasProvider { final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim(); if (!addresses.contains(address)) - addresses.add(new Location(LocationType.ANY, 0, address)); + addresses.add(new Location(LocationType.ANY, 0, 0, 0, address)); } if (type == null) diff --git a/src/de/schildbach/pte/SbbProvider.java b/src/de/schildbach/pte/SbbProvider.java index 97f7ea57..2fb005fa 100644 --- a/src/de/schildbach/pte/SbbProvider.java +++ b/src/de/schildbach/pte/SbbProvider.java @@ -72,13 +72,14 @@ public class SbbProvider extends AbstractHafasProvider final Matcher mSingle = P_SINGLE_NAME.matcher(page); if (mSingle.matches()) { - results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), ParserUtils.resolveEntities(mSingle.group(1)))); + results.add(new Location(LocationType.STATION, Integer.parseInt(mSingle.group(2)), 0, 0, ParserUtils.resolveEntities(mSingle.group(1)))); } else { final Matcher mMulti = P_MULTI_NAME.matcher(page); while (mMulti.find()) - results.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), ParserUtils.resolveEntities(mMulti.group(2)))); + results + .add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), 0, 0, ParserUtils.resolveEntities(mMulti.group(2)))); } return results; @@ -179,7 +180,7 @@ public class SbbProvider extends AbstractHafasProvider { final String address = ParserUtils.resolveEntities(mAddresses.group(1)).trim(); if (!addresses.contains(address)) - addresses.add(new Location(LocationType.ANY, 0, address)); + addresses.add(new Location(LocationType.ANY, 0, 0, 0, address)); } if (type.equals("REQ0JourneyStopsS0K")) diff --git a/src/de/schildbach/pte/VbbProvider.java b/src/de/schildbach/pte/VbbProvider.java index 53a6ec85..1c6fc1f8 100644 --- a/src/de/schildbach/pte/VbbProvider.java +++ b/src/de/schildbach/pte/VbbProvider.java @@ -83,7 +83,7 @@ public final class VbbProvider implements NetworkProvider final Matcher mSingle = P_SINGLE_MASTID.matcher(page); if (mSingle.matches()) { - results.add(new Location(LocationType.ANY, 0 /* TODO */, ParserUtils.resolveEntities(mSingle.group(1)))); + results.add(new Location(LocationType.ANY, 0, 0, 0, ParserUtils.resolveEntities(mSingle.group(1)))); } } else @@ -93,14 +93,14 @@ public final class VbbProvider implements NetworkProvider final Matcher mSingle = P_SINGLE_NAME.matcher(page); if (mSingle.matches()) { - results.add(new Location(LocationType.ANY, 0 /* TODO */, ParserUtils.resolveEntities(mSingle.group(1)))); + results.add(new Location(LocationType.ANY, 0, 0, 0, ParserUtils.resolveEntities(mSingle.group(1)))); } else { final Matcher mMulti = P_MULTI_NAME.matcher(page); while (mMulti.find()) - results.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), ParserUtils - .resolveEntities(mMulti.group(2)))); + results.add(new Location(LocationType.STATION, Integer.parseInt(mMulti.group(1)), 0, 0, ParserUtils.resolveEntities(mMulti + .group(2)))); } } @@ -244,7 +244,7 @@ public final class VbbProvider implements NetworkProvider { final String address = ParserUtils.resolveEntities(mAddress.group(1)); if (!addresses.contains(address)) - addresses.add(new Location(LocationType.ANY, 0, address)); + addresses.add(new Location(LocationType.ANY, 0, 0, 0, address)); } if (addresses.isEmpty()) diff --git a/src/de/schildbach/pte/dto/Location.java b/src/de/schildbach/pte/dto/Location.java index 606d5947..4b944bca 100644 --- a/src/de/schildbach/pte/dto/Location.java +++ b/src/de/schildbach/pte/dto/Location.java @@ -23,12 +23,15 @@ public final class Location { public final LocationType type; public final int id; + public final int lat, lon; public final String name; - public Location(final LocationType type, final int id, final String name) + public Location(final LocationType type, final int id, final int lat, final int lon, final String name) { this.type = type; this.id = id; + this.lat = lat; + this.lon = lon; this.name = name; }