1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-07 03:21:08 +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

@ -29,9 +29,8 @@ import org.jivesoftware.smack.sm.packet.StreamManagement.Enabled;
import org.jivesoftware.smack.sm.packet.StreamManagement.Failed;
import org.jivesoftware.smack.sm.packet.StreamManagement.Resumed;
import org.jivesoftware.smack.util.ParserUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
public class ParseStreamManagement {
@ -53,9 +52,9 @@ public class ParseStreamManagement {
List<StanzaErrorTextElement> textElements = new ArrayList<>(4);
outerloop:
while (true) {
int event = parser.next();
XmlPullParser.Event event = parser.next();
switch (event) {
case XmlPullParser.START_TAG:
case START_ELEMENT:
name = parser.getName();
String namespace = parser.getNamespace();
if (StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE.equals(namespace)) {
@ -69,12 +68,15 @@ public class ParseStreamManagement {
}
}
break;
case XmlPullParser.END_TAG:
case END_ELEMENT:
name = parser.getName();
if (Failed.ELEMENT.equals(name)) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}
ParserUtils.assertAtEndTag(parser);

View file

@ -19,8 +19,7 @@ package org.jivesoftware.smack.sm.provider;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.sm.packet.StreamManagement.StreamManagementFeature;
import org.xmlpull.v1.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParser;
public class StreamManagementStreamFeatureProvider extends ExtensionElementProvider<StreamManagementFeature> {

View file

@ -117,12 +117,13 @@ import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.TLSUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smack.util.dns.HostAddress;
import org.jivesoftware.smack.xml.SmackXmlParser;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jxmpp.jid.impl.JidCreate;
import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Creates a socket connection to an XMPP server. This is the default connection
@ -851,7 +852,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
*/
void openStream() throws SmackException, InterruptedException, XmlPullParserException {
sendStreamOpen();
packetReader.parser = PacketParserUtils.newXmppParser(reader);
packetReader.parser = SmackXmlParser.newXmlParser(reader);
}
protected class PacketReader {
@ -898,10 +899,10 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
try {
openStream();
initialStreamOpenSend = true;
int eventType = parser.getEventType();
XmlPullParser.Event eventType = parser.getEventType();
while (!done) {
switch (eventType) {
case XmlPullParser.START_TAG:
case START_ELEMENT:
final String name = parser.getName();
switch (name) {
case Message.ELEMENT:
@ -1069,7 +1070,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
break;
}
break;
case XmlPullParser.END_TAG:
case END_ELEMENT:
final String endTagName = parser.getName();
if ("stream".equals(endTagName)) {
if (!parser.getNamespace().equals("http://etherx.jabber.org/streams")) {
@ -1105,11 +1106,14 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
}
}
break;
case XmlPullParser.END_DOCUMENT:
case END_DOCUMENT:
// END_DOCUMENT only happens in an error case, as otherwise we would see a
// closing stream element before.
throw new SmackException.SmackMessageException(
"Parser got END_DOCUMENT event. This could happen e.g. if the server closed the connection without sending a closing stream element");
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
eventType = parser.next();
}

View file

@ -91,6 +91,8 @@ import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.UTF8;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smack.util.dns.HostAddress;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.Jid;
@ -102,8 +104,6 @@ import org.jxmpp.xml.splitter.XmlPrettyPrinter;
import org.jxmpp.xml.splitter.XmlPrinter;
import org.jxmpp.xml.splitter.XmppElementCallback;
import org.jxmpp.xml.splitter.XmppXmlSplitter;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* Represents and manages a client connection to an XMPP server via TCP.