Nuremberg

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@857 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-12-14 10:28:49 +00:00
parent c532d90402
commit 16e77717ca
7 changed files with 184 additions and 9 deletions

View file

@ -71,6 +71,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
protected final static String SERVER_PRODUCT = "efa";
private final String apiBase;
private final String departureMonitorEndpoint;
private final String tripEndpoint;
private final String additionalQueryParameter;
private final boolean canAcceptPoiID;
private final boolean needsSpEncId;
@ -88,10 +90,11 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
public AbstractEfaProvider(final String apiBase, final String additionalQueryParameter, final boolean canAcceptPoiID)
{
this(apiBase, additionalQueryParameter, false, false);
this(apiBase, null, null, additionalQueryParameter, false, false);
}
public AbstractEfaProvider(final String apiBase, final String additionalQueryParameter, final boolean canAcceptPoiID, final boolean needsSpEncId)
public AbstractEfaProvider(final String apiBase, final String departureMonitorEndpoint, final String tripEndpoint,
final String additionalQueryParameter, final boolean canAcceptPoiID, final boolean needsSpEncId)
{
try
{
@ -103,6 +106,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
}
this.apiBase = apiBase;
this.departureMonitorEndpoint = departureMonitorEndpoint != null ? departureMonitorEndpoint : "XSLT_DM_REQUEST";
this.tripEndpoint = tripEndpoint != null ? tripEndpoint : "XSLT_TRIP_REQUEST2";
this.additionalQueryParameter = additionalQueryParameter;
this.canAcceptPoiID = canAcceptPoiID;
this.needsSpEncId = needsSpEncId;
@ -270,7 +275,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
{
final StringBuilder uri = new StringBuilder(apiBase);
uri.append("XSLT_TRIP_REQUEST2");
uri.append(tripEndpoint);
appendCommonRequestParams(uri);
uri.append("&type_origin=any");
uri.append("&name_origin=").append(ParserUtils.urlEncode(constraint.toString(), "ISO-8859-1"));
@ -1175,7 +1180,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
{
final StringBuilder uri = new StringBuilder(apiBase);
uri.append("XSLT_DM_REQUEST");
uri.append(departureMonitorEndpoint);
appendCommonRequestParams(uri);
uri.append("&type_dm=stop&useRealtime=1&mode=direct");
uri.append("&name_dm=").append(stationId);
@ -1469,7 +1474,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
final DateFormat TIME_FORMAT = new SimpleDateFormat("HHmm");
final StringBuilder uri = new StringBuilder(apiBase);
uri.append("XSLT_TRIP_REQUEST2");
uri.append(tripEndpoint);
appendCommonRequestParams(uri);
uri.append("&sessionID=0");
@ -1548,7 +1553,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
private String commandLink(final String sessionId, final String requestId, final String command)
{
final StringBuilder uri = new StringBuilder(apiBase);
uri.append("XSLT_TRIP_REQUEST2");
uri.append(tripEndpoint);
uri.append("?sessionID=").append(sessionId);
uri.append("&requestID=").append(requestId);

View file

@ -26,7 +26,7 @@ public enum NetworkId
RT,
// Germany
DB, BVG, VBB, RMV, NVV, VRT, BAYERN, MVV, INVG, AVV, VMV, HVV, SH, GVH, BSVAG, BSAG, VBN, NASA, VVO, VMS, VGS, VRR, VRS, MVG, NPH, VRN, VVS, NALDO, DING, KVV, VVM, VAGFR, NVBW,
DB, BVG, VBB, RMV, NVV, VRT, BAYERN, MVV, INVG, AVV, VGN, VVM, VMV, HVV, SH, GVH, BSVAG, BSAG, VBN, NASA, VVO, VMS, VGS, VRR, VRS, MVG, NPH, VRN, VVS, NALDO, DING, KVV, VAGFR, NVBW,
// Austria
OEBB, VOR, LINZ, SVV, VVT, VMOBIL, IVB, STV,

View file

@ -35,6 +35,7 @@ public class SeProvider extends AbstractHafasProvider
{
public static final NetworkId NETWORK_ID = NetworkId.SE;
private static final String API_BASE = "http://reseplanerare.resrobot.se/bin/";
// http://api.vasttrafik.se/bin/query.exe/sn
public SeProvider()
{

View file

@ -0,0 +1,70 @@
/*
* 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;
import java.io.IOException;
import java.util.List;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
/**
* @author Andreas Schildbach
*/
public class VgnProvider extends AbstractEfaProvider
{
public static final NetworkId NETWORK_ID = NetworkId.VGN;
private String apiBase;
private static final String DEPARTURE_MONITOR_ENDPOINT = "XML_DM_REQUEST";
private static final String TRIP_ENDPOINT = "XML_TRIP_REQUEST2";
public VgnProvider(final String apiBase)
{
super(apiBase, DEPARTURE_MONITOR_ENDPOINT, TRIP_ENDPOINT, null, false, false);
this.apiBase = apiBase;
}
public NetworkId id()
{
return NETWORK_ID;
}
public boolean hasCapabilities(Capability... capabilities)
{
for (final Capability capability : capabilities)
if (capability == Capability.AUTOCOMPLETE_ONE_LINE || capability == Capability.DEPARTURES || capability == Capability.CONNECTIONS)
return true;
return false;
}
private static final String NEARBY_STATION_URI = DEPARTURE_MONITOR_ENDPOINT
+ "?outputFormat=XML&coordOutputFormat=WGS84&type_dm=stop&name_dm=%s&itOptionsActive=1&ptOptionsActive=1&useProxFootSearch=1&mergeDep=1&useAllStops=1&mode=direct";
@Override
protected String nearbyStationUri(final int stationId)
{
return String.format(apiBase + NEARBY_STATION_URI, stationId);
}
@Override
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
{
return xmlStopfinderRequest(new Location(LocationType.ANY, 0, null, constraint.toString()));
}
}

View file

@ -37,7 +37,7 @@ public class VrrProvider extends AbstractEfaProvider
public VrrProvider()
{
super(API_BASE, null, false, true);
super(API_BASE, null, null, null, false, true);
}
public NetworkId id()

View file

@ -33,7 +33,7 @@ public class VvmProvider extends AbstractEfaProvider
public VvmProvider()
{
super(API_BASE, null, false, true);
super(API_BASE, null, null, null, false, true);
}
public NetworkId id()

View file

@ -0,0 +1,99 @@
/*
* 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.live;
import java.util.Date;
import java.util.List;
import org.junit.Test;
import de.schildbach.pte.NetworkProvider.Accessibility;
import de.schildbach.pte.NetworkProvider.WalkSpeed;
import de.schildbach.pte.VgnProvider;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
import de.schildbach.pte.dto.NearbyStationsResult;
import de.schildbach.pte.dto.QueryConnectionsResult;
import de.schildbach.pte.dto.QueryDeparturesResult;
/**
* @author Andreas Schildbach
*/
public class VgnProviderLiveTest
{
private final VgnProvider provider = new VgnProvider(Secrets.VGN_API_BASE);
private static final String ALL_PRODUCTS = "IRSUTBFC";
@Test
public void nearbyStations() throws Exception
{
final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.STATION, 3000510), 0, 0);
System.out.println(result.stations.size() + " " + result.stations);
}
@Test
public void nearbyStationsByCoordinate() throws Exception
{
final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.ADDRESS, 49455472, 11079655), 0, 0);
System.out.println(result.stations.size() + " " + result.stations);
}
@Test
public void queryDepartures() throws Exception
{
final QueryDeparturesResult result = provider.queryDepartures(3000510, 0, false);
System.out.println(result.stationDepartures);
}
@Test
public void autocompleteIncomplete() throws Exception
{
final List<Location> autocompletes = provider.autocompleteStations("Kur");
list(autocompletes);
}
@Test
public void autocompleteWithUmlaut() throws Exception
{
final List<Location> autocompletes = provider.autocompleteStations("grün");
list(autocompletes);
}
private void list(final List<Location> autocompletes)
{
System.out.print(autocompletes.size() + " ");
for (final Location autocomplete : autocompletes)
System.out.print(autocomplete.toDebugString() + " ");
System.out.println();
}
@Test
public void shortConnection() throws Exception
{
final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 0, null, "Hauptwache"), null,
new Location(LocationType.STATION, 0, null, "Südbahnhof"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
System.out.println(result);
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context);
System.out.println(moreResult);
}
}