1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-26 00:02:06 +01:00

Throw more exceptions when parsing Presences

when parsing core elements of Presences.
This commit is contained in:
Florian Schmaus 2014-06-10 18:40:15 +02:00
parent 009057e2e2
commit b083449cc3

View file

@ -259,13 +259,8 @@ public class PacketParserUtils {
Presence.Type type = Presence.Type.available;
String typeString = parser.getAttributeValue("", "type");
if (typeString != null && !typeString.equals("")) {
try {
type = Presence.Type.fromString(typeString);
}
catch (IllegalArgumentException iae) {
LOGGER.warning("Found invalid presence type " + typeString);
}
}
Presence presence = new Presence(type);
presence.setTo(parser.getAttributeValue("", "to"));
presence.setFrom(parser.getAttributeValue("", "from"));
@ -289,32 +284,20 @@ public class PacketParserUtils {
presence.setStatus(parser.nextText());
}
else if (elementName.equals("priority")) {
try {
int priority = Integer.parseInt(parser.nextText());
presence.setPriority(priority);
}
catch (NumberFormatException nfe) {
// Ignore.
}
catch (IllegalArgumentException iae) {
// Presence priority is out of range so assume priority to be zero
presence.setPriority(0);
}
}
else if (elementName.equals("show")) {
String modeText = parser.nextText();
try {
presence.setMode(Presence.Mode.fromString(modeText));
}
catch (IllegalArgumentException iae) {
LOGGER.warning("Found invalid presence mode " + modeText);
}
}
else if (elementName.equals("error")) {
presence.setError(parseError(parser));
}
// Otherwise, it must be a packet extension.
else {
// Be extra robust: Skip PacketExtensions that cause Exceptions, instead of
// failing completely here. See SMACK-390 for more information.
try {
presence.addExtension(PacketParserUtils.parsePacketExtension(elementName, namespace, parser));
}