mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-13 16:20:34 +00:00
server product and server time in results
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@772 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
df12d363da
commit
0458890f5c
13 changed files with 169 additions and 79 deletions
|
@ -20,6 +20,7 @@ package de.schildbach.pte;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -51,8 +52,8 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.Point;
|
import de.schildbach.pte.dto.Point;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult;
|
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult.Status;
|
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
|
import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.dto.Stop;
|
import de.schildbach.pte.dto.Stop;
|
||||||
import de.schildbach.pte.exception.ParserException;
|
import de.schildbach.pte.exception.ParserException;
|
||||||
|
@ -66,6 +67,8 @@ import de.schildbach.pte.util.XmlPullUtil;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractEfaProvider implements NetworkProvider
|
public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
{
|
{
|
||||||
|
protected final static String SERVER_PRODUCT = "EFA";
|
||||||
|
|
||||||
private final String apiBase;
|
private final String apiBase;
|
||||||
private final String additionalQueryParameter;
|
private final String additionalQueryParameter;
|
||||||
private final boolean canAcceptPoiID;
|
private final boolean canAcceptPoiID;
|
||||||
|
@ -195,7 +198,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
uri.append("&coordListOutputFormat=STRING");
|
uri.append("&coordListOutputFormat=STRING");
|
||||||
uri.append("&max=").append(maxStations != 0 ? maxStations : 50);
|
uri.append("&max=").append(maxStations != 0 ? maxStations : 50);
|
||||||
uri.append("&inclFilter=1&radius_1=").append(maxDistance != 0 ? maxDistance : 1320);
|
uri.append("&inclFilter=1&radius_1=").append(maxDistance != 0 ? maxDistance : 1320);
|
||||||
uri.append("&type_1=STOP");
|
uri.append("&type_1=STOP"); // ENTRANCE, BUS_POINT, POI_POINT
|
||||||
|
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try
|
try
|
||||||
|
@ -1030,6 +1033,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
return 'R' + type;
|
return 'R' + type;
|
||||||
if ("Pressnitztalbahn".equals(type)) // Bayern
|
if ("Pressnitztalbahn".equals(type)) // Bayern
|
||||||
return 'R' + type;
|
return 'R' + type;
|
||||||
|
if ("Schneeberg".equals(type)) // VOR
|
||||||
|
return 'R' + type;
|
||||||
|
|
||||||
if (type.equals("BSB")) // Breisgau-S-Bahn
|
if (type.equals("BSB")) // Breisgau-S-Bahn
|
||||||
return 'S' + str;
|
return 'S' + str;
|
||||||
|
@ -1157,7 +1162,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
|
|
||||||
final XmlPullParser pp = parserFactory.newPullParser();
|
final XmlPullParser pp = parserFactory.newPullParser();
|
||||||
pp.setInput(is, null);
|
pp.setInput(is, null);
|
||||||
enterItdRequest(pp);
|
final ResultHeader header = enterItdRequest(pp);
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "itdDepartureMonitorRequest");
|
XmlPullUtil.enter(pp, "itdDepartureMonitorRequest");
|
||||||
|
|
||||||
|
@ -1172,7 +1177,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
XmlPullUtil.enter(pp, "itdOdvName");
|
XmlPullUtil.enter(pp, "itdOdvName");
|
||||||
if ("identified".equals(nameState))
|
if ("identified".equals(nameState))
|
||||||
{
|
{
|
||||||
final QueryDeparturesResult result = new QueryDeparturesResult();
|
final QueryDeparturesResult result = new QueryDeparturesResult(header);
|
||||||
|
|
||||||
final Location location = processOdvNameElem(pp, place);
|
final Location location = processOdvNameElem(pp, place);
|
||||||
result.stationDepartures.add(new StationDepartures(location, new LinkedList<Departure>(), new LinkedList<LineDestination>()));
|
result.stationDepartures.add(new StationDepartures(location, new LinkedList<Departure>(), new LinkedList<LineDestination>()));
|
||||||
|
@ -1308,7 +1313,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
}
|
}
|
||||||
else if ("notidentified".equals(nameState))
|
else if ("notidentified".equals(nameState))
|
||||||
{
|
{
|
||||||
return new QueryDeparturesResult(QueryDeparturesResult.Status.INVALID_STATION);
|
return new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1573,7 +1578,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
{
|
{
|
||||||
final XmlPullParser pp = parserFactory.newPullParser();
|
final XmlPullParser pp = parserFactory.newPullParser();
|
||||||
pp.setInput(is, null);
|
pp.setInput(is, null);
|
||||||
final String sessionId = enterItdRequest(pp);
|
final ResultHeader header = enterItdRequest(pp);
|
||||||
|
final String context = header.context;
|
||||||
|
|
||||||
XmlPullUtil.require(pp, "itdTripRequest");
|
XmlPullUtil.require(pp, "itdTripRequest");
|
||||||
final String requestId = XmlPullUtil.attr(pp, "requestID");
|
final String requestId = XmlPullUtil.attr(pp, "requestID");
|
||||||
|
@ -1583,7 +1589,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
{
|
{
|
||||||
final int code = XmlPullUtil.intAttr(pp, "code");
|
final int code = XmlPullUtil.intAttr(pp, "code");
|
||||||
if (code == -4000) // no connection
|
if (code == -4000) // no connection
|
||||||
return new QueryConnectionsResult(Status.NO_CONNECTIONS);
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.NO_CONNECTIONS);
|
||||||
XmlPullUtil.next(pp);
|
XmlPullUtil.next(pp);
|
||||||
}
|
}
|
||||||
if (XmlPullUtil.test(pp, "itdPrintConfiguration"))
|
if (XmlPullUtil.test(pp, "itdPrintConfiguration"))
|
||||||
|
@ -1653,7 +1659,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ambiguousFrom != null || ambiguousTo != null || ambiguousVia != null)
|
if (ambiguousFrom != null || ambiguousTo != null || ambiguousVia != null)
|
||||||
return new QueryConnectionsResult(ambiguousFrom, ambiguousVia, ambiguousTo);
|
return new QueryConnectionsResult(header, ambiguousFrom, ambiguousVia, ambiguousTo);
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "itdTripDateTime");
|
XmlPullUtil.enter(pp, "itdTripDateTime");
|
||||||
XmlPullUtil.enter(pp, "itdDateTime");
|
XmlPullUtil.enter(pp, "itdDateTime");
|
||||||
|
@ -1666,7 +1672,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
throw new IllegalStateException("cannot find <itdMessage />");
|
throw new IllegalStateException("cannot find <itdMessage />");
|
||||||
final String message = pp.nextText();
|
final String message = pp.nextText();
|
||||||
if (message.equals("invalid date"))
|
if (message.equals("invalid date"))
|
||||||
return new QueryConnectionsResult(Status.INVALID_DATE);
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.INVALID_DATE);
|
||||||
XmlPullUtil.exit(pp, "itdDate");
|
XmlPullUtil.exit(pp, "itdDate");
|
||||||
}
|
}
|
||||||
XmlPullUtil.exit(pp, "itdDateTime");
|
XmlPullUtil.exit(pp, "itdDateTime");
|
||||||
|
@ -1913,11 +1919,11 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
|
|
||||||
XmlPullUtil.exit(pp, "itdRouteList");
|
XmlPullUtil.exit(pp, "itdRouteList");
|
||||||
|
|
||||||
return new QueryConnectionsResult(uri, from, via, to, commandLink(sessionId, requestId, "tripNext"), connections);
|
return new QueryConnectionsResult(header, uri, from, via, to, commandLink(context, requestId, "tripNext"), connections);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new QueryConnectionsResult(Status.NO_CONNECTIONS);
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.NO_CONNECTIONS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2133,15 +2139,30 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
return LINES.get(line.charAt(0));
|
return LINES.get(line.charAt(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String enterItdRequest(final XmlPullParser pp) throws XmlPullParserException, IOException
|
private ResultHeader enterItdRequest(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||||
{
|
{
|
||||||
if (pp.getEventType() == XmlPullParser.START_DOCUMENT)
|
if (pp.getEventType() == XmlPullParser.START_DOCUMENT)
|
||||||
pp.next();
|
pp.next();
|
||||||
|
|
||||||
XmlPullUtil.require(pp, "itdRequest");
|
XmlPullUtil.require(pp, "itdRequest");
|
||||||
|
|
||||||
|
final String serverVersion = XmlPullUtil.attr(pp, "version");
|
||||||
|
final String now = XmlPullUtil.attr(pp, "now") + " " + timeZone().getDisplayName(true, TimeZone.SHORT);
|
||||||
final String sessionId = XmlPullUtil.attr(pp, "sessionID");
|
final String sessionId = XmlPullUtil.attr(pp, "sessionID");
|
||||||
|
|
||||||
|
final DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss z");
|
||||||
|
long serverTime = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
serverTime = format.parse(now).getTime();
|
||||||
|
}
|
||||||
|
catch (final ParseException x)
|
||||||
|
{
|
||||||
|
System.out.println("cannot parse time: '" + now + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT, serverVersion, serverTime, sessionId);
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "itdRequest");
|
XmlPullUtil.enter(pp, "itdRequest");
|
||||||
|
|
||||||
if (XmlPullUtil.test(pp, "clientHeaderLines"))
|
if (XmlPullUtil.test(pp, "clientHeaderLines"))
|
||||||
|
@ -2156,6 +2177,6 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
if (XmlPullUtil.test(pp, "serverMetaInfo"))
|
if (XmlPullUtil.test(pp, "serverMetaInfo"))
|
||||||
XmlPullUtil.next(pp);
|
XmlPullUtil.next(pp);
|
||||||
|
|
||||||
return sessionId;
|
return header;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,8 @@ import de.schildbach.pte.dto.Location;
|
||||||
import de.schildbach.pte.dto.LocationType;
|
import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult;
|
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult.Status;
|
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
|
import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.dto.Stop;
|
import de.schildbach.pte.dto.Stop;
|
||||||
import de.schildbach.pte.util.Color;
|
import de.schildbach.pte.util.Color;
|
||||||
|
@ -63,6 +63,8 @@ import de.schildbach.pte.util.XmlPullUtil;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractHafasProvider implements NetworkProvider
|
public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
{
|
{
|
||||||
|
protected final static String SERVER_PRODUCT = "HAFAS";
|
||||||
|
|
||||||
private static final String DEFAULT_ENCODING = "ISO-8859-1";
|
private static final String DEFAULT_ENCODING = "ISO-8859-1";
|
||||||
private static final String PROD = "hafas";
|
private static final String PROD = "hafas";
|
||||||
private static final int NUM_CONNECTIONS = 6;
|
private static final int NUM_CONNECTIONS = 6;
|
||||||
|
@ -448,7 +450,8 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
|
|
||||||
pp.nextTag();
|
pp.nextTag();
|
||||||
|
|
||||||
final QueryDeparturesResult result = new QueryDeparturesResult();
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
||||||
|
final QueryDeparturesResult result = new QueryDeparturesResult(header);
|
||||||
final List<Departure> departures = new ArrayList<Departure>(8);
|
final List<Departure> departures = new ArrayList<Departure>(8);
|
||||||
|
|
||||||
if (XmlPullUtil.test(pp, "Err"))
|
if (XmlPullUtil.test(pp, "Err"))
|
||||||
|
@ -457,7 +460,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
final String text = XmlPullUtil.attr(pp, "text");
|
final String text = XmlPullUtil.attr(pp, "text");
|
||||||
|
|
||||||
if (code.equals("H730")) // Your input is not valid
|
if (code.equals("H730")) // Your input is not valid
|
||||||
return new QueryDeparturesResult(QueryDeparturesResult.Status.INVALID_STATION);
|
return new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION);
|
||||||
if (code.equals("H890"))
|
if (code.equals("H890"))
|
||||||
{
|
{
|
||||||
result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, stationId), Collections
|
result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, stationId), Collections
|
||||||
|
@ -605,13 +608,15 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
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 String products, final WalkSpeed walkSpeed) throws IOException
|
final String products, final WalkSpeed walkSpeed) throws IOException
|
||||||
{
|
{
|
||||||
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
||||||
|
|
||||||
if (from.type == LocationType.ANY || (from.type == LocationType.ADDRESS && !from.hasLocation()))
|
if (from.type == LocationType.ANY || (from.type == LocationType.ADDRESS && !from.hasLocation()))
|
||||||
{
|
{
|
||||||
final List<Location> autocompletes = autocompleteStations(from.name);
|
final List<Location> autocompletes = autocompleteStations(from.name);
|
||||||
if (autocompletes.isEmpty())
|
if (autocompletes.isEmpty())
|
||||||
return new QueryConnectionsResult(QueryConnectionsResult.Status.NO_CONNECTIONS); // TODO
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.NO_CONNECTIONS); // TODO
|
||||||
if (autocompletes.size() > 1)
|
if (autocompletes.size() > 1)
|
||||||
return new QueryConnectionsResult(autocompletes, null, null);
|
return new QueryConnectionsResult(header, autocompletes, null, null);
|
||||||
from = autocompletes.get(0);
|
from = autocompletes.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,9 +624,9 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
{
|
{
|
||||||
final List<Location> autocompletes = autocompleteStations(via.name);
|
final List<Location> autocompletes = autocompleteStations(via.name);
|
||||||
if (autocompletes.isEmpty())
|
if (autocompletes.isEmpty())
|
||||||
return new QueryConnectionsResult(QueryConnectionsResult.Status.NO_CONNECTIONS); // TODO
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.NO_CONNECTIONS); // TODO
|
||||||
if (autocompletes.size() > 1)
|
if (autocompletes.size() > 1)
|
||||||
return new QueryConnectionsResult(null, autocompletes, null);
|
return new QueryConnectionsResult(header, null, autocompletes, null);
|
||||||
via = autocompletes.get(0);
|
via = autocompletes.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -629,9 +634,9 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
{
|
{
|
||||||
final List<Location> autocompletes = autocompleteStations(to.name);
|
final List<Location> autocompletes = autocompleteStations(to.name);
|
||||||
if (autocompletes.isEmpty())
|
if (autocompletes.isEmpty())
|
||||||
return new QueryConnectionsResult(QueryConnectionsResult.Status.NO_CONNECTIONS); // TODO
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.NO_CONNECTIONS); // TODO
|
||||||
if (autocompletes.size() > 1)
|
if (autocompletes.size() > 1)
|
||||||
return new QueryConnectionsResult(null, null, autocompletes);
|
return new QueryConnectionsResult(header, null, null, autocompletes);
|
||||||
to = autocompletes.get(0);
|
to = autocompletes.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,15 +700,17 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
pp.setInput(is, DEFAULT_ENCODING);
|
pp.setInput(is, DEFAULT_ENCODING);
|
||||||
|
|
||||||
assertResC(pp);
|
assertResC(pp);
|
||||||
|
final String product = XmlPullUtil.attr(pp, "prod");
|
||||||
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT, product, 0, null);
|
||||||
XmlPullUtil.enter(pp, "ResC");
|
XmlPullUtil.enter(pp, "ResC");
|
||||||
|
|
||||||
if (XmlPullUtil.test(pp, "Err"))
|
if (XmlPullUtil.test(pp, "Err"))
|
||||||
{
|
{
|
||||||
final String code = XmlPullUtil.attr(pp, "code");
|
final String code = XmlPullUtil.attr(pp, "code");
|
||||||
if (code.equals("I3")) // Input: date outside of the timetable period
|
if (code.equals("I3")) // Input: date outside of the timetable period
|
||||||
return new QueryConnectionsResult(Status.INVALID_DATE);
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.INVALID_DATE);
|
||||||
if (code.equals("F1")) // Spool: Error reading the spoolfile
|
if (code.equals("F1")) // Spool: Error reading the spoolfile
|
||||||
return new QueryConnectionsResult(Status.SERVICE_DOWN);
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.SERVICE_DOWN);
|
||||||
throw new IllegalStateException("error " + code + " " + XmlPullUtil.attr(pp, "text"));
|
throw new IllegalStateException("error " + code + " " + XmlPullUtil.attr(pp, "text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,19 +720,19 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
{
|
{
|
||||||
final String code = XmlPullUtil.attr(pp, "code");
|
final String code = XmlPullUtil.attr(pp, "code");
|
||||||
if (code.equals("K9380") || code.equals("K895")) // Departure/Arrival are too near
|
if (code.equals("K9380") || code.equals("K895")) // Departure/Arrival are too near
|
||||||
return QueryConnectionsResult.TOO_CLOSE;
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.TOO_CLOSE);
|
||||||
if (code.equals("K9220")) // Nearby to the given address stations could not be found
|
if (code.equals("K9220")) // Nearby to the given address stations could not be found
|
||||||
return QueryConnectionsResult.UNRESOLVABLE_ADDRESS;
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.UNRESOLVABLE_ADDRESS);
|
||||||
if (code.equals("K9240")) // Internal error
|
if (code.equals("K9240")) // Internal error
|
||||||
return new QueryConnectionsResult(Status.SERVICE_DOWN);
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.SERVICE_DOWN);
|
||||||
if (code.equals("K9260")) // Departure station does not exist
|
if (code.equals("K9260")) // Departure station does not exist
|
||||||
return QueryConnectionsResult.NO_CONNECTIONS;
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.NO_CONNECTIONS);
|
||||||
if (code.equals("K890")) // No connections found
|
if (code.equals("K890")) // No connections found
|
||||||
return QueryConnectionsResult.NO_CONNECTIONS;
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.NO_CONNECTIONS);
|
||||||
if (code.equals("K891")) // No route found (try entering an intermediate station)
|
if (code.equals("K891")) // No route found (try entering an intermediate station)
|
||||||
return QueryConnectionsResult.NO_CONNECTIONS;
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.NO_CONNECTIONS);
|
||||||
if (code.equals("K899")) // An error occurred
|
if (code.equals("K899")) // An error occurred
|
||||||
return new QueryConnectionsResult(Status.SERVICE_DOWN);
|
return new QueryConnectionsResult(header, QueryConnectionsResult.Status.SERVICE_DOWN);
|
||||||
// if (code.equals("K1:890")) // Unsuccessful or incomplete search (direction: forward)
|
// if (code.equals("K1:890")) // Unsuccessful or incomplete search (direction: forward)
|
||||||
throw new IllegalStateException("error " + code + " " + XmlPullUtil.attr(pp, "text"));
|
throw new IllegalStateException("error " + code + " " + XmlPullUtil.attr(pp, "text"));
|
||||||
}
|
}
|
||||||
|
@ -992,7 +999,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
|
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
|
|
||||||
return new QueryConnectionsResult(null, from, via, to, context, connections);
|
return new QueryConnectionsResult(header, null, from, via, to, context, connections);
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult;
|
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
|
import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.exception.SessionExpiredException;
|
import de.schildbach.pte.exception.SessionExpiredException;
|
||||||
import de.schildbach.pte.util.ParserUtils;
|
import de.schildbach.pte.util.ParserUtils;
|
||||||
|
|
||||||
|
@ -290,7 +291,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromAddresses != null || viaAddresses != null || toAddresses != null)
|
if (fromAddresses != null || viaAddresses != null || toAddresses != null)
|
||||||
return new QueryConnectionsResult(fromAddresses, viaAddresses, toAddresses);
|
return new QueryConnectionsResult(new ResultHeader(SERVER_PRODUCT), fromAddresses, viaAddresses, toAddresses);
|
||||||
else
|
else
|
||||||
return queryConnections(uri, page);
|
return queryConnections(uri, page);
|
||||||
}
|
}
|
||||||
|
@ -322,13 +323,13 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
if (mError.find())
|
if (mError.find())
|
||||||
{
|
{
|
||||||
if (mError.group(1) != null)
|
if (mError.group(1) != null)
|
||||||
return QueryConnectionsResult.TOO_CLOSE;
|
return new QueryConnectionsResult(null, QueryConnectionsResult.Status.TOO_CLOSE);
|
||||||
if (mError.group(2) != null)
|
if (mError.group(2) != null)
|
||||||
return QueryConnectionsResult.UNRESOLVABLE_ADDRESS;
|
return new QueryConnectionsResult(null, QueryConnectionsResult.Status.UNRESOLVABLE_ADDRESS);
|
||||||
if (mError.group(3) != null)
|
if (mError.group(3) != null)
|
||||||
return QueryConnectionsResult.NO_CONNECTIONS;
|
return new QueryConnectionsResult(null, QueryConnectionsResult.Status.NO_CONNECTIONS);
|
||||||
if (mError.group(4) != null)
|
if (mError.group(4) != null)
|
||||||
return QueryConnectionsResult.INVALID_DATE;
|
return new QueryConnectionsResult(null, QueryConnectionsResult.Status.INVALID_DATE);
|
||||||
if (mError.group(5) != null)
|
if (mError.group(5) != null)
|
||||||
throw new SessionExpiredException();
|
throw new SessionExpiredException();
|
||||||
}
|
}
|
||||||
|
@ -378,7 +379,7 @@ public final class BahnProvider extends AbstractHafasProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new QueryConnectionsResult(uri, from, null, to, linkLater, connections);
|
return new QueryConnectionsResult(new ResultHeader(SERVER_PRODUCT), uri, from, null, to, linkLater, connections);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryConnectionsResult;
|
import de.schildbach.pte.dto.QueryConnectionsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.dto.Stop;
|
import de.schildbach.pte.dto.Stop;
|
||||||
import de.schildbach.pte.exception.SessionExpiredException;
|
import de.schildbach.pte.exception.SessionExpiredException;
|
||||||
|
@ -253,7 +253,8 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
||||||
{
|
{
|
||||||
final QueryDeparturesResult result = new QueryDeparturesResult();
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
||||||
|
final QueryDeparturesResult result = new QueryDeparturesResult(header);
|
||||||
|
|
||||||
if (stationId < 1000000) // live
|
if (stationId < 1000000) // live
|
||||||
{
|
{
|
||||||
|
@ -265,9 +266,9 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
if (mError.find())
|
if (mError.find())
|
||||||
{
|
{
|
||||||
if (mError.group(1) != null)
|
if (mError.group(1) != null)
|
||||||
return new QueryDeparturesResult(Status.INVALID_STATION);
|
return new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION);
|
||||||
if (mError.group(2) != null)
|
if (mError.group(2) != null)
|
||||||
return new QueryDeparturesResult(Status.SERVICE_DOWN);
|
return new QueryDeparturesResult(header, QueryDeparturesResult.Status.SERVICE_DOWN);
|
||||||
if (mError.group(3) != null)
|
if (mError.group(3) != null)
|
||||||
throw new UnexpectedRedirectException();
|
throw new UnexpectedRedirectException();
|
||||||
}
|
}
|
||||||
|
@ -361,9 +362,9 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
if (mError.find())
|
if (mError.find())
|
||||||
{
|
{
|
||||||
if (mError.group(1) != null)
|
if (mError.group(1) != null)
|
||||||
return new QueryDeparturesResult(Status.INVALID_STATION);
|
return new QueryDeparturesResult(header, QueryDeparturesResult.Status.INVALID_STATION);
|
||||||
if (mError.group(2) != null)
|
if (mError.group(2) != null)
|
||||||
return new QueryDeparturesResult(Status.SERVICE_DOWN);
|
return new QueryDeparturesResult(header, QueryDeparturesResult.Status.SERVICE_DOWN);
|
||||||
if (mError.group(3) != null)
|
if (mError.group(3) != null)
|
||||||
throw new UnexpectedRedirectException();
|
throw new UnexpectedRedirectException();
|
||||||
}
|
}
|
||||||
|
@ -595,7 +596,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fromAddresses != null || viaAddresses != null || toAddresses != null)
|
if (fromAddresses != null || viaAddresses != null || toAddresses != null)
|
||||||
return new QueryConnectionsResult(fromAddresses, viaAddresses, toAddresses);
|
return new QueryConnectionsResult(new ResultHeader(SERVER_PRODUCT), fromAddresses, viaAddresses, toAddresses);
|
||||||
else
|
else
|
||||||
return queryConnections(uri, page);
|
return queryConnections(uri, page);
|
||||||
}
|
}
|
||||||
|
@ -688,13 +689,13 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
if (mError.find())
|
if (mError.find())
|
||||||
{
|
{
|
||||||
if (mError.group(1) != null)
|
if (mError.group(1) != null)
|
||||||
return QueryConnectionsResult.TOO_CLOSE;
|
return new QueryConnectionsResult(null, QueryConnectionsResult.Status.TOO_CLOSE);
|
||||||
if (mError.group(2) != null)
|
if (mError.group(2) != null)
|
||||||
return QueryConnectionsResult.UNRESOLVABLE_ADDRESS;
|
return new QueryConnectionsResult(null, QueryConnectionsResult.Status.UNRESOLVABLE_ADDRESS);
|
||||||
if (mError.group(3) != null)
|
if (mError.group(3) != null)
|
||||||
return QueryConnectionsResult.NO_CONNECTIONS;
|
return new QueryConnectionsResult(null, QueryConnectionsResult.Status.NO_CONNECTIONS);
|
||||||
if (mError.group(4) != null)
|
if (mError.group(4) != null)
|
||||||
return QueryConnectionsResult.INVALID_DATE;
|
return new QueryConnectionsResult(null, QueryConnectionsResult.Status.INVALID_DATE);
|
||||||
if (mError.group(5) != null)
|
if (mError.group(5) != null)
|
||||||
throw new SessionExpiredException();
|
throw new SessionExpiredException();
|
||||||
if (mError.group(6) != null)
|
if (mError.group(6) != null)
|
||||||
|
@ -864,7 +865,7 @@ public final class BvgProvider extends AbstractHafasProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new QueryConnectionsResult(firstUri, from, via, to, linkLater, connections);
|
return new QueryConnectionsResult(new ResultHeader(SERVER_PRODUCT), firstUri, from, via, to, linkLater, connections);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,7 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
||||||
|
import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.util.Color;
|
import de.schildbach.pte.util.Color;
|
||||||
import de.schildbach.pte.util.ParserUtils;
|
import de.schildbach.pte.util.ParserUtils;
|
||||||
|
@ -157,7 +158,8 @@ public class InvgProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
||||||
{
|
{
|
||||||
final QueryDeparturesResult result = new QueryDeparturesResult();
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
||||||
|
final QueryDeparturesResult result = new QueryDeparturesResult(header);
|
||||||
|
|
||||||
// scrape page
|
// scrape page
|
||||||
final String uri = departuresQueryUri(stationId, maxDepartures);
|
final String uri = departuresQueryUri(stationId, maxDepartures);
|
||||||
|
@ -175,9 +177,9 @@ public class InvgProvider extends AbstractHafasProvider
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else if (mHeadCoarse.group(5) != null)
|
else if (mHeadCoarse.group(5) != null)
|
||||||
return new QueryDeparturesResult(Status.INVALID_STATION);
|
return new QueryDeparturesResult(header, Status.INVALID_STATION);
|
||||||
else if (mHeadCoarse.group(6) != null)
|
else if (mHeadCoarse.group(6) != null)
|
||||||
return new QueryDeparturesResult(Status.SERVICE_DOWN);
|
return new QueryDeparturesResult(header, Status.SERVICE_DOWN);
|
||||||
|
|
||||||
final int locationId = Integer.parseInt(mHeadCoarse.group(2));
|
final int locationId = Integer.parseInt(mHeadCoarse.group(2));
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
||||||
|
import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.util.ParserUtils;
|
import de.schildbach.pte.util.ParserUtils;
|
||||||
|
|
||||||
|
@ -126,7 +127,8 @@ public class NsProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
||||||
{
|
{
|
||||||
final QueryDeparturesResult result = new QueryDeparturesResult();
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
||||||
|
final QueryDeparturesResult result = new QueryDeparturesResult(header);
|
||||||
|
|
||||||
// scrape page
|
// scrape page
|
||||||
final String uri = departuresQueryUri(stationId, maxDepartures);
|
final String uri = departuresQueryUri(stationId, maxDepartures);
|
||||||
|
@ -138,9 +140,9 @@ public class NsProvider extends AbstractHafasProvider
|
||||||
{
|
{
|
||||||
// messages
|
// messages
|
||||||
if (mHeadCoarse.group(3) != null)
|
if (mHeadCoarse.group(3) != null)
|
||||||
return new QueryDeparturesResult(Status.INVALID_STATION);
|
return new QueryDeparturesResult(header, Status.INVALID_STATION);
|
||||||
else if (mHeadCoarse.group(4) != null)
|
else if (mHeadCoarse.group(4) != null)
|
||||||
return new QueryDeparturesResult(Status.SERVICE_DOWN);
|
return new QueryDeparturesResult(header, Status.SERVICE_DOWN);
|
||||||
|
|
||||||
final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(mHeadCoarse.group(1));
|
final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(mHeadCoarse.group(1));
|
||||||
if (mHeadFine.matches())
|
if (mHeadFine.matches())
|
||||||
|
|
|
@ -32,6 +32,7 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
||||||
|
import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.util.ParserUtils;
|
import de.schildbach.pte.util.ParserUtils;
|
||||||
|
|
||||||
|
@ -205,7 +206,8 @@ public class RmvProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
||||||
{
|
{
|
||||||
final QueryDeparturesResult result = new QueryDeparturesResult();
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
||||||
|
final QueryDeparturesResult result = new QueryDeparturesResult(header);
|
||||||
|
|
||||||
// scrape page
|
// scrape page
|
||||||
final String uri = departuresQueryUri(stationId, maxDepartures);
|
final String uri = departuresQueryUri(stationId, maxDepartures);
|
||||||
|
@ -217,9 +219,9 @@ public class RmvProvider extends AbstractHafasProvider
|
||||||
{
|
{
|
||||||
// messages
|
// messages
|
||||||
if (mHeadCoarse.group(4) != null)
|
if (mHeadCoarse.group(4) != null)
|
||||||
return new QueryDeparturesResult(Status.INVALID_STATION);
|
return new QueryDeparturesResult(header, Status.INVALID_STATION);
|
||||||
else if (mHeadCoarse.group(5) != null)
|
else if (mHeadCoarse.group(5) != null)
|
||||||
return new QueryDeparturesResult(Status.SERVICE_DOWN);
|
return new QueryDeparturesResult(header, Status.SERVICE_DOWN);
|
||||||
|
|
||||||
final int locationId = Integer.parseInt(mHeadCoarse.group(3));
|
final int locationId = Integer.parseInt(mHeadCoarse.group(3));
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
||||||
|
import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.util.ParserUtils;
|
import de.schildbach.pte.util.ParserUtils;
|
||||||
|
|
||||||
|
@ -183,7 +184,8 @@ public class SeptaProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
||||||
{
|
{
|
||||||
final QueryDeparturesResult result = new QueryDeparturesResult();
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
||||||
|
final QueryDeparturesResult result = new QueryDeparturesResult(header);
|
||||||
|
|
||||||
// scrape page
|
// scrape page
|
||||||
final String uri = departuresQueryUri(stationId, maxDepartures);
|
final String uri = departuresQueryUri(stationId, maxDepartures);
|
||||||
|
@ -201,9 +203,9 @@ public class SeptaProvider extends AbstractHafasProvider
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else if (mPageCoarse.group(6) != null)
|
else if (mPageCoarse.group(6) != null)
|
||||||
return new QueryDeparturesResult(Status.INVALID_STATION);
|
return new QueryDeparturesResult(header, Status.INVALID_STATION);
|
||||||
else if (mPageCoarse.group(7) != null)
|
else if (mPageCoarse.group(7) != null)
|
||||||
return new QueryDeparturesResult(Status.SERVICE_DOWN);
|
return new QueryDeparturesResult(header, Status.SERVICE_DOWN);
|
||||||
|
|
||||||
final String location = ParserUtils.resolveEntities(mPageCoarse.group(1));
|
final String location = ParserUtils.resolveEntities(mPageCoarse.group(1));
|
||||||
final Calendar currentTime = new GregorianCalendar(timeZone());
|
final Calendar currentTime = new GregorianCalendar(timeZone());
|
||||||
|
|
|
@ -33,6 +33,7 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
||||||
|
import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.util.ParserUtils;
|
import de.schildbach.pte.util.ParserUtils;
|
||||||
|
|
||||||
|
@ -168,7 +169,8 @@ public class ShProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
||||||
{
|
{
|
||||||
final QueryDeparturesResult result = new QueryDeparturesResult();
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
||||||
|
final QueryDeparturesResult result = new QueryDeparturesResult(header);
|
||||||
|
|
||||||
// scrape page
|
// scrape page
|
||||||
final String uri = departuresQueryUri(stationId, maxDepartures);
|
final String uri = departuresQueryUri(stationId, maxDepartures);
|
||||||
|
@ -186,9 +188,9 @@ public class ShProvider extends AbstractHafasProvider
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else if (mHeadCoarse.group(6) != null)
|
else if (mHeadCoarse.group(6) != null)
|
||||||
return new QueryDeparturesResult(Status.INVALID_STATION);
|
return new QueryDeparturesResult(header, Status.INVALID_STATION);
|
||||||
else if (mHeadCoarse.group(7) != null)
|
else if (mHeadCoarse.group(7) != null)
|
||||||
return new QueryDeparturesResult(Status.SERVICE_DOWN);
|
return new QueryDeparturesResult(header, Status.SERVICE_DOWN);
|
||||||
|
|
||||||
final String location = ParserUtils.resolveEntities(mHeadCoarse.group(1));
|
final String location = ParserUtils.resolveEntities(mHeadCoarse.group(1));
|
||||||
final Calendar currentTime = new GregorianCalendar(timeZone());
|
final Calendar currentTime = new GregorianCalendar(timeZone());
|
||||||
|
|
|
@ -33,6 +33,7 @@ import de.schildbach.pte.dto.LocationType;
|
||||||
import de.schildbach.pte.dto.NearbyStationsResult;
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
import de.schildbach.pte.dto.QueryDeparturesResult.Status;
|
||||||
|
import de.schildbach.pte.dto.ResultHeader;
|
||||||
import de.schildbach.pte.dto.StationDepartures;
|
import de.schildbach.pte.dto.StationDepartures;
|
||||||
import de.schildbach.pte.util.ParserUtils;
|
import de.schildbach.pte.util.ParserUtils;
|
||||||
|
|
||||||
|
@ -188,7 +189,8 @@ public class VgsProvider extends AbstractHafasProvider
|
||||||
|
|
||||||
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
|
||||||
{
|
{
|
||||||
final QueryDeparturesResult result = new QueryDeparturesResult();
|
final ResultHeader header = new ResultHeader(SERVER_PRODUCT);
|
||||||
|
final QueryDeparturesResult result = new QueryDeparturesResult(header);
|
||||||
|
|
||||||
// scrape page
|
// scrape page
|
||||||
final String uri = departuresQueryUri(stationId, maxDepartures);
|
final String uri = departuresQueryUri(stationId, maxDepartures);
|
||||||
|
@ -206,9 +208,9 @@ public class VgsProvider extends AbstractHafasProvider
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else if (mHeadCoarse.group(4) != null)
|
else if (mHeadCoarse.group(4) != null)
|
||||||
return new QueryDeparturesResult(Status.INVALID_STATION);
|
return new QueryDeparturesResult(header, Status.INVALID_STATION);
|
||||||
else if (mHeadCoarse.group(5) != null)
|
else if (mHeadCoarse.group(5) != null)
|
||||||
return new QueryDeparturesResult(Status.SERVICE_DOWN);
|
return new QueryDeparturesResult(header, Status.SERVICE_DOWN);
|
||||||
|
|
||||||
final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(mHeadCoarse.group(1));
|
final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(mHeadCoarse.group(1));
|
||||||
if (mHeadFine.matches())
|
if (mHeadFine.matches())
|
||||||
|
|
|
@ -30,11 +30,7 @@ public final class QueryConnectionsResult implements Serializable
|
||||||
OK, AMBIGUOUS, TOO_CLOSE, UNRESOLVABLE_ADDRESS, NO_CONNECTIONS, INVALID_DATE, SERVICE_DOWN;
|
OK, AMBIGUOUS, TOO_CLOSE, UNRESOLVABLE_ADDRESS, NO_CONNECTIONS, INVALID_DATE, SERVICE_DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final QueryConnectionsResult TOO_CLOSE = new QueryConnectionsResult(Status.TOO_CLOSE);
|
public final ResultHeader header;
|
||||||
public static final QueryConnectionsResult UNRESOLVABLE_ADDRESS = new QueryConnectionsResult(Status.UNRESOLVABLE_ADDRESS);
|
|
||||||
public static final QueryConnectionsResult NO_CONNECTIONS = new QueryConnectionsResult(Status.NO_CONNECTIONS);
|
|
||||||
public static final QueryConnectionsResult INVALID_DATE = new QueryConnectionsResult(Status.INVALID_DATE);
|
|
||||||
|
|
||||||
public final Status status;
|
public final Status status;
|
||||||
|
|
||||||
public final List<Location> ambiguousFrom;
|
public final List<Location> ambiguousFrom;
|
||||||
|
@ -48,9 +44,10 @@ public final class QueryConnectionsResult implements Serializable
|
||||||
public final String context;
|
public final String context;
|
||||||
public final List<Connection> connections;
|
public final List<Connection> connections;
|
||||||
|
|
||||||
public QueryConnectionsResult(final String queryUri, final Location from, final Location via, final Location to, final String context,
|
public QueryConnectionsResult(final ResultHeader header, final String queryUri, final Location from, final Location via, final Location to,
|
||||||
final List<Connection> connections)
|
final String context, final List<Connection> connections)
|
||||||
{
|
{
|
||||||
|
this.header = header;
|
||||||
this.status = Status.OK;
|
this.status = Status.OK;
|
||||||
this.queryUri = queryUri;
|
this.queryUri = queryUri;
|
||||||
this.from = from;
|
this.from = from;
|
||||||
|
@ -64,8 +61,10 @@ public final class QueryConnectionsResult implements Serializable
|
||||||
this.ambiguousTo = null;
|
this.ambiguousTo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryConnectionsResult(final List<Location> ambiguousFrom, final List<Location> ambiguousVia, final List<Location> ambiguousTo)
|
public QueryConnectionsResult(final ResultHeader header, final List<Location> ambiguousFrom, final List<Location> ambiguousVia,
|
||||||
|
final List<Location> ambiguousTo)
|
||||||
{
|
{
|
||||||
|
this.header = header;
|
||||||
this.status = Status.AMBIGUOUS;
|
this.status = Status.AMBIGUOUS;
|
||||||
this.ambiguousFrom = ambiguousFrom;
|
this.ambiguousFrom = ambiguousFrom;
|
||||||
this.ambiguousVia = ambiguousVia;
|
this.ambiguousVia = ambiguousVia;
|
||||||
|
@ -79,8 +78,9 @@ public final class QueryConnectionsResult implements Serializable
|
||||||
this.connections = null;
|
this.connections = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryConnectionsResult(final Status status)
|
public QueryConnectionsResult(final ResultHeader header, final Status status)
|
||||||
{
|
{
|
||||||
|
this.header = header;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
|
||||||
this.ambiguousFrom = null;
|
this.ambiguousFrom = null;
|
||||||
|
|
|
@ -30,16 +30,19 @@ public final class QueryDeparturesResult
|
||||||
OK, INVALID_STATION, SERVICE_DOWN
|
OK, INVALID_STATION, SERVICE_DOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final ResultHeader header;
|
||||||
public final Status status;
|
public final Status status;
|
||||||
public final List<StationDepartures> stationDepartures = new LinkedList<StationDepartures>();
|
public final List<StationDepartures> stationDepartures = new LinkedList<StationDepartures>();
|
||||||
|
|
||||||
public QueryDeparturesResult()
|
public QueryDeparturesResult(final ResultHeader header)
|
||||||
{
|
{
|
||||||
|
this.header = header;
|
||||||
this.status = Status.OK;
|
this.status = Status.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
public QueryDeparturesResult(final Status status)
|
public QueryDeparturesResult(final ResultHeader header, final Status status)
|
||||||
{
|
{
|
||||||
|
this.header = header;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
45
src/de/schildbach/pte/dto/ResultHeader.java
Normal file
45
src/de/schildbach/pte/dto/ResultHeader.java
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2010, 2011 the original author or authors.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.schildbach.pte.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andreas Schildbach
|
||||||
|
*/
|
||||||
|
public final class ResultHeader
|
||||||
|
{
|
||||||
|
public final String serverProduct;
|
||||||
|
public final String serverVersion;
|
||||||
|
public final long serverTime;
|
||||||
|
public final String context;
|
||||||
|
|
||||||
|
public ResultHeader(final String serverProduct)
|
||||||
|
{
|
||||||
|
this.serverProduct = serverProduct;
|
||||||
|
this.serverVersion = null;
|
||||||
|
this.serverTime = 0;
|
||||||
|
this.context = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResultHeader(final String serverProduct, final String serverVersion, final long serverTime, final String context)
|
||||||
|
{
|
||||||
|
this.serverProduct = serverProduct;
|
||||||
|
this.serverVersion = serverVersion;
|
||||||
|
this.serverTime = serverTime;
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue