From 505493d8895df421f2205fdf7d72006a592f7d17 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 7 May 2019 10:18:55 +0200 Subject: [PATCH] Add XmlStringBuilder.optAttribute(String, Number) --- .../org/jivesoftware/smack/util/XmlStringBuilder.java | 7 +++++++ .../smackx/jingle_filetransfer/element/Range.java | 9 ++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java b/smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java index 92b1f6a33..e710f52e2 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java @@ -327,6 +327,13 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element { return this; } + public XmlStringBuilder optAttribute(String name, Number number) { + if (number != null) { + attribute(name, number.toString()); + } + return this; + } + /** * Add the given attribute if {@code value => 0}. * diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/element/Range.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/element/Range.java index 71a418818..312aca703 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/element/Range.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/element/Range.java @@ -103,13 +103,8 @@ public class Range implements NamedElement { public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { XmlStringBuilder sb = new XmlStringBuilder(this); - // TODO: (Introduce and) use XmlStringBuilder.optXmlAttribute(name, Number). - if (offset != null) { - sb.attribute(ATTR_OFFSET, offset); - } - if (length != null) { - sb.attribute(ATTR_LENGTH, length); - } + sb.optAttribute(ATTR_OFFSET, offset); + sb.optAttribute(ATTR_LENGTH, length); if (hash != null) { sb.rightAngleBracket();