mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +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();
|
tag = parser.next();
|
||||||
|
|
||||||
if (tag == XmlPullParser.START_TAG)
|
if (tag == XmlPullParser.START_TAG)
|
||||||
extensions.add(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
|
PacketParserUtils.addPacketExtension(extensions, parser);
|
||||||
} while (!(tag == XmlPullParser.END_TAG && parser.getDepth() == initialDepth));
|
} while (!(tag == XmlPullParser.END_TAG && parser.getDepth() == initialDepth));
|
||||||
|
|
||||||
return createReturnExtension(name, namespace, attMap, extensions);
|
return createReturnExtension(name, namespace, attMap, extensions);
|
||||||
|
|
|
@ -245,8 +245,7 @@ public class PacketParserUtils {
|
||||||
message.setError(parseError(parser));
|
message.setError(parseError(parser));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
message.addExtension(
|
PacketParserUtils.addPacketExtension(message, parser, elementName, namespace);
|
||||||
PacketParserUtils.parsePacketExtension(elementName, namespace, parser));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -504,15 +503,12 @@ public class PacketParserUtils {
|
||||||
// Otherwise, it must be a packet extension.
|
// Otherwise, it must be a packet extension.
|
||||||
// Be extra robust: Skip PacketExtensions that cause Exceptions, instead of
|
// Be extra robust: Skip PacketExtensions that cause Exceptions, instead of
|
||||||
// failing completely here. See SMACK-390 for more information.
|
// failing completely here. See SMACK-390 for more information.
|
||||||
try {
|
try {
|
||||||
presence.addExtension(PacketParserUtils.parsePacketExtension(elementName, namespace, parser));
|
PacketParserUtils.addPacketExtension(presence, parser, elementName, namespace);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
LOGGER.log(Level.WARNING, "Failed to parse extension packet in Presence packet.", e);
|
||||||
LOGGER.log(Level.WARNING,
|
}
|
||||||
"Failed to parse extension packet in Presence packet.",
|
break;
|
||||||
e);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case XmlPullParser.END_TAG:
|
case XmlPullParser.END_TAG:
|
||||||
if (parser.getDepth() == initialDepth) {
|
if (parser.getDepth() == initialDepth) {
|
||||||
|
@ -871,8 +867,8 @@ public class PacketParserUtils {
|
||||||
if (namespace.equals(XMPPError.NAMESPACE)) {
|
if (namespace.equals(XMPPError.NAMESPACE)) {
|
||||||
condition = elementName;
|
condition = elementName;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
extensions.add(parsePacketExtension(elementName, namespace, parser));
|
PacketParserUtils.addPacketExtension(extensions, parser, elementName, namespace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -906,6 +902,7 @@ public class PacketParserUtils {
|
||||||
public static PacketExtension parsePacketExtension(String elementName, String namespace,
|
public static PacketExtension parsePacketExtension(String elementName, String namespace,
|
||||||
XmlPullParser parser) throws XmlPullParserException,
|
XmlPullParser parser) throws XmlPullParserException,
|
||||||
IOException, SmackException {
|
IOException, SmackException {
|
||||||
|
ParserUtils.assertAtStartTag(parser);
|
||||||
// See if a provider is registered to handle the extension.
|
// See if a provider is registered to handle the extension.
|
||||||
PacketExtensionProvider<PacketExtension> provider = ProviderManager.getExtensionProvider(elementName, namespace);
|
PacketExtensionProvider<PacketExtension> provider = ProviderManager.getExtensionProvider(elementName, namespace);
|
||||||
if (provider != null) {
|
if (provider != null) {
|
||||||
|
@ -923,12 +920,14 @@ public class PacketParserUtils {
|
||||||
throw new SmackException(e);
|
throw new SmackException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int initialDepth = parser.getDepth();
|
||||||
// No providers registered, so use a default extension.
|
// No providers registered, so use a default extension.
|
||||||
DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace);
|
DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace);
|
||||||
boolean done = false;
|
outerloop: while (true) {
|
||||||
while (!done) {
|
|
||||||
int eventType = parser.next();
|
int eventType = parser.next();
|
||||||
if (eventType == XmlPullParser.START_TAG) {
|
switch (eventType) {
|
||||||
|
case XmlPullParser.START_TAG:
|
||||||
String name = parser.getName();
|
String name = parser.getName();
|
||||||
// If an empty element, set the value with the empty string.
|
// If an empty element, set the value with the empty string.
|
||||||
if (parser.isEmptyElementTag()) {
|
if (parser.isEmptyElementTag()) {
|
||||||
|
@ -942,10 +941,10 @@ public class PacketParserUtils {
|
||||||
extension.setValue(name, value);
|
extension.setValue(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if (eventType == XmlPullParser.END_TAG) {
|
case XmlPullParser.END_TAG:
|
||||||
if (parser.getName().equals(elementName)) {
|
if (parser.getDepth() == initialDepth) {
|
||||||
done = true;
|
break outerloop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1022,6 +1021,29 @@ public class PacketParserUtils {
|
||||||
return object;
|
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
|
* Decodes a String into an object of the specified type. If the object
|
||||||
* type is not supported, null will be returned.
|
* 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.
|
// Otherwise, it must be a packet extension.
|
||||||
else {
|
else {
|
||||||
discoverInfo.addExtension(PacketParserUtils.parsePacketExtension(parser
|
PacketParserUtils.addPacketExtension(discoverInfo, parser);
|
||||||
.getName(), parser.getNamespace(), parser));
|
|
||||||
}
|
}
|
||||||
} else if (eventType == XmlPullParser.END_TAG) {
|
} else if (eventType == XmlPullParser.END_TAG) {
|
||||||
if (parser.getName().equals("identity")) {
|
if (parser.getName().equals("identity")) {
|
||||||
|
|
|
@ -62,9 +62,7 @@ public class RegistrationProvider extends IQProvider<Registration> {
|
||||||
}
|
}
|
||||||
// Otherwise, it must be a packet extension.
|
// Otherwise, it must be a packet extension.
|
||||||
else {
|
else {
|
||||||
packetExtensions.add(PacketParserUtils.parsePacketExtension(
|
PacketParserUtils.addPacketExtension(packetExtensions, parser);
|
||||||
parser.getName(), parser.getNamespace(),
|
|
||||||
parser));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (eventType == XmlPullParser.END_TAG) {
|
else if (eventType == XmlPullParser.END_TAG) {
|
||||||
|
|
|
@ -49,8 +49,7 @@ public class MUCOwnerProvider extends IQProvider<MUCOwner> {
|
||||||
}
|
}
|
||||||
// Otherwise, it must be a packet extension.
|
// Otherwise, it must be a packet extension.
|
||||||
else {
|
else {
|
||||||
mucOwner.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(),
|
PacketParserUtils.addPacketExtension(mucOwner, parser);
|
||||||
parser.getNamespace(), parser));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (eventType == XmlPullParser.END_TAG) {
|
else if (eventType == XmlPullParser.END_TAG) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.PacketExtension;
|
|
||||||
import org.jivesoftware.smack.provider.IQProvider;
|
import org.jivesoftware.smack.provider.IQProvider;
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
||||||
|
@ -50,8 +49,7 @@ public class PubSubProvider extends IQProvider<PubSub>
|
||||||
|
|
||||||
if (eventType == XmlPullParser.START_TAG)
|
if (eventType == XmlPullParser.START_TAG)
|
||||||
{
|
{
|
||||||
PacketExtension ext = PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser);
|
PacketParserUtils.addPacketExtension(pubsub, parser);
|
||||||
pubsub.addExtension(ext);
|
|
||||||
}
|
}
|
||||||
else if (eventType == XmlPullParser.END_TAG)
|
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")) {
|
else if (eventType == XmlPullParser.START_TAG && parser.getNamespace().equals("jabber:x:data")) {
|
||||||
// Otherwise, it must be a packet extension.
|
// Otherwise, it must be a packet extension.
|
||||||
search = new UserSearch();
|
search = new UserSearch();
|
||||||
search.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(),
|
PacketParserUtils.addPacketExtension(search, parser);
|
||||||
parser.getNamespace(), parser));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (eventType == XmlPullParser.END_TAG) {
|
else if (eventType == XmlPullParser.END_TAG) {
|
||||||
if (parser.getName().equals("query")) {
|
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")) {
|
else if (eventType == XmlPullParser.START_TAG && parser.getNamespace().equals("jabber:x:data")) {
|
||||||
search.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(),
|
PacketParserUtils.addPacketExtension(search, parser);
|
||||||
parser.getNamespace(), parser));
|
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,7 @@ public class WorkgroupForm extends IQ {
|
||||||
int eventType = parser.next();
|
int eventType = parser.next();
|
||||||
if (eventType == XmlPullParser.START_TAG) {
|
if (eventType == XmlPullParser.START_TAG) {
|
||||||
// Parse the packet extension
|
// Parse the packet extension
|
||||||
answer.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(),
|
PacketParserUtils.addPacketExtension(answer, parser);
|
||||||
parser.getNamespace(), parser));
|
|
||||||
}
|
}
|
||||||
else if (eventType == XmlPullParser.END_TAG) {
|
else if (eventType == XmlPullParser.END_TAG) {
|
||||||
if (parser.getName().equals(ELEMENT_NAME)) {
|
if (parser.getName().equals(ELEMENT_NAME)) {
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class TranscriptSearch extends IQ {
|
||||||
int eventType = parser.next();
|
int eventType = parser.next();
|
||||||
if (eventType == XmlPullParser.START_TAG) {
|
if (eventType == XmlPullParser.START_TAG) {
|
||||||
// Parse the packet extension
|
// Parse the packet extension
|
||||||
answer.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
|
PacketParserUtils.addPacketExtension(answer, parser);
|
||||||
}
|
}
|
||||||
else if (eventType == XmlPullParser.END_TAG) {
|
else if (eventType == XmlPullParser.END_TAG) {
|
||||||
if (parser.getName().equals(ELEMENT_NAME)) {
|
if (parser.getName().equals(ELEMENT_NAME)) {
|
||||||
|
|
Loading…
Reference in a new issue