diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java index f8fcb0693..cc7b8432b 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Message.java @@ -51,7 +51,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder; * * @author Matt Tucker */ -public class Message extends XmlLangStanza { +public class Message extends Packet { public static final String ELEMENT = "message"; public static final String BODY = "body"; @@ -396,7 +396,6 @@ public class Message extends XmlLangStanza { public XmlStringBuilder toXML() { XmlStringBuilder buf = new XmlStringBuilder(); buf.halfOpenElement(ELEMENT); - buf.xmllangAttribute(language); addCommonAttributes(buf); if (type != Type.normal) { buf.attribute("type", type); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Packet.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Packet.java index e3dd49830..4311dcf32 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Packet.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Packet.java @@ -61,6 +61,18 @@ public abstract class Packet extends TopLevelStreamElement { private XMPPError error = null; + /** + * Optional value of the 'xml:lang' attribute of the outermost element of + * the stanza. + *

+ * Such an attribute is defined for all stanza types. For IQ, see for + * example XEP-50 3.7: + * "The requester SHOULD provide its locale information using the "xml:lang + * " attribute on either the (RECOMMENDED) or element." + *

+ */ + protected String language; + public Packet() { this(prefix + Long.toString(id.incrementAndGet())); } @@ -165,6 +177,24 @@ public abstract class Packet extends TopLevelStreamElement { this.error = error; } + /** + * Returns the xml:lang of this Stanza, or null if one has not been set. + * + * @return the xml:lang of this Stanza, or null. + */ + public String getLanguage() { + return language; + } + + /** + * Sets the xml:lang of this Stanza. + * + * @param language the xml:lang of this Stanza. + */ + public void setLanguage(String language) { + this.language = language; + } + /** * Returns an unmodifiable collection of the packet extensions attached to the packet. * @@ -305,7 +335,7 @@ public abstract class Packet extends TopLevelStreamElement { } /** - * Add to, from and id attributes + * Add to, from, id and 'xml:lang' attributes * * @param xml */ @@ -313,5 +343,6 @@ public abstract class Packet extends TopLevelStreamElement { xml.optAttribute("id", getPacketID()); xml.optAttribute("to", getTo()); xml.optAttribute("from", getFrom()); + xml.xmllangAttribute(getLanguage()); } } diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java index 198d8e44d..9c12d2061 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/Presence.java @@ -55,7 +55,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder; * @see RosterPacket * @author Matt Tucker */ -public class Presence extends XmlLangStanza { +public class Presence extends Packet { public static final String ELEMENT = "presence"; @@ -207,7 +207,6 @@ public class Presence extends XmlLangStanza { public XmlStringBuilder toXML() { XmlStringBuilder buf = new XmlStringBuilder(); buf.halfOpenElement(ELEMENT); - buf.xmllangAttribute(language); addCommonAttributes(buf); if (type != Type.available) { buf.attribute("type", type); diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/XmlLangStanza.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/XmlLangStanza.java deleted file mode 100644 index 59be3b9cb..000000000 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/XmlLangStanza.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * Copyright © 2014 Florian Schmaus - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jivesoftware.smack.packet; - - -/** - * Abstract class for stanzas that can contain a 'xml:lang' definition in their - * top level element, ie. Message and Presence stanzas. - */ -public abstract class XmlLangStanza extends Packet { - protected String language; - - /** - * Returns the xml:lang of this Stanza, or null if one has not been set. - * - * @return the xml:lang of this Stanza, or null. - */ - public String getLanguage() { - return language; - } - - /** - * Sets the xml:lang of this Stanza. - * - * @param language the xml:lang of this Stanza. - */ - public void setLanguage(String language) { - this.language = language; - } - -}