diff --git a/src/de/schildbach/pte/AbstractHafasProvider.java b/src/de/schildbach/pte/AbstractHafasProvider.java index 311cdf66..db6ce12a 100644 --- a/src/de/schildbach/pte/AbstractHafasProvider.java +++ b/src/de/schildbach/pte/AbstractHafasProvider.java @@ -347,6 +347,79 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider } } + protected final List xmlLocationList(final String uri) throws IOException + { + InputStream is = null; + + try + { + is = ParserUtils.scrapeInputStream(uri); + + final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null); + final XmlPullParser pp = factory.newPullParser(); + pp.setInput(is, "UTF-8"); + + final List results = new ArrayList(); + + pp.require(XmlPullParser.START_DOCUMENT, null, null); + pp.next(); + + XmlPullUtil.enter(pp, "LocationList"); + + if (pp.isWhitespace()) + pp.next(); + + while (XmlPullUtil.test(pp, "StopLocation") || XmlPullUtil.test(pp, "CoordLocation")) + { + final String name = XmlPullUtil.attr(pp, "name"); + final int lon = XmlPullUtil.intAttr(pp, "x"); + final int lat = XmlPullUtil.intAttr(pp, "y"); + + if (XmlPullUtil.test(pp, "StopLocation")) + { + final int id = XmlPullUtil.intAttr(pp, "id"); + final String[] placeAndName = splitPlaceAndName(name); + results.add(new Location(LocationType.STATION, id, lat, lon, placeAndName[0], placeAndName[1])); + } + else + { + final String type = XmlPullUtil.attr(pp, "type"); + if ("POI".equals(type)) + results.add(new Location(LocationType.POI, 0, lat, lon, null, name)); + else if ("ADR".equals(type)) + results.add(new Location(LocationType.ADDRESS, 0, lat, lon, null, name)); + else + throw new IllegalStateException("unknown type " + type + " on " + uri); + } + + if (pp.isEmptyElementTag()) + { + XmlPullUtil.next(pp); + } + else + { + XmlPullUtil.enter(pp); + XmlPullUtil.exit(pp); + } + + if (pp.isWhitespace()) + pp.next(); + } + XmlPullUtil.exit(pp, "LocationList"); + + return results; + } + catch (final XmlPullParserException x) + { + throw new RuntimeException(x); + } + finally + { + if (is != null) + is.close(); + } + } + private static final Pattern P_XML_MLC_REQ_ID = Pattern.compile(".*?@L=(\\d+)@.*?"); private static final Pattern P_XML_MLC_REQ_LONLAT = Pattern.compile(".*?@X=(-?\\d+)@Y=(-?\\d+)@.*?"); diff --git a/src/de/schildbach/pte/DsbProvider.java b/src/de/schildbach/pte/DsbProvider.java index cad48379..07f51e65 100644 --- a/src/de/schildbach/pte/DsbProvider.java +++ b/src/de/schildbach/pte/DsbProvider.java @@ -33,7 +33,7 @@ import de.schildbach.pte.util.ParserUtils; public class DsbProvider extends AbstractHafasProvider { public static final NetworkId NETWORK_ID = NetworkId.DSB; - private static final String API_BASE = "http://dk.hafas.de/bin/mobile/"; + private static final String API_BASE = "http://mobil.rejseplanen.dk/mobil-bin/"; // http://dk.hafas.de/bin/fat/ // http://mobil.rejseplanen.dk/mobil-bin/ @@ -152,14 +152,14 @@ public class DsbProvider extends AbstractHafasProvider return xmlQueryDepartures(uri.toString(), stationId); } - private static final String AUTOCOMPLETE_URI = API_BASE + "ajax-getstop.exe/dn?getstop=1&REQ0JourneyStopsS0A=255&S=%s?&js=true&"; + private static final String AUTOCOMPLETE_URI = "http://xmlopen.rejseplanen.dk/bin/rest.exe/location.name?input=%s"; private static final String ENCODING = "ISO-8859-1"; public List autocompleteStations(final CharSequence constraint) throws IOException { final String uri = String.format(AUTOCOMPLETE_URI, ParserUtils.urlEncode(constraint.toString(), ENCODING)); - return jsonGetStops(uri); + return xmlLocationList(uri); } @Override