mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-22 20:47:57 +01:00
Add 'PacketParserUtils.addPacketextension()'
This commit is contained in:
parent
6980c8e63d
commit
452b2aca0f
9 changed files with 52 additions and 40 deletions
|
@ -102,8 +102,8 @@ abstract public class EmbeddedExtensionProvider<PE extends PacketExtension> exte
|
|||
{
|
||||
tag = parser.next();
|
||||
|
||||
if (tag == XmlPullParser.START_TAG)
|
||||
extensions.add(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
|
||||
if (tag == XmlPullParser.START_TAG)
|
||||
PacketParserUtils.addPacketExtension(extensions, parser);
|
||||
} while (!(tag == XmlPullParser.END_TAG && parser.getDepth() == initialDepth));
|
||||
|
||||
return createReturnExtension(name, namespace, attMap, extensions);
|
||||
|
|
|
@ -245,8 +245,7 @@ public class PacketParserUtils {
|
|||
message.setError(parseError(parser));
|
||||
break;
|
||||
default:
|
||||
message.addExtension(
|
||||
PacketParserUtils.parsePacketExtension(elementName, namespace, parser));
|
||||
PacketParserUtils.addPacketExtension(message, parser, elementName, namespace);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -504,15 +503,12 @@ public class PacketParserUtils {
|
|||
// Otherwise, it must be a packet extension.
|
||||
// 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));
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.log(Level.WARNING,
|
||||
"Failed to parse extension packet in Presence packet.",
|
||||
e);
|
||||
}
|
||||
break;
|
||||
try {
|
||||
PacketParserUtils.addPacketExtension(presence, parser, elementName, namespace);
|
||||
} catch (Exception e) {
|
||||
LOGGER.log(Level.WARNING, "Failed to parse extension packet in Presence packet.", e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case XmlPullParser.END_TAG:
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
|
@ -871,8 +867,8 @@ public class PacketParserUtils {
|
|||
if (namespace.equals(XMPPError.NAMESPACE)) {
|
||||
condition = elementName;
|
||||
}
|
||||
else {
|
||||
extensions.add(parsePacketExtension(elementName, namespace, parser));
|
||||
else {
|
||||
PacketParserUtils.addPacketExtension(extensions, parser, elementName, namespace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -906,6 +902,7 @@ public class PacketParserUtils {
|
|||
public static PacketExtension parsePacketExtension(String elementName, String namespace,
|
||||
XmlPullParser parser) throws XmlPullParserException,
|
||||
IOException, SmackException {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
// See if a provider is registered to handle the extension.
|
||||
PacketExtensionProvider<PacketExtension> provider = ProviderManager.getExtensionProvider(elementName, namespace);
|
||||
if (provider != null) {
|
||||
|
@ -923,12 +920,14 @@ public class PacketParserUtils {
|
|||
throw new SmackException(e);
|
||||
}
|
||||
}
|
||||
|
||||
final int initialDepth = parser.getDepth();
|
||||
// No providers registered, so use a default extension.
|
||||
DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace);
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
String name = parser.getName();
|
||||
// If an empty element, set the value with the empty string.
|
||||
if (parser.isEmptyElementTag()) {
|
||||
|
@ -942,10 +941,10 @@ public class PacketParserUtils {
|
|||
extension.setValue(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals(elementName)) {
|
||||
done = true;
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1022,6 +1021,29 @@ public class PacketParserUtils {
|
|||
return object;
|
||||
}
|
||||
|
||||
public static void addPacketExtension(Packet packet, XmlPullParser parser) throws XmlPullParserException,
|
||||
IOException, SmackException {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
addPacketExtension(packet, parser, parser.getName(), parser.getNamespace());
|
||||
}
|
||||
|
||||
public static void addPacketExtension(Packet packet, XmlPullParser parser, String elementName, String namespace)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
PacketExtension packetExtension = parsePacketExtension(elementName, namespace, parser);
|
||||
packet.addExtension(packetExtension);
|
||||
}
|
||||
|
||||
public static void addPacketExtension(Collection<PacketExtension> collection, XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
addPacketExtension(collection, parser, parser.getName(), parser.getNamespace());
|
||||
}
|
||||
|
||||
public static void addPacketExtension(Collection<PacketExtension> collection, XmlPullParser parser,
|
||||
String elementName, String namespace) throws XmlPullParserException, IOException, SmackException {
|
||||
PacketExtension packetExtension = parsePacketExtension(elementName, namespace, parser);
|
||||
collection.add(packetExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a String into an object of the specified type. If the object
|
||||
* type is not supported, null will be returned.
|
||||
|
|
|
@ -61,8 +61,7 @@ public class DiscoverInfoProvider extends IQProvider<DiscoverInfo> {
|
|||
}
|
||||
// Otherwise, it must be a packet extension.
|
||||
else {
|
||||
discoverInfo.addExtension(PacketParserUtils.parsePacketExtension(parser
|
||||
.getName(), parser.getNamespace(), parser));
|
||||
PacketParserUtils.addPacketExtension(discoverInfo, parser);
|
||||
}
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals("identity")) {
|
||||
|
|
|
@ -62,9 +62,7 @@ public class RegistrationProvider extends IQProvider<Registration> {
|
|||
}
|
||||
// Otherwise, it must be a packet extension.
|
||||
else {
|
||||
packetExtensions.add(PacketParserUtils.parsePacketExtension(
|
||||
parser.getName(), parser.getNamespace(),
|
||||
parser));
|
||||
PacketParserUtils.addPacketExtension(packetExtensions, parser);
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
|
|
|
@ -49,8 +49,7 @@ public class MUCOwnerProvider extends IQProvider<MUCOwner> {
|
|||
}
|
||||
// Otherwise, it must be a packet extension.
|
||||
else {
|
||||
mucOwner.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(),
|
||||
parser.getNamespace(), parser));
|
||||
PacketParserUtils.addPacketExtension(mucOwner, parser);
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.io.IOException;
|
|||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
||||
|
@ -50,8 +49,7 @@ public class PubSubProvider extends IQProvider<PubSub>
|
|||
|
||||
if (eventType == XmlPullParser.START_TAG)
|
||||
{
|
||||
PacketExtension ext = PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser);
|
||||
pubsub.addExtension(ext);
|
||||
PacketParserUtils.addPacketExtension(pubsub, parser);
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG)
|
||||
{
|
||||
|
|
|
@ -150,9 +150,7 @@ public class UserSearch extends IQ {
|
|||
else if (eventType == XmlPullParser.START_TAG && parser.getNamespace().equals("jabber:x:data")) {
|
||||
// Otherwise, it must be a packet extension.
|
||||
search = new UserSearch();
|
||||
search.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(),
|
||||
parser.getNamespace(), parser));
|
||||
|
||||
PacketParserUtils.addPacketExtension(search, parser);
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals("query")) {
|
||||
|
@ -205,8 +203,7 @@ public class UserSearch extends IQ {
|
|||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.START_TAG && parser.getNamespace().equals("jabber:x:data")) {
|
||||
search.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(),
|
||||
parser.getNamespace(), parser));
|
||||
PacketParserUtils.addPacketExtension(search, parser);
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,8 +67,7 @@ public class WorkgroupForm extends IQ {
|
|||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
// Parse the packet extension
|
||||
answer.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(),
|
||||
parser.getNamespace(), parser));
|
||||
PacketParserUtils.addPacketExtension(answer, parser);
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals(ELEMENT_NAME)) {
|
||||
|
|
|
@ -71,7 +71,7 @@ public class TranscriptSearch extends IQ {
|
|||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
// Parse the packet extension
|
||||
answer.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
|
||||
PacketParserUtils.addPacketExtension(answer, parser);
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals(ELEMENT_NAME)) {
|
||||
|
|
Loading…
Reference in a new issue