mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-18 16:29:51 +00:00
Consolidate XmlPullUtil API for pure value tags.
This commit is contained in:
parent
7f9755d896
commit
0dc08c103a
3 changed files with 114 additions and 183 deletions
|
@ -174,20 +174,34 @@ public final class XmlPullUtil
|
|||
throw new IllegalStateException("cannot find " + attrName + "=\"" + requiredValue + "\" />");
|
||||
}
|
||||
|
||||
public static String text(final XmlPullParser pp) throws XmlPullParserException, IOException
|
||||
public static String valueTag(final XmlPullParser pp, final String tagName) throws XmlPullParserException, IOException
|
||||
{
|
||||
if (pp.getEventType() != XmlPullParser.START_TAG || pp.isEmptyElementTag())
|
||||
throw new IllegalStateException("expecting start tag to get text from");
|
||||
XmlPullUtil.enter(pp, tagName);
|
||||
final String value = pp.getText();
|
||||
XmlPullUtil.exit(pp, tagName);
|
||||
|
||||
enter(pp);
|
||||
return value != null ? value.trim() : null;
|
||||
}
|
||||
|
||||
String text = "";
|
||||
if (pp.getEventType() == XmlPullParser.TEXT)
|
||||
text = pp.getText();
|
||||
|
||||
exit(pp);
|
||||
|
||||
return text;
|
||||
public static String optValueTag(final XmlPullParser pp, final String tagName, final String defaultValue) throws XmlPullParserException,
|
||||
IOException
|
||||
{
|
||||
if (XmlPullUtil.test(pp, tagName))
|
||||
{
|
||||
if (!pp.isEmptyElementTag())
|
||||
{
|
||||
return valueTag(pp, tagName);
|
||||
}
|
||||
else
|
||||
{
|
||||
pp.next();
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue