1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-12 22:11:07 +01:00

Replace XPP3 by XmlPullParser interface wrapping StAX and XPP3

Introducing Smack's own XmlPullParser interface which tries to stay as
compatible as possible to XPP3. The interface is used to either wrap
StAX's XMLStreamReader if Smack is used on Java SE, and XPP3's
XmlPullParser if Smack is used on on Android.

Fixes SMACK-591.

Also introduce JUnit 5 and non-strict javadoc projects.
This commit is contained in:
Florian Schmaus 2019-05-06 22:06:13 +02:00
parent b3646abecd
commit 4133eb175c
414 changed files with 3855 additions and 2041 deletions

View file

@ -27,7 +27,7 @@ import org.jivesoftware.smack.util.PacketParserUtils;
* extensions. This effectively extends the idea of an extension within one of the
* top level {@link Stanza} types to consider any embedded element to be an extension
* of its parent. This more easily enables the usage of some of Smacks parsing
* utilities such as {@link PacketParserUtils#parseExtensionElement(String, String, org.xmlpull.v1.XmlPullParser, org.jivesoftware.smack.packet.XmlEnvironment)} to be used
* utilities such as {@link PacketParserUtils#parseExtensionElement(String, String, org.jivesoftware.smack.xml.XmlPullParser, org.jivesoftware.smack.packet.XmlEnvironment)} to be used
* to parse any element of the XML being parsed.
*
* <p>Top level extensions have only one element, but they can have multiple children, or

View file

@ -24,9 +24,8 @@ import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.util.StringUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
/**
* The default payload representation for {@link PayloadItem#getPayload()}. It simply

View file

@ -21,12 +21,12 @@ import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smackx.pubsub.Affiliation;
import org.jivesoftware.smackx.pubsub.Affiliation.AffiliationNamespace;
import org.jxmpp.jid.BareJid;
import org.xmlpull.v1.XmlPullParser;
/**
* Parses the affiliation element out of the reply stanza from the server

View file

@ -24,6 +24,8 @@ import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.pubsub.Item;
import org.jivesoftware.smackx.pubsub.Item.ItemNamespace;
@ -31,9 +33,6 @@ import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.SimplePayload;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Parses an <b>item</b> element as is defined in both the {@link PubSubNamespace#basic} and
* {@link PubSubNamespace#event} namespaces. To parse the item contents, it will use whatever
@ -51,9 +50,9 @@ public class ItemProvider extends ExtensionElementProvider<Item> {
String xmlns = parser.getNamespace();
ItemNamespace itemNamespace = ItemNamespace.fromXmlns(xmlns);
int tag = parser.next();
XmlPullParser.Event tag = parser.next();
if (tag == XmlPullParser.END_TAG) {
if (tag == XmlPullParser.Event.END_ELEMENT) {
return new Item(itemNamespace, id, node);
}
else {

View file

@ -23,13 +23,12 @@ import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Parses the root PubSub stanza extensions of the {@link IQ} stanza and returns
* a {@link PubSub} instance.
@ -44,16 +43,19 @@ public class PubSubProvider extends IQProvider<PubSub> {
PubSub pubsub = new PubSub(pubSubNamespace);
outerloop: while (true) {
int eventType = parser.next();
XmlPullParser.Event eventType = parser.next();
switch (eventType) {
case XmlPullParser.START_TAG:
case START_ELEMENT:
PacketParserUtils.addExtensionElement(pubsub, parser, xmlEnvironment);
break;
case XmlPullParser.END_TAG:
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}
return pubsub;

View file

@ -21,12 +21,12 @@ import java.io.IOException;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.pubsub.Subscription;
import org.jxmpp.jid.Jid;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Parses the <b>subscription</b> element out of the PubSub IQ message from
@ -44,17 +44,17 @@ public class SubscriptionProvider extends ExtensionElementProvider<Subscription>
String state = parser.getAttributeValue(null, "subscription");
boolean isRequired = false;
int tag = parser.next();
XmlPullParser.Event tag = parser.next();
if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("subscribe-options")) {
if ((tag == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals("subscribe-options")) {
tag = parser.next();
if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("required"))
if ((tag == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals("required"))
isRequired = true;
while (tag != XmlPullParser.END_TAG && !parser.getName().equals("subscribe-options")) tag = parser.next();
while (tag != XmlPullParser.Event.END_ELEMENT && !parser.getName().equals("subscribe-options")) tag = parser.next();
}
while (parser.getEventType() != XmlPullParser.END_TAG) parser.next();
while (parser.getEventType() != XmlPullParser.Event.END_ELEMENT) parser.next();
return new Subscription(jid, nodeId, subId, (state == null ? null : Subscription.State.valueOf(state)), isRequired);
}