mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 18:48:00 +01:00
[core] Factor PacketParserUtils.parseIqData() in extra method
This commit is contained in:
parent
1dae0c0c32
commit
0e637068e6
1 changed files with 23 additions and 17 deletions
|
@ -500,6 +500,23 @@ public class PacketParserUtils {
|
||||||
return parseIQ(parser, null);
|
return parseIQ(parser, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IqData parseIqData(XmlPullParser parser) throws XmppStringprepException {
|
||||||
|
final String id = parser.getAttributeValue("", "id");
|
||||||
|
IqData iqData = StanzaBuilder.buildIqData(id);
|
||||||
|
|
||||||
|
final Jid to = ParserUtils.getJidAttribute(parser, "to");
|
||||||
|
iqData.to(to);
|
||||||
|
|
||||||
|
final Jid from = ParserUtils.getJidAttribute(parser, "from");
|
||||||
|
iqData.from(from);
|
||||||
|
|
||||||
|
String typeString = parser.getAttributeValue("", "type");
|
||||||
|
final IQ.Type type = IQ.Type.fromString(typeString);
|
||||||
|
iqData.ofType(type);
|
||||||
|
|
||||||
|
return iqData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses an IQ packet.
|
* Parses an IQ packet.
|
||||||
*
|
*
|
||||||
|
@ -517,18 +534,7 @@ public class PacketParserUtils {
|
||||||
XmlEnvironment iqXmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
|
XmlEnvironment iqXmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
|
||||||
IQ iqPacket = null;
|
IQ iqPacket = null;
|
||||||
StanzaError error = null;
|
StanzaError error = null;
|
||||||
|
IqData iqData = parseIqData(parser);
|
||||||
final String id = parser.getAttributeValue("", "id");
|
|
||||||
IqData iqData = StanzaBuilder.buildIqData(id);
|
|
||||||
|
|
||||||
final Jid to = ParserUtils.getJidAttribute(parser, "to");
|
|
||||||
iqData.to(to);
|
|
||||||
|
|
||||||
final Jid from = ParserUtils.getJidAttribute(parser, "from");
|
|
||||||
iqData.from(from);
|
|
||||||
|
|
||||||
final IQ.Type type = IQ.Type.fromString(parser.getAttributeValue("", "type"));
|
|
||||||
iqData.ofType(type);
|
|
||||||
|
|
||||||
outerloop: while (true) {
|
outerloop: while (true) {
|
||||||
XmlPullParser.Event eventType = parser.next();
|
XmlPullParser.Event eventType = parser.next();
|
||||||
|
@ -570,7 +576,7 @@ public class PacketParserUtils {
|
||||||
}
|
}
|
||||||
// Decide what to do when an IQ packet was not understood
|
// Decide what to do when an IQ packet was not understood
|
||||||
if (iqPacket == null) {
|
if (iqPacket == null) {
|
||||||
switch (type) {
|
switch (iqData.getType()) {
|
||||||
case error:
|
case error:
|
||||||
// If an IQ packet wasn't created above, create an empty error IQ packet.
|
// If an IQ packet wasn't created above, create an empty error IQ packet.
|
||||||
iqPacket = new ErrorIQ(error);
|
iqPacket = new ErrorIQ(error);
|
||||||
|
@ -584,10 +590,10 @@ public class PacketParserUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set basic values on the iq packet.
|
// Set basic values on the iq packet.
|
||||||
iqPacket.setStanzaId(id);
|
iqPacket.setStanzaId(iqData.getStanzaId());
|
||||||
iqPacket.setTo(to);
|
iqPacket.setTo(iqData.getTo());
|
||||||
iqPacket.setFrom(from);
|
iqPacket.setFrom(iqData.getFrom());
|
||||||
iqPacket.setType(type);
|
iqPacket.setType(iqData.getType());
|
||||||
iqPacket.setError(error);
|
iqPacket.setError(error);
|
||||||
|
|
||||||
return iqPacket;
|
return iqPacket;
|
||||||
|
|
Loading…
Reference in a new issue