mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 00:50:31 +00:00
Vienna
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@370 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
d4aaecbe7a
commit
2cd371a3f2
2 changed files with 219 additions and 56 deletions
|
@ -84,11 +84,18 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
// parse odv name elements
|
||||
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"origin".equals(pp.getAttributeValue(null, "usage")))
|
||||
throw new IllegalStateException("cannot find <itdOdv usage=\"origin\" />");
|
||||
if (!XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvName"))
|
||||
XmlPullUtil.enter(pp, "itdOdv");
|
||||
XmlPullUtil.enter(pp, "itdOdvPlace");
|
||||
XmlPullUtil.exit(pp, "itdOdvPlace");
|
||||
if (!XmlPullUtil.test(pp, "itdOdvName"))
|
||||
throw new IllegalStateException("cannot find <itdOdvName />");
|
||||
final String nameState = pp.getAttributeValue(null, "state");
|
||||
final String nameState = XmlPullUtil.attr(pp, "state");
|
||||
XmlPullUtil.enter(pp, "itdOdvName");
|
||||
if (XmlPullUtil.test(pp, "itdMessage"))
|
||||
XmlPullUtil.next(pp);
|
||||
|
||||
if ("identified".equals(nameState) || "list".equals(nameState))
|
||||
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
while (XmlPullUtil.test(pp, "odvNameElem"))
|
||||
results.add(processOdvNameElem(pp));
|
||||
|
||||
// parse assigned stops
|
||||
|
@ -119,6 +126,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
|
||||
private Location processOdvNameElem(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||
{
|
||||
if (!XmlPullUtil.test(pp, "odvNameElem"))
|
||||
throw new IllegalStateException("expecting <odvNameElem />");
|
||||
|
||||
final String anyType = pp.getAttributeValue(null, "anyType");
|
||||
final String idStr = pp.getAttributeValue(null, "id");
|
||||
final String stopIdStr = pp.getAttributeValue(null, "stopID");
|
||||
|
@ -179,7 +189,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
throw new IllegalArgumentException("unknown type: " + anyType + " " + idStr + " " + stopIdStr);
|
||||
}
|
||||
|
||||
final String name = normalizeLocationName(pp.nextText());
|
||||
XmlPullUtil.enter(pp, "odvNameElem");
|
||||
final String name = normalizeLocationName(pp.getText());
|
||||
XmlPullUtil.exit(pp, "odvNameElem");
|
||||
|
||||
return new Location(type, id, lat, lon, name);
|
||||
}
|
||||
|
@ -543,6 +555,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
return 'R' + str;
|
||||
if (type.equals("ÖBA")) // Eisenbahn-Betriebsgesellschaft Ochsenhausen
|
||||
return 'R' + str;
|
||||
if (type.equals("MBS")) // Montafonerbahn
|
||||
return 'R' + str;
|
||||
if (type.equals("Abellio-Zug")) // Abellio
|
||||
return 'R' + str;
|
||||
if (type.equals("KBS")) // Kursbuchstrecke
|
||||
|
@ -621,6 +635,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
if (type.equals("STR")) // Nordhausen
|
||||
return 'T' + str;
|
||||
|
||||
if (type.equals("BUS"))
|
||||
return 'B' + str;
|
||||
|
||||
if (type.length() == 0)
|
||||
return "?";
|
||||
if (P_LINE_NUMBER.matcher(type).matches())
|
||||
|
@ -891,79 +908,98 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
|
||||
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdTripRequest"))
|
||||
throw new IllegalStateException("cannot find <itdTripRequest />");
|
||||
XmlPullUtil.enter(pp, "itdTripRequest");
|
||||
|
||||
if (XmlPullUtil.test(pp, "itdMessage"))
|
||||
{
|
||||
final int code = XmlPullUtil.intAttr(pp, "code");
|
||||
if (code == -4000) // no connection
|
||||
return new QueryConnectionsResult(Status.NO_CONNECTIONS);
|
||||
XmlPullUtil.next(pp);
|
||||
}
|
||||
if (XmlPullUtil.test(pp, "itdPrintConfiguration"))
|
||||
XmlPullUtil.next(pp);
|
||||
if (XmlPullUtil.test(pp, "itdAddress"))
|
||||
XmlPullUtil.next(pp);
|
||||
|
||||
// parse odv name elements
|
||||
List<Location> ambiguousFrom = null, ambiguousTo = null, ambiguousVia = null;
|
||||
Location from = null, via = null, to = null;
|
||||
|
||||
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"origin".equals(pp.getAttributeValue(null, "usage")))
|
||||
throw new IllegalStateException("cannot find <itdOdv usage=\"origin\" />");
|
||||
XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvName");
|
||||
final String originState = pp.getAttributeValue(null, "state");
|
||||
if ("list".equals(originState))
|
||||
while (XmlPullUtil.test(pp, "itdOdv"))
|
||||
{
|
||||
final String usage = XmlPullUtil.attr(pp, "usage");
|
||||
XmlPullUtil.enter(pp, "itdOdv");
|
||||
XmlPullUtil.enter(pp, "itdOdvPlace");
|
||||
XmlPullUtil.exit(pp, "itdOdvPlace");
|
||||
if (!XmlPullUtil.test(pp, "itdOdvName"))
|
||||
throw new IllegalStateException("cannot find <itdOdvName /> inside " + usage);
|
||||
final String state = XmlPullUtil.attr(pp, "state");
|
||||
XmlPullUtil.enter(pp, "itdOdvName");
|
||||
if (XmlPullUtil.test(pp, "itdMessage"))
|
||||
XmlPullUtil.next(pp);
|
||||
|
||||
if ("list".equals(state))
|
||||
{
|
||||
if ("origin".equals(usage))
|
||||
{
|
||||
ambiguousFrom = new ArrayList<Location>();
|
||||
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
while (XmlPullUtil.test(pp, "odvNameElem"))
|
||||
ambiguousFrom.add(processOdvNameElem(pp));
|
||||
}
|
||||
else if ("identified".equals(originState))
|
||||
{
|
||||
if (!XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
throw new IllegalStateException("cannot find <odvNameElem />");
|
||||
from = processOdvNameElem(pp);
|
||||
}
|
||||
|
||||
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"destination".equals(pp.getAttributeValue(null, "usage")))
|
||||
throw new IllegalStateException("cannot find <itdOdv usage=\"destination\" />");
|
||||
XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvName");
|
||||
final String destinationState = pp.getAttributeValue(null, "state");
|
||||
if ("list".equals(destinationState))
|
||||
{
|
||||
ambiguousTo = new ArrayList<Location>();
|
||||
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
ambiguousTo.add(processOdvNameElem(pp));
|
||||
}
|
||||
else if ("identified".equals(destinationState))
|
||||
{
|
||||
if (!XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
throw new IllegalStateException("cannot find <odvNameElem />");
|
||||
to = processOdvNameElem(pp);
|
||||
}
|
||||
|
||||
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"via".equals(pp.getAttributeValue(null, "usage")))
|
||||
throw new IllegalStateException("cannot find <itdOdv usage=\"via\" />");
|
||||
XmlPullUtil.nextStartTagInsideTree(pp, null, "itdOdvName");
|
||||
final String viaState = pp.getAttributeValue(null, "state");
|
||||
if ("list".equals(viaState))
|
||||
else if ("via".equals(usage))
|
||||
{
|
||||
ambiguousVia = new ArrayList<Location>();
|
||||
while (XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
while (XmlPullUtil.test(pp, "odvNameElem"))
|
||||
ambiguousVia.add(processOdvNameElem(pp));
|
||||
}
|
||||
else if ("identified".equals(viaState))
|
||||
else if ("destination".equals(usage))
|
||||
{
|
||||
if (!XmlPullUtil.nextStartTagInsideTree(pp, null, "odvNameElem"))
|
||||
throw new IllegalStateException("cannot find <odvNameElem />");
|
||||
ambiguousTo = new ArrayList<Location>();
|
||||
while (XmlPullUtil.test(pp, "odvNameElem"))
|
||||
ambiguousTo.add(processOdvNameElem(pp));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("unknown usage: " + usage);
|
||||
}
|
||||
}
|
||||
else if ("identified".equals(state))
|
||||
{
|
||||
if (!XmlPullUtil.test(pp, "odvNameElem"))
|
||||
throw new IllegalStateException("cannot find <odvNameElem /> inside " + usage);
|
||||
|
||||
if ("origin".equals(usage))
|
||||
from = processOdvNameElem(pp);
|
||||
else if ("via".equals(usage))
|
||||
via = processOdvNameElem(pp);
|
||||
else if ("destination".equals(usage))
|
||||
to = processOdvNameElem(pp);
|
||||
else
|
||||
throw new IllegalStateException("unknown usage: " + usage);
|
||||
}
|
||||
XmlPullUtil.exit(pp, "itdOdvName");
|
||||
XmlPullUtil.exit(pp, "itdOdv");
|
||||
}
|
||||
|
||||
if (ambiguousFrom != null || ambiguousTo != null || ambiguousVia != null)
|
||||
return new QueryConnectionsResult(ambiguousFrom, ambiguousVia, ambiguousTo);
|
||||
|
||||
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdTripDateTime"))
|
||||
throw new IllegalStateException("cannot find <itdTripDateTime />");
|
||||
if (!XmlPullUtil.nextStartTagInsideTree(pp, null, "itdDateTime"))
|
||||
throw new IllegalStateException("cannot find <itdDateTime />");
|
||||
if (!XmlPullUtil.nextStartTagInsideTree(pp, null, "itdDate"))
|
||||
XmlPullUtil.enter(pp, "itdTripDateTime");
|
||||
XmlPullUtil.enter(pp, "itdDateTime");
|
||||
if (!XmlPullUtil.test(pp, "itdDate"))
|
||||
throw new IllegalStateException("cannot find <itdDate />");
|
||||
if (!pp.isEmptyElementTag())
|
||||
{
|
||||
if (!XmlPullUtil.nextStartTagInsideTree(pp, null, "itdMessage"))
|
||||
XmlPullUtil.enter(pp, "itdDate");
|
||||
if (!XmlPullUtil.test(pp, "itdMessage"))
|
||||
throw new IllegalStateException("cannot find <itdMessage />");
|
||||
final String message = pp.nextText();
|
||||
if (message.equals("invalid date"))
|
||||
return new QueryConnectionsResult(Status.INVALID_DATE);
|
||||
XmlPullUtil.exit(pp, "itdDate");
|
||||
}
|
||||
XmlPullUtil.exit(pp, "itdDateTime");
|
||||
|
||||
final Calendar departureTime = new GregorianCalendar(), arrivalTime = new GregorianCalendar(), stopTime = new GregorianCalendar();
|
||||
departureTime.setTimeZone(timeZone());
|
||||
|
@ -1174,6 +1210,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
protected static final void appendCommonConnectionParams(final StringBuilder uri)
|
||||
{
|
||||
uri.append("&outputFormat=XML");
|
||||
uri.append("&coordListOutputFormat=STRING");
|
||||
uri.append("&coordOutputFormat=WGS84");
|
||||
uri.append("&calcNumberOfTrips=4");
|
||||
}
|
||||
|
|
126
src/de/schildbach/pte/VorProvider.java
Normal file
126
src/de/schildbach/pte/VorProvider.java
Normal file
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* Copyright 2010 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;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import de.schildbach.pte.dto.Location;
|
||||
import de.schildbach.pte.util.ParserUtils;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class VorProvider extends AbstractEfaProvider
|
||||
{
|
||||
public static final String NETWORK_ID = "efa.vor.at";
|
||||
private final static String API_BASE = "http://efa.vor.at/wvb/";
|
||||
|
||||
public boolean hasCapabilities(Capability... capabilities)
|
||||
{
|
||||
for (final Capability capability : capabilities)
|
||||
if (capability == Capability.DEPARTURES || capability == Capability.CONNECTIONS)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final String AUTOCOMPLETE_URI = API_BASE
|
||||
+ "XSLT_TRIP_REQUEST2?outputFormat=XML&coordOutputFormat=WGS84&locationServerActive=1&type_origin=any&name_origin=%s";
|
||||
|
||||
@Override
|
||||
protected String autocompleteUri(final CharSequence constraint)
|
||||
{
|
||||
return String.format(AUTOCOMPLETE_URI, ParserUtils.urlEncode(constraint.toString(), "ISO-8859-1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String nearbyLatLonUri(final int lat, final int lon)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final String NEARBY_STATION_URI = API_BASE
|
||||
+ "XSLT_DM_REQUEST"
|
||||
+ "?outputFormat=XML&coordOutputFormat=WGS84&name_dm=%s&type_dm=stop&itOptionsActive=1&ptOptionsActive=1&useProxFootSearch=1&mergeDep=1&useAllStops=1&mode=direct";
|
||||
|
||||
@Override
|
||||
protected String nearbyStationUri(final String stationId)
|
||||
{
|
||||
return String.format(NEARBY_STATION_URI, ParserUtils.urlEncode(stationId));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String departuresQueryUri(final String stationId, final int maxDepartures)
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder();
|
||||
uri.append(API_BASE).append("XSLT_DM_REQUEST");
|
||||
uri.append("?outputFormat=XML");
|
||||
uri.append("&coordOutputFormat=WGS84");
|
||||
uri.append("&type_dm=stop");
|
||||
uri.append("&name_dm=").append(stationId);
|
||||
uri.append("&mode=direct");
|
||||
uri.append("&useRealtime=1");
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String connectionsQueryUri(final Location from, final Location via, final Location to, final Date date, final boolean dep,
|
||||
final String products, final WalkSpeed walkSpeed)
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
|
||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HHmm");
|
||||
|
||||
final StringBuilder uri = new StringBuilder();
|
||||
uri.append(API_BASE);
|
||||
uri.append("XSLT_TRIP_REQUEST2");
|
||||
|
||||
uri.append("?language=de");
|
||||
appendCommonConnectionParams(uri);
|
||||
|
||||
appendLocation(uri, from, "origin");
|
||||
appendLocation(uri, to, "destination");
|
||||
if (via != null)
|
||||
appendLocation(uri, via, "via");
|
||||
|
||||
uri.append("&itdDate=").append(ParserUtils.urlEncode(DATE_FORMAT.format(date)));
|
||||
uri.append("&itdTime=").append(ParserUtils.urlEncode(TIME_FORMAT.format(date)));
|
||||
uri.append("&itdTripDateTimeDepArr=").append(dep ? "dep" : "arr");
|
||||
|
||||
uri.append("&ptOptionsActive=1");
|
||||
uri.append("&changeSpeed=").append(WALKSPEED_MAP.get(walkSpeed));
|
||||
uri.append(productParams(products));
|
||||
|
||||
uri.append("&locationServerActive=1");
|
||||
uri.append("&useRealtime=1");
|
||||
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String commandLink(final String sessionId, final String command)
|
||||
{
|
||||
final StringBuilder uri = new StringBuilder();
|
||||
uri.append(API_BASE);
|
||||
uri.append("XSLT_TRIP_REQUEST2");
|
||||
uri.append("?sessionID=").append(sessionId);
|
||||
appendCommonConnectionParams(uri);
|
||||
uri.append("&command=").append(command);
|
||||
return uri.toString();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue