From f320d25a18675657d2fc4216d77a15003f235fa1 Mon Sep 17 00:00:00 2001 From: "andreas.schildbach@gmail.com" Date: Fri, 29 Apr 2011 15:53:11 +0000 Subject: [PATCH] extract method for itdRequest parsing git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@583 0924bc21-9374-b0fa-ee44-9ff1593b38f0 --- .../schildbach/pte/AbstractEfaProvider.java | 85 +++++++------------ 1 file changed, 30 insertions(+), 55 deletions(-) diff --git a/src/de/schildbach/pte/AbstractEfaProvider.java b/src/de/schildbach/pte/AbstractEfaProvider.java index d3222c2b..ecb1cb40 100644 --- a/src/de/schildbach/pte/AbstractEfaProvider.java +++ b/src/de/schildbach/pte/AbstractEfaProvider.java @@ -131,21 +131,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(is, null); - assertItdRequest(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); + enterItdRequest(pp); final List results = new ArrayList(); @@ -218,21 +204,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(is, null); - assertItdRequest(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); + enterItdRequest(pp); XmlPullUtil.enter(pp, "itdCoordInfoRequest"); @@ -300,7 +272,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(is, null); - assertItdRequest(pp); + enterItdRequest(pp); final List results = new ArrayList(); @@ -483,7 +455,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(is, null); - assertItdRequest(pp); + enterItdRequest(pp); if (!XmlPullUtil.jumpToStartTag(pp, null, "itdOdv") || !"dm".equals(pp.getAttributeValue(null, "usage"))) throw new IllegalStateException("cannot find "); @@ -1071,21 +1043,7 @@ public abstract class AbstractEfaProvider implements NetworkProvider final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(is, null); - assertItdRequest(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); + enterItdRequest(pp); XmlPullUtil.enter(pp, "itdDepartureMonitorRequest"); @@ -1367,12 +1325,9 @@ public abstract class AbstractEfaProvider implements NetworkProvider { final XmlPullParser pp = parserFactory.newPullParser(); pp.setInput(is, null); - assertItdRequest(pp); + final String sessionId = enterItdRequest(pp); - final String sessionId = XmlPullUtil.attr(pp, "sessionID"); - - if (!XmlPullUtil.jumpToStartTag(pp, null, "itdTripRequest")) - throw new IllegalStateException("cannot find "); + XmlPullUtil.require(pp, "itdTripRequest"); final String requestId = XmlPullUtil.attr(pp, "requestID"); XmlPullUtil.enter(pp, "itdTripRequest"); @@ -2034,9 +1989,29 @@ public abstract class AbstractEfaProvider implements NetworkProvider 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")) - throw new IOException("cannot find "); + if (pp.getEventType() == XmlPullParser.START_DOCUMENT) + 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; } }