1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 00:59:39 +02: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,11 +27,11 @@ public MyExtension parse(XmlPullParser parser, int initialDepth) {
outerloop: while(true) {
// Make sure to have already parse all attributes of the outermost element,
// i.e. 'attrFoo' of 'myExtension' in this example. Then advance the parser
int event = parser.next();
XmlPullParser.Event event = parser.next();
// Use switch/case of int instead of a if/else-if cascade
switch (event) {
case XmlPullParser.START_TAG:
case START_ELEMENT:
// Determine the name of the element which start tag we are seeing
String name = parser.getName();
// We can use switch/case of Strings since Java7, make use of its advantages
@ -52,12 +52,15 @@ public MyExtension parse(XmlPullParser parser, int initialDepth) {
break;
}
break;
case XmlPullParser.END_TAG:
case END_ELEMENT:
// The abort condition with the break labeled loop statement
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}

View file

@ -23,7 +23,7 @@ Whenever a packet extension is found in a packet, parsing will be
passed to the correct provider. Each provider must extend the
ExtensionElementProvider abstract class. Each extension provider is
responsible for parsing the raw XML stream, via the
[XML Pull Parser](http://www.xmlpull.org/), to contruct an object.
Smack's `XmlPullParser` interface, to construct an object.
You can also create an introspection provider
(`provider.IntrospectionProvider.PacketExtensionIntrospectionProvider`). Here,
@ -161,9 +161,9 @@ public class MyIQProvider extends IQProvider<MyIQ> {
// Start parsing loop
outerloop: while(true) {
int eventType = parser.next();
XmlPullParser.Event eventType = parser.next();
switch(eventType) {
case XmlPullParser.START_TAG:
case START_ELEMENT:
String elementName = parser.getName();
switch (elementName) {
case "user":
@ -175,12 +175,15 @@ public class MyIQProvider extends IQProvider<MyIQ> {
break;
}
break;
case XmlPullParser.END_TAG:
case END_ELEMENT:
// Abort condition: if the are on a end tag (closing element) of the same depth
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}
@ -225,9 +228,9 @@ _Disco Items IQProvider_
String node = "";
discoverItems.setNode(parser.getAttributeValue("", "node"));
outerloop: while (true) {
int eventType = parser.next();
XmlPullParser.Event eventType = parser.next();
switch (eventType) {
case XmlPullParser.START_TAG:
case START_ELEMENT:
String elementName = parser.getName();
switch (elementName) {
case "item":
@ -239,7 +242,7 @@ _Disco Items IQProvider_
break;
}
break;
case XmlPullParser.END_TAG:
case END_ELEMENT:
String elementName = parser.getName();
switch (elementName) {
case "item":
@ -295,17 +298,17 @@ _Subscription PacketExtensionProvider Implementation_
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.START_ELEMENT) && parser.getName().equals("subscribe-options")) {
tag = parser.next();
if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("required"))
if ((tag == XmlPullParser.START_ELEMENT) && parser.getName().equals("required"))
isRequired = true;
while (parser.next() != XmlPullParser.END_TAG && parser.getName() != "subscribe-options");
while (parser.next() != XmlPullParser.END_ELEMENT && parser.getName() != "subscribe-options");
}
while (parser.getEventType() != XmlPullParser.END_TAG) parser.next();
while (parser.getEventType() != XmlPullParser.END_ELEMENT) parser.next();
return new Subscription(jid, nodeId, subId, state == null ? null : Subscription.State.valueOf(state), isRequired);
}
}