rudimentary connnections using API for Belgium and Switzerland

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@302 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-10-17 14:17:11 +00:00
parent b990d82f8e
commit b9f572b658
10 changed files with 515 additions and 69 deletions

View file

@ -32,7 +32,8 @@ public final class XmlPullUtil
/**
* enters current tag
* @throws IOException
*
* @throws IOException
*/
public static void enter(final XmlPullParser pp) throws XmlPullParserException, IOException
{
@ -40,22 +41,34 @@ public final class XmlPullUtil
throw new IllegalStateException("expecting start tag to enter");
if (pp.isEmptyElementTag())
throw new IllegalStateException("cannot enter empty tag");
pp.next();
}
public static void exit(final XmlPullParser pp) throws XmlPullParserException, IOException
{
while (pp.getEventType() != XmlPullParser.END_TAG)
{
if (pp.getEventType() == XmlPullParser.START_TAG)
next(pp);
else if (pp.getEventType() == XmlPullParser.TEXT)
pp.next();
else
throw new IllegalStateException();
}
if (pp.getEventType() != XmlPullParser.END_TAG)
throw new IllegalStateException("expecting end tag to exit");
pp.next();
}
public static boolean test(final XmlPullParser pp, final String tagName) throws XmlPullParserException
{
return pp.getEventType() == XmlPullParser.START_TAG && pp.getName().equals(tagName);
}
public static void skipTree(final XmlPullParser pp) throws XmlPullParserException, IOException
public static void next(final XmlPullParser pp) throws XmlPullParserException, IOException
{
skipSubTree(pp);
pp.next();
@ -82,6 +95,22 @@ public final class XmlPullUtil
throw new IllegalStateException("cannot find " + attrName + "=\"" + requiredValue + "\" />");
}
public static String text(final XmlPullParser pp) throws XmlPullParserException, IOException
{
if (pp.getEventType() != XmlPullParser.START_TAG || pp.isEmptyElementTag())
throw new IllegalStateException("expecting start tag to get text from");
enter(pp);
String text = "";
if (pp.getEventType() == XmlPullParser.TEXT)
text = pp.getText();
exit(pp);
return text;
}
/**
* Return value of attribute with given name and no namespace.
*/