1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

Improve MUC code

Removes a ton of duplicate code, mostly related to MUCItem being
duplicated in MUCOwner and MUCAdmin, but also some other duplicate code.

Make MUC code use XmlStringBuilder.

Add ELEMENT and NAMESPACE constants to the appropriate places. Also add
"static <MUCPacketExtension> getFrom(Packet)" methods.

Make some MUC classes implement Element.
This commit is contained in:
Florian Schmaus 2014-07-14 19:22:02 +02:00
parent 7735a5224c
commit e6aa2416e4
16 changed files with 578 additions and 948 deletions

View file

@ -66,6 +66,13 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return this;
}
public XmlStringBuilder optElement(Element element) {
if (element != null) {
append(element.toXML());
}
return this;
}
public XmlStringBuilder optElement(String name, Enum<?> content) {
if (content != null) {
element(name, content);
@ -139,6 +146,20 @@ public class XmlStringBuilder implements Appendable, CharSequence {
return this;
}
/**
* Add the given attribute if value => 0
*
* @param name
* @param value
* @return a reference to this object
*/
public XmlStringBuilder optIntAttribute(String name, int value) {
if (value >= 0) {
attribute(name, Integer.toString(value));
}
return this;
}
public XmlStringBuilder xmlnsAttribute(String value) {
optAttribute("xmlns", value);
return this;