From 9c43aa8dc16831748445d8b0b2860bb9cfc3cd72 Mon Sep 17 00:00:00 2001 From: "andreas.schildbach@gmail.com" Date: Sun, 17 Apr 2011 20:43:43 +0000 Subject: [PATCH] fixed parsing of connections with bare coordinates git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@570 0924bc21-9374-b0fa-ee44-9ff1593b38f0 --- src/de/schildbach/pte/BvgProvider.java | 22 ++++++++++--------- .../pte/live/BvgProviderLiveTest.java | 21 +++++++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/de/schildbach/pte/BvgProvider.java b/src/de/schildbach/pte/BvgProvider.java index a4881c00..377665e7 100644 --- a/src/de/schildbach/pte/BvgProvider.java +++ b/src/de/schildbach/pte/BvgProvider.java @@ -26,6 +26,7 @@ import java.util.GregorianCalendar; import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -295,6 +296,9 @@ public final class BvgProvider extends AbstractHafasProvider { uri.append("&REQ0JourneyStops").append(paramSuffix).append("X=").append(location.lon); uri.append("&REQ0JourneyStops").append(paramSuffix).append("Y=").append(location.lat); + if (location.name == null) + uri.append("&REQ0JourneyStops").append(paramSuffix).append("O=") + .append(ParserUtils.urlEncode(String.format(Locale.ENGLISH, "%.6f, %.6f", location.lat / 1E6, location.lon / 1E6))); } if (location.name != null) @@ -430,15 +434,13 @@ public final class BvgProvider extends AbstractHafasProvider private static final Pattern P_CONNECTIONS_ALL_DETAILS = Pattern.compile("]*>Details für alle"); private static final Pattern P_CONNECTIONS_HEAD = Pattern.compile(".*?" // + "]*>\n" // - + "([^\n]*)\n" // from name - + "]*>\n" // + "([^\n]*)<.*?)?" // via name + "]*>\n" // - + "([^\n]*)\n" // to name - + "]*>.., (\\d{2}\\.\\d{2}\\.\\d{2}) \\d{1,2}:\\d{2}.*?" // date + "(?:]*?>.*?)?" // linkEarlier + "(?:]*?>.*?)?" // linkLater @@ -489,11 +491,11 @@ public final class BvgProvider extends AbstractHafasProvider final Matcher mHead = P_CONNECTIONS_HEAD.matcher(page); if (mHead.matches()) { - final Location from = location(mHead.group(3), mHead.group(2), mHead.group(5), mHead.group(4), - ParserUtils.resolveEntities(mHead.group(1))); + final Location from = mHead.group(1) != null ? location(mHead.group(3), mHead.group(2), mHead.group(5), mHead.group(4), + ParserUtils.resolveEntities(mHead.group(1))) : null; final Location via = mHead.group(6) != null ? location(null, null, null, null, ParserUtils.resolveEntities(mHead.group(6))) : null; - final Location to = location(mHead.group(9), mHead.group(8), mHead.group(11), mHead.group(10), - ParserUtils.resolveEntities(mHead.group(7))); + final Location to = mHead.group(7) != null ? location(mHead.group(9), mHead.group(8), mHead.group(11), mHead.group(10), + ParserUtils.resolveEntities(mHead.group(7))) : null; final Calendar currentDate = new GregorianCalendar(timeZone()); currentDate.clear(); ParserUtils.parseGermanDate(currentDate, mHead.group(12)); diff --git a/test/de/schildbach/pte/live/BvgProviderLiveTest.java b/test/de/schildbach/pte/live/BvgProviderLiveTest.java index 2d0e6f81..9eff74c9 100644 --- a/test/de/schildbach/pte/live/BvgProviderLiveTest.java +++ b/test/de/schildbach/pte/live/BvgProviderLiveTest.java @@ -93,8 +93,8 @@ public class BvgProviderLiveTest @Test public void connectionBetweenCoordinates() throws Exception { - final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 52501507, 13357026, null, "from"), - null, new Location(LocationType.ADDRESS, 0, 52513639, 13568648, null, "to"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 52501507, 13357026, null, null), null, + new Location(LocationType.ADDRESS, 0, 52513639, 13568648, null, null), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); System.out.println(moreResult); @@ -103,9 +103,9 @@ public class BvgProviderLiveTest @Test public void viaConnectionBetweenCoordinates() throws Exception { - final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 52501507, 13357026, null, "from"), - new Location(LocationType.ADDRESS, 0, 52479868, 13324247, null, "via"), new Location(LocationType.ADDRESS, 0, 52513639, 13568648, - null, "to"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 52501507, 13357026, null, null), + new Location(LocationType.ADDRESS, 0, 52479868, 13324247, null, null), new Location(LocationType.ADDRESS, 0, 52513639, 13568648, + null, null), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); System.out.println(moreResult); @@ -114,8 +114,9 @@ public class BvgProviderLiveTest @Test public void connectionBetweenAddresses() throws Exception { - final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null, "10715 Bln Charlb.-Wilm., Weimarische Str. 7"), - null, new Location(LocationType.ADDRESS, 0, null, "10178 Bln Mitte, Sophienstr. 24"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null, + "10715 Bln Charlb.-Wilm., Weimarische Str. 7"), null, new Location(LocationType.ADDRESS, 0, null, "10178 Bln Mitte, Sophienstr. 24"), + new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); System.out.println(moreResult); @@ -124,9 +125,9 @@ public class BvgProviderLiveTest @Test public void viaConnectionBetweenAddresses() throws Exception { - final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null, "10715 Bln Charlb.-Wilm., Weimarische Str. 7"), - new Location(LocationType.ADDRESS, 0, null, "10115 Bln Mitte, Hannoversche Str. 20"), new Location(LocationType.ADDRESS, 0, null, - "10178 Bln Mitte, Sophienstr. 24"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null, + "10715 Bln Charlb.-Wilm., Weimarische Str. 7"), new Location(LocationType.ADDRESS, 0, null, "10115 Bln Mitte, Hannoversche Str. 20"), + new Location(LocationType.ADDRESS, 0, null, "10178 Bln Mitte, Sophienstr. 24"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); System.out.println(result); final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); System.out.println(moreResult);