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:
andreas.schildbach 2010-09-30 10:43:57 +00:00
parent f66cb36bb5
commit abb935cf6d

View file

@ -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,12 +130,15 @@ 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, "itdOdvName");
final String nameState = pp.getAttributeValue(null, "state");
if (nameState.equals("identified"))
{
XmlPullUtil.jumpToStartTag(pp, null, "odvNameElem"); XmlPullUtil.jumpToStartTag(pp, null, "odvNameElem");
final int locationId = Integer.parseInt(pp.getAttributeValue(null, "stopID")); final int locationId = Integer.parseInt(pp.getAttributeValue(null, "stopID"));
@ -159,8 +163,8 @@ public abstract class AbstractEfaProvider implements NetworkProvider
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");
@ -175,6 +179,15 @@ public abstract class AbstractEfaProvider implements NetworkProvider
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)
{ {
throw new RuntimeException(x); throw new RuntimeException(x);