mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 17:10:30 +00:00
Consolidate XmlPullUtil API for pure value tags.
This commit is contained in:
parent
7f9755d896
commit
0dc08c103a
3 changed files with 114 additions and 183 deletions
|
@ -517,11 +517,11 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "p");
|
XmlPullUtil.enter(pp, "p");
|
||||||
|
|
||||||
final String name = normalizeLocationName(requireValueTag(pp, "n"));
|
final String name = normalizeLocationName(XmlPullUtil.valueTag(pp, "n"));
|
||||||
final String u = requireValueTag(pp, "u");
|
final String u = XmlPullUtil.valueTag(pp, "u");
|
||||||
if (!"sf".equals(u))
|
if (!"sf".equals(u))
|
||||||
throw new RuntimeException("unknown usage: " + u);
|
throw new RuntimeException("unknown usage: " + u);
|
||||||
final String ty = requireValueTag(pp, "ty");
|
final String ty = XmlPullUtil.valueTag(pp, "ty");
|
||||||
final LocationType type;
|
final LocationType type;
|
||||||
if ("stop".equals(ty))
|
if ("stop".equals(ty))
|
||||||
type = LocationType.STATION;
|
type = LocationType.STATION;
|
||||||
|
@ -538,16 +538,16 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "r");
|
XmlPullUtil.enter(pp, "r");
|
||||||
|
|
||||||
final String id = requireValueTag(pp, "id");
|
final String id = XmlPullUtil.valueTag(pp, "id");
|
||||||
requireValueTag(pp, "stateless");
|
XmlPullUtil.valueTag(pp, "stateless");
|
||||||
requireValueTag(pp, "omc");
|
XmlPullUtil.valueTag(pp, "omc");
|
||||||
final String place = normalizeLocationName(optValueTag(pp, "pc"));
|
final String place = normalizeLocationName(XmlPullUtil.optValueTag(pp, "pc", null));
|
||||||
requireValueTag(pp, "pid");
|
XmlPullUtil.valueTag(pp, "pid");
|
||||||
final Point coord = coordStrToPoint(optValueTag(pp, "c"));
|
final Point coord = coordStrToPoint(XmlPullUtil.optValueTag(pp, "c", null));
|
||||||
|
|
||||||
XmlPullUtil.exit(pp, "r");
|
XmlPullUtil.exit(pp, "r");
|
||||||
|
|
||||||
final String qal = optValueTag(pp, "qal");
|
final String qal = XmlPullUtil.optValueTag(pp, "qal", null);
|
||||||
final int quality = qal != null ? Integer.parseInt(qal) : 0;
|
final int quality = qal != null ? Integer.parseInt(qal) : 0;
|
||||||
|
|
||||||
XmlPullUtil.exit(pp, "p");
|
XmlPullUtil.exit(pp, "p");
|
||||||
|
@ -707,19 +707,19 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "pi");
|
XmlPullUtil.enter(pp, "pi");
|
||||||
|
|
||||||
final String name = normalizeLocationName(requireValueTag(pp, "de"));
|
final String name = normalizeLocationName(XmlPullUtil.valueTag(pp, "de"));
|
||||||
final String type = requireValueTag(pp, "ty");
|
final String type = XmlPullUtil.valueTag(pp, "ty");
|
||||||
if (!"STOP".equals(type))
|
if (!"STOP".equals(type))
|
||||||
throw new RuntimeException("unknown type");
|
throw new RuntimeException("unknown type");
|
||||||
|
|
||||||
final String id = requireValueTag(pp, "id");
|
final String id = XmlPullUtil.valueTag(pp, "id");
|
||||||
requireValueTag(pp, "omc");
|
XmlPullUtil.valueTag(pp, "omc");
|
||||||
requireValueTag(pp, "pid");
|
XmlPullUtil.valueTag(pp, "pid");
|
||||||
final String place = normalizeLocationName(requireValueTag(pp, "locality"));
|
final String place = normalizeLocationName(XmlPullUtil.valueTag(pp, "locality"));
|
||||||
requireValueTag(pp, "layer");
|
XmlPullUtil.valueTag(pp, "layer");
|
||||||
requireValueTag(pp, "gisID");
|
XmlPullUtil.valueTag(pp, "gisID");
|
||||||
requireValueTag(pp, "ds");
|
XmlPullUtil.valueTag(pp, "ds");
|
||||||
final Point coord = coordStrToPoint(requireValueTag(pp, "c"));
|
final Point coord = coordStrToPoint(XmlPullUtil.valueTag(pp, "c"));
|
||||||
|
|
||||||
stations.add(new Location(LocationType.STATION, id, coord.lat, coord.lon, place, name));
|
stations.add(new Location(LocationType.STATION, id, coord.lat, coord.lon, place, name));
|
||||||
|
|
||||||
|
@ -761,11 +761,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
if ("identified".equals(placeState))
|
if ("identified".equals(placeState))
|
||||||
{
|
{
|
||||||
if (XmlPullUtil.test(pp, "odvPlaceElem"))
|
if (XmlPullUtil.test(pp, "odvPlaceElem"))
|
||||||
{
|
place = normalizeLocationName(XmlPullUtil.valueTag(pp, "odvPlaceElem"));
|
||||||
XmlPullUtil.enter(pp, "odvPlaceElem");
|
|
||||||
place = normalizeLocationName(pp.getText());
|
|
||||||
XmlPullUtil.exit(pp, "odvPlaceElem");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
XmlPullUtil.exit(pp, "itdOdvPlace");
|
XmlPullUtil.exit(pp, "itdOdvPlace");
|
||||||
|
|
||||||
|
@ -789,9 +785,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
final float x = XmlPullUtil.optFloatAttr(pp, "x", 0);
|
final float x = XmlPullUtil.optFloatAttr(pp, "x", 0);
|
||||||
final float y = XmlPullUtil.optFloatAttr(pp, "y", 0);
|
final float y = XmlPullUtil.optFloatAttr(pp, "y", 0);
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "odvNameElem");
|
final String elemName = normalizeLocationName(XmlPullUtil.valueTag(pp, "odvNameElem"));
|
||||||
final String elemName = normalizeLocationName(pp.getText());
|
|
||||||
XmlPullUtil.exit(pp, "odvNameElem");
|
|
||||||
|
|
||||||
final int lat;
|
final int lat;
|
||||||
final int lon;
|
final int lon;
|
||||||
|
@ -917,9 +911,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
|
|
||||||
final String place = normalizeLocationName(XmlPullUtil.attr(pp, "place"));
|
final String place = normalizeLocationName(XmlPullUtil.attr(pp, "place"));
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "itdOdvAssignedStop");
|
final String name = normalizeLocationName(XmlPullUtil.valueTag(pp, "itdOdvAssignedStop"));
|
||||||
final String name = normalizeLocationName(pp.getText());
|
|
||||||
XmlPullUtil.exit(pp, "itdOdvAssignedStop");
|
|
||||||
|
|
||||||
return new Location(LocationType.STATION, id, lat, lon, place, name);
|
return new Location(LocationType.STATION, id, lat, lon, place, name);
|
||||||
}
|
}
|
||||||
|
@ -1724,8 +1716,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
XmlPullUtil.enter(pp, "dp");
|
XmlPullUtil.enter(pp, "dp");
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
/* final String stationName = */normalizeLocationName(requireValueTag(pp, "n"));
|
/* final String stationName = */normalizeLocationName(XmlPullUtil.valueTag(pp, "n"));
|
||||||
final boolean isRealtime = requireValueTag(pp, "realtime").equals("1");
|
final boolean isRealtime = XmlPullUtil.valueTag(pp, "realtime").equals("1");
|
||||||
|
|
||||||
XmlPullUtil.optSkip(pp, "dt");
|
XmlPullUtil.optSkip(pp, "dt");
|
||||||
|
|
||||||
|
@ -1735,12 +1727,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
final LineDestination lineDestination = parseMobileM(pp, true);
|
final LineDestination lineDestination = parseMobileM(pp, true);
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "r");
|
XmlPullUtil.enter(pp, "r");
|
||||||
final String assignedId = requireValueTag(pp, "id");
|
final String assignedId = XmlPullUtil.valueTag(pp, "id");
|
||||||
requireValueTag(pp, "a");
|
XmlPullUtil.valueTag(pp, "a");
|
||||||
final Position position = new Position(optValueTag(pp, "pl"));
|
final Position position = new Position(XmlPullUtil.optValueTag(pp, "pl", null));
|
||||||
XmlPullUtil.exit(pp, "r");
|
XmlPullUtil.exit(pp, "r");
|
||||||
|
|
||||||
/* final Point positionCoordinate = */coordStrToPoint(optValueTag(pp, "c"));
|
/* final Point positionCoordinate = */coordStrToPoint(XmlPullUtil.optValueTag(pp, "c", null));
|
||||||
|
|
||||||
// TODO messages
|
// TODO messages
|
||||||
|
|
||||||
|
@ -1785,9 +1777,9 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "m");
|
XmlPullUtil.enter(pp, "m");
|
||||||
|
|
||||||
final String n = optValueTag(pp, "n");
|
final String n = XmlPullUtil.optValueTag(pp, "n", null);
|
||||||
final String productNu = requireValueTag(pp, "nu");
|
final String productNu = XmlPullUtil.valueTag(pp, "nu");
|
||||||
final String ty = requireValueTag(pp, "ty");
|
final String ty = XmlPullUtil.valueTag(pp, "ty");
|
||||||
|
|
||||||
final Line line;
|
final Line line;
|
||||||
final Location destination;
|
final Location destination;
|
||||||
|
@ -1813,12 +1805,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
final String co = requireValueTag(pp, "co");
|
final String co = XmlPullUtil.valueTag(pp, "co");
|
||||||
final String productType = tyOrCo ? ty : co;
|
final String productType = tyOrCo ? ty : co;
|
||||||
final String destinationName = normalizeLocationName(requireValueTag(pp, "des"));
|
final String destinationName = normalizeLocationName(XmlPullUtil.valueTag(pp, "des"));
|
||||||
destination = new Location(LocationType.ANY, null, null, destinationName);
|
destination = new Location(LocationType.ANY, null, null, destinationName);
|
||||||
optValueTag(pp, "dy");
|
XmlPullUtil.optValueTag(pp, "dy", null);
|
||||||
final String de = optValueTag(pp, "de");
|
final String de = XmlPullUtil.optValueTag(pp, "de", null);
|
||||||
final String productName = n != null ? n : de;
|
final String productName = n != null ? n : de;
|
||||||
final String lineId = parseMobileDv(pp);
|
final String lineId = parseMobileDv(pp);
|
||||||
|
|
||||||
|
@ -1851,12 +1843,12 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
private String parseMobileDv(final XmlPullParser pp) throws XmlPullParserException, IOException
|
private String parseMobileDv(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "dv");
|
XmlPullUtil.enter(pp, "dv");
|
||||||
optValueTag(pp, "branch");
|
XmlPullUtil.optValueTag(pp, "branch", null);
|
||||||
final String lineIdLi = requireValueTag(pp, "li");
|
final String lineIdLi = XmlPullUtil.valueTag(pp, "li");
|
||||||
final String lineIdSu = requireValueTag(pp, "su");
|
final String lineIdSu = XmlPullUtil.valueTag(pp, "su");
|
||||||
final String lineIdPr = requireValueTag(pp, "pr");
|
final String lineIdPr = XmlPullUtil.valueTag(pp, "pr");
|
||||||
final String lineIdDct = requireValueTag(pp, "dct");
|
final String lineIdDct = XmlPullUtil.valueTag(pp, "dct");
|
||||||
final String lineIdNe = requireValueTag(pp, "ne");
|
final String lineIdNe = XmlPullUtil.valueTag(pp, "ne");
|
||||||
XmlPullUtil.exit(pp, "dv");
|
XmlPullUtil.exit(pp, "dv");
|
||||||
|
|
||||||
return lineIdNe + ":" + lineIdLi + ":" + lineIdSu + ":" + lineIdDct + ":" + lineIdPr;
|
return lineIdNe + ":" + lineIdLi + ":" + lineIdSu + ":" + lineIdDct + ":" + lineIdPr;
|
||||||
|
@ -1868,14 +1860,14 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
XmlPullUtil.enter(pp, "st");
|
XmlPullUtil.enter(pp, "st");
|
||||||
|
|
||||||
plannedDepartureTime.clear();
|
plannedDepartureTime.clear();
|
||||||
ParserUtils.parseIsoDate(plannedDepartureTime, requireValueTag(pp, "da"));
|
ParserUtils.parseIsoDate(plannedDepartureTime, XmlPullUtil.valueTag(pp, "da"));
|
||||||
ParserUtils.parseIsoTime(plannedDepartureTime, requireValueTag(pp, "t"));
|
ParserUtils.parseIsoTime(plannedDepartureTime, XmlPullUtil.valueTag(pp, "t"));
|
||||||
|
|
||||||
predictedDepartureTime.clear();
|
predictedDepartureTime.clear();
|
||||||
if (XmlPullUtil.test(pp, "rda"))
|
if (XmlPullUtil.test(pp, "rda"))
|
||||||
{
|
{
|
||||||
ParserUtils.parseIsoDate(predictedDepartureTime, requireValueTag(pp, "rda"));
|
ParserUtils.parseIsoDate(predictedDepartureTime, XmlPullUtil.valueTag(pp, "rda"));
|
||||||
ParserUtils.parseIsoTime(predictedDepartureTime, requireValueTag(pp, "rt"));
|
ParserUtils.parseIsoTime(predictedDepartureTime, XmlPullUtil.valueTag(pp, "rt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlPullUtil.exit(pp, "st");
|
XmlPullUtil.exit(pp, "st");
|
||||||
|
@ -2007,13 +1999,11 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
itdTrainType = pp.getAttributeValue(null, "type");
|
itdTrainType = pp.getAttributeValue(null, "type");
|
||||||
if (!pp.isEmptyElementTag())
|
if (!pp.isEmptyElementTag())
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "itdNoTrain");
|
final String text = XmlPullUtil.valueTag(pp, "itdNoTrain");
|
||||||
final String text = pp.getText();
|
|
||||||
if (itdTrainName != null && itdTrainName.toLowerCase().contains("ruf"))
|
if (itdTrainName != null && itdTrainName.toLowerCase().contains("ruf"))
|
||||||
itdMessage = text;
|
itdMessage = text;
|
||||||
else if (text != null && text.toLowerCase().contains("ruf"))
|
else if (text != null && text.toLowerCase().contains("ruf"))
|
||||||
itdMessage = text;
|
itdMessage = text;
|
||||||
XmlPullUtil.exit(pp, "itdNoTrain");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2620,18 +2610,13 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
XmlPullUtil.enter(pp, "itdInfoTextList");
|
XmlPullUtil.enter(pp, "itdInfoTextList");
|
||||||
while (XmlPullUtil.test(pp, "infoTextListElem"))
|
while (XmlPullUtil.test(pp, "infoTextListElem"))
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "infoTextListElem");
|
final String text = XmlPullUtil.valueTag(pp, "infoTextListElem");
|
||||||
final String text = pp.getText();
|
|
||||||
if (text != null)
|
|
||||||
{
|
|
||||||
final String lcText = text.toLowerCase();
|
final String lcText = text.toLowerCase();
|
||||||
if ("niederflurwagen soweit verfügbar".equals(lcText)) // KVV
|
if ("niederflurwagen soweit verfügbar".equals(lcText)) // KVV
|
||||||
lowFloorVehicle = true;
|
lowFloorVehicle = true;
|
||||||
else if (lcText.contains("ruf") || lcText.contains("anmeld")) // Bedarfsverkehr
|
else if (lcText.contains("ruf") || lcText.contains("anmeld")) // Bedarfsverkehr
|
||||||
message = text;
|
message = text;
|
||||||
}
|
}
|
||||||
XmlPullUtil.exit(pp, "infoTextListElem");
|
|
||||||
}
|
|
||||||
XmlPullUtil.exit(pp, "itdInfoTextList");
|
XmlPullUtil.exit(pp, "itdInfoTextList");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2734,12 +2719,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
while (XmlPullUtil.test(pp, "genAttrElem"))
|
while (XmlPullUtil.test(pp, "genAttrElem"))
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "genAttrElem");
|
XmlPullUtil.enter(pp, "genAttrElem");
|
||||||
XmlPullUtil.enter(pp, "name");
|
final String name = XmlPullUtil.valueTag(pp, "name");
|
||||||
final String name = pp.getText();
|
final String value = XmlPullUtil.valueTag(pp, "value");
|
||||||
XmlPullUtil.exit(pp, "name");
|
|
||||||
XmlPullUtil.enter(pp, "value");
|
|
||||||
final String value = pp.getText();
|
|
||||||
XmlPullUtil.exit(pp, "value");
|
|
||||||
XmlPullUtil.exit(pp, "genAttrElem");
|
XmlPullUtil.exit(pp, "genAttrElem");
|
||||||
|
|
||||||
// System.out.println("genAttrElem: name='" + name + "' value='" + value + "'");
|
// System.out.println("genAttrElem: name='" + name + "' value='" + value + "'");
|
||||||
|
@ -2883,9 +2864,9 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
|
|
||||||
XmlPullUtil.optSkip(pp, "attrs");
|
XmlPullUtil.optSkip(pp, "attrs");
|
||||||
|
|
||||||
requireValueTag(pp, "d"); // duration
|
XmlPullUtil.valueTag(pp, "d"); // duration
|
||||||
final int numChanges = Integer.parseInt(requireValueTag(pp, "ic"));
|
final int numChanges = Integer.parseInt(XmlPullUtil.valueTag(pp, "ic"));
|
||||||
final String tripId = requireValueTag(pp, "de");
|
final String tripId = XmlPullUtil.valueTag(pp, "de");
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "ls");
|
XmlPullUtil.enter(pp, "ls");
|
||||||
|
|
||||||
|
@ -2906,9 +2887,9 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "p");
|
XmlPullUtil.enter(pp, "p");
|
||||||
|
|
||||||
final String name = requireValueTag(pp, "n");
|
final String name = XmlPullUtil.valueTag(pp, "n");
|
||||||
final String usage = requireValueTag(pp, "u");
|
final String usage = XmlPullUtil.valueTag(pp, "u");
|
||||||
optValueTag(pp, "de");
|
XmlPullUtil.optValueTag(pp, "de", null);
|
||||||
|
|
||||||
XmlPullUtil.requireSkip(pp, "dt");
|
XmlPullUtil.requireSkip(pp, "dt");
|
||||||
|
|
||||||
|
@ -2917,11 +2898,11 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
XmlPullUtil.requireSkip(pp, "lis");
|
XmlPullUtil.requireSkip(pp, "lis");
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "r");
|
XmlPullUtil.enter(pp, "r");
|
||||||
final String id = requireValueTag(pp, "id");
|
final String id = XmlPullUtil.valueTag(pp, "id");
|
||||||
optValueTag(pp, "a");
|
XmlPullUtil.optValueTag(pp, "a", null);
|
||||||
final Position position = new Position(optValueTag(pp, "pl"));
|
final Position position = new Position(XmlPullUtil.optValueTag(pp, "pl", null));
|
||||||
final String place = normalizeLocationName(optValueTag(pp, "pc"));
|
final String place = normalizeLocationName(XmlPullUtil.optValueTag(pp, "pc", null));
|
||||||
final Point coord = coordStrToPoint(requireValueTag(pp, "c"));
|
final Point coord = coordStrToPoint(XmlPullUtil.valueTag(pp, "c"));
|
||||||
XmlPullUtil.exit(pp, "r");
|
XmlPullUtil.exit(pp, "r");
|
||||||
|
|
||||||
final Location location;
|
final Location location;
|
||||||
|
@ -2955,7 +2936,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
|
|
||||||
XmlPullUtil.exit(pp, "ps");
|
XmlPullUtil.exit(pp, "ps");
|
||||||
|
|
||||||
final boolean isRealtime = requireValueTag(pp, "realtime").equals("1");
|
final boolean isRealtime = XmlPullUtil.valueTag(pp, "realtime").equals("1");
|
||||||
|
|
||||||
final LineDestination lineDestination = parseMobileM(pp, false);
|
final LineDestination lineDestination = parseMobileM(pp, false);
|
||||||
|
|
||||||
|
@ -2980,7 +2961,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
plannedTime.clear();
|
plannedTime.clear();
|
||||||
predictedTime.clear();
|
predictedTime.clear();
|
||||||
|
|
||||||
final String s = requireValueTag(pp, "s");
|
final String s = XmlPullUtil.valueTag(pp, "s");
|
||||||
final String[] intermediateParts = s.split(";");
|
final String[] intermediateParts = s.split(";");
|
||||||
final String id = intermediateParts[0];
|
final String id = intermediateParts[0];
|
||||||
if (!id.equals(departure.location.id) && !id.equals(arrival.location.id))
|
if (!id.equals(departure.location.id) && !id.equals(arrival.location.id))
|
||||||
|
@ -3123,17 +3104,11 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "itdPathCoordinates");
|
XmlPullUtil.enter(pp, "itdPathCoordinates");
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "coordEllipsoid");
|
final String ellipsoid = XmlPullUtil.valueTag(pp, "coordEllipsoid");
|
||||||
final String ellipsoid = pp.getText();
|
|
||||||
XmlPullUtil.exit(pp, "coordEllipsoid");
|
|
||||||
|
|
||||||
if (!"WGS84".equals(ellipsoid))
|
if (!"WGS84".equals(ellipsoid))
|
||||||
throw new IllegalStateException("unknown ellipsoid: " + ellipsoid);
|
throw new IllegalStateException("unknown ellipsoid: " + ellipsoid);
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "coordType");
|
final String type = XmlPullUtil.valueTag(pp, "coordType");
|
||||||
final String type = pp.getText();
|
|
||||||
XmlPullUtil.exit(pp, "coordType");
|
|
||||||
|
|
||||||
if (!"GEO_DECIMAL".equals(type))
|
if (!"GEO_DECIMAL".equals(type))
|
||||||
throw new IllegalStateException("unknown type: " + type);
|
throw new IllegalStateException("unknown type: " + type);
|
||||||
|
|
||||||
|
@ -3160,7 +3135,7 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
{
|
{
|
||||||
final List<Point> path = new LinkedList<Point>();
|
final List<Point> path = new LinkedList<Point>();
|
||||||
|
|
||||||
final String value = requireValueTag(pp, tag);
|
final String value = XmlPullUtil.valueTag(pp, tag);
|
||||||
for (final String coordStr : value.split(" +"))
|
for (final String coordStr : value.split(" +"))
|
||||||
path.add(coordStrToPoint(coordStr));
|
path.add(coordStrToPoint(coordStr));
|
||||||
|
|
||||||
|
@ -3177,8 +3152,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "itdCoordinateBaseElem");
|
XmlPullUtil.enter(pp, "itdCoordinateBaseElem");
|
||||||
|
|
||||||
final int lon = Math.round(Float.parseFloat(requireValueTag(pp, "x")));
|
final int lon = Math.round(Float.parseFloat(XmlPullUtil.valueTag(pp, "x")));
|
||||||
final int lat = Math.round(Float.parseFloat(requireValueTag(pp, "y")));
|
final int lat = Math.round(Float.parseFloat(XmlPullUtil.valueTag(pp, "y")));
|
||||||
path.add(new Point(lat, lon));
|
path.add(new Point(lat, lon));
|
||||||
|
|
||||||
XmlPullUtil.exit(pp, "itdCoordinateBaseElem");
|
XmlPullUtil.exit(pp, "itdCoordinateBaseElem");
|
||||||
|
@ -3210,24 +3185,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "itdGenericTicket");
|
XmlPullUtil.enter(pp, "itdGenericTicket");
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "ticket");
|
final String key = XmlPullUtil.valueTag(pp, "ticket");
|
||||||
final String key = pp.getText().trim();
|
final String value = XmlPullUtil.valueTag(pp, "value");
|
||||||
XmlPullUtil.exit(pp, "ticket");
|
|
||||||
|
|
||||||
String value = null;
|
|
||||||
XmlPullUtil.require(pp, "value");
|
|
||||||
if (!pp.isEmptyElementTag())
|
|
||||||
{
|
|
||||||
XmlPullUtil.enter(pp, "value");
|
|
||||||
value = pp.getText();
|
|
||||||
if (value != null)
|
|
||||||
value = value.trim();
|
|
||||||
XmlPullUtil.exit(pp, "value");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
XmlPullUtil.next(pp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key.equals("FOR_RIDER"))
|
if (key.equals("FOR_RIDER"))
|
||||||
{
|
{
|
||||||
|
@ -3392,12 +3351,10 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "efa");
|
XmlPullUtil.enter(pp, "efa");
|
||||||
|
|
||||||
XmlPullUtil.enter(pp, "now");
|
final String now = XmlPullUtil.valueTag(pp, "now");
|
||||||
final String now = pp.getText();
|
|
||||||
final Calendar serverTime = new GregorianCalendar(timeZone());
|
final Calendar serverTime = new GregorianCalendar(timeZone());
|
||||||
ParserUtils.parseIsoDate(serverTime, now.substring(0, 10));
|
ParserUtils.parseIsoDate(serverTime, now.substring(0, 10));
|
||||||
ParserUtils.parseEuropeanTime(serverTime, now.substring(11));
|
ParserUtils.parseEuropeanTime(serverTime, now.substring(11));
|
||||||
XmlPullUtil.exit(pp, "now");
|
|
||||||
|
|
||||||
final Map<String, String> params = processPas(pp);
|
final Map<String, String> params = processPas(pp);
|
||||||
final String sessionId = params.get("sessionID");
|
final String sessionId = params.get("sessionID");
|
||||||
|
@ -3417,8 +3374,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
while (XmlPullUtil.test(pp, "pa"))
|
while (XmlPullUtil.test(pp, "pa"))
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "pa");
|
XmlPullUtil.enter(pp, "pa");
|
||||||
final String name = requireValueTag(pp, "n");
|
final String name = XmlPullUtil.valueTag(pp, "n");
|
||||||
final String value = requireValueTag(pp, "v");
|
final String value = XmlPullUtil.valueTag(pp, "v");
|
||||||
params.put(name, value);
|
params.put(name, value);
|
||||||
XmlPullUtil.exit(pp, "pa");
|
XmlPullUtil.exit(pp, "pa");
|
||||||
}
|
}
|
||||||
|
@ -3427,33 +3384,4 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String optValueTag(final XmlPullParser pp, final String name) throws XmlPullParserException, IOException
|
|
||||||
{
|
|
||||||
if (XmlPullUtil.test(pp, name))
|
|
||||||
{
|
|
||||||
if (!pp.isEmptyElementTag())
|
|
||||||
{
|
|
||||||
return requireValueTag(pp, name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pp.next();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String requireValueTag(final XmlPullParser pp, final String name) throws XmlPullParserException, IOException
|
|
||||||
{
|
|
||||||
XmlPullUtil.enter(pp, name);
|
|
||||||
final String value = pp.getText();
|
|
||||||
XmlPullUtil.exit(pp, name);
|
|
||||||
|
|
||||||
return value != null ? value.trim() : null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -309,8 +309,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
private static final Position parsePlatform(final XmlPullParser pp) throws XmlPullParserException, IOException
|
private static final Position parsePlatform(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "Platform");
|
XmlPullUtil.enter(pp, "Platform");
|
||||||
XmlPullUtil.require(pp, "Text");
|
final String platformText = XmlPullUtil.valueTag(pp, "Text");
|
||||||
final String platformText = XmlPullUtil.text(pp).trim();
|
|
||||||
XmlPullUtil.exit(pp, "Platform");
|
XmlPullUtil.exit(pp, "Platform");
|
||||||
|
|
||||||
if (platformText.length() == 0)
|
if (platformText.length() == 0)
|
||||||
|
@ -1070,7 +1069,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
throw new IllegalStateException("error " + code + " " + XmlPullUtil.attr(pp, "text"));
|
throw new IllegalStateException("error " + code + " " + XmlPullUtil.attr(pp, "text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
final String c = XmlPullUtil.test(pp, "ConResCtxt") ? XmlPullUtil.text(pp) : null;
|
final String c = XmlPullUtil.optValueTag(pp, "ConResCtxt", null);
|
||||||
final Context context;
|
final Context context;
|
||||||
if (previousContext == null)
|
if (previousContext == null)
|
||||||
context = new Context(c, c, 0);
|
context = new Context(c, c, 0);
|
||||||
|
@ -1092,10 +1091,9 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
XmlPullUtil.next(pp);
|
XmlPullUtil.next(pp);
|
||||||
XmlPullUtil.enter(pp, "Overview");
|
XmlPullUtil.enter(pp, "Overview");
|
||||||
|
|
||||||
XmlPullUtil.require(pp, "Date");
|
|
||||||
final Calendar currentDate = new GregorianCalendar(timeZone());
|
final Calendar currentDate = new GregorianCalendar(timeZone());
|
||||||
currentDate.clear();
|
currentDate.clear();
|
||||||
parseDate(currentDate, XmlPullUtil.text(pp));
|
parseDate(currentDate, XmlPullUtil.valueTag(pp, "Date"));
|
||||||
XmlPullUtil.enter(pp, "Departure");
|
XmlPullUtil.enter(pp, "Departure");
|
||||||
XmlPullUtil.enter(pp, "BasicStop");
|
XmlPullUtil.enter(pp, "BasicStop");
|
||||||
while (pp.getName().equals("StAttrList"))
|
while (pp.getName().equals("StAttrList"))
|
||||||
|
@ -1113,8 +1111,8 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
XmlPullUtil.next(pp);
|
XmlPullUtil.next(pp);
|
||||||
XmlPullUtil.enter(pp, "Status");
|
XmlPullUtil.enter(pp, "Status");
|
||||||
XmlPullUtil.exit(pp, "Status");
|
XmlPullUtil.exit(pp, "Status");
|
||||||
final int capacity1st = XmlPullUtil.test(pp, "Capacity1st") ? Integer.parseInt(XmlPullUtil.text(pp)) : 0;
|
final int capacity1st = Integer.parseInt(XmlPullUtil.optValueTag(pp, "Capacity1st", "0"));
|
||||||
final int capacity2nd = XmlPullUtil.test(pp, "Capacity2nd") ? Integer.parseInt(XmlPullUtil.text(pp)) : 0;
|
final int capacity2nd = Integer.parseInt(XmlPullUtil.optValueTag(pp, "Capacity2nd", "0"));
|
||||||
if (capacity1st > 0 || capacity2nd > 0)
|
if (capacity1st > 0 || capacity2nd > 0)
|
||||||
capacity = new int[] { capacity1st, capacity2nd };
|
capacity = new int[] { capacity1st, capacity2nd };
|
||||||
else
|
else
|
||||||
|
@ -1136,8 +1134,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
XmlPullUtil.exit(pp, "BasicStop");
|
XmlPullUtil.exit(pp, "BasicStop");
|
||||||
XmlPullUtil.exit(pp, "Arrival");
|
XmlPullUtil.exit(pp, "Arrival");
|
||||||
|
|
||||||
XmlPullUtil.require(pp, "Transfers");
|
final int numTransfers = Integer.parseInt(XmlPullUtil.valueTag(pp, "Transfers"));
|
||||||
final int numTransfers = Integer.parseInt(XmlPullUtil.text(pp));
|
|
||||||
|
|
||||||
XmlPullUtil.exit(pp, "Overview");
|
XmlPullUtil.exit(pp, "Overview");
|
||||||
|
|
||||||
|
@ -1164,9 +1161,8 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
XmlPullUtil.exit(pp, "Arr");
|
XmlPullUtil.exit(pp, "Arr");
|
||||||
}
|
}
|
||||||
XmlPullUtil.enter(pp, "Dep");
|
XmlPullUtil.enter(pp, "Dep");
|
||||||
XmlPullUtil.require(pp, "Time");
|
|
||||||
time.setTimeInMillis(currentDate.getTimeInMillis());
|
time.setTimeInMillis(currentDate.getTimeInMillis());
|
||||||
parseTime(time, XmlPullUtil.text(pp));
|
parseTime(time, XmlPullUtil.valueTag(pp, "Time"));
|
||||||
final Date departureTime = time.getTime();
|
final Date departureTime = time.getTime();
|
||||||
final Position departurePos = parsePlatform(pp);
|
final Position departurePos = parsePlatform(pp);
|
||||||
XmlPullUtil.exit(pp, "Dep");
|
XmlPullUtil.exit(pp, "Dep");
|
||||||
|
@ -1246,9 +1242,8 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
if (XmlPullUtil.test(pp, "Arr"))
|
if (XmlPullUtil.test(pp, "Arr"))
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "Arr");
|
XmlPullUtil.enter(pp, "Arr");
|
||||||
XmlPullUtil.require(pp, "Time");
|
|
||||||
time.setTimeInMillis(currentDate.getTimeInMillis());
|
time.setTimeInMillis(currentDate.getTimeInMillis());
|
||||||
parseTime(time, XmlPullUtil.text(pp));
|
parseTime(time, XmlPullUtil.valueTag(pp, "Time"));
|
||||||
stopArrivalTime = time.getTime();
|
stopArrivalTime = time.getTime();
|
||||||
stopArrivalPosition = parsePlatform(pp);
|
stopArrivalPosition = parsePlatform(pp);
|
||||||
XmlPullUtil.exit(pp, "Arr");
|
XmlPullUtil.exit(pp, "Arr");
|
||||||
|
@ -1257,9 +1252,8 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
if (XmlPullUtil.test(pp, "Dep"))
|
if (XmlPullUtil.test(pp, "Dep"))
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp, "Dep");
|
XmlPullUtil.enter(pp, "Dep");
|
||||||
XmlPullUtil.require(pp, "Time");
|
|
||||||
time.setTimeInMillis(currentDate.getTimeInMillis());
|
time.setTimeInMillis(currentDate.getTimeInMillis());
|
||||||
parseTime(time, XmlPullUtil.text(pp));
|
parseTime(time, XmlPullUtil.valueTag(pp, "Time"));
|
||||||
stopDepartureTime = time.getTime();
|
stopDepartureTime = time.getTime();
|
||||||
stopDeparturePosition = parsePlatform(pp);
|
stopDeparturePosition = parsePlatform(pp);
|
||||||
XmlPullUtil.exit(pp, "Dep");
|
XmlPullUtil.exit(pp, "Dep");
|
||||||
|
@ -1322,9 +1316,8 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
XmlPullUtil.next(pp);
|
XmlPullUtil.next(pp);
|
||||||
final Location sectionArrivalLocation = parseLocation(pp);
|
final Location sectionArrivalLocation = parseLocation(pp);
|
||||||
XmlPullUtil.enter(pp, "Arr");
|
XmlPullUtil.enter(pp, "Arr");
|
||||||
XmlPullUtil.require(pp, "Time");
|
|
||||||
time.setTimeInMillis(currentDate.getTimeInMillis());
|
time.setTimeInMillis(currentDate.getTimeInMillis());
|
||||||
parseTime(time, XmlPullUtil.text(pp));
|
parseTime(time, XmlPullUtil.valueTag(pp, "Time"));
|
||||||
final Date arrivalTime = time.getTime();
|
final Date arrivalTime = time.getTime();
|
||||||
final Position arrivalPos = parsePlatform(pp);
|
final Position arrivalPos = parsePlatform(pp);
|
||||||
XmlPullUtil.exit(pp, "Arr");
|
XmlPullUtil.exit(pp, "Arr");
|
||||||
|
@ -1408,11 +1401,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
|
||||||
{
|
{
|
||||||
final String type = XmlPullUtil.attr(pp, "type");
|
final String type = XmlPullUtil.attr(pp, "type");
|
||||||
XmlPullUtil.enter(pp, "AttributeVariant");
|
XmlPullUtil.enter(pp, "AttributeVariant");
|
||||||
final String value;
|
final String value = XmlPullUtil.optValueTag(pp, "Text", null);
|
||||||
if (XmlPullUtil.test(pp, "Text"))
|
|
||||||
value = XmlPullUtil.text(pp).trim();
|
|
||||||
else
|
|
||||||
value = null;
|
|
||||||
XmlPullUtil.exit(pp, "AttributeVariant");
|
XmlPullUtil.exit(pp, "AttributeVariant");
|
||||||
|
|
||||||
attributeVariants.put(type, value);
|
attributeVariants.put(type, value);
|
||||||
|
|
|
@ -174,20 +174,34 @@ public final class XmlPullUtil
|
||||||
throw new IllegalStateException("cannot find " + attrName + "=\"" + requiredValue + "\" />");
|
throw new IllegalStateException("cannot find " + attrName + "=\"" + requiredValue + "\" />");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String text(final XmlPullParser pp) throws XmlPullParserException, IOException
|
public static String valueTag(final XmlPullParser pp, final String tagName) throws XmlPullParserException, IOException
|
||||||
{
|
{
|
||||||
if (pp.getEventType() != XmlPullParser.START_TAG || pp.isEmptyElementTag())
|
XmlPullUtil.enter(pp, tagName);
|
||||||
throw new IllegalStateException("expecting start tag to get text from");
|
final String value = pp.getText();
|
||||||
|
XmlPullUtil.exit(pp, tagName);
|
||||||
|
|
||||||
enter(pp);
|
return value != null ? value.trim() : null;
|
||||||
|
}
|
||||||
|
|
||||||
String text = "";
|
public static String optValueTag(final XmlPullParser pp, final String tagName, final String defaultValue) throws XmlPullParserException,
|
||||||
if (pp.getEventType() == XmlPullParser.TEXT)
|
IOException
|
||||||
text = pp.getText();
|
{
|
||||||
|
if (XmlPullUtil.test(pp, tagName))
|
||||||
exit(pp);
|
{
|
||||||
|
if (!pp.isEmptyElementTag())
|
||||||
return text;
|
{
|
||||||
|
return valueTag(pp, tagName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pp.next();
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue