mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 17:18:49 +00:00
fixed parsing of connections with bare coordinates
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@570 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
5ea8573fc8
commit
9c43aa8dc1
2 changed files with 23 additions and 20 deletions
|
@ -26,6 +26,7 @@ import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
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("X=").append(location.lon);
|
||||||
uri.append("&REQ0JourneyStops").append(paramSuffix).append("Y=").append(location.lat);
|
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)
|
if (location.name != null)
|
||||||
|
@ -430,15 +434,13 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
private static final Pattern P_CONNECTIONS_ALL_DETAILS = Pattern.compile("<a href=\"([^\"]*)\"[^>]*>Details für alle</a>");
|
private static final Pattern P_CONNECTIONS_ALL_DETAILS = Pattern.compile("<a href=\"([^\"]*)\"[^>]*>Details für alle</a>");
|
||||||
private static final Pattern P_CONNECTIONS_HEAD = Pattern.compile(".*?" //
|
private static final Pattern P_CONNECTIONS_HEAD = Pattern.compile(".*?" //
|
||||||
+ "<td headers=\"ivuAnfFrom\"[^>]*>\n" //
|
+ "<td headers=\"ivuAnfFrom\"[^>]*>\n" //
|
||||||
+ "([^\n]*)\n" // from name
|
+ "(?:([^\n]*)\n)?" // from name
|
||||||
+ "<a href=\"[^\"]*location=(?:(\\d+)|),(?:(\\w+)|),WGS84,(\\d+\\.\\d+),(\\d+\\.\\d+)&.*?" // from id, lat,
|
+ "<a href=\"[^\"]*location=(?:(\\d+)|),(?:(\\w+)|),WGS84,(\\d+\\.\\d+),(\\d+\\.\\d+)&.*?" // fr id,lat,lon
|
||||||
// lon
|
|
||||||
+ "(?:<td headers=\"ivuAnfVia1\"[^>]*>\n" //
|
+ "(?:<td headers=\"ivuAnfVia1\"[^>]*>\n" //
|
||||||
+ "([^\n]*)<.*?)?" // via name
|
+ "([^\n]*)<.*?)?" // via name
|
||||||
+ "<td headers=\"ivuAnfTo\"[^>]*>\n" //
|
+ "<td headers=\"ivuAnfTo\"[^>]*>\n" //
|
||||||
+ "([^\n]*)\n" // to name
|
+ "(?:([^\n]*)\n)?" // to name
|
||||||
+ "<a href=\"[^\"]*location=(?:(\\d+)|),(?:(\\w+)|),WGS84,(\\d+\\.\\d+),(\\d+\\.\\d+)&.*?" // to id, lat,
|
+ "<a href=\"[^\"]*location=(?:(\\d+)|),(?:(\\w+)|),WGS84,(\\d+\\.\\d+),(\\d+\\.\\d+)&.*?" // to id,lat,lon
|
||||||
// lon
|
|
||||||
+ "<td headers=\"ivuAnfTime\"[^>]*>.., (\\d{2}\\.\\d{2}\\.\\d{2}) \\d{1,2}:\\d{2}</td>.*?" // date
|
+ "<td headers=\"ivuAnfTime\"[^>]*>.., (\\d{2}\\.\\d{2}\\.\\d{2}) \\d{1,2}:\\d{2}</td>.*?" // date
|
||||||
+ "(?:<a href=\"([^\"]*)\" title=\"frühere Verbindungen\"[^>]*?>.*?)?" // linkEarlier
|
+ "(?:<a href=\"([^\"]*)\" title=\"frühere Verbindungen\"[^>]*?>.*?)?" // linkEarlier
|
||||||
+ "(?:<a href=\"([^\"]*)\" title=\"spätere Verbindungen\"[^>]*?>.*?)?" // linkLater
|
+ "(?:<a href=\"([^\"]*)\" title=\"spätere Verbindungen\"[^>]*?>.*?)?" // linkLater
|
||||||
|
@ -489,11 +491,11 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
final Matcher mHead = P_CONNECTIONS_HEAD.matcher(page);
|
final Matcher mHead = P_CONNECTIONS_HEAD.matcher(page);
|
||||||
if (mHead.matches())
|
if (mHead.matches())
|
||||||
{
|
{
|
||||||
final Location from = location(mHead.group(3), mHead.group(2), mHead.group(5), mHead.group(4),
|
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)));
|
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 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),
|
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)));
|
ParserUtils.resolveEntities(mHead.group(7))) : null;
|
||||||
final Calendar currentDate = new GregorianCalendar(timeZone());
|
final Calendar currentDate = new GregorianCalendar(timeZone());
|
||||||
currentDate.clear();
|
currentDate.clear();
|
||||||
ParserUtils.parseGermanDate(currentDate, mHead.group(12));
|
ParserUtils.parseGermanDate(currentDate, mHead.group(12));
|
||||||
|
|
|
@ -93,8 +93,8 @@ public class BvgProviderLiveTest
|
||||||
@Test
|
@Test
|
||||||
public void connectionBetweenCoordinates() throws Exception
|
public void connectionBetweenCoordinates() throws Exception
|
||||||
{
|
{
|
||||||
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 52501507, 13357026, null, "from"),
|
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 52501507, 13357026, null, null), null,
|
||||||
null, new Location(LocationType.ADDRESS, 0, 52513639, 13568648, null, "to"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
|
new Location(LocationType.ADDRESS, 0, 52513639, 13568648, null, null), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
|
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
|
||||||
System.out.println(moreResult);
|
System.out.println(moreResult);
|
||||||
|
@ -103,9 +103,9 @@ public class BvgProviderLiveTest
|
||||||
@Test
|
@Test
|
||||||
public void viaConnectionBetweenCoordinates() throws Exception
|
public void viaConnectionBetweenCoordinates() throws Exception
|
||||||
{
|
{
|
||||||
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 52501507, 13357026, null, "from"),
|
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, 52501507, 13357026, null, null),
|
||||||
new Location(LocationType.ADDRESS, 0, 52479868, 13324247, null, "via"), new Location(LocationType.ADDRESS, 0, 52513639, 13568648,
|
new Location(LocationType.ADDRESS, 0, 52479868, 13324247, null, null), new Location(LocationType.ADDRESS, 0, 52513639, 13568648,
|
||||||
null, "to"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
|
null, null), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
|
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
|
||||||
System.out.println(moreResult);
|
System.out.println(moreResult);
|
||||||
|
@ -114,8 +114,9 @@ public class BvgProviderLiveTest
|
||||||
@Test
|
@Test
|
||||||
public void connectionBetweenAddresses() throws Exception
|
public void connectionBetweenAddresses() throws Exception
|
||||||
{
|
{
|
||||||
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null, "10715 Bln Charlb.-Wilm., Weimarische Str. 7"),
|
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null,
|
||||||
null, new Location(LocationType.ADDRESS, 0, null, "10178 Bln Mitte, Sophienstr. 24"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
|
"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);
|
System.out.println(result);
|
||||||
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
|
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
|
||||||
System.out.println(moreResult);
|
System.out.println(moreResult);
|
||||||
|
@ -124,9 +125,9 @@ public class BvgProviderLiveTest
|
||||||
@Test
|
@Test
|
||||||
public void viaConnectionBetweenAddresses() throws Exception
|
public void viaConnectionBetweenAddresses() throws Exception
|
||||||
{
|
{
|
||||||
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null, "10715 Bln Charlb.-Wilm., Weimarische Str. 7"),
|
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null,
|
||||||
new Location(LocationType.ADDRESS, 0, null, "10115 Bln Mitte, Hannoversche Str. 20"), 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"),
|
||||||
"10178 Bln Mitte, Sophienstr. 24"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
|
new Location(LocationType.ADDRESS, 0, null, "10178 Bln Mitte, Sophienstr. 24"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
|
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
|
||||||
System.out.println(moreResult);
|
System.out.println(moreResult);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue