parse lineLink for Germany

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@179 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-09-22 18:52:34 +00:00
parent 76026f46ce
commit 5812a35d67
6 changed files with 55 additions and 39 deletions

View file

@ -456,7 +456,7 @@ public final class BahnProvider implements NetworkProvider
, Pattern.DOTALL);
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<div class=\"sqdetailsDep trow\">\n(.+?)</div>", Pattern.DOTALL);
static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" //
+ "<a href=\"http://mobile\\.bahn\\.de/bin/mobil/traininfo.exe/dox[^\"]*\">\n" //
+ "<a href=\"(http://mobile\\.bahn\\.de/bin/mobil/traininfo.exe/dox[^\"]*)\">\n" // lineLink
+ "<span class=\"bold\">(.*?)</span>\n" // line
+ "</a>\n" //
+ "&gt;&gt;\n" //
@ -504,14 +504,16 @@ public final class BahnProvider implements NetworkProvider
final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(1));
if (mDepFine.matches())
{
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(1)));
final String lineLink = ParserUtils.resolveEntities(mDepFine.group(1));
final String destination = ParserUtils.resolveEntities(mDepFine.group(2));
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(2)));
final String destination = ParserUtils.resolveEntities(mDepFine.group(3));
final Calendar current = new GregorianCalendar();
current.setTime(currentTime);
final Calendar parsed = new GregorianCalendar();
parsed.setTime(ParserUtils.parseTime(mDepFine.group(3)));
parsed.setTime(ParserUtils.parseTime(mDepFine.group(4)));
parsed.set(Calendar.YEAR, current.get(Calendar.YEAR));
parsed.set(Calendar.MONTH, current.get(Calendar.MONTH));
parsed.set(Calendar.DAY_OF_MONTH, current.get(Calendar.DAY_OF_MONTH));
@ -520,23 +522,23 @@ public final class BahnProvider implements NetworkProvider
final Date plannedTime = parsed.getTime();
Date predictedTime = null;
if (mDepFine.group(4) != null)
if (mDepFine.group(5) != null)
{
predictedTime = plannedTime;
}
else if (mDepFine.group(5) != null)
else if (mDepFine.group(6) != null)
{
final int delay = Integer.parseInt(mDepFine.group(5));
final int delay = Integer.parseInt(mDepFine.group(6));
parsed.add(Calendar.MINUTE, delay);
predictedTime = parsed.getTime();
}
final String message = ParserUtils.resolveEntities(mDepFine.group(6));
final String message = ParserUtils.resolveEntities(mDepFine.group(7));
final String position = ParserUtils.resolveEntities(mDepFine.group(7));
final String position = ParserUtils.resolveEntities(mDepFine.group(8));
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
position, 0, destination, message);
lineLink, position, 0, destination, message);
if (!departures.contains(dep))
departures.add(dep);
}

View file

@ -28,18 +28,20 @@ public final class Departure
final public Date predictedTime;
final public String line;
final public int[] lineColors;
final public String lineLink;
final public String position;
final public int destinationId;
final public String destination;
final public String message;
public Departure(final Date plannedTime, final Date predictedTime, final String line, final int[] lineColors, final String position,
final int destinationId, final String destination, final String message)
public Departure(final Date plannedTime, final Date predictedTime, final String line, final int[] lineColors, final String lineLink,
final String position, final int destinationId, final String destination, final String message)
{
this.plannedTime = plannedTime;
this.predictedTime = predictedTime;
this.line = line;
this.lineColors = lineColors;
this.lineLink = lineLink;
this.position = position;
this.destinationId = destinationId;
this.destination = destination;
@ -53,6 +55,7 @@ public final class Departure
this.predictedTime = null;
this.line = line;
this.lineColors = lineColors;
this.lineLink = null;
this.position = position;
this.destinationId = destinationId;
this.destination = destination;

View file

@ -572,7 +572,7 @@ public class OebbProvider implements NetworkProvider
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null, null,
position, destinationId, destination, null);
if (!departures.contains(dep))

View file

@ -568,7 +568,7 @@ public class RmvProvider implements NetworkProvider
final String position = ParserUtils.resolveEntities(ParserUtils.selectNotNull(mDepFine.group(5), mDepFine.group(6)));
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null, null,
position, 0, destination, null);
if (!departures.contains(dep))

View file

@ -589,7 +589,7 @@ public final class VbbProvider implements NetworkProvider
final String destination = ParserUtils.resolveEntities(mDepFine.group(live ? 4 : 5));
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line) : null, position,
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line) : null, null, position,
destinationId, destination, null);
if (!departures.contains(dep))
departures.add(dep);