diff --git a/src/de/schildbach/pte/AbstractEfaProvider.java b/src/de/schildbach/pte/AbstractEfaProvider.java index f46b2b5a..2fc036c8 100644 --- a/src/de/schildbach/pte/AbstractEfaProvider.java +++ b/src/de/schildbach/pte/AbstractEfaProvider.java @@ -88,8 +88,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"origin".equals(pp.getAttributeValue(null, "usage"))) throw new IllegalStateException("cannot find "); XmlPullUtil.enter(pp, "itdOdv"); - XmlPullUtil.enter(pp, "itdOdvPlace"); - XmlPullUtil.exit(pp, "itdOdvPlace"); + + final String place = processItdOdvPlace(pp); + if (!XmlPullUtil.test(pp, "itdOdvName")) throw new IllegalStateException("cannot find "); final String nameState = XmlPullUtil.attr(pp, "state"); @@ -99,7 +100,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider if ("identified".equals(nameState) || "list".equals(nameState)) while (XmlPullUtil.test(pp, "odvNameElem")) - results.add(processOdvNameElem(pp)); + results.add(processOdvNameElem(pp, place)); // parse assigned stops if (XmlPullUtil.jumpToStartTag(pp, null, "itdOdvAssignedStops")) @@ -127,7 +128,30 @@ public abstract class AbstractEfaProvider implements NetworkProvider } } - private Location processOdvNameElem(final XmlPullParser pp) throws XmlPullParserException, IOException + private String processItdOdvPlace(final XmlPullParser pp) throws XmlPullParserException, IOException + { + if (!XmlPullUtil.test(pp, "itdOdvPlace")) + throw new IllegalStateException("expecting "); + + final String placeState = XmlPullUtil.attr(pp, "state"); + + XmlPullUtil.enter(pp, "itdOdvPlace"); + String place = null; + if ("identified".equals(placeState)) + { + if (XmlPullUtil.test(pp, "odvPlaceElem")) + { + XmlPullUtil.enter(pp, "odvPlaceElem"); + place = normalizeLocationName(pp.getText()); + XmlPullUtil.exit(pp, "odvPlaceElem"); + } + } + XmlPullUtil.exit(pp, "itdOdvPlace"); + + return place; + } + + private Location processOdvNameElem(final XmlPullParser pp, final String defaultPlace) throws XmlPullParserException, IOException { if (!XmlPullUtil.test(pp, "odvNameElem")) throw new IllegalStateException("expecting "); @@ -137,6 +161,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider final String stopIdStr = pp.getAttributeValue(null, "stopID"); final String poiIdStr = pp.getAttributeValue(null, "poiID"); final String streetIdStr = pp.getAttributeValue(null, "streetID"); + final String place = !"loc".equals(anyType) ? normalizeLocationName(pp.getAttributeValue(null, "locality")) : null; + final String name = normalizeLocationName(pp.getAttributeValue(null, "objectName")); int lat = 0, lon = 0; if ("WGS84".equals(pp.getAttributeValue(null, "mapName"))) { @@ -193,10 +219,10 @@ public abstract class AbstractEfaProvider implements NetworkProvider } XmlPullUtil.enter(pp, "odvNameElem"); - final String name = normalizeLocationName(pp.getText()); + final String longName = normalizeLocationName(pp.getText()); XmlPullUtil.exit(pp, "odvNameElem"); - return new Location(type, id, lat, lon, name); + return new Location(type, id, lat, lon, place != null ? place : defaultPlace, name != null ? name : longName); } private Location processItdOdvAssignedStop(final XmlPullParser pp) @@ -209,7 +235,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider lon = Integer.parseInt(pp.getAttributeValue(null, "x")); } final String name = normalizeLocationName(pp.getAttributeValue(null, "nameWithPlace")); - return new Location(LocationType.STATION, id, lat, lon, name); + return new Location(LocationType.STATION, id, lat, lon, null, name); } protected abstract String nearbyLatLonUri(int lat, int lon); @@ -242,17 +268,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider throw new IllegalStateException("cannot find "); 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"); + final String place = processItdOdvPlace(pp); XmlPullUtil.require(pp, "itdOdvName"); final String nameState = pp.getAttributeValue(null, "state"); @@ -311,8 +327,15 @@ public abstract class AbstractEfaProvider implements NetworkProvider } else { - XmlPullUtil.enter(pp, "itdOdvAssignedStop"); - XmlPullUtil.exit(pp, "itdOdvAssignedStop"); + if (!pp.isEmptyElementTag()) + { + XmlPullUtil.enter(pp, "itdOdvAssignedStop"); + XmlPullUtil.exit(pp, "itdOdvAssignedStop"); + } + else + { + XmlPullUtil.next(pp); + } } } } @@ -333,7 +356,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider XmlPullUtil.next(pp); while (XmlPullUtil.test(pp, "odvNameElem")) { - final Location location = processOdvNameElem(pp); + final Location location = processOdvNameElem(pp, place); if (location.type == LocationType.STATION) { final Station newStation = new Station(location.id, null, location.name, null, location.lat, location.lon, 0, null, null); @@ -391,6 +414,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider return 'T' + str; if (noTrainName.equals("Badner Bahn")) return 'T' + str; + if (noTrainName.equals("Stadtbus")) + return 'B' + str; if (noTrainName.equals("Citybus")) return 'B' + str; if (noTrainName.equals("Regionalbus")) @@ -967,6 +992,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider protected static String normalizeLocationName(final String name) { + if (name == null || name.length() == 0) + return null; + return P_STATION_NAME_WHITESPACE.matcher(name).replaceAll(" "); } @@ -1043,51 +1071,52 @@ public abstract class AbstractEfaProvider implements NetworkProvider { final String usage = XmlPullUtil.attr(pp, "usage"); XmlPullUtil.enter(pp, "itdOdv"); - XmlPullUtil.enter(pp, "itdOdvPlace"); - XmlPullUtil.exit(pp, "itdOdvPlace"); + + final String place = processItdOdvPlace(pp); + if (!XmlPullUtil.test(pp, "itdOdvName")) throw new IllegalStateException("cannot find inside " + usage); - final String state = XmlPullUtil.attr(pp, "state"); + final String nameState = XmlPullUtil.attr(pp, "state"); XmlPullUtil.enter(pp, "itdOdvName"); if (XmlPullUtil.test(pp, "itdMessage")) XmlPullUtil.next(pp); - if ("list".equals(state)) + if ("list".equals(nameState)) { if ("origin".equals(usage)) { ambiguousFrom = new ArrayList(); while (XmlPullUtil.test(pp, "odvNameElem")) - ambiguousFrom.add(processOdvNameElem(pp)); + ambiguousFrom.add(processOdvNameElem(pp, place)); } else if ("via".equals(usage)) { ambiguousVia = new ArrayList(); while (XmlPullUtil.test(pp, "odvNameElem")) - ambiguousVia.add(processOdvNameElem(pp)); + ambiguousVia.add(processOdvNameElem(pp, place)); } else if ("destination".equals(usage)) { ambiguousTo = new ArrayList(); while (XmlPullUtil.test(pp, "odvNameElem")) - ambiguousTo.add(processOdvNameElem(pp)); + ambiguousTo.add(processOdvNameElem(pp, place)); } else { throw new IllegalStateException("unknown usage: " + usage); } } - else if ("identified".equals(state)) + else if ("identified".equals(nameState)) { if (!XmlPullUtil.test(pp, "odvNameElem")) throw new IllegalStateException("cannot find inside " + usage); if ("origin".equals(usage)) - from = processOdvNameElem(pp); + from = processOdvNameElem(pp, place); else if ("via".equals(usage)) - via = processOdvNameElem(pp); + via = processOdvNameElem(pp, place); else if ("destination".equals(usage)) - to = processOdvNameElem(pp); + to = processOdvNameElem(pp, place); else throw new IllegalStateException("unknown usage: " + usage); } diff --git a/src/de/schildbach/pte/AbstractHafasProvider.java b/src/de/schildbach/pte/AbstractHafasProvider.java index cc1b1439..9fca2afc 100644 --- a/src/de/schildbach/pte/AbstractHafasProvider.java +++ b/src/de/schildbach/pte/AbstractHafasProvider.java @@ -81,7 +81,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider final int id = Integer.parseInt(pp.getAttributeValue(null, "externalStationNr")); final int x = Integer.parseInt(pp.getAttributeValue(null, "x")); final int y = Integer.parseInt(pp.getAttributeValue(null, "y")); - return new Location(LocationType.STATION, id, y, x, name); + return new Location(LocationType.STATION, id, y, x, null, name); } throw new IllegalStateException("cannot handle: " + type); } @@ -96,7 +96,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider name = null; final int x = Integer.parseInt(pp.getAttributeValue(null, "x")); final int y = Integer.parseInt(pp.getAttributeValue(null, "y")); - return new Location(LocationType.POI, 0, y, x, name); + return new Location(LocationType.POI, 0, y, x, null, name); } throw new IllegalStateException("cannot handle: " + type); } @@ -111,7 +111,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider name = null; final int x = Integer.parseInt(pp.getAttributeValue(null, "x")); final int y = Integer.parseInt(pp.getAttributeValue(null, "y")); - return new Location(LocationType.ADDRESS, 0, y, x, name); + return new Location(LocationType.ADDRESS, 0, y, x, null, name); } throw new IllegalStateException("cannot handle: " + type); } diff --git a/src/de/schildbach/pte/OebbProvider.java b/src/de/schildbach/pte/OebbProvider.java index c36c39cc..f3a9f5b0 100644 --- a/src/de/schildbach/pte/OebbProvider.java +++ b/src/de/schildbach/pte/OebbProvider.java @@ -110,15 +110,15 @@ public class OebbProvider extends AbstractHafasProvider if (type == 1) // station { - results.add(new Location(LocationType.STATION, localId, lat, lon, value)); + results.add(new Location(LocationType.STATION, localId, lat, lon, null, value)); } else if (type == 2) // address { - results.add(new Location(LocationType.ADDRESS, 0, lat, lon, value)); + results.add(new Location(LocationType.ADDRESS, 0, lat, lon, null, value)); } else if (type == 4) // poi { - results.add(new Location(LocationType.POI, localId, lat, lon, value)); + results.add(new Location(LocationType.POI, localId, lat, lon, null, value)); } else { diff --git a/src/de/schildbach/pte/dto/Location.java b/src/de/schildbach/pte/dto/Location.java index 204fede7..ce58629e 100644 --- a/src/de/schildbach/pte/dto/Location.java +++ b/src/de/schildbach/pte/dto/Location.java @@ -27,14 +27,16 @@ public final class Location implements Serializable public final LocationType type; public final int id; public final int lat, lon; + public final String place; public final String name; - public Location(final LocationType type, final int id, final int lat, final int lon, final String name) + public Location(final LocationType type, final int id, final int lat, final int lon, final String place, final String name) { this.type = type; this.id = id; this.lat = lat; this.lon = lon; + this.place = place; this.name = name; } @@ -44,6 +46,7 @@ public final class Location implements Serializable this.id = id; this.lat = 0; this.lon = 0; + this.place = null; this.name = name; } @@ -55,7 +58,7 @@ public final class Location implements Serializable public String toDebugString() { - return "[" + type + " " + id + " " + lat + "/" + lon + " '" + name + "']"; + return "[" + type + " " + id + " " + lat + "/" + lon + " " + (place != null ? "'" + place + "'" : "null") + " '" + name + "']"; } @Override diff --git a/test/de/schildbach/pte/live/GvhProviderLiveTest.java b/test/de/schildbach/pte/live/GvhProviderLiveTest.java index de5de438..4f82a90f 100644 --- a/test/de/schildbach/pte/live/GvhProviderLiveTest.java +++ b/test/de/schildbach/pte/live/GvhProviderLiveTest.java @@ -96,16 +96,17 @@ public class GvhProviderLiveTest @Test public void shortConnection() throws Exception { - final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 25000031, 0, 0, "Hannover Hauptbahnhof"), - null, new Location(LocationType.STATION, 25001141, "Hannover Bismarckstraße"), new Date(), true, ALL_PRODUCTS, WalkSpeed.FAST); + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 25000031, 0, 0, null, + "Hannover Hauptbahnhof"), null, new Location(LocationType.STATION, 25001141, "Hannover Bismarckstraße"), new Date(), true, + ALL_PRODUCTS, WalkSpeed.FAST); System.out.println(result); } @Test public void connectionBetweenAnyAndAddress() throws Exception { - final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ANY, 0, 53069619, 8799202, - "bremen, neustadtswall 12"), null, new Location(LocationType.ADDRESS, 0, 53104124, 8788575, "Bremen Glücksburger Straße 37"), + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ANY, 0, 53069619, 8799202, null, + "bremen, neustadtswall 12"), null, new Location(LocationType.ADDRESS, 0, 53104124, 8788575, null, "Bremen Glücksburger Straße 37"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); @@ -115,8 +116,8 @@ public class GvhProviderLiveTest @Test public void connectionBetweenAddresses() throws Exception { - final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 53622859, 10133545, - "Zamenhofweg 14, 22159 Hamburg, Deutschland"), null, new Location(LocationType.ADDRESS, 0, 53734260, 9674990, + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 53622859, 10133545, null, + "Zamenhofweg 14, 22159 Hamburg, Deutschland"), null, new Location(LocationType.ADDRESS, 0, 53734260, 9674990, null, "Lehmkuhlen 5, 25337 Elmshorn, Deutschland"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); diff --git a/test/de/schildbach/pte/live/KvvProviderLiveTest.java b/test/de/schildbach/pte/live/KvvProviderLiveTest.java index c93a9559..f108598f 100644 --- a/test/de/schildbach/pte/live/KvvProviderLiveTest.java +++ b/test/de/schildbach/pte/live/KvvProviderLiveTest.java @@ -14,6 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + package de.schildbach.pte.live; import java.util.Date; @@ -55,8 +56,8 @@ public class KvvProviderLiveTest @Test public void connectionBetweenAddresses() throws Exception { - final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48985089, 8402709, - "Konstanzer Straße 17, 76199 Karlsruhe, Deutschland"), null, new Location(LocationType.ADDRESS, 0, 49007706, 8356358, + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48985089, 8402709, null, + "Konstanzer Straße 17, 76199 Karlsruhe, Deutschland"), null, new Location(LocationType.ADDRESS, 0, 49007706, 8356358, null, "Durmersheimer Straße 6, 76185 Karlsruhe, Deutschland"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); diff --git a/test/de/schildbach/pte/live/MvvProviderLiveTest.java b/test/de/schildbach/pte/live/MvvProviderLiveTest.java index 0263f2fb..754eb671 100644 --- a/test/de/schildbach/pte/live/MvvProviderLiveTest.java +++ b/test/de/schildbach/pte/live/MvvProviderLiveTest.java @@ -57,8 +57,8 @@ public class MvvProviderLiveTest @Test public void connectionBetweenCoordinates() throws Exception { - final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48165238, 11577473, null), null, - new Location(LocationType.ADDRESS, 0, 47987199, 11326532, null), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48165238, 11577473, null, null), null, + new Location(LocationType.ADDRESS, 0, 47987199, 11326532, null, null), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); System.out.println(moreResult); @@ -67,7 +67,7 @@ public class MvvProviderLiveTest @Test public void connectionBetweenCoordinateAndStation() throws Exception { - final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48238341, 11478230, null), null, + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 48238341, 11478230, null, null), null, new Location(LocationType.ANY, 0, "Ostbahnhof"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); @@ -88,7 +88,7 @@ public class MvvProviderLiveTest public void connectionBetweenStationAndAddress() throws Exception { final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 1220, "Josephsburg"), null, new Location( - LocationType.ADDRESS, 0, 48188018, 11574239, "München Frankfurter Ring 35"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); + LocationType.ADDRESS, 0, 48188018, 11574239, null, "München Frankfurter Ring 35"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); System.out.println(moreResult); diff --git a/test/de/schildbach/pte/live/TflProviderLiveTest.java b/test/de/schildbach/pte/live/TflProviderLiveTest.java index 0365a16c..d0abf80f 100644 --- a/test/de/schildbach/pte/live/TflProviderLiveTest.java +++ b/test/de/schildbach/pte/live/TflProviderLiveTest.java @@ -57,7 +57,7 @@ public class TflProviderLiveTest public void postcodeConnection() throws Exception { final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ANY, 0, "sw19 8ta"), null, new Location( - LocationType.STATION, 1016019, 51655903, -397249, "Watford (Herts), Watford Town Centre"), new Date(), true, ALL_PRODUCTS, + LocationType.STATION, 1016019, 51655903, -397249, null, "Watford (Herts), Watford Town Centre"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); }