extract method for itdRequest parsing

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@583 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach@gmail.com 2011-04-29 15:53:11 +00:00
parent c43dc6014b
commit f320d25a18

View file

@ -131,21 +131,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
final XmlPullParser pp = parserFactory.newPullParser(); final XmlPullParser pp = parserFactory.newPullParser();
pp.setInput(is, null); pp.setInput(is, null);
assertItdRequest(pp); enterItdRequest(pp);
XmlPullUtil.enter(pp, "itdRequest");
if (XmlPullUtil.test(pp, "clientHeaderLines"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "itdVersionInfo"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "itdInfoLinkList"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "serverMetaInfo"))
XmlPullUtil.next(pp);
final List<Location> results = new ArrayList<Location>(); final List<Location> results = new ArrayList<Location>();
@ -218,21 +204,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
final XmlPullParser pp = parserFactory.newPullParser(); final XmlPullParser pp = parserFactory.newPullParser();
pp.setInput(is, null); pp.setInput(is, null);
assertItdRequest(pp); enterItdRequest(pp);
XmlPullUtil.enter(pp, "itdRequest");
if (XmlPullUtil.test(pp, "clientHeaderLines"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "itdVersionInfo"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "itdInfoLinkList"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "serverMetaInfo"))
XmlPullUtil.next(pp);
XmlPullUtil.enter(pp, "itdCoordInfoRequest"); XmlPullUtil.enter(pp, "itdCoordInfoRequest");
@ -300,7 +272,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
final XmlPullParser pp = parserFactory.newPullParser(); final XmlPullParser pp = parserFactory.newPullParser();
pp.setInput(is, null); pp.setInput(is, null);
assertItdRequest(pp); enterItdRequest(pp);
final List<Location> results = new ArrayList<Location>(); final List<Location> results = new ArrayList<Location>();
@ -483,7 +455,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
final XmlPullParser pp = parserFactory.newPullParser(); final XmlPullParser pp = parserFactory.newPullParser();
pp.setInput(is, null); pp.setInput(is, null);
assertItdRequest(pp); enterItdRequest(pp);
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"dm".equals(pp.getAttributeValue(null, "usage"))) if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"dm".equals(pp.getAttributeValue(null, "usage")))
throw new IllegalStateException("cannot find <itdOdv usage=\"dm\" />"); throw new IllegalStateException("cannot find <itdOdv usage=\"dm\" />");
@ -1071,21 +1043,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider
final XmlPullParser pp = parserFactory.newPullParser(); final XmlPullParser pp = parserFactory.newPullParser();
pp.setInput(is, null); pp.setInput(is, null);
assertItdRequest(pp); enterItdRequest(pp);
XmlPullUtil.enter(pp, "itdRequest");
if (XmlPullUtil.test(pp, "clientHeaderLines"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "itdVersionInfo"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "itdInfoLinkList"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "serverMetaInfo"))
XmlPullUtil.next(pp);
XmlPullUtil.enter(pp, "itdDepartureMonitorRequest"); XmlPullUtil.enter(pp, "itdDepartureMonitorRequest");
@ -1367,12 +1325,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider
{ {
final XmlPullParser pp = parserFactory.newPullParser(); final XmlPullParser pp = parserFactory.newPullParser();
pp.setInput(is, null); pp.setInput(is, null);
assertItdRequest(pp); final String sessionId = enterItdRequest(pp);
final String sessionId = XmlPullUtil.attr(pp, "sessionID"); XmlPullUtil.require(pp, "itdTripRequest");
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdTripRequest"))
throw new IllegalStateException("cannot find <itdTripRequest />");
final String requestId = XmlPullUtil.attr(pp, "requestID"); final String requestId = XmlPullUtil.attr(pp, "requestID");
XmlPullUtil.enter(pp, "itdTripRequest"); XmlPullUtil.enter(pp, "itdTripRequest");
@ -2034,9 +1989,29 @@ public abstract class AbstractEfaProvider implements NetworkProvider
return LINES.get(line.charAt(0)); return LINES.get(line.charAt(0));
} }
private void assertItdRequest(final XmlPullParser pp) throws XmlPullParserException, IOException private String enterItdRequest(final XmlPullParser pp) throws XmlPullParserException, IOException
{ {
if (!XmlPullUtil.jumpToStartTag(pp, null, "itdRequest")) if (pp.getEventType() == XmlPullParser.START_DOCUMENT)
throw new IOException("cannot find <itdRequest />"); pp.next();
XmlPullUtil.require(pp, "itdRequest");
final String sessionId = XmlPullUtil.attr(pp, "sessionID");
XmlPullUtil.enter(pp, "itdRequest");
if (XmlPullUtil.test(pp, "clientHeaderLines"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "itdVersionInfo"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "itdInfoLinkList"))
XmlPullUtil.next(pp);
if (XmlPullUtil.test(pp, "serverMetaInfo"))
XmlPullUtil.next(pp);
return sessionId;
} }
} }