1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

Added support for multiple message bodies and language on the message. SMACK-99

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@8113 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Alex Wenckus 2007-04-26 06:22:55 +00:00 committed by alex
parent 985bc79aca
commit 8e08a8ba4a
11 changed files with 926 additions and 42 deletions

View file

@ -42,6 +42,11 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/
public abstract class Packet {
protected static final String DEFAULT_LANGUAGE =
java.util.Locale.getDefault().getLanguage().toLowerCase();
private static String DEFAULT_XML_NS = null;
/**
* Constant used as packetID to indicate that a packet has no id. To indicate that a packet
* has no id set this constant as the packet's id. When the packet is asked for its id the
@ -60,23 +65,29 @@ public abstract class Packet {
*/
private static long id = 0;
private String xmlns = DEFAULT_XML_NS;
/**
* Returns the next unique id. Each id made up of a short alphanumeric
* prefix along with a unique numeric value.
*
* @return the next id.
*/
private static synchronized String nextID() {
public static synchronized String nextID() {
return prefix + Long.toString(id++);
}
public static void setDefaultXmlns(String defaultXmlns) {
DEFAULT_XML_NS = defaultXmlns;
}
private String packetID = null;
private String to = null;
private String from = null;
private final List<PacketExtension> packetExtensions
= new CopyOnWriteArrayList<PacketExtension>();
private Map<String,Object> properties = null;
private final Map<String,Object> properties = null;
private XMPPError error = null;
/**
@ -280,9 +291,6 @@ public abstract class Packet {
if (!(value instanceof Serializable)) {
throw new IllegalArgumentException("Value must be serialiazble");
}
if (properties == null) {
properties = new HashMap<String, Object>();
}
properties.put(name, value);
}
@ -403,4 +411,52 @@ public abstract class Packet {
}
return buf.toString();
}
public String getXmlns() {
return this.xmlns;
}
protected static String parseXMLLang(String language) {
if (language == null || "".equals(language)) {
language = DEFAULT_LANGUAGE;
}
return language;
}
protected static String getDefaultLanguage() {
return DEFAULT_LANGUAGE;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Packet packet = (Packet) o;
if (error != null ? !error.equals(packet.error) : packet.error != null) { return false; }
if (from != null ? !from.equals(packet.from) : packet.from != null) { return false; }
if (!packetExtensions.equals(packet.packetExtensions)) { return false; }
if (packetID != null ? !packetID.equals(packet.packetID) : packet.packetID != null) {
return false;
}
if (properties != null ? !properties.equals(packet.properties)
: packet.properties != null) {
return false;
}
if (to != null ? !to.equals(packet.to) : packet.to != null) { return false; }
return !(xmlns != null ? !xmlns.equals(packet.xmlns) : packet.xmlns != null);
}
public int hashCode() {
int result;
result = (xmlns != null ? xmlns.hashCode() : 0);
result = 31 * result + (packetID != null ? packetID.hashCode() : 0);
result = 31 * result + (to != null ? to.hashCode() : 0);
result = 31 * result + (from != null ? from.hashCode() : 0);
result = 31 * result + packetExtensions.hashCode();
result = 31 * result + properties.hashCode();
result = 31 * result + (error != null ? error.hashCode() : 0);
return result;
}
}