departures for Hannover

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@208 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-09-29 15:39:44 +00:00
parent 75ac46e270
commit f66cb36bb5
7 changed files with 716 additions and 131 deletions

View file

@ -19,14 +19,27 @@ package de.schildbach.pte;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
/**
* @author Andreas Schildbach
*/
public class GvhProvider extends AbstractEfaProvider
{
public static final String NETWORK_ID = "mobil.gvh.de";
private static final String API_BASE = "http://mobil.gvh.de/mobile2/";
public boolean hasCapabilities(final Capability... capabilities)
{
for (final Capability capability : capabilities)
if (capability == Capability.DEPARTURES)
return true;
return false;
}
private static final String AUTOCOMPLETE_URI = API_BASE
+ "XML_STOPFINDER_REQUEST?outputFormat=XML&coordOutputFormat=WGS84&name_sf=%s&type_sf=any";
private static final String ENCODING = "ISO-8859-1";
@ -52,24 +65,94 @@ public class GvhProvider extends AbstractEfaProvider
return null;
}
public StationLocationResult stationLocation(String stationId) throws IOException
{
throw new UnsupportedOperationException();
}
public String departuresQueryUri(String stationId, int maxDepartures)
{
throw new UnsupportedOperationException();
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");
return uri.toString();
}
public GetConnectionDetailsResult getConnectionDetails(String connectionUri) throws IOException
{
throw new UnsupportedOperationException();
}
private static final Pattern P_LINE_RE = Pattern.compile("RE\\d+");
private static final Pattern P_LINE_RB = Pattern.compile("RB\\d+");
public boolean hasCapabilities(Capability... capabilities)
@Override
protected String parseLine(final String number, final String symbol, final String mot)
{
throw new UnsupportedOperationException();
}
if (!number.equals(symbol))
throw new IllegalStateException("number " + number + ", symbol " + symbol);
public int[] lineColors(String line)
{
throw new UnsupportedOperationException();
int t = Integer.parseInt(mot);
if (t == 0)
{
final String[] parts = number.split(" ", 3);
final String type = parts[0];
final String num = parts.length >= 2 ? parts[1] : null;
final String str = type + (num != null ? num : "");
if (type.equals("EC")) // Eurocity
return 'I' + str;
if (type.equals("IC")) // Intercity
return 'I' + str;
if (type.equals("ICE")) // Intercity Express
return 'I' + str;
if (type.equals("THA")) // Thalys
return 'I' + str;
if (type.equals("IR")) // Interregio
return 'R' + str;
if (type.equals("RE")) // Regional-Express
return 'R' + str;
if (P_LINE_RE.matcher(type).matches())
return 'R' + str;
if (type.equals("RB")) // Regionalbahn
return 'R' + str;
if (P_LINE_RB.matcher(type).matches())
return 'R' + str;
if (type.equals("R")) // Regionalzug
return 'R' + str;
if (type.equals("WFB")) // Westfalenbahn
return 'R' + str;
if (type.equals("NWB")) // NordWestBahn
return 'R' + str;
if (type.equals("ME")) // Metronom
return 'R' + str;
if (type.equals("ERB")) // eurobahn
return 'R' + str;
if (type.equals("CAN")) // cantus
return 'R' + str;
if (type.equals("HEX")) // Veolia Verkehr Sachsen-Anhalt
return 'R' + str;
if (type.equals("EB")) // Erfurter Bahn
return 'R' + str;
if (type.equals("MRB")) // Mittelrheinbahn
return 'R' + str;
if (type.equals("ABR")) // ABELLIO Rail NRW
return 'R' + str;
throw new IllegalArgumentException("cannot normalize: " + number);
}
if (t == 1)
return 'S' + number;
if (t == 3 || t == 4)
return 'T' + number;
if (t == 5 || t == 6 || t == 7 || t == 10)
return 'B' + number;
if (t == 9)
return 'F' + number;
if (t == 11)
return '?' + number;
throw new IllegalStateException("cannot normalize mot '" + mot + "' number '" + number + "'");
}
public QueryConnectionsResult queryConnections(LocationType fromType, String from, LocationType viaType, String via, LocationType toType,
@ -78,18 +161,32 @@ public class GvhProvider extends AbstractEfaProvider
throw new UnsupportedOperationException();
}
public QueryDeparturesResult queryDepartures(String queryUri) throws IOException
{
throw new UnsupportedOperationException();
}
public QueryConnectionsResult queryMoreConnections(String uri) throws IOException
{
throw new UnsupportedOperationException();
}
public StationLocationResult stationLocation(String stationId) throws IOException
public GetConnectionDetailsResult getConnectionDetails(String connectionUri) throws IOException
{
throw new UnsupportedOperationException();
}
private static final Map<Character, int[]> LINES = new HashMap<Character, int[]>();
static
{
LINES.put('I', new int[] { Color.WHITE, Color.RED, Color.RED });
LINES.put('R', new int[] { Color.GRAY, Color.WHITE });
LINES.put('S', new int[] { Color.parseColor("#006e34"), Color.WHITE });
LINES.put('U', new int[] { Color.parseColor("#003090"), Color.WHITE });
LINES.put('T', new int[] { Color.parseColor("#cc0000"), Color.WHITE });
LINES.put('B', new int[] { Color.parseColor("#993399"), Color.WHITE });
LINES.put('F', new int[] { Color.BLUE, Color.WHITE });
LINES.put('?', new int[] { Color.DKGRAY, Color.WHITE });
}
public int[] lineColors(final String line)
{
return LINES.get(line.charAt(0));
}
}