From ee6199ce1c630b71f5261be67240cd35616f42a1 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sun, 13 Jan 2013 16:49:21 +0100 Subject: [PATCH] also parse itdTrain in itdServingLine for efa based providers --- .../schildbach/pte/AbstractEfaProvider.java | 62 ++++++++++++++----- .../src/de/schildbach/pte/TflProvider.java | 36 ++++++----- .../de/schildbach/pte/util/ParserUtils.java | 9 +++ 3 files changed, 76 insertions(+), 31 deletions(-) diff --git a/enabler/src/de/schildbach/pte/AbstractEfaProvider.java b/enabler/src/de/schildbach/pte/AbstractEfaProvider.java index 58a7d75b..a77015c4 100644 --- a/enabler/src/de/schildbach/pte/AbstractEfaProvider.java +++ b/enabler/src/de/schildbach/pte/AbstractEfaProvider.java @@ -1667,29 +1667,53 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider private Line processItdServingLine(final XmlPullParser pp) throws XmlPullParserException, IOException { XmlPullUtil.require(pp, "itdServingLine"); - final String motType = pp.getAttributeValue(null, "motType"); - final String number = pp.getAttributeValue(null, "number"); - final String id = pp.getAttributeValue(null, "stateless"); + final String slMotType = pp.getAttributeValue(null, "motType"); + final String slNumber = pp.getAttributeValue(null, "number"); + final String slStateless = pp.getAttributeValue(null, "stateless"); + final String slTrainType = pp.getAttributeValue(null, "trainType"); + final String slTrainName = pp.getAttributeValue(null, "trainName"); + /* final String slTrainNum = */pp.getAttributeValue(null, "trainNum"); XmlPullUtil.enter(pp, "itdServingLine"); - String noTrainName = null; - String message = null; + String itdTrainName = null; + String itdTrainType = null; + String itdMessage = null; + if (XmlPullUtil.test(pp, "itdTrain")) + { + itdTrainName = pp.getAttributeValue(null, "name"); + itdTrainType = pp.getAttributeValue(null, "type"); + if (!pp.isEmptyElementTag()) + { + XmlPullUtil.enter(pp, "itdTrain"); + XmlPullUtil.exit(pp, "itdTrain"); + } + else + { + XmlPullUtil.next(pp); + } + } if (XmlPullUtil.test(pp, "itdNoTrain")) { - noTrainName = pp.getAttributeValue(null, "name"); + itdTrainName = pp.getAttributeValue(null, "name"); if (!pp.isEmptyElementTag()) { XmlPullUtil.enter(pp, "itdNoTrain"); final String text = pp.getText(); - if (noTrainName.toLowerCase().contains("ruf") && text.toLowerCase().contains("ruf")) - message = text; + if (itdTrainName.toLowerCase().contains("ruf") && text.toLowerCase().contains("ruf")) + itdMessage = text; XmlPullUtil.exit(pp, "itdNoTrain"); } + else + { + XmlPullUtil.next(pp); + } } XmlPullUtil.exit(pp, "itdServingLine"); - final String label = parseLine(motType, number, number, noTrainName); - return new Line(id, label, lineStyle(label), message); + final String trainName = ParserUtils.firstNotEmpty(slTrainName, itdTrainName, slTrainType, itdTrainType); + + final String label = parseLine(slMotType, slNumber, slNumber, trainName); + return new Line(slStateless, label, lineStyle(label), itdMessage); } private static final Pattern P_STATION_NAME_WHITESPACE = Pattern.compile("\\s+"); @@ -2147,11 +2171,21 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider final Location destination = new Location(destinationId > 0 ? LocationType.STATION : LocationType.ANY, destinationId > 0 ? destinationId : 0, null, destinationName); final String lineLabel; - if ("AST".equals(pp.getAttributeValue(null, "symbol"))) + final String motSymbol = pp.getAttributeValue(null, "symbol"); + if ("AST".equals(motSymbol)) + { lineLabel = "BAST"; + } else - lineLabel = parseLine(pp.getAttributeValue(null, "motType"), pp.getAttributeValue(null, "shortname"), - pp.getAttributeValue(null, "name"), null); + { + final String motType = pp.getAttributeValue(null, "motType"); + final String motShortName = pp.getAttributeValue(null, "shortname"); + final String motName = pp.getAttributeValue(null, "name"); + final String motTrainName = pp.getAttributeValue(null, "trainName"); + final String motTrainType = pp.getAttributeValue(null, "trainType"); + final String trainName = ParserUtils.firstNotEmpty(motTrainName, motTrainType); + lineLabel = parseLine(motType, motShortName, motName, trainName); + } XmlPullUtil.enter(pp, "itdMeansOfTransport"); XmlPullUtil.require(pp, "motDivaParams"); final String lineId = XmlPullUtil.attr(pp, "network") + ':' + XmlPullUtil.attr(pp, "line") + ':' @@ -2277,7 +2311,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider while (XmlPullUtil.test(pp, "itdDateTime")) { processItdDateTime(pp, time); - final Date nextDepartureTime = time.getTime(); + /* final Date nextDepartureTime = */time.getTime(); } XmlPullUtil.exit(pp, "nextDeps"); } diff --git a/enabler/src/de/schildbach/pte/TflProvider.java b/enabler/src/de/schildbach/pte/TflProvider.java index 0536f944..4937d427 100644 --- a/enabler/src/de/schildbach/pte/TflProvider.java +++ b/enabler/src/de/schildbach/pte/TflProvider.java @@ -62,52 +62,54 @@ public class TflProvider extends AbstractEfaProvider if ("0".equals(mot) && "First Hull Trains".equals(noTrainName)) return "I" + name; - else if ("0".equals(mot) && "Southern".equals(noTrainName)) + else if ("0".equals(mot) && ("Southern".equals(noTrainName) || "=SN".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "Southeastern".equals(noTrainName)) + else if ("0".equals(mot) && ("Southeastern".equals(noTrainName) || "=SE".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "South West Trains".equals(noTrainName)) + else if ("0".equals(mot) && ("South West Trains".equals(noTrainName) || "=SW".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "Greater Anglia".equals(noTrainName)) + else if ("0".equals(mot) && ("Greater Anglia".equals(noTrainName) || "=LE".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "First Great Western".equals(noTrainName)) + else if ("0".equals(mot) && ("First Great Western".equals(noTrainName) || "=GW".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "First Capital Connect".equals(noTrainName)) + else if ("0".equals(mot) && ("First Capital Connect".equals(noTrainName) || "=FC".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "Northern Rail".equals(noTrainName)) + else if ("0".equals(mot) && ("Northern Rail".equals(noTrainName) || "=NT".equals(noTrainName))) return "R" + name; else if ("0".equals(mot) && "Chiltern Railways".equals(noTrainName)) return "R" + name; else if ("0".equals(mot) && "Heathrow Connect".equals(noTrainName)) return "R" + name; - else if ("0".equals(mot) && "Heathrow Express".equals(noTrainName)) + else if ("0".equals(mot) && ("Heathrow Express".equals(noTrainName) || "=HX".equals(noTrainName))) return "R" + name; else if ("0".equals(mot) && "Gatwick Express".equals(noTrainName)) return "R" + name; - else if ("0".equals(mot) && "Merseyrail".equals(noTrainName)) + else if ("0".equals(mot) && ("Merseyrail".equals(noTrainName) || "=ME".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "East Coast".equals(noTrainName)) + else if ("0".equals(mot) && ("East Coast".equals(noTrainName) || "=GR".equals(noTrainName))) return "R" + name; else if ("0".equals(mot) && "Cross Country".equals(noTrainName)) return "R" + name; - else if ("0".equals(mot) && "East Midlands Trains".equals(noTrainName)) + else if ("0".equals(mot) && ("East Midlands Trains".equals(noTrainName) || "=EM".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "Arriva Trains Wales".equals(noTrainName)) + else if ("0".equals(mot) && ("Arriva Trains Wales".equals(noTrainName) || "=AW".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "First TransPennine Express".equals(noTrainName)) + else if ("0".equals(mot) && ("First TransPennine Express".equals(noTrainName) || "=TP".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "ScotRail".equals(noTrainName)) + else if ("0".equals(mot) && ("ScotRail".equals(noTrainName) || "=SR".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "London Midland".equals(noTrainName)) + else if ("0".equals(mot) && ("London Midland".equals(noTrainName) || "=LM".equals(noTrainName))) return "R" + name; - else if ("0".equals(mot) && "c2c".equals(noTrainName)) + else if ("0".equals(mot) && ("c2c".equals(noTrainName) || "=CC".equals(noTrainName))) return "R" + name; else if ("0".equals(mot) && "Grand Central".equals(noTrainName)) return "R" + name; - else if ("0".equals(mot) && "Virgin Trains".equals(noTrainName)) + else if ("0".equals(mot) && ("Virgin Trains".equals(noTrainName) || "=VT".equals(noTrainName))) return "R" + name; else if ("0".equals(mot) && "Island Line".equals(noTrainName)) return "R" + name; + else if ("0".equals(mot) && ("Chiltern Railways".equals(noTrainName) || "=CH".equals(noTrainName))) + return "R" + name; else return super.parseLine(mot, name, longName, noTrainName); diff --git a/enabler/src/de/schildbach/pte/util/ParserUtils.java b/enabler/src/de/schildbach/pte/util/ParserUtils.java index 7e12b678..adb2e467 100644 --- a/enabler/src/de/schildbach/pte/util/ParserUtils.java +++ b/enabler/src/de/schildbach/pte/util/ParserUtils.java @@ -586,5 +586,14 @@ public final class ParserUtils return selected; } + public static String firstNotEmpty(final String... strings) + { + for (final String str : strings) + if (str != null && str.length() > 0) + return str; + + return null; + } + public static final String P_PLATFORM = "[\\wÄÖÜäöüßáàâéèêíìîóòôúùû\\. -/&#;]+?"; }