mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-18 00:09:55 +00:00
parse connection departure and arrival
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@347 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
8bea4d14b8
commit
31e2686794
1 changed files with 61 additions and 57 deletions
|
@ -261,8 +261,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
assertResC(pp);
|
assertResC(pp);
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
|
|
||||||
XmlPullUtil.require(pp, "ConRes");
|
XmlPullUtil.enter(pp, "ConRes");
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
if (pp.getName().equals("Err"))
|
if (pp.getName().equals("Err"))
|
||||||
{
|
{
|
||||||
final String code = XmlPullUtil.attr(pp, "code");
|
final String code = XmlPullUtil.attr(pp, "code");
|
||||||
|
@ -277,8 +276,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
|
|
||||||
XmlPullUtil.require(pp, "ConResCtxt");
|
XmlPullUtil.require(pp, "ConResCtxt");
|
||||||
final String context = XmlPullUtil.text(pp);
|
final String context = XmlPullUtil.text(pp);
|
||||||
XmlPullUtil.require(pp, "ConnectionList");
|
XmlPullUtil.enter(pp, "ConnectionList");
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
|
|
||||||
final List<Connection> connections = new ArrayList<Connection>();
|
final List<Connection> connections = new ArrayList<Connection>();
|
||||||
|
|
||||||
|
@ -289,14 +287,30 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
while (pp.getName().equals("RtStateList"))
|
while (pp.getName().equals("RtStateList"))
|
||||||
XmlPullUtil.next(pp);
|
XmlPullUtil.next(pp);
|
||||||
XmlPullUtil.require(pp, "Overview");
|
XmlPullUtil.enter(pp, "Overview");
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
XmlPullUtil.require(pp, "Date");
|
XmlPullUtil.require(pp, "Date");
|
||||||
final Calendar currentDate = new GregorianCalendar();
|
final Calendar currentDate = new GregorianCalendar();
|
||||||
currentDate.setTime(DATE_FORMAT.parse(XmlPullUtil.text(pp)));
|
currentDate.setTime(DATE_FORMAT.parse(XmlPullUtil.text(pp)));
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.enter(pp, "Departure");
|
||||||
XmlPullUtil.require(pp, "ConSectionList");
|
XmlPullUtil.enter(pp, "BasicStop");
|
||||||
XmlPullUtil.enter(pp);
|
while (pp.getName().equals("StAttrList"))
|
||||||
|
XmlPullUtil.next(pp);
|
||||||
|
final Location departure = parseLocation(pp);
|
||||||
|
XmlPullUtil.exit(pp, "BasicStop");
|
||||||
|
XmlPullUtil.exit(pp, "Departure");
|
||||||
|
|
||||||
|
XmlPullUtil.enter(pp, "Arrival");
|
||||||
|
XmlPullUtil.enter(pp, "BasicStop");
|
||||||
|
while (pp.getName().equals("StAttrList"))
|
||||||
|
XmlPullUtil.next(pp);
|
||||||
|
final Location arrival = parseLocation(pp);
|
||||||
|
XmlPullUtil.exit(pp, "BasicStop");
|
||||||
|
XmlPullUtil.exit(pp, "Arrival");
|
||||||
|
|
||||||
|
XmlPullUtil.exit(pp, "Overview");
|
||||||
|
|
||||||
|
XmlPullUtil.enter(pp, "ConSectionList");
|
||||||
|
|
||||||
final List<Connection.Part> parts = new ArrayList<Connection.Part>(4);
|
final List<Connection.Part> parts = new ArrayList<Connection.Part>(4);
|
||||||
Date firstDepartureTime = null;
|
Date firstDepartureTime = null;
|
||||||
|
@ -307,33 +321,20 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
|
|
||||||
// departure
|
// departure
|
||||||
XmlPullUtil.require(pp, "Departure");
|
XmlPullUtil.enter(pp, "Departure");
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp, "BasicStop");
|
||||||
XmlPullUtil.require(pp, "BasicStop");
|
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
while (pp.getName().equals("StAttrList"))
|
while (pp.getName().equals("StAttrList"))
|
||||||
XmlPullUtil.next(pp);
|
XmlPullUtil.next(pp);
|
||||||
Location departure;
|
final Location sectionDeparture = parseLocation(pp);
|
||||||
if (pp.getName().equals("Station"))
|
XmlPullUtil.enter(pp, "Dep");
|
||||||
departure = parseStation(pp);
|
|
||||||
else if (pp.getName().equals("Poi"))
|
|
||||||
departure = parsePoi(pp);
|
|
||||||
else if (pp.getName().equals("Address"))
|
|
||||||
departure = parseAddress(pp);
|
|
||||||
else
|
|
||||||
throw new IllegalStateException("cannot parse: " + pp.getName());
|
|
||||||
XmlPullUtil.next(pp);
|
|
||||||
XmlPullUtil.require(pp, "Dep");
|
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
XmlPullUtil.require(pp, "Time");
|
XmlPullUtil.require(pp, "Time");
|
||||||
final Date departureTime = parseTime(currentDate, XmlPullUtil.text(pp));
|
final Date departureTime = parseTime(currentDate, XmlPullUtil.text(pp));
|
||||||
XmlPullUtil.require(pp, "Platform");
|
XmlPullUtil.enter(pp, "Platform");
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
XmlPullUtil.require(pp, "Text");
|
XmlPullUtil.require(pp, "Text");
|
||||||
String departurePos = XmlPullUtil.text(pp).trim();
|
String departurePos = XmlPullUtil.text(pp).trim();
|
||||||
if (departurePos.length() == 0)
|
if (departurePos.length() == 0)
|
||||||
departurePos = null;
|
departurePos = null;
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp, "Platform");
|
||||||
|
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
|
|
||||||
|
@ -351,8 +352,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
while (pp.getName().equals("JHandle"))
|
while (pp.getName().equals("JHandle"))
|
||||||
XmlPullUtil.next(pp);
|
XmlPullUtil.next(pp);
|
||||||
XmlPullUtil.require(pp, "JourneyAttributeList");
|
XmlPullUtil.enter(pp, "JourneyAttributeList");
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
String name = null;
|
String name = null;
|
||||||
String category = null;
|
String category = null;
|
||||||
String longCategory = null;
|
String longCategory = null;
|
||||||
|
@ -388,8 +388,7 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
else if (tag.equals("Walk") || tag.equals("Transfer") || tag.equals("GisRoute"))
|
else if (tag.equals("Walk") || tag.equals("Transfer") || tag.equals("GisRoute"))
|
||||||
{
|
{
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp);
|
||||||
XmlPullUtil.require(pp, "Duration");
|
XmlPullUtil.enter(pp, "Duration");
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
XmlPullUtil.require(pp, "Time");
|
XmlPullUtil.require(pp, "Time");
|
||||||
min = parseDuration(XmlPullUtil.text(pp).substring(3, 8));
|
min = parseDuration(XmlPullUtil.text(pp).substring(3, 8));
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
|
@ -401,33 +400,20 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
// arrival
|
// arrival
|
||||||
XmlPullUtil.require(pp, "Arrival");
|
XmlPullUtil.enter(pp, "Arrival");
|
||||||
XmlPullUtil.enter(pp);
|
XmlPullUtil.enter(pp, "BasicStop");
|
||||||
XmlPullUtil.require(pp, "BasicStop");
|
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
while (pp.getName().equals("StAttrList"))
|
while (pp.getName().equals("StAttrList"))
|
||||||
XmlPullUtil.next(pp);
|
XmlPullUtil.next(pp);
|
||||||
Location arrival;
|
final Location sectionArrival = parseLocation(pp);
|
||||||
if (pp.getName().equals("Station"))
|
XmlPullUtil.enter(pp, "Arr");
|
||||||
arrival = parseStation(pp);
|
|
||||||
else if (pp.getName().equals("Poi"))
|
|
||||||
arrival = parsePoi(pp);
|
|
||||||
else if (pp.getName().equals("Address"))
|
|
||||||
arrival = parseAddress(pp);
|
|
||||||
else
|
|
||||||
throw new IllegalStateException("cannot parse: " + pp.getName());
|
|
||||||
XmlPullUtil.next(pp);
|
|
||||||
XmlPullUtil.require(pp, "Arr");
|
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
XmlPullUtil.require(pp, "Time");
|
XmlPullUtil.require(pp, "Time");
|
||||||
final Date arrivalTime = parseTime(currentDate, XmlPullUtil.text(pp));
|
final Date arrivalTime = parseTime(currentDate, XmlPullUtil.text(pp));
|
||||||
XmlPullUtil.require(pp, "Platform");
|
XmlPullUtil.enter(pp, "Platform");
|
||||||
XmlPullUtil.enter(pp);
|
|
||||||
XmlPullUtil.require(pp, "Text");
|
XmlPullUtil.require(pp, "Text");
|
||||||
String arrivalPos = XmlPullUtil.text(pp).trim();
|
String arrivalPos = XmlPullUtil.text(pp).trim();
|
||||||
if (arrivalPos.length() == 0)
|
if (arrivalPos.length() == 0)
|
||||||
arrivalPos = null;
|
arrivalPos = null;
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp, "Platform");
|
||||||
|
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
|
|
||||||
|
@ -438,20 +424,22 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
|
|
||||||
if (min == 0 || line != null)
|
if (min == 0 || line != null)
|
||||||
{
|
{
|
||||||
parts.add(new Connection.Trip(line, lineColors(line), 0, direction, departureTime, departurePos, departure.id,
|
parts.add(new Connection.Trip(line, lineColors(line), 0, direction, departureTime, departurePos, sectionDeparture.id,
|
||||||
departure.name, arrivalTime, arrivalPos, arrival.id, arrival.name, null));
|
sectionDeparture.name, arrivalTime, arrivalPos, sectionArrival.id, sectionArrival.name, null));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (parts.size() > 0 && parts.get(parts.size() - 1) instanceof Connection.Footway)
|
if (parts.size() > 0 && parts.get(parts.size() - 1) instanceof Connection.Footway)
|
||||||
{
|
{
|
||||||
final Connection.Footway lastFootway = (Connection.Footway) parts.remove(parts.size() - 1);
|
final Connection.Footway lastFootway = (Connection.Footway) parts.remove(parts.size() - 1);
|
||||||
parts.add(new Connection.Footway(lastFootway.min + min, lastFootway.departureId, lastFootway.departure, arrival.id,
|
parts.add(new Connection.Footway(lastFootway.min + min, lastFootway.departureId, lastFootway.departure,
|
||||||
arrival.name));
|
sectionArrival.id, sectionArrival.name));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
parts.add(new Connection.Footway(min, departure.id, departure.name, arrival.id, arrival.name));
|
parts
|
||||||
|
.add(new Connection.Footway(min, sectionDeparture.id, sectionDeparture.name, sectionArrival.id,
|
||||||
|
sectionArrival.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,7 +452,8 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
|
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
|
|
||||||
connections.add(new Connection(id, null, firstDepartureTime, lastArrivalTime, null, null, 0, null, 0, null, parts));
|
connections.add(new Connection(id, null, firstDepartureTime, lastArrivalTime, null, null, departure.id, departure.name, arrival.id,
|
||||||
|
arrival.name, parts));
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlPullUtil.exit(pp);
|
XmlPullUtil.exit(pp);
|
||||||
|
@ -486,6 +475,21 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final Location parseLocation(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||||
|
{
|
||||||
|
Location location;
|
||||||
|
if (pp.getName().equals("Station"))
|
||||||
|
location = parseStation(pp);
|
||||||
|
else if (pp.getName().equals("Poi"))
|
||||||
|
location = parsePoi(pp);
|
||||||
|
else if (pp.getName().equals("Address"))
|
||||||
|
location = parseAddress(pp);
|
||||||
|
else
|
||||||
|
throw new IllegalStateException("cannot parse: " + pp.getName());
|
||||||
|
XmlPullUtil.next(pp);
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
private final Map<String, String> parseAttributeVariants(final XmlPullParser pp) throws XmlPullParserException, IOException
|
private final Map<String, String> parseAttributeVariants(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||||
{
|
{
|
||||||
final Map<String, String> attributeVariants = new HashMap<String, String>();
|
final Map<String, String> attributeVariants = new HashMap<String, String>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue