mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-15 00:50:31 +00:00
parse 'invalid station' from XML
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@209 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
f66cb36bb5
commit
abb935cf6d
1 changed files with 43 additions and 30 deletions
|
@ -30,6 +30,7 @@ import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
import org.xmlpull.v1.XmlPullParserFactory;
|
import org.xmlpull.v1.XmlPullParserFactory;
|
||||||
|
|
||||||
|
import de.schildbach.pte.QueryDeparturesResult.Status;
|
||||||
import de.schildbach.pte.util.XmlPullUtil;
|
import de.schildbach.pte.util.XmlPullUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,51 +130,63 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final CharSequence page = ParserUtils.scrape(uri);
|
final CharSequence page = ParserUtils.scrape(uri);
|
||||||
// System.out.println(page);
|
|
||||||
|
|
||||||
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
final XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
|
||||||
final XmlPullParser pp = factory.newPullParser();
|
final XmlPullParser pp = factory.newPullParser();
|
||||||
pp.setInput(new StringReader(page.toString()));
|
pp.setInput(new StringReader(page.toString()));
|
||||||
|
|
||||||
XmlPullUtil.jumpToStartTag(pp, null, "odvNameElem");
|
XmlPullUtil.jumpToStartTag(pp, null, "itdOdvName");
|
||||||
final int locationId = Integer.parseInt(pp.getAttributeValue(null, "stopID"));
|
final String nameState = pp.getAttributeValue(null, "state");
|
||||||
|
if (nameState.equals("identified"))
|
||||||
final String location = pp.nextText();
|
|
||||||
|
|
||||||
final Calendar departureTime = new GregorianCalendar();
|
|
||||||
final List<Departure> departures = new ArrayList<Departure>(8);
|
|
||||||
|
|
||||||
XmlPullUtil.jumpToStartTag(pp, null, "itdDepartureList");
|
|
||||||
while (XmlPullUtil.jumpToStartTag(pp, null, "itdDeparture"))
|
|
||||||
{
|
{
|
||||||
if (Integer.parseInt(pp.getAttributeValue(null, "stopID")) == locationId)
|
XmlPullUtil.jumpToStartTag(pp, null, "odvNameElem");
|
||||||
|
final int locationId = Integer.parseInt(pp.getAttributeValue(null, "stopID"));
|
||||||
|
|
||||||
|
final String location = pp.nextText();
|
||||||
|
|
||||||
|
final Calendar departureTime = new GregorianCalendar();
|
||||||
|
final List<Departure> departures = new ArrayList<Departure>(8);
|
||||||
|
|
||||||
|
XmlPullUtil.jumpToStartTag(pp, null, "itdDepartureList");
|
||||||
|
while (XmlPullUtil.jumpToStartTag(pp, null, "itdDeparture"))
|
||||||
{
|
{
|
||||||
String position = pp.getAttributeValue(null, "platform");
|
if (Integer.parseInt(pp.getAttributeValue(null, "stopID")) == locationId)
|
||||||
if (position != null)
|
{
|
||||||
position = "Gl. " + position;
|
String position = pp.getAttributeValue(null, "platform");
|
||||||
|
if (position != null)
|
||||||
|
position = "Gl. " + position;
|
||||||
|
|
||||||
departureTime.clear();
|
departureTime.clear();
|
||||||
XmlPullUtil.jumpToStartTag(pp, null, "itdDate");
|
XmlPullUtil.jumpToStartTag(pp, null, "itdDate");
|
||||||
processItdDate(pp, departureTime);
|
processItdDate(pp, departureTime);
|
||||||
XmlPullUtil.jumpToStartTag(pp, null, "itdTime");
|
XmlPullUtil.jumpToStartTag(pp, null, "itdTime");
|
||||||
processItdTime(pp, departureTime);
|
processItdTime(pp, departureTime);
|
||||||
XmlPullUtil.jumpToStartTag(pp, null, "itdServingLine");
|
XmlPullUtil.jumpToStartTag(pp, null, "itdServingLine");
|
||||||
|
|
||||||
final String line = parseLine(pp.getAttributeValue(null, "number"), pp.getAttributeValue(null, "symbol"), pp.getAttributeValue(
|
final String line = parseLine(pp.getAttributeValue(null, "number"), pp.getAttributeValue(null, "symbol"), pp
|
||||||
null, "motType"));
|
.getAttributeValue(null, "motType"));
|
||||||
|
|
||||||
final boolean isRealtime = pp.getAttributeValue(null, "realtime").equals("1");
|
final boolean isRealtime = pp.getAttributeValue(null, "realtime").equals("1");
|
||||||
|
|
||||||
final String destination = pp.getAttributeValue(null, "direction");
|
final String destination = pp.getAttributeValue(null, "direction");
|
||||||
|
|
||||||
final int destinationId = Integer.parseInt(pp.getAttributeValue(null, "destID"));
|
final int destinationId = Integer.parseInt(pp.getAttributeValue(null, "destID"));
|
||||||
|
|
||||||
departures.add(new Departure(!isRealtime ? departureTime.getTime() : null, isRealtime ? departureTime.getTime() : null, line,
|
departures.add(new Departure(!isRealtime ? departureTime.getTime() : null, isRealtime ? departureTime.getTime() : null, line,
|
||||||
lineColors(line), null, position, destinationId, destination, null));
|
lineColors(line), null, position, destinationId, destination, null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return new QueryDeparturesResult(uri, locationId, location, departures);
|
return new QueryDeparturesResult(uri, locationId, location, departures);
|
||||||
|
}
|
||||||
|
else if (nameState.equals("notidentified"))
|
||||||
|
{
|
||||||
|
return new QueryDeparturesResult(uri, Status.INVALID_STATION);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new RuntimeException("unknown nameState '" + nameState + "' on " + uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (final XmlPullParserException x)
|
catch (final XmlPullParserException x)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue