1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Add XmlStringBuilder API for Date

Fixes XEP-0080 GeoLoc timestamp element formating
This commit is contained in:
Vyacheslav Blinov 2015-03-30 19:24:56 +03:00 committed by Florian Schmaus
parent 64d134052d
commit 5272680d47

View file

@ -17,10 +17,12 @@
package org.jivesoftware.smack.util;
import java.util.Collection;
import java.util.Date;
import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jxmpp.util.XmppDateTime;
public class XmlStringBuilder implements Appendable, CharSequence {
public static final String RIGHT_ANGLE_BRACKET = Character.toString('>');
@ -64,6 +66,19 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return this;
}
/**
* Add a new element to this builder, with the {@link java.util.Date} instance as its content,
* which will get formated with {@link XmppDateTime#formatXEP0082Date(Date)}.
*
* @param name element name
* @param content content of element
* @return this XmlStringBuilder
*/
public XmlStringBuilder element(String name, Date content) {
assert content != null;
return element(name, XmppDateTime.formatXEP0082Date(content));
}
/**
* Add a new element to this builder.
*
@ -93,6 +108,22 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return this;
}
/**
* Add a new element to this builder, with the {@link java.util.Date} instance as its content,
* which will get formated with {@link XmppDateTime#formatXEP0082Date(Date)}
* if {@link java.util.Date} instance is not <code>null</code>.
*
* @param name element name
* @param content content of element
* @return this XmlStringBuilder
*/
public XmlStringBuilder optElement(String name, Date content) {
if (content != null) {
element(name, content);
}
return this;
}
public XmlStringBuilder optElement(String name, CharSequence content) {
if (content != null) {
element(name, content.toString());
@ -171,6 +202,7 @@ public class XmlStringBuilder implements Appendable, CharSequence {
/**
* Add a right angle bracket '>'.
*
* @return a reference to this object
* @deprecated use {@link #rightAngleBracket()} instead
*/
@ -194,6 +226,19 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return this;
}
/**
* Add a new attribute to this builder, with the {@link java.util.Date} instance as its value,
* which will get formated with {@link XmppDateTime#formatXEP0082Date(Date)}.
*
* @param name name of attribute
* @param value value of attribute
* @return this XmlStringBuilder
*/
public XmlStringBuilder attribute(String name, Date value) {
assert value != null;
return attribute(name, XmppDateTime.formatXEP0082Date(value));
}
public XmlStringBuilder attribute(String name, CharSequence value) {
return attribute(name, value.toString());
}
@ -216,6 +261,22 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return this;
}
/**
* Add a new attribute to this builder, with the {@link java.util.Date} instance as its value,
* which will get formated with {@link XmppDateTime#formatXEP0082Date(Date)}
* if {@link java.util.Date} instance is not <code>null</code>.
*
* @param name attribute name
* @param value value of this attribute
* @return this XmlStringBuilder
*/
public XmlStringBuilder optAttribute(String name, Date value) {
if (value != null) {
attribute(name, value);
}
return this;
}
public XmlStringBuilder optAttribute(String name, CharSequence value) {
if (value != null) {
attribute(name, value.toString());