1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package de.thedevstack.conversationsplus.xmpp.utils;
import de.thedevstack.conversationsplus.xml.Element;
import de.thedevstack.conversationsplus.xmpp.IqPacketParser;
import de.thedevstack.conversationsplus.xmpp.exceptions.BadRequestIqErrorException;
import de.thedevstack.conversationsplus.xmpp.exceptions.InternalServerErrorException;
import de.thedevstack.conversationsplus.xmpp.exceptions.IqPacketErrorException;
import de.thedevstack.conversationsplus.xmpp.exceptions.ServiceUnavailableException;
import de.thedevstack.conversationsplus.xmpp.exceptions.UndefinedConditionException;
import de.thedevstack.conversationsplus.xmpp.stanzas.ErrorIqPacket;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqErrorCondition;
/**
*/
public final class ErrorIqPacketExceptionHelper {
public static void throwIqErrorException(Element errorIqPacket) throws IqPacketErrorException {
Element packet = IqPacketParser.findChild(errorIqPacket, "error", "jabber:client");
if (null != packet) {
if (hasErrorElement(packet, IqErrorCondition.BAD_REQUEST.toString())) {
throw new BadRequestIqErrorException(errorIqPacket, getErrorText(packet));
}
if (hasErrorElement(packet, IqErrorCondition.SERVICE_UNAVAILABLE.toString())) {
throw new ServiceUnavailableException(errorIqPacket, getErrorText(packet));
}
if (hasErrorElement(packet, IqErrorCondition.INTERNAL_SERVER_ERROR.toString())) {
throw new InternalServerErrorException(errorIqPacket, getErrorText(packet));
}
if (hasErrorElement(packet, IqErrorCondition.UNDEFINED_CONDITION.toString())) {
throw new UndefinedConditionException(errorIqPacket, getErrorText(packet));
}
}
throw new IqPacketErrorException(errorIqPacket, "Unknown error packet.");
}
private static boolean hasErrorElement(Element packet, String elementName) {
return null != IqPacketParser.findChild(packet, elementName, ErrorIqPacket.NAMESPACE);
}
private static String getErrorText(Element packet) {
return IqPacketParser.findChildContent(packet, "text", ErrorIqPacket.NAMESPACE);
}
private ErrorIqPacketExceptionHelper() {
}
}
|