mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-13 16:20:34 +00:00
connection query option for bicycle carriage
This commit is contained in:
parent
825cdc61db
commit
e3b7215b37
9 changed files with 59 additions and 31 deletions
|
@ -47,6 +47,7 @@ import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
import org.xmlpull.v1.XmlPullParserFactory;
|
import org.xmlpull.v1.XmlPullParserFactory;
|
||||||
|
|
||||||
|
import de.schildbach.pte.NetworkProvider.Option;
|
||||||
import de.schildbach.pte.dto.Connection;
|
import de.schildbach.pte.dto.Connection;
|
||||||
import de.schildbach.pte.dto.Departure;
|
import de.schildbach.pte.dto.Departure;
|
||||||
import de.schildbach.pte.dto.Fare;
|
import de.schildbach.pte.dto.Fare;
|
||||||
|
@ -1577,7 +1578,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String xsltTripRequest2Uri(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
protected String xsltTripRequest2Uri(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
||||||
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility)
|
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility, final Set<Option> options)
|
||||||
{
|
{
|
||||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
|
final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
|
||||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HHmm");
|
final DateFormat TIME_FORMAT = new SimpleDateFormat("HHmm");
|
||||||
|
@ -1655,6 +1656,9 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
uri.append("&lineRestriction=403"); // means: all but ice
|
uri.append("&lineRestriction=403"); // means: all but ice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options != null && options.contains(Option.BIKE))
|
||||||
|
uri.append("&bikeTakeAlong=1");
|
||||||
|
|
||||||
uri.append("&locationServerActive=1");
|
uri.append("&locationServerActive=1");
|
||||||
uri.append("&useRealtime=1");
|
uri.append("&useRealtime=1");
|
||||||
uri.append("&useProxFootSearch=1"); // walk if it makes journeys quicker
|
uri.append("&useProxFootSearch=1"); // walk if it makes journeys quicker
|
||||||
|
@ -1681,9 +1685,10 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryConnectionsResult queryConnections(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
public QueryConnectionsResult queryConnections(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
||||||
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility) throws IOException
|
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility, final Set<Option> options)
|
||||||
|
throws IOException
|
||||||
{
|
{
|
||||||
final String uri = xsltTripRequest2Uri(from, via, to, date, dep, numConnections, products, walkSpeed, accessibility);
|
final String uri = xsltTripRequest2Uri(from, via, to, date, dep, numConnections, products, walkSpeed, accessibility, options);
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try
|
try
|
||||||
|
|
|
@ -732,7 +732,8 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryConnectionsResult queryConnections(Location from, Location via, Location to, final Date date, final boolean dep,
|
public QueryConnectionsResult queryConnections(Location from, Location via, Location to, final Date date, final boolean dep,
|
||||||
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility) throws IOException
|
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility, final Set<Option> options)
|
||||||
|
throws IOException
|
||||||
{
|
{
|
||||||
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
||||||
|
|
||||||
|
@ -782,14 +783,18 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
productsStr.append(allProductsString());
|
productsStr.append(allProductsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final char bikeChar = (options != null && options.contains(Option.BIKE)) ? '1' : '0';
|
||||||
|
|
||||||
final StringBuilder request = new StringBuilder("<ConReq deliverPolyline=\"1\">");
|
final StringBuilder request = new StringBuilder("<ConReq deliverPolyline=\"1\">");
|
||||||
request.append("<Start>").append(locationXml(from));
|
request.append("<Start>").append(locationXml(from));
|
||||||
request.append("<Prod prod=\"").append(productsStr).append("\" bike=\"0\" couchette=\"0\" direct=\"0\" sleeper=\"0\"/>");
|
request.append("<Prod prod=\"").append(productsStr).append("\" bike=\"").append(bikeChar)
|
||||||
|
.append("\" couchette=\"0\" direct=\"0\" sleeper=\"0\"/>");
|
||||||
request.append("</Start>");
|
request.append("</Start>");
|
||||||
if (via != null)
|
if (via != null)
|
||||||
{
|
{
|
||||||
request.append("<Via>").append(locationXml(via));
|
request.append("<Via>").append(locationXml(via));
|
||||||
request.append("<Prod prod=\"").append(productsStr).append("\" bike=\"0\" couchette=\"0\" direct=\"0\" sleeper=\"0\"/>");
|
request.append("<Prod prod=\"").append(productsStr).append("\" bike=\"").append(bikeChar)
|
||||||
|
.append("\" couchette=\"0\" direct=\"0\" sleeper=\"0\"/>");
|
||||||
request.append("</Via>");
|
request.append("</Via>");
|
||||||
}
|
}
|
||||||
request.append("<Dest>").append(locationXml(to)).append("</Dest>");
|
request.append("<Dest>").append(locationXml(to)).append("</Dest>");
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -158,7 +159,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
private String connectionsQueryUri(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
private String connectionsQueryUri(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
||||||
final String products)
|
final String products, final Set<Option> options)
|
||||||
{
|
{
|
||||||
final Calendar c = new GregorianCalendar(timeZone());
|
final Calendar c = new GregorianCalendar(timeZone());
|
||||||
c.setTime(date);
|
c.setTime(date);
|
||||||
|
@ -264,6 +265,9 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options != null && options.contains(Option.BIKE))
|
||||||
|
uri.append("&REQ0JourneyProduct_opt3=1");
|
||||||
|
|
||||||
return uri.toString();
|
return uri.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,9 +277,10 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryConnectionsResult queryConnections(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
public QueryConnectionsResult queryConnections(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
||||||
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility) throws IOException
|
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility, final Set<Option> options)
|
||||||
|
throws IOException
|
||||||
{
|
{
|
||||||
final String uri = connectionsQueryUri(from, via, to, date, dep, products);
|
final String uri = connectionsQueryUri(from, via, to, date, dep, products, options);
|
||||||
final CharSequence page = ParserUtils.scrape(uri);
|
final CharSequence page = ParserUtils.scrape(uri);
|
||||||
|
|
||||||
List<Location> fromAddresses = null;
|
List<Location> fromAddresses = null;
|
||||||
|
@ -285,10 +290,10 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
final Matcher mPreAddress = P_PRE_ADDRESS.matcher(page);
|
final Matcher mPreAddress = P_PRE_ADDRESS.matcher(page);
|
||||||
while (mPreAddress.find())
|
while (mPreAddress.find())
|
||||||
{
|
{
|
||||||
final String type = mPreAddress.group(1);
|
final String suggestionType = mPreAddress.group(1);
|
||||||
final String options = mPreAddress.group(2);
|
final String suggestion = mPreAddress.group(2);
|
||||||
|
|
||||||
final Matcher mAddresses = P_ADDRESSES.matcher(options);
|
final Matcher mAddresses = P_ADDRESSES.matcher(suggestion);
|
||||||
final List<Location> addresses = new ArrayList<Location>();
|
final List<Location> addresses = new ArrayList<Location>();
|
||||||
while (mAddresses.find())
|
while (mAddresses.find())
|
||||||
{
|
{
|
||||||
|
@ -297,14 +302,14 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
addresses.add(address);
|
addresses.add(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.equals("REQ0JourneyStopsS0K"))
|
if (suggestionType.equals("REQ0JourneyStopsS0K"))
|
||||||
fromAddresses = addresses;
|
fromAddresses = addresses;
|
||||||
else if (type.equals("REQ0JourneyStopsZ0K"))
|
else if (suggestionType.equals("REQ0JourneyStopsZ0K"))
|
||||||
toAddresses = addresses;
|
toAddresses = addresses;
|
||||||
else if (type.equals("REQ0JourneyStops1.0K"))
|
else if (suggestionType.equals("REQ0JourneyStops1.0K"))
|
||||||
viaAddresses = addresses;
|
viaAddresses = addresses;
|
||||||
else
|
else
|
||||||
throw new IllegalStateException(type);
|
throw new IllegalStateException(suggestionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromAddresses != null || viaAddresses != null || toAddresses != null)
|
if (fromAddresses != null || viaAddresses != null || toAddresses != null)
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -569,7 +570,8 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryConnectionsResult queryConnections(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
public QueryConnectionsResult queryConnections(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
||||||
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility) throws IOException
|
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility, final Set<Option> options)
|
||||||
|
throws IOException
|
||||||
{
|
{
|
||||||
final String uri = connectionsQueryUri(from, via, to, date, dep, products);
|
final String uri = connectionsQueryUri(from, via, to, date, dep, products);
|
||||||
final CharSequence page = ParserUtils.scrape(uri);
|
final CharSequence page = ParserUtils.scrape(uri);
|
||||||
|
@ -581,10 +583,10 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
final Matcher mPreAddress = P_PRE_ADDRESS.matcher(page);
|
final Matcher mPreAddress = P_PRE_ADDRESS.matcher(page);
|
||||||
while (mPreAddress.find())
|
while (mPreAddress.find())
|
||||||
{
|
{
|
||||||
final String optionsType = mPreAddress.group(1);
|
final String suggestionType = mPreAddress.group(1);
|
||||||
final String options = mPreAddress.group(2);
|
final String suggestion = mPreAddress.group(2);
|
||||||
|
|
||||||
final Matcher mAddresses = P_ADDRESSES.matcher(options);
|
final Matcher mAddresses = P_ADDRESSES.matcher(suggestion);
|
||||||
final List<Location> addresses = new ArrayList<Location>();
|
final List<Location> addresses = new ArrayList<Location>();
|
||||||
while (mAddresses.find())
|
while (mAddresses.find())
|
||||||
{
|
{
|
||||||
|
@ -607,14 +609,14 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
addresses.add(location);
|
addresses.add(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optionsType.equals("REQ0JourneyStopsS0K"))
|
if (suggestionType.equals("REQ0JourneyStopsS0K"))
|
||||||
fromAddresses = addresses;
|
fromAddresses = addresses;
|
||||||
else if (optionsType.equals("REQ0JourneyStopsZ0K"))
|
else if (suggestionType.equals("REQ0JourneyStopsZ0K"))
|
||||||
toAddresses = addresses;
|
toAddresses = addresses;
|
||||||
else if (optionsType.equals("REQ0JourneyStops1.0K"))
|
else if (suggestionType.equals("REQ0JourneyStops1.0K"))
|
||||||
viaAddresses = addresses;
|
viaAddresses = addresses;
|
||||||
else
|
else
|
||||||
throw new IllegalStateException("cannot handle: '" + optionsType + "'");
|
throw new IllegalStateException("cannot handle: '" + suggestionType + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromAddresses != null || viaAddresses != null || toAddresses != null)
|
if (fromAddresses != null || viaAddresses != null || toAddresses != null)
|
||||||
|
|
|
@ -20,6 +20,7 @@ package de.schildbach.pte;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import de.schildbach.pte.dto.Connection;
|
import de.schildbach.pte.dto.Connection;
|
||||||
import de.schildbach.pte.dto.GetConnectionDetailsResult;
|
import de.schildbach.pte.dto.GetConnectionDetailsResult;
|
||||||
|
@ -60,6 +61,11 @@ public interface NetworkProvider
|
||||||
NEUTRAL, LIMITED, BARRIER_FREE
|
NEUTRAL, LIMITED, BARRIER_FREE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Option
|
||||||
|
{
|
||||||
|
BIKE
|
||||||
|
}
|
||||||
|
|
||||||
NetworkId id();
|
NetworkId id();
|
||||||
|
|
||||||
boolean hasCapabilities(Capability... capabilities);
|
boolean hasCapabilities(Capability... capabilities);
|
||||||
|
@ -123,11 +129,13 @@ public interface NetworkProvider
|
||||||
* how fast can you walk?
|
* how fast can you walk?
|
||||||
* @param accessibility
|
* @param accessibility
|
||||||
* how accessible do you need the route to be?
|
* how accessible do you need the route to be?
|
||||||
|
* @param options
|
||||||
|
* additional options
|
||||||
* @return result object that can contain alternatives to clear up ambiguousnesses, or contains possible connections
|
* @return result object that can contain alternatives to clear up ambiguousnesses, or contains possible connections
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
QueryConnectionsResult queryConnections(Location from, Location via, Location to, Date date, boolean dep, int numConnections, String products,
|
QueryConnectionsResult queryConnections(Location from, Location via, Location to, Date date, boolean dep, int numConnections, String products,
|
||||||
WalkSpeed walkSpeed, Accessibility accessibility) throws IOException;
|
WalkSpeed walkSpeed, Accessibility accessibility, Set<Option> options) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query more connections (e.g. earlier or later)
|
* Query more connections (e.g. earlier or later)
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.ksoap2.SoapEnvelope;
|
import org.ksoap2.SoapEnvelope;
|
||||||
|
@ -121,7 +122,7 @@ public class SadProvider extends AbstractNetworkProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryConnectionsResult queryConnections(Location from, Location via, Location to, Date date, boolean dep, final int numConnections, String products,
|
public QueryConnectionsResult queryConnections(Location from, Location via, Location to, Date date, boolean dep, final int numConnections, String products,
|
||||||
WalkSpeed walkSpeed, Accessibility accessibility) throws IOException {
|
WalkSpeed walkSpeed, Accessibility accessibility, Set<Option> options) throws IOException {
|
||||||
|
|
||||||
// Select correct SOAP method depending on the dep flag
|
// Select correct SOAP method depending on the dep flag
|
||||||
final String soapMethod = dep ? "searchCollPartenza" : "searchCollArrivo";
|
final String soapMethod = dep ? "searchCollPartenza" : "searchCollArrivo";
|
||||||
|
@ -220,7 +221,7 @@ public class SadProvider extends AbstractNetworkProvider {
|
||||||
// Query for connections with new date/time value
|
// Query for connections with new date/time value
|
||||||
// NOTE: via, products, walkSpeed, accessibility are set to null
|
// NOTE: via, products, walkSpeed, accessibility are set to null
|
||||||
return queryConnections(new Location(LocationType.STATION, fromId), null, new Location(LocationType.STATION, toId), date, dep,
|
return queryConnections(new Location(LocationType.STATION, fromId), null, new Location(LocationType.STATION, toId), date, dep,
|
||||||
0, null, null, null);
|
0, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TimeZone timeZone() {
|
protected TimeZone timeZone() {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package de.schildbach.pte;
|
package de.schildbach.pte;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import de.schildbach.pte.dto.Location;
|
import de.schildbach.pte.dto.Location;
|
||||||
|
|
||||||
|
@ -51,8 +52,9 @@ public class VgnProvider extends AbstractEfaProvider
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String xsltTripRequest2Uri(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
protected String xsltTripRequest2Uri(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
||||||
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility)
|
final int numConnections, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility, final Set<Option> options)
|
||||||
{
|
{
|
||||||
return super.xsltTripRequest2Uri(from, via, to, date, dep, numConnections, products, walkSpeed, accessibility) + "&itdLPxx_showTariffLevel=1";
|
return super.xsltTripRequest2Uri(from, via, to, date, dep, numConnections, products, walkSpeed, accessibility, options)
|
||||||
|
+ "&itdLPxx_showTariffLevel=1";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ public abstract class AbstractProviderLiveTest
|
||||||
protected final QueryConnectionsResult queryConnections(final Location from, final Location via, final Location to, final Date date,
|
protected final QueryConnectionsResult queryConnections(final Location from, final Location via, final Location to, final Date date,
|
||||||
final boolean dep, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility) throws IOException
|
final boolean dep, final String products, final WalkSpeed walkSpeed, final Accessibility accessibility) throws IOException
|
||||||
{
|
{
|
||||||
return provider.queryConnections(from, via, to, date, dep, 4, products, walkSpeed, accessibility);
|
return provider.queryConnections(from, via, to, date, dep, 4, products, walkSpeed, accessibility, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final QueryConnectionsResult queryMoreConnections(final QueryConnectionsContext context, final boolean later) throws IOException
|
protected final QueryConnectionsResult queryMoreConnections(final QueryConnectionsContext context, final boolean later) throws IOException
|
||||||
|
|
|
@ -53,6 +53,6 @@ public class ConnectionController
|
||||||
final Location fromLocation = new Location(fromType, fromId, null, from);
|
final Location fromLocation = new Location(fromType, fromId, null, from);
|
||||||
final Location toLocation = new Location(toType, toId, null, to);
|
final Location toLocation = new Location(toType, toId, null, to);
|
||||||
final String products = "IRSUTBFC";
|
final String products = "IRSUTBFC";
|
||||||
return provider.queryConnections(fromLocation, null, toLocation, new Date(), true, 4, products, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
|
return provider.queryConnections(fromLocation, null, toLocation, new Date(), true, 4, products, WalkSpeed.NORMAL, Accessibility.NEUTRAL, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue