mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42:07 +01:00
Add utility methods
ParserUtils: getShortAttribute XmlStringBuilder: attribute(String, long), optAttribute(String, Long)
This commit is contained in:
parent
84f282befe
commit
27c77fcb1c
2 changed files with 28 additions and 0 deletions
|
@ -224,6 +224,22 @@ public class ParserUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static Short getShortAttribute(XmlPullParser parser, String name) {
|
||||
String valueString = parser.getAttributeValue("", name);
|
||||
if (valueString == null) {
|
||||
return null;
|
||||
}
|
||||
return Short.valueOf(valueString);
|
||||
}
|
||||
|
||||
public static short getShortAttribute(XmlPullParser parser, String name, short defaultValue) {
|
||||
Short s = getShortAttribute(parser, name);
|
||||
if (s == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static Date getDateFromNextText(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
|
||||
String dateString = parser.nextText();
|
||||
return XmppDateTime.parseDate(dateString);
|
||||
|
|
|
@ -274,6 +274,11 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
|
|||
return attribute(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public XmlStringBuilder attribute(String name, long value) {
|
||||
assert name != null;
|
||||
return attribute(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
public XmlStringBuilder optAttribute(String name, String value) {
|
||||
if (value != null) {
|
||||
attribute(name, value);
|
||||
|
@ -281,6 +286,13 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
|
|||
return this;
|
||||
}
|
||||
|
||||
public XmlStringBuilder optAttribute(String name, Long value) {
|
||||
if (value != null) {
|
||||
attribute(name, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new attribute to this builder, with the {@link java.util.Date} instance as its value,
|
||||
* which will get formatted with {@link XmppDateTime#formatXEP0082Date(Date)}
|
||||
|
|
Loading…
Reference in a new issue