adapt to API change

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@733 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-07-22 09:29:14 +00:00
parent 37bec3b3cb
commit 457e29ff49

View file

@ -145,31 +145,24 @@ public class ShProvider extends AbstractHafasProvider
return uri.toString(); return uri.toString();
} }
private static final Pattern P_DEPARTURES_HEAD_COARSE = Pattern private static final Pattern P_DEPARTURES_HEAD_COARSE = Pattern.compile(".*?" //
.compile(
".*?" //
+ "(?:" // + "(?:" //
+ "<table class=\"hafasResult\"[^>]*>(.+?)</table>.*?" // + "Bhf\\./Haltest\\.:</span>\\n<span class=\"output\">([^<]*)<.*?" // location
+ "(?:<table cellspacing=\"0\" class=\"hafasResult\"[^>]*>(.+?)</table>|(verkehren an dieser Haltestelle keine))"// + "Fahrplan:</span>\\n<span class=\"output\">\n" //
+ "|(Eingabe kann nicht interpretiert)|(Verbindung zum Server konnte leider nicht hergestellt werden|kann vom Server derzeit leider nicht bearbeitet werden))" // + "(\\d{2}\\.\\d{2}\\.\\d{2})[^\n]*,\n" // date
+ "Abfahrt (\\d{1,2}:\\d{2}).*?" // time
+ "<table class=\"resultTable\"[^>]*>(.+?)</table>" // content
+ "|(verkehren an dieser Haltestelle keine)" //
+ "|(Eingabe kann nicht interpretiert)" //
+ "|(Verbindung zum Server konnte leider nicht hergestellt werden|kann vom Server derzeit leider nicht bearbeitet werden))" //
+ ".*?" // + ".*?" //
, Pattern.DOTALL); , Pattern.DOTALL);
private static final Pattern P_DEPARTURES_HEAD_FINE = Pattern.compile(".*?" //
+ "<td class=\"querysummary screennowrap\">\\s*(.*?)\\s*<.*?" // location
+ "(\\d{2}\\.\\d{2}\\.\\d{2}).*?" // date
+ "Abfahrt (\\d{1,2}:\\d{2}).*?" // time
, Pattern.DOTALL);
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<tr class=\"(depboard-\\w*)\">(.*?)</tr>", Pattern.DOTALL); private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<tr class=\"(depboard-\\w*)\">(.*?)</tr>", Pattern.DOTALL);
private static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" // private static final Pattern P_DEPARTURES_FINE = Pattern.compile("\n" //
+ "<td class=\"[\\w ]*\">(\\d{1,2}:\\d{2})</td>\n" // plannedTime + "<td class=\"time\">(\\d{1,2}:\\d{2}).*?" // plannedTime
+ "(?:<td class=\"[\\w ]*prognosis[\\w ]*\">\n" // + "<img class=\"product\" src=\"/hafas-res/img/products/(\\w+)_pic\\.png\"[^>]*>\\s*([^<]*)<.*?" // type,line
+ "(?:&nbsp;|<span class=\"rtLimit\\d\">(p&#252;nktlich|\\d{1,2}:\\d{2})</span>)\n</td>\n" // predictedTime + "<a href=\"http://nah\\.sh\\.hafas\\.de/bin/stboard\\.exe/dn\\?input=(\\d+)&[^>]*>\n" // destinationId
+ ")?.*?" // + "([^\n]*)\n.*?" // destination
+ "<img src=\"/hafas-res/img/(\\w+)_pic\\.gif\"[^>]*>\\s*(.*?)\\s*</.*?" // type, line
+ "<span class=\"bold\">\n" //
+ "<a href=\"http://scout\\.hafas\\.de/bin/stboard\\.exe/dn\\?input=(\\d+)&[^>]*>" // destinationId
+ "\\s*(.*?)\\s*</a>\n" // destination
+ "</span>.*?" //
+ "(?:<td class=\"center sepline top\">\n(" + ParserUtils.P_PLATFORM + ").*?)?" // position + "(?:<td class=\"center sepline top\">\n(" + ParserUtils.P_PLATFORM + ").*?)?" // position
, Pattern.DOTALL); , Pattern.DOTALL);
@ -186,29 +179,27 @@ public class ShProvider extends AbstractHafasProvider
if (mHeadCoarse.matches()) if (mHeadCoarse.matches())
{ {
// messages // messages
if (mHeadCoarse.group(3) != null) if (mHeadCoarse.group(5) != null)
{ {
result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, stationId), result.stationDepartures.add(new StationDepartures(new Location(LocationType.STATION, stationId),
Collections.<Departure> emptyList(), null)); Collections.<Departure> emptyList(), null));
return result; return result;
} }
else if (mHeadCoarse.group(4) != null) else if (mHeadCoarse.group(6) != null)
return new QueryDeparturesResult(Status.INVALID_STATION); return new QueryDeparturesResult(Status.INVALID_STATION);
else if (mHeadCoarse.group(5) != null) else if (mHeadCoarse.group(7) != null)
return new QueryDeparturesResult(Status.SERVICE_DOWN); return new QueryDeparturesResult(Status.SERVICE_DOWN);
final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(mHeadCoarse.group(1)); final String location = ParserUtils.resolveEntities(mHeadCoarse.group(1));
if (mHeadFine.matches())
{
final String location = ParserUtils.resolveEntities(mHeadFine.group(1));
final Calendar currentTime = new GregorianCalendar(timeZone()); final Calendar currentTime = new GregorianCalendar(timeZone());
currentTime.clear(); currentTime.clear();
ParserUtils.parseGermanDate(currentTime, mHeadFine.group(2)); ParserUtils.parseGermanDate(currentTime, mHeadCoarse.group(2));
ParserUtils.parseEuropeanTime(currentTime, mHeadFine.group(3)); ParserUtils.parseEuropeanTime(currentTime, mHeadCoarse.group(3));
final List<Departure> departures = new ArrayList<Departure>(8); final List<Departure> departures = new ArrayList<Departure>(8);
String oldZebra = null; String oldZebra = null;
final Matcher mDepCoarse = P_DEPARTURES_COARSE.matcher(mHeadCoarse.group(2)); final Matcher mDepCoarse = P_DEPARTURES_COARSE.matcher(mHeadCoarse.group(4));
while (mDepCoarse.find()) while (mDepCoarse.find())
{ {
final String zebra = mDepCoarse.group(1); final String zebra = mDepCoarse.group(1);
@ -227,38 +218,18 @@ public class ShProvider extends AbstractHafasProvider
if (plannedTime.getTimeInMillis() - currentTime.getTimeInMillis() < -PARSER_DAY_ROLLOVER_THRESHOLD_MS) if (plannedTime.getTimeInMillis() - currentTime.getTimeInMillis() < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
plannedTime.add(Calendar.DAY_OF_MONTH, 1); plannedTime.add(Calendar.DAY_OF_MONTH, 1);
final Calendar predictedTime; final String lineType = mDepFine.group(2);
final String prognosis = ParserUtils.resolveEntities(mDepFine.group(2));
if (prognosis != null)
{
predictedTime = new GregorianCalendar(timeZone());
if (prognosis.equals("pünktlich"))
{
predictedTime.setTimeInMillis(plannedTime.getTimeInMillis());
}
else
{
predictedTime.setTimeInMillis(currentTime.getTimeInMillis());
ParserUtils.parseEuropeanTime(predictedTime, prognosis);
}
}
else
{
predictedTime = null;
}
final String lineType = mDepFine.group(3); final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDepFine.group(3).trim()));
final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4))); final int destinationId = mDepFine.group(4) != null ? Integer.parseInt(mDepFine.group(4)) : 0;
final int destinationId = mDepFine.group(5) != null ? Integer.parseInt(mDepFine.group(5)) : 0; final String destination = ParserUtils.resolveEntities(mDepFine.group(5));
final String destination = ParserUtils.resolveEntities(mDepFine.group(6)); final String position = mDepFine.group(6) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(6)) : null;
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null; final Departure dep = new Departure(plannedTime.getTime(), null, new Line(null, line, line != null ? lineColors(line) : null),
position, destinationId, destination, null, null);
final Departure dep = new Departure(plannedTime.getTime(), predictedTime != null ? predictedTime.getTime() : null, new Line(
null, line, line != null ? lineColors(line) : null), position, destinationId, destination, null, null);
if (!departures.contains(dep)) if (!departures.contains(dep))
departures.add(dep); departures.add(dep);
@ -273,11 +244,6 @@ public class ShProvider extends AbstractHafasProvider
return result; return result;
} }
else else
{
throw new IllegalArgumentException("cannot parse '" + mHeadCoarse.group(1) + "' on " + stationId);
}
}
else
{ {
throw new IllegalArgumentException("cannot parse '" + page + "' on " + stationId); throw new IllegalArgumentException("cannot parse '" + page + "' on " + stationId);
} }