Commit 425dbc55 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Handle invalid show element in presence.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@8894 b35dd754-fafc-0310-a699-88a17e54d16e
parent ae5c6768
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
package org.xmpp.packet; package org.xmpp.packet;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.Log;
import java.util.Iterator; import java.util.Iterator;
...@@ -16,7 +17,7 @@ import java.util.Iterator; ...@@ -16,7 +17,7 @@ import java.util.Iterator;
* network availability and to notify other entities of that availability. * network availability and to notify other entities of that availability.
* Presence packets are also used to negotiate and manage subscriptions to the * Presence packets are also used to negotiate and manage subscriptions to the
* presence of other entities.<p> * presence of other entities.<p>
* * <p/>
* A presence optionally has a {@link Type}. * A presence optionally has a {@link Type}.
* *
* @author Matt Tucker * @author Matt Tucker
...@@ -81,9 +82,8 @@ public class Presence extends Packet { ...@@ -81,9 +82,8 @@ public class Presence extends Packet {
/** /**
* Returns true if the presence type is "available". This is a * Returns true if the presence type is "available". This is a
* convenience method that is equivalent to: * convenience method that is equivalent to:
* * <p/>
* <pre>getType() == null</pre> * <pre>getType() == null</pre>
*
*/ */
public boolean isAvailable() { public boolean isAvailable() {
return getType() == null; return getType() == null;
...@@ -114,7 +114,7 @@ public class Presence extends Packet { ...@@ -114,7 +114,7 @@ public class Presence extends Packet {
* @see Type * @see Type
*/ */
public void setType(Type type) { public void setType(Type type) {
element.addAttribute("type", type==null?null:type.toString()); element.addAttribute("type", type == null ? null : type.toString());
} }
/** /**
...@@ -133,8 +133,14 @@ public class Presence extends Packet { ...@@ -133,8 +133,14 @@ public class Presence extends Packet {
return null; return null;
} }
else { else {
try {
return Show.valueOf(show); return Show.valueOf(show);
} }
catch (IllegalArgumentException e) {
Log.error("Unable to retrieve show value for " + show);
return null;
}
}
} }
/** /**
...@@ -243,7 +249,7 @@ public class Presence extends Packet { ...@@ -243,7 +249,7 @@ public class Presence extends Packet {
* given name and namespace. If no matching element is found, * given name and namespace. If no matching element is found,
* <tt>null</tt> will be returned. This is a convenience method to avoid * <tt>null</tt> will be returned. This is a convenience method to avoid
* manipulating this underlying packet's Element instance directly.<p> * manipulating this underlying packet's Element instance directly.<p>
* * <p/>
* Child elements in extended namespaces are used to extend the features * Child elements in extended namespaces are used to extend the features
* of XMPP. Examples include a "user is typing" indicator and invitations to * of XMPP. Examples include a "user is typing" indicator and invitations to
* group chat rooms. Although any valid XML can be included in a child element * group chat rooms. Although any valid XML can be included in a child element
...@@ -257,7 +263,7 @@ public class Presence extends Packet { ...@@ -257,7 +263,7 @@ public class Presence extends Packet {
* is no matching child element. * is no matching child element.
*/ */
public Element getChildElement(String name, String namespace) { public Element getChildElement(String name, String namespace) {
for (Iterator i=element.elementIterator(name); i.hasNext(); ) { for (Iterator i = element.elementIterator(name); i.hasNext();) {
Element element = (Element)i.next(); Element element = (Element)i.next();
if (element.getNamespaceURI().equals(namespace)) { if (element.getNamespaceURI().equals(namespace)) {
return element; return element;
...@@ -271,7 +277,7 @@ public class Presence extends Packet { ...@@ -271,7 +277,7 @@ public class Presence extends Packet {
* namespace. The newly created Element is returned. This is a * namespace. The newly created Element is returned. This is a
* convenience method to avoid manipulating this underlying packet's * convenience method to avoid manipulating this underlying packet's
* Element instance directly.<p> * Element instance directly.<p>
* * <p/>
* Child elements in extended namespaces are used to extend the features * Child elements in extended namespaces are used to extend the features
* of XMPP. Examples include a "user is typing" indicator and invitations to * of XMPP. Examples include a "user is typing" indicator and invitations to
* group chat rooms. Although any valid XML can be included in a child element * group chat rooms. Although any valid XML can be included in a child element
...@@ -300,7 +306,7 @@ public class Presence extends Packet { ...@@ -300,7 +306,7 @@ public class Presence extends Packet {
* Represents the type of a presence packet. Note: the presence is assumed * Represents the type of a presence packet. Note: the presence is assumed
* to be "available" when the type attribute of the packet is <tt>null</tt>. * to be "available" when the type attribute of the packet is <tt>null</tt>.
* The valid types are: * The valid types are:
* * <p/>
* <ul> * <ul>
* <li>{@link #unavailable Presence.Type.unavailable} -- signals that the * <li>{@link #unavailable Presence.Type.unavailable} -- signals that the
* entity is no longer available for communication. * entity is no longer available for communication.
...@@ -362,7 +368,7 @@ public class Presence extends Packet { ...@@ -362,7 +368,7 @@ public class Presence extends Packet {
/** /**
* Represents the presence "show" value. Note: a <tt>null</tt> "show" value is the * Represents the presence "show" value. Note: a <tt>null</tt> "show" value is the
* default, which means "available". Valid values are: * default, which means "available". Valid values are:
* * <p/>
* <ul> * <ul>
* <li>{@link #chat Presence.Show.chat} -- the entity or resource is actively * <li>{@link #chat Presence.Show.chat} -- the entity or resource is actively
* interested in chatting. * interested in chatting.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment