1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-12 05:51:08 +01:00

Rework XML Element hierarchy and XmlStringBuilder

- Reduce the amount of types that are subtypes of NamedElement. See
javadoc of NamedElement for rationale.
- Work more with XmlEnvironment in XmlStringBuilder.
- Some minor changes to XmlStringBuilder API.
This commit is contained in:
Florian Schmaus 2019-09-07 18:17:08 +02:00
parent e9bcdf3e6d
commit 65576cf3c2
74 changed files with 653 additions and 523 deletions

View file

@ -17,8 +17,10 @@
package org.jivesoftware.smackx.mood.element;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.FullyQualifiedElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.XmlStringBuilder;
@ -107,8 +109,8 @@ public class MoodElement implements ExtensionElement {
}
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
XmlStringBuilder xml = new XmlStringBuilder(this);
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
if (mood == null && text == null) {
// Empty mood element used as STOP signal
@ -152,7 +154,7 @@ public class MoodElement implements ExtensionElement {
* {@link NamedElement} which represents the mood.
* This element has the element name of the mood selected from {@link Mood}.
*/
public static class MoodSubjectElement implements NamedElement {
public static class MoodSubjectElement implements FullyQualifiedElement {
private final Mood mood;
private final MoodConcretisation concretisation;
@ -168,16 +170,17 @@ public class MoodElement implements ExtensionElement {
}
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
XmlStringBuilder xml = new XmlStringBuilder();
public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
XmlStringBuilder xml = new XmlStringBuilder(this, xmlEnvironment);
if (concretisation == null) {
return xml.emptyElement(getElementName());
return xml.closeEmptyElement();
}
return xml.openElement(getElementName())
.append(concretisation.toXML())
.closeElement(getElementName());
xml.rightAngleBracket()
.append(concretisation)
.closeElement(this);
return xml;
}
/**
@ -197,5 +200,10 @@ public class MoodElement implements ExtensionElement {
public MoodConcretisation getConcretisation() {
return concretisation;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
}
}