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

Make Body and Subject implement ExtensionElement

This commit is contained in:
Florian Schmaus 2017-03-03 21:10:58 +01:00
parent f51ea33036
commit 52a52e12d2

View file

@ -490,9 +490,7 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
// Skip the default language
if(subject.equals(defaultSubject))
continue;
buf.halfOpenElement("subject").xmllangAttribute(subject.language).rightAngleBracket();
buf.escape(subject.subject);
buf.closeElement("subject");
buf.append(subject.toXML());
}
// Add the body in the default language
Body defaultBody = getMessageBody(null);
@ -504,9 +502,7 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
// Skip the default language
if(body.equals(defaultBody))
continue;
buf.halfOpenElement(BODY).xmllangAttribute(body.getLanguage()).rightAngleBracket();
buf.escape(body.getMessage());
buf.closeElement(BODY);
buf.append(body.toXML());
}
buf.optElement("thread", thread);
// Append the error subpacket if the message type is an error.
@ -535,7 +531,10 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
/**
* Represents a message subject, its language and the content of the subject.
*/
public static final class Subject {
public static final class Subject implements ExtensionElement {
public static final String ELEMENT = "subject";
public static final String NAMESPACE = StreamOpen.CLIENT_NAMESPACE;
private final String subject;
private final String language;
@ -595,12 +594,34 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
return this.language.equals(other.language) && this.subject.equals(other.subject);
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(getElementName()).xmllangAttribute(getLanguage()).rightAngleBracket();
xml.escape(subject);
xml.closeElement(getElementName());
return xml;
}
}
/**
* Represents a message body, its language and the content of the message.
*/
public static final class Body {
public static final class Body implements ExtensionElement {
public static final String ELEMENT = "body";
public static final String NAMESPACE = StreamOpen.CLIENT_NAMESPACE;
private final String message;
private final String language;
@ -659,6 +680,25 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
return this.language.equals(other.language) && this.message.equals(other.message);
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(getElementName()).xmllangAttribute(getLanguage()).rightAngleBracket();
xml.escape(message);
xml.closeElement(getElementName());
return xml;
}
}
/**