mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 10:37:59 +01:00
Make Body and Subject implement ExtensionElement
This commit is contained in:
parent
f51ea33036
commit
52a52e12d2
1 changed files with 48 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue