1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

Phase 1 of large refactoring. Removing dead code, bug fixes, updates to JDK 1.5.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4511 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2006-07-17 08:39:08 +00:00 committed by matt
parent 1a08715f67
commit bbbfe09c31
62 changed files with 291 additions and 3524 deletions

View file

@ -26,16 +26,16 @@ import org.jivesoftware.smack.util.StringUtils;
* Represents XMPP presence packets. Every presence packet has a type, which is one of
* the following values:
* <ul>
* <li><tt>Presence.Type.AVAILABLE</tt> -- (Default) indicates the user is available to
* <li>{@link Presence.Type#available available} -- (Default) indicates the user is available to
* receive messages.
* <li><tt>Presence.Type.UNAVAILABLE</tt> -- the user is unavailable to receive messages.
* <li><tt>Presence.Type.SUBSCRIBE</tt> -- request subscription to recipient's presence.
* <li><tt>Presence.Type.SUBSCRIBED</tt> -- grant subscription to sender's presence.
* <li><tt>Presence.Type.UNSUBSCRIBE</tt> -- request removal of subscription to sender's
* presence.
* <li><tt>Presence.Type.UNSUBSCRIBED</tt> -- grant removal of subscription to sender's
* presence.
* <li><tt>Presence.Type.ERROR</tt> -- the presence packet contains an error message.
* <li>{@link Presence.Type#unavailable unavailable} -- the user is unavailable to receive messages.
* <li>{@link Presence.Type#subscribe subscribe} -- request subscription to recipient's presence.
* <li>{@link Presence.Type#subscribed subscribed} -- grant subscription to sender's presence.
* <li>{@link Presence.Type#unsubscribe unsubscribe} -- request removal of subscription to
* sender's presence.
* <li>{@link Presence.Type#unsubscribed unsubscribed} -- grant removal of subscription to
* sender's presence.
* <li>{@link Presence.Type#error error} -- the presence packet contains an error message.
* </ul><p>
*
* A number of attributes are optional:
@ -44,8 +44,9 @@ import org.jivesoftware.smack.util.StringUtils;
* <li>Priority -- non-negative numerical priority of a sender's resource. The
* highest resource priority is the default recipient of packets not addressed
* to a particular resource.
* <li>Mode -- one of five presence modes: available (the default), chat, away,
* xa (extended away, and dnd (do not disturb).
* <li>Mode -- one of five presence modes: {@link Mode#available available} (the default),
* {@link Mode#chat chat}, {@link Mode#away away}, {@link Mode#xa xa} (extended away), and
* {@link Mode#dnd dnd} (do not disturb).
* </ul><p>
*
* Presence packets are used for two purposes. First, to notify the server of our
@ -57,10 +58,10 @@ import org.jivesoftware.smack.util.StringUtils;
*/
public class Presence extends Packet {
private Type type = Type.AVAILABLE;
private Type type = Type.available;
private String status = null;
private int priority = -1;
private Mode mode = Mode.AVAILABLE;
private Mode mode = Mode.available;
/**
* Creates a new presence update. Status, priority, and mode are left un-set.
@ -179,7 +180,7 @@ public class Presence extends Packet {
if (getFrom() != null) {
buf.append(" from=\"").append(StringUtils.escapeForXML(getFrom())).append("\"");
}
if (type != Type.AVAILABLE) {
if (type != Type.available) {
buf.append(" type=\"").append(type).append("\"");
}
buf.append(">");
@ -189,7 +190,7 @@ public class Presence extends Packet {
if (priority != -1) {
buf.append("<priority>").append(priority).append("</priority>");
}
if (mode != null && mode != Mode.AVAILABLE) {
if (mode != null && mode != Mode.available) {
buf.append("<show>").append(mode).append("</show>");
}
@ -219,105 +220,78 @@ public class Presence extends Packet {
}
/**
* A typsafe enum class to represent the presecence type.
* A enum to represent the presecence type. Not that presence type is often confused
* with presence mode. Generally, if a user is signed into a server, they have a presence
* type of {@link #available available}, even if the mode is {@link Mode#away away},
* {@link Mode#dnd dnd}, etc. The presence type is only {@link #unavailable unavailable} when
* the user is signing out of the server.
*/
public static class Type {
public enum Type {
public static final Type AVAILABLE = new Type("available");
public static final Type UNAVAILABLE = new Type("unavailable");
public static final Type SUBSCRIBE = new Type("subscribe");
public static final Type SUBSCRIBED = new Type("subscribed");
public static final Type UNSUBSCRIBE = new Type("unsubscribe");
public static final Type UNSUBSCRIBED = new Type("unsubscribed");
public static final Type ERROR = new Type("error");
private String value;
private Type(String value) {
this.value = value;
}
public String toString() {
return value;
}
/**
* The user is available to receive messages (default).
*/
available,
/**
* Returns the type constant associated with the String value.
* The user is unavailable to receive messages.
*/
public static Type fromString(String value) {
if (value == null) {
return AVAILABLE;
}
value = value.toLowerCase();
if ("unavailable".equals(value)) {
return UNAVAILABLE;
}
else if ("subscribe".equals(value)) {
return SUBSCRIBE;
}
else if ("subscribed".equals(value)) {
return SUBSCRIBED;
}
else if ("unsubscribe".equals(value)) {
return UNSUBSCRIBE;
}
else if ("unsubscribed".equals(value)) {
return UNSUBSCRIBED;
}
else if ("error".equals(value)) {
return ERROR;
}
// Default to available.
else {
return AVAILABLE;
}
}
unavailable,
/**
* Request subscription to recipient's presence.
*/
subscribe,
/**
* Grant subscription to sender's presence.
*/
subscribed,
/**
* Request removal of subscription to sender's presence.
*/
unsubscribe,
/**
* Grant removal of subscription to sender's presence.
*/
unsubscribed,
/**
* The presence packet contains an error message.
*/
error
}
/**
* A typsafe enum class to represent the presence mode.
* An enum to represent the presence mode.
*/
public static class Mode {
public static final Mode AVAILABLE = new Mode("available");
public static final Mode CHAT = new Mode("chat");
public static final Mode AWAY = new Mode("away");
public static final Mode EXTENDED_AWAY = new Mode("xa");
public static final Mode DO_NOT_DISTURB = new Mode("dnd");
private String value;
private Mode(String value) {
this.value = value;
}
public String toString() {
return value;
}
public enum Mode {
/**
* Returns the mode constant associated with the String value.
* Available (the default).
*/
public static Mode fromString(String value) {
if (value == null) {
return AVAILABLE;
}
value = value.toLowerCase();
if (value.equals("chat")) {
return CHAT;
}
else if (value.equals("away")) {
return AWAY;
}
else if (value.equals("xa")) {
return EXTENDED_AWAY;
}
else if (value.equals("dnd")) {
return DO_NOT_DISTURB;
}
else {
return AVAILABLE;
}
}
available,
/**
* Free to chat.
*/
chat,
/**
* Away.
*/
away,
/**
* Away for an extended period of time.
*/
xa,
/**
* Do not disturb.
*/
dnd
}
}
}

View file

@ -23,6 +23,7 @@ package org.jivesoftware.smack.packet;
import org.jivesoftware.smack.util.StringUtils;
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* Represents XMPP roster packets.
@ -31,7 +32,7 @@ import java.util.*;
*/
public class RosterPacket extends IQ {
private final List rosterItems = new ArrayList();
private final List<Item> rosterItems = new ArrayList<Item>();
/**
* Adds a roster item to the packet.
@ -56,14 +57,13 @@ public class RosterPacket extends IQ {
}
/**
* Returns an Iterator for the roster items in the packet.
* Returns an unmodifiable collection for the roster items in the packet.
*
* @return and Iterator for the roster items in the packet.
* @return an unmodifiable collection for the roster items in the packet.
*/
public Iterator getRosterItems() {
public Collection<Item> getRosterItems() {
synchronized (rosterItems) {
List entries = Collections.unmodifiableList(new ArrayList(rosterItems));
return entries.iterator();
return Collections.unmodifiableList(new ArrayList<Item>(rosterItems));
}
}
@ -71,8 +71,7 @@ public class RosterPacket extends IQ {
StringBuffer buf = new StringBuffer();
buf.append("<query xmlns=\"jabber:iq:roster\">");
synchronized (rosterItems) {
for (int i=0; i<rosterItems.size(); i++) {
Item entry = (Item)rosterItems.get(i);
for (Item entry : rosterItems) {
buf.append(entry.toXML());
}
}
@ -90,7 +89,7 @@ public class RosterPacket extends IQ {
private String name;
private ItemType itemType;
private ItemStatus itemStatus;
private final List groupNames;
private final Set<String> groupNames;
/**
* Creates a new roster item.
@ -103,7 +102,7 @@ public class RosterPacket extends IQ {
this.name = name;
itemType = null;
itemStatus = null;
groupNames = new ArrayList();
groupNames = new CopyOnWriteArraySet<String>();
}
/**
@ -170,15 +169,13 @@ public class RosterPacket extends IQ {
}
/**
* Returns an Iterator for the group names (as Strings) that the roster item
* Returns an unmodifiable set of the group names that the roster item
* belongs to.
*
* @return an Iterator for the group names.
* @return an unmodifiable set of the group names.
*/
public Iterator getGroupNames() {
synchronized (groupNames) {
return Collections.unmodifiableList(groupNames).iterator();
}
public Set<String> getGroupNames() {
return Collections.unmodifiableSet(groupNames);
}
/**
@ -187,11 +184,7 @@ public class RosterPacket extends IQ {
* @param groupName the group name.
*/
public void addGroupName(String groupName) {
synchronized (groupNames) {
if (!groupNames.contains(groupName)) {
groupNames.add(groupName);
}
}
groupNames.add(groupName);
}
/**
@ -200,9 +193,7 @@ public class RosterPacket extends IQ {
* @param groupName the group name.
*/
public void removeGroupName(String groupName) {
synchronized (groupNames) {
groupNames.remove(groupName);
}
groupNames.remove(groupName);
}
public String toXML() {
@ -218,11 +209,8 @@ public class RosterPacket extends IQ {
buf.append(" ask=\"").append(itemStatus).append("\"");
}
buf.append(">");
synchronized (groupNames) {
for (int i=0; i<groupNames.size(); i++) {
String groupName = (String)groupNames.get(i);
buf.append("<group>").append(StringUtils.escapeForXML(groupName)).append("</group>");
}
for (String groupName : groupNames) {
buf.append("<group>").append(StringUtils.escapeForXML(groupName)).append("</group>");
}
buf.append("</item>");
return buf.toString();