mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Add XmlLangStanza, to share the language field
between Message and Presence.
This commit is contained in:
parent
67011fc322
commit
90c0064394
3 changed files with 49 additions and 46 deletions
|
@ -51,13 +51,12 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
*
|
*
|
||||||
* @author Matt Tucker
|
* @author Matt Tucker
|
||||||
*/
|
*/
|
||||||
public class Message extends Packet {
|
public class Message extends XmlLangStanza {
|
||||||
|
|
||||||
public static final String BODY = "body";
|
public static final String BODY = "body";
|
||||||
|
|
||||||
private Type type = Type.normal;
|
private Type type = Type.normal;
|
||||||
private String thread = null;
|
private String thread = null;
|
||||||
private String language;
|
|
||||||
|
|
||||||
private final Set<Subject> subjects = new HashSet<Subject>();
|
private final Set<Subject> subjects = new HashSet<Subject>();
|
||||||
private final Set<Body> bodies = new HashSet<Body>();
|
private final Set<Body> bodies = new HashSet<Body>();
|
||||||
|
@ -374,26 +373,6 @@ public class Message extends Packet {
|
||||||
this.thread = thread;
|
this.thread = thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the xml:lang of this Message.
|
|
||||||
*
|
|
||||||
* @return the xml:lang of this Message.
|
|
||||||
* @since 3.0.2
|
|
||||||
*/
|
|
||||||
public String getLanguage() {
|
|
||||||
return language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the xml:lang of this Message.
|
|
||||||
*
|
|
||||||
* @param language the xml:lang of this Message.
|
|
||||||
* @since 3.0.2
|
|
||||||
*/
|
|
||||||
public void setLanguage(String language) {
|
|
||||||
this.language = language;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String determineLanguage(String language) {
|
private String determineLanguage(String language) {
|
||||||
|
|
||||||
// empty string is passed by #setSubject() and #setBody() and is the same as null
|
// empty string is passed by #setSubject() and #setBody() and is the same as null
|
||||||
|
@ -416,7 +395,7 @@ public class Message extends Packet {
|
||||||
public XmlStringBuilder toXML() {
|
public XmlStringBuilder toXML() {
|
||||||
XmlStringBuilder buf = new XmlStringBuilder();
|
XmlStringBuilder buf = new XmlStringBuilder();
|
||||||
buf.halfOpenElement("message");
|
buf.halfOpenElement("message");
|
||||||
buf.xmllangAttribute(getLanguage());
|
buf.xmllangAttribute(language);
|
||||||
addCommonAttributes(buf);
|
addCommonAttributes(buf);
|
||||||
if (type != Type.normal) {
|
if (type != Type.normal) {
|
||||||
buf.attribute("type", type);
|
buf.attribute("type", type);
|
||||||
|
|
|
@ -55,7 +55,7 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||||
* @see RosterPacket
|
* @see RosterPacket
|
||||||
* @author Matt Tucker
|
* @author Matt Tucker
|
||||||
*/
|
*/
|
||||||
public class Presence extends Packet {
|
public class Presence extends XmlLangStanza {
|
||||||
|
|
||||||
public static final String ELEMENT = "presence";
|
public static final String ELEMENT = "presence";
|
||||||
|
|
||||||
|
@ -63,7 +63,6 @@ public class Presence extends Packet {
|
||||||
private String status = null;
|
private String status = null;
|
||||||
private int priority = Integer.MIN_VALUE;
|
private int priority = Integer.MIN_VALUE;
|
||||||
private Mode mode = null;
|
private Mode mode = null;
|
||||||
private String language;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new presence update. Status, priority, and mode are left un-set.
|
* Creates a new presence update. Status, priority, and mode are left un-set.
|
||||||
|
@ -204,31 +203,11 @@ public class Presence extends Packet {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the xml:lang of this Presence, or null if one has not been set.
|
|
||||||
*
|
|
||||||
* @return the xml:lang of this Presence, or null if one has not been set.
|
|
||||||
* @since 3.0.2
|
|
||||||
*/
|
|
||||||
public String getLanguage() {
|
|
||||||
return language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the xml:lang of this Presence.
|
|
||||||
*
|
|
||||||
* @param language the xml:lang of this Presence.
|
|
||||||
* @since 3.0.2
|
|
||||||
*/
|
|
||||||
public void setLanguage(String language) {
|
|
||||||
this.language = language;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlStringBuilder toXML() {
|
public XmlStringBuilder toXML() {
|
||||||
XmlStringBuilder buf = new XmlStringBuilder();
|
XmlStringBuilder buf = new XmlStringBuilder();
|
||||||
buf.halfOpenElement(ELEMENT);
|
buf.halfOpenElement(ELEMENT);
|
||||||
buf.xmllangAttribute(getLanguage());
|
buf.xmllangAttribute(language);
|
||||||
addCommonAttributes(buf);
|
addCommonAttributes(buf);
|
||||||
if (type != Type.available) {
|
if (type != Type.available) {
|
||||||
buf.attribute("type", type);
|
buf.attribute("type", type);
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue