mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-14 00:30:31 +00:00
Stricter structure check for Hafas station board.
This commit is contained in:
parent
0b5ee4ffb7
commit
b50dc033fd
15 changed files with 76 additions and 18 deletions
|
@ -91,9 +91,11 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
private Charset jsonGetStopsEncoding;
|
||||
private Charset jsonNearbyStationsEncoding;
|
||||
private boolean dominantPlanStopTime = false;
|
||||
private boolean canDoEquivs = true;
|
||||
private boolean useIso8601 = false;
|
||||
private String extXmlEndpoint = null;
|
||||
private boolean stationBoardHasStationTable = true;
|
||||
private boolean stationBoardHasLocation = false;
|
||||
private boolean stationBoardCanDoEquivs = true;
|
||||
|
||||
private static class Context implements QueryTripsContext
|
||||
{
|
||||
|
@ -186,11 +188,6 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
this.jsonNearbyStationsEncoding = jsonNearbyStationsEncoding;
|
||||
}
|
||||
|
||||
protected void setCanDoEquivs(final boolean canDoEquivs)
|
||||
{
|
||||
this.canDoEquivs = canDoEquivs;
|
||||
}
|
||||
|
||||
protected void setUseIso8601(final boolean useIso8601)
|
||||
{
|
||||
this.useIso8601 = useIso8601;
|
||||
|
@ -201,6 +198,21 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
this.extXmlEndpoint = extXmlEndpoint;
|
||||
}
|
||||
|
||||
protected void setStationBoardHasStationTable(final boolean stationBoardHasStationTable)
|
||||
{
|
||||
this.stationBoardHasStationTable = stationBoardHasStationTable;
|
||||
}
|
||||
|
||||
protected void setStationBoardHasLocation(final boolean stationBoardHasLocation)
|
||||
{
|
||||
this.stationBoardHasLocation = stationBoardHasLocation;
|
||||
}
|
||||
|
||||
protected void setStationBoardCanDoEquivs(final boolean canDoEquivs)
|
||||
{
|
||||
this.stationBoardCanDoEquivs = canDoEquivs;
|
||||
}
|
||||
|
||||
protected final String allProductsString()
|
||||
{
|
||||
final StringBuilder allProducts = new StringBuilder(numProductBits);
|
||||
|
@ -428,7 +440,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
final StringBuilder parameters = new StringBuilder();
|
||||
parameters.append("?productsFilter=").append(allProductsString());
|
||||
parameters.append("&boardType=dep");
|
||||
if (canDoEquivs)
|
||||
if (stationBoardCanDoEquivs)
|
||||
parameters.append("&disableEquivs=yes"); // don't use nearby stations
|
||||
parameters.append("&maxJourneys=").append(maxDepartures > 0 ? maxDepartures : DEFAULT_MAX_DEPARTURES);
|
||||
parameters.append("&start=yes");
|
||||
|
@ -491,14 +503,15 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
throw new IllegalArgumentException("unknown error " + code + ", " + text);
|
||||
}
|
||||
|
||||
if (XmlPullUtil.test(pp, "StationTable"))
|
||||
{
|
||||
XmlPullUtil.enter(pp, "StationTable");
|
||||
}
|
||||
|
||||
String[] stationPlaceAndName = null;
|
||||
if (XmlPullUtil.test(pp, "St"))
|
||||
|
||||
if (stationBoardHasStationTable)
|
||||
XmlPullUtil.enter(pp, "StationTable");
|
||||
|
||||
if (stationBoardHasLocation)
|
||||
{
|
||||
XmlPullUtil.require(pp, "St");
|
||||
|
||||
final String evaId = XmlPullUtil.attr(pp, "evaId");
|
||||
if (evaId != null)
|
||||
{
|
||||
|
@ -532,7 +545,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
// TODO is_reachable
|
||||
// TODO disableTrainInfo
|
||||
|
||||
final boolean isEquivStation = canDoEquivs && depStation != null;
|
||||
final boolean isEquivStation = stationBoardCanDoEquivs && depStation != null;
|
||||
|
||||
if (!isEquivStation && !"cancel".equals(eDelay))
|
||||
{
|
||||
|
@ -649,6 +662,11 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
|||
XmlPullUtil.requireSkip(pp, "Journey");
|
||||
}
|
||||
|
||||
if (stationBoardHasStationTable)
|
||||
XmlPullUtil.exit(pp, "StationTable");
|
||||
|
||||
XmlPullUtil.requireEndDocument(pp);
|
||||
|
||||
result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, normalizedStationId,
|
||||
stationPlaceAndName != null ? stationPlaceAndName[0] : null, stationPlaceAndName != null ? stationPlaceAndName[1] : null),
|
||||
departures, null));
|
||||
|
|
|
@ -34,6 +34,8 @@ public final class BahnProvider extends AbstractHafasProvider
|
|||
public BahnProvider()
|
||||
{
|
||||
super(API_BASE + "bhftafel.exe/dn", API_BASE + "ajax-getstop.exe/dn", API_BASE + "query.exe/dn", 14);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -35,6 +35,8 @@ public class DsbProvider extends AbstractHafasProvider
|
|||
public DsbProvider()
|
||||
{
|
||||
super(API_BASE + "stboard.exe/mn", API_BASE + "ajax-getstop.exe/mn", API_BASE + "query.exe/dn", 11);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -43,6 +43,8 @@ public class EireannProvider extends AbstractHafasProvider
|
|||
public EireannProvider()
|
||||
{
|
||||
super(API_BASE + "stboard.exe/en", API_BASE + "ajax-getstop.exe/en", API_BASE + "query.exe/en", 4);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -36,6 +36,8 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
public NasaProvider()
|
||||
{
|
||||
super(API_BASE + "stboard.exe/dn", API_BASE + "ajax-getstop.exe/dn", API_BASE + "query.exe/dn", 8, UTF_8);
|
||||
|
||||
setStationBoardHasLocation(true);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -32,6 +32,8 @@ public class RtProvider extends AbstractHafasProvider
|
|||
public RtProvider()
|
||||
{
|
||||
super(API_BASE + "stboard.exe/dn", API_BASE + "ajax-getstop.exe/dn", API_BASE + "query.exe/dn", 10, UTF_8);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -32,6 +32,8 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
public SbbProvider()
|
||||
{
|
||||
super(API_BASE + "stboard.exe/dn", API_BASE + "ajax-getstop.exe/dn", API_BASE + "query.exe/dn", 10);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -40,8 +40,9 @@ public class SeProvider extends AbstractHafasProvider
|
|||
super(API_BASE + "stboard.exe/sn", API_BASE + "ajax-getstop.exe/sny", API_BASE + "query.exe/sn", 14, UTF_8);
|
||||
|
||||
setClientType("ANDROID");
|
||||
setCanDoEquivs(false);
|
||||
setUseIso8601(true);
|
||||
setStationBoardHasStationTable(false);
|
||||
setStationBoardCanDoEquivs(false);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -39,6 +39,7 @@ public class SncbProvider extends AbstractHafasProvider
|
|||
|
||||
setJsonGetStopsEncoding(UTF_8);
|
||||
setJsonNearbyStationsEncoding(UTF_8);
|
||||
setStationBoardHasLocation(true);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -40,7 +40,8 @@ public class StockholmProvider extends AbstractHafasProvider
|
|||
super(API_BASE + "stboard.exe/sn", API_BASE + "ajax-getstop.exe/sny", API_BASE + "query.exe/sn", 7);
|
||||
|
||||
setStyles(STYLES);
|
||||
setCanDoEquivs(false);
|
||||
setStationBoardHasStationTable(false);
|
||||
setStationBoardCanDoEquivs(false);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -30,6 +30,8 @@ public class VbnProvider extends AbstractHafasProvider
|
|||
public VbnProvider()
|
||||
{
|
||||
super(API_BASE + "stboard.exe/dn", API_BASE + "ajax-getstop.exe/dny", API_BASE + "query.exe/dn", 10);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -34,6 +34,8 @@ public class VgsProvider extends AbstractHafasProvider
|
|||
public VgsProvider()
|
||||
{
|
||||
super(API_BASE + "stboard.exe/dn", API_BASE + "ajax-getstop.exe/dn", API_BASE + "query.exe/dn", 11);
|
||||
|
||||
setStationBoardHasStationTable(false);
|
||||
}
|
||||
|
||||
public NetworkId id()
|
||||
|
|
|
@ -67,6 +67,12 @@ public final class XmlPullUtil
|
|||
pp.next();
|
||||
}
|
||||
|
||||
public static void exit(final XmlPullParser pp, final String tagName) throws XmlPullParserException, IOException
|
||||
{
|
||||
pp.require(XmlPullParser.END_TAG, null, tagName);
|
||||
pp.next();
|
||||
}
|
||||
|
||||
private static void skipToEnd(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||
{
|
||||
while (pp.getEventType() != XmlPullParser.END_TAG)
|
||||
|
@ -244,4 +250,12 @@ public final class XmlPullUtil
|
|||
|
||||
return text;
|
||||
}
|
||||
|
||||
public static void requireEndDocument(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||
{
|
||||
skipWhitespace(pp);
|
||||
|
||||
if (pp.getEventType() != XmlPullParser.END_DOCUMENT)
|
||||
throw new IllegalStateException("expecting end of document: " + pp.getPositionDescription());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,6 +68,13 @@ public class BahnProviderLiveTest extends AbstractProviderLiveTest
|
|||
print(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryDeparturesInvalidStation() throws Exception
|
||||
{
|
||||
final QueryDeparturesResult resultLive = provider.queryDepartures("999999", 0, false);
|
||||
assertEquals(QueryDeparturesResult.Status.INVALID_STATION, resultLive.status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suggestLocationsUmlaut() throws Exception
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ public class LuProviderLiveTest extends AbstractProviderLiveTest
|
|||
@Test
|
||||
public void nearbyStations() throws Exception
|
||||
{
|
||||
final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.STATION, "120405001"), 0, 0);
|
||||
final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.STATION, "200501001"), 0, 0);
|
||||
|
||||
print(result);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class LuProviderLiveTest extends AbstractProviderLiveTest
|
|||
@Test
|
||||
public void queryDepartures() throws Exception
|
||||
{
|
||||
final QueryDeparturesResult result = provider.queryDepartures("120405001", 0, false);
|
||||
final QueryDeparturesResult result = provider.queryDepartures("200501001", 0, false);
|
||||
|
||||
print(result);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue