From f1fb03d08cbe2aaf99e4fbc18930d0c2e6c353e7 Mon Sep 17 00:00:00 2001
From: V Lau
Date: Sat, 19 Jan 2019 13:36:38 -0800
Subject: [PATCH 01/72] Add a success callback for auto-join on reconnect.
When auto-join on reconnection is success, invoke a callback.
Conform to the proper copyright format.
---
.../smackx/muc/AutoJoinSuccessCallback.java | 31 +++++++++++++++++++
.../smackx/muc/MultiUserChatManager.java | 21 +++++++++++++
2 files changed, 52 insertions(+)
create mode 100644 smack-extensions/src/main/java/org/jivesoftware/smackx/muc/AutoJoinSuccessCallback.java
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/AutoJoinSuccessCallback.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/AutoJoinSuccessCallback.java
new file mode 100644
index 000000000..87bc0b19f
--- /dev/null
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/AutoJoinSuccessCallback.java
@@ -0,0 +1,31 @@
+/**
+ *
+ * Copyright 2019 Vincent Lau
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jivesoftware.smackx.muc;
+
+import org.jxmpp.jid.parts.Resourcepart;
+
+public interface AutoJoinSuccessCallback {
+
+ /**
+ * Invoked after the automatic rejoin rooms on reconnect success.
+ *
+ * @param muc the joined MultiUserChat.
+ * @param nickname nickname used by participant to join the room.
+ */
+ void autoJoinSuccess(MultiUserChat muc, Resourcepart nickname);
+
+}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java
index 639e2f792..7d4691370 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java
@@ -152,6 +152,8 @@ public final class MultiUserChatManager extends Manager {
private AutoJoinFailedCallback autoJoinFailedCallback;
+ private AutoJoinSuccessCallback autoJoinSuccessCallback;
+
private final ServiceDiscoveryManager serviceDiscoveryManager;
private MultiUserChatManager(XMPPConnection connection) {
@@ -200,6 +202,7 @@ public final class MultiUserChatManager extends Manager {
@Override
public void run() {
final AutoJoinFailedCallback failedCallback = autoJoinFailedCallback;
+ final AutoJoinSuccessCallback successCallback = autoJoinSuccessCallback;
for (EntityBareJid mucJid : mucs) {
MultiUserChat muc = getMultiUserChat(mucJid);
@@ -221,6 +224,9 @@ public final class MultiUserChatManager extends Manager {
}
try {
muc.join(nickname);
+ if (successCallback != null) {
+ successCallback.autoJoinSuccess(muc, nickname);
+ }
} catch (NotAMucServiceException | NoResponseException | XMPPErrorException
| NotConnectedException | InterruptedException e) {
if (failedCallback != null) {
@@ -481,6 +487,21 @@ public final class MultiUserChatManager extends Manager {
}
}
+ /**
+ * Set a callback invoked by this manager when automatic join on reconnect success.
+ * If successCallback is not null, automatic rejoin will also
+ * be enabled.
+ *
+ * @param successCallback the callback
+ */
+ public void setAutoJoinSuccessCallback(AutoJoinSuccessCallback successCallback) {
+ autoJoinSuccessCallback = successCallback;
+ if (successCallback != null) {
+ setAutoJoinOnReconnect(true);
+ }
+ }
+
+
void addJoinedRoom(EntityBareJid room) {
joinedRooms.add(room);
}
From 4e7cd832204090fdcb3126b579a43642a1bdb35d Mon Sep 17 00:00:00 2001
From: Florian Schmaus
Date: Sun, 28 Apr 2019 23:18:52 +0200
Subject: [PATCH 02/72] Fix (Privacy|Time)ProviderTest
XML attributes must be separated by a whitespace.
---
.../privacy/provider/PrivacyProviderTest.java | 14 +++++++-------
.../smackx/time/provider/TimeProviderTest.java | 14 +++++++-------
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/privacy/provider/PrivacyProviderTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/privacy/provider/PrivacyProviderTest.java
index 9903d38d2..829e0a4f4 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/privacy/provider/PrivacyProviderTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/privacy/provider/PrivacyProviderTest.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2012 Florian Schmaus
+ * Copyright 2012-2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,9 +40,9 @@ public class PrivacyProviderTest extends InitExtensions {
""
+ ""
+ ""
- + ""
+ ""
+ ""
@@ -73,9 +73,9 @@ public class PrivacyProviderTest extends InitExtensions {
""
+ ""
+ ""
- + ""
+ ""
+ ""
diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/time/provider/TimeProviderTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/time/provider/TimeProviderTest.java
index 5d852f0f1..3cc6ed46b 100644
--- a/smack-extensions/src/test/java/org/jivesoftware/smackx/time/provider/TimeProviderTest.java
+++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/time/provider/TimeProviderTest.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2014 Florian Schmaus
+ * Copyright 2014-2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,9 +32,9 @@ public class TimeProviderTest {
public void parseTimeWithIntrospectionTest() throws Exception {
// @formatter:off
final String request =
- ""
+ ""
+ "";
@@ -44,9 +44,9 @@ public class TimeProviderTest {
// @formatter:off
final String response =
- ""
+ "
-If you dont' use a
-dependency resolution system, like gradle or maven, then you will need
-to download at least
-the Xml
-Pull Parser 3rd Edition (XPP3) library or any other library that
-implements the XmlPullParser interface
-(like kXML) and the set of
-jXMPP libraries.
+ Smack tries to depend on as few as possible libraries. The only
+ requirement is jXMPP. For DNS
+ resolution we recommend to
+ use MiniDNS.
diff --git a/settings.gradle b/settings.gradle
index 6188d60b6..d3b53d80e 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -28,4 +28,7 @@ include 'smack-core',
'smack-omemo-signal',
'smack-omemo-signal-integration-test',
'smack-repl',
- 'smack-openpgp'
+ 'smack-openpgp',
+ 'smack-xmlparser',
+ 'smack-xmlparser-stax',
+ 'smack-xmlparser-xpp3'
diff --git a/smack-android/build.gradle b/smack-android/build.gradle
index 63fa35d2f..46827c09f 100644
--- a/smack-android/build.gradle
+++ b/smack-android/build.gradle
@@ -7,6 +7,7 @@ smack-extensions and smack-experimental."""
// Note that the test dependencies (junit, …) are inferred from the
// sourceSet.test of the core subproject
dependencies {
+ api project(':smack-xmlparser-xpp3')
// Depend on minidns-android21 as optional dependency, even if may
// not need it. Can't hurt to have it in the programm path with
// the correct MiniDNS version as it won't hurt even if the
diff --git a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java
index 7e1d97122..592e0633c 100644
--- a/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java
+++ b/smack-bosh/src/main/java/org/jivesoftware/smack/bosh/XMPPBOSHConnection.java
@@ -20,7 +20,6 @@ package org.jivesoftware.smack.bosh;
import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;
-import java.io.StringReader;
import java.io.Writer;
import java.util.Map;
import java.util.logging.Level;
@@ -44,6 +43,7 @@ import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Success;
import org.jivesoftware.smack.util.CloseableUtil;
import org.jivesoftware.smack.util.PacketParserUtils;
+import org.jivesoftware.smack.xml.XmlPullParser;
import org.igniterealtime.jbosh.AbstractBody;
import org.igniterealtime.jbosh.BOSHClient;
@@ -56,11 +56,8 @@ import org.igniterealtime.jbosh.BOSHException;
import org.igniterealtime.jbosh.BOSHMessageEvent;
import org.igniterealtime.jbosh.BodyQName;
import org.igniterealtime.jbosh.ComposableBody;
-
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.parts.Resourcepart;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserFactory;
/**
* Creates a connection to an XMPP server via HTTP binding.
@@ -479,14 +476,13 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
if (streamId == null) {
streamId = body.getAttribute(BodyQName.create(XMPPBOSHConnection.BOSH_URI, "authid"));
}
- final XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
- parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- parser.setInput(new StringReader(body.toXML()));
- int eventType = parser.getEventType();
+ final XmlPullParser parser = PacketParserUtils.getParserFor(body.toXML());
+
+ XmlPullParser.Event eventType = parser.getEventType();
do {
eventType = parser.next();
switch (eventType) {
- case XmlPullParser.START_TAG:
+ case START_ELEMENT:
String name = parser.getName();
switch (name) {
case Message.ELEMENT:
@@ -528,9 +524,12 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
}
}
break;
+ default:
+ // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
+ break;
}
}
- while (eventType != XmlPullParser.END_DOCUMENT);
+ while (eventType != XmlPullParser.Event.END_DOCUMENT);
}
catch (Exception e) {
if (isConnected()) {
diff --git a/smack-core/build.gradle b/smack-core/build.gradle
index 69ee5d468..c2ce38504 100644
--- a/smack-core/build.gradle
+++ b/smack-core/build.gradle
@@ -2,23 +2,19 @@ description = """\
Smack core components."""
ext {
- xmlUnitVersion = "2.6.0"
- powerMockVersion = "1.7.3"
+ xmlUnitVersion = '2.6.2'
}
dependencies {
- compile 'xpp3:xpp3:1.1.4c'
+ compile project(':smack-xmlparser')
compile "org.jxmpp:jxmpp-core:$jxmppVersion"
compile "org.jxmpp:jxmpp-jid:$jxmppVersion"
compile "org.minidns:minidns-core:$miniDnsVersion"
+ testCompile project(':smack-xmlparser-stax')
+ testCompile project(':smack-xmlparser-xpp3')
testCompile "org.jxmpp:jxmpp-jid:$jxmppVersion:tests"
- testCompile "org.junit.jupiter:junit-jupiter-api:$junitVersion"
- testCompile "org.junit.vintage:junit-vintage-engine:$junitVersion"
testCompile "org.xmlunit:xmlunit-core:$xmlUnitVersion"
testCompile "org.xmlunit:xmlunit-legacy:$xmlUnitVersion"
- testCompile "org.powermock:powermock-module-junit4:$powerMockVersion"
- testCompile "org.powermock:powermock-module-junit4-rule:$powerMockVersion"
- testCompile "org.powermock:powermock-api-mockito2:$powerMockVersion"
testCompile 'com.jamesmurty.utils:java-xmlbuilder:1.2'
}
diff --git a/smack-core/src/integration-test/java/org/jivesoftware/smack/packet/PrivacyProviderTest.java b/smack-core/src/integration-test/java/org/jivesoftware/smack/packet/PrivacyProviderTest.java
index e9261f516..ef7d5ee85 100644
--- a/smack-core/src/integration-test/java/org/jivesoftware/smack/packet/PrivacyProviderTest.java
+++ b/smack-core/src/integration-test/java/org/jivesoftware/smack/packet/PrivacyProviderTest.java
@@ -16,9 +16,9 @@ package org.jivesoftware.smack.packet;
import org.jivesoftware.smack.provider.PrivacyProvider;
import org.jivesoftware.smack.test.SmackTestCase;
-import org.xmlpull.v1.XmlPullParserFactory;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
+import org.jivesoftware.smack.xml.XmlPullParserFactory;
+import org.jivesoftware.smack.xml.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParserException;
import java.io.StringReader;
diff --git a/smack-core/src/integration-test/java/org/jivesoftware/smack/test/SmackTestCase.java b/smack-core/src/integration-test/java/org/jivesoftware/smack/test/SmackTestCase.java
index e44c6e15a..9bceba3f7 100644
--- a/smack-core/src/integration-test/java/org/jivesoftware/smack/test/SmackTestCase.java
+++ b/smack-core/src/integration-test/java/org/jivesoftware/smack/test/SmackTestCase.java
@@ -32,8 +32,8 @@ import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.TCPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.util.ConnectionUtils;
-import org.xmlpull.v1.XmlPullParserFactory;
-import org.xmlpull.v1.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParserFactory;
+import org.jivesoftware.smack.xml.XmlPullParser;
/**
* Base class for all the test cases which provides a pre-configured execution context. This
@@ -414,9 +414,9 @@ public abstract class SmackTestCase extends TestCase {
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(systemStream, "UTF-8");
- int eventType = parser.getEventType();
+ XmlPullParser.Event eventType = parser.getEventType();
do {
- if (eventType == XmlPullParser.START_TAG) {
+ if (eventType == START_ELEMENT) {
if (parser.getName().equals("host")) {
host = parser.nextText();
}
@@ -459,7 +459,7 @@ public abstract class SmackTestCase extends TestCase {
}
eventType = parser.next();
}
- while (eventType != XmlPullParser.END_DOCUMENT);
+ while (eventType != END_DOCUMENT);
parsedOK = true;
}
catch (Exception e) {
diff --git a/smack-core/src/integration-test/java/org/jivesoftware/smack/util/XMPPErrorTest.java b/smack-core/src/integration-test/java/org/jivesoftware/smack/util/XMPPErrorTest.java
index a375e0d81..8d2a0df4f 100644
--- a/smack-core/src/integration-test/java/org/jivesoftware/smack/util/XMPPErrorTest.java
+++ b/smack-core/src/integration-test/java/org/jivesoftware/smack/util/XMPPErrorTest.java
@@ -20,9 +20,9 @@ import java.io.StringReader;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.test.SmackTestCase;
-import org.xmlpull.v1.XmlPullParserFactory;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
+import org.jivesoftware.smack.xml.XmlPullParserFactory;
+import org.jivesoftware.smack.xml.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParserException;
public class XMPPErrorTest extends SmackTestCase {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
index e82ad15aa..632855ac2 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java
@@ -121,6 +121,8 @@ import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.dns.HostAddress;
import org.jivesoftware.smack.util.dns.SmackDaneProvider;
import org.jivesoftware.smack.util.dns.SmackDaneVerifier;
+import org.jivesoftware.smack.xml.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityFullJid;
@@ -130,8 +132,6 @@ import org.jxmpp.jid.parts.Resourcepart;
import org.jxmpp.stringprep.XmppStringprepException;
import org.jxmpp.util.XmppStringUtils;
import org.minidns.dnsname.DnsName;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
/**
@@ -1614,9 +1614,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
streamFeatures.clear();
final int initialDepth = parser.getDepth();
while (true) {
- int eventType = parser.next();
+ XmlPullParser.Event eventType = parser.next();
- if (eventType == XmlPullParser.START_TAG && parser.getDepth() == initialDepth + 1) {
+ if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getDepth() == initialDepth + 1) {
FullyQualifiedElement streamFeature = null;
String name = parser.getName();
String namespace = parser.getNamespace();
@@ -1647,7 +1647,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
addStreamFeature(streamFeature);
}
}
- else if (eventType == XmlPullParser.END_TAG && parser.getDepth() == initialDepth) {
+ else if (eventType == XmlPullParser.Event.END_ELEMENT && parser.getDepth() == initialDepth) {
break;
}
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java
index 10695df47..6f06e4d33 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackConfiguration.java
@@ -29,6 +29,7 @@ import javax.net.ssl.HostnameVerifier;
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
import org.jivesoftware.smack.debugger.ReflectionDebuggerFactory;
import org.jivesoftware.smack.debugger.SmackDebuggerFactory;
+import org.jivesoftware.smack.parsing.ExceptionThrowingCallback;
import org.jivesoftware.smack.parsing.ExceptionThrowingCallbackWithHint;
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.util.Objects;
@@ -380,4 +381,5 @@ public final class SmackConfiguration {
public static int getDefaultConcurrencyLevelLimit() {
return defaultConcurrencyLevelLimit;
}
+
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java
index 701004696..56ce677ce 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/SmackInitialization.java
@@ -44,10 +44,10 @@ import org.jivesoftware.smack.sasl.core.SCRAMSHA1Mechanism;
import org.jivesoftware.smack.sasl.core.ScramSha1PlusMechanism;
import org.jivesoftware.smack.util.CloseableUtil;
import org.jivesoftware.smack.util.FileUtils;
+import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.StringUtils;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserFactory;
+import org.jivesoftware.smack.xml.XmlPullParser;
public final class SmackInitialization {
@@ -141,12 +141,10 @@ public final class SmackInitialization {
public static void processConfigFile(InputStream cfgFileStream,
Collection exceptions, ClassLoader classLoader) throws Exception {
- XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
- parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- parser.setInput(cfgFileStream, "UTF-8");
- int eventType = parser.getEventType();
+ XmlPullParser parser = PacketParserUtils.getParserFor(cfgFileStream);
+ XmlPullParser.Event eventType = parser.getEventType();
do {
- if (eventType == XmlPullParser.START_TAG) {
+ if (eventType == XmlPullParser.Event.START_ELEMENT) {
if (parser.getName().equals("startupClasses")) {
parseClassesToLoad(parser, false, exceptions, classLoader);
}
@@ -156,7 +154,7 @@ public final class SmackInitialization {
}
eventType = parser.next();
}
- while (eventType != XmlPullParser.END_DOCUMENT);
+ while (eventType != XmlPullParser.Event.END_DOCUMENT);
CloseableUtil.maybeClose(cfgFileStream, LOGGER);
}
@@ -164,12 +162,10 @@ public final class SmackInitialization {
Collection exceptions, ClassLoader classLoader)
throws Exception {
final String startName = parser.getName();
- int eventType;
- String name;
+ XmlPullParser.Event eventType;
outerloop: do {
eventType = parser.next();
- name = parser.getName();
- if (eventType == XmlPullParser.START_TAG && "className".equals(name)) {
+ if (eventType == XmlPullParser.Event.START_ELEMENT && "className".equals(parser.getName())) {
String classToLoad = parser.nextText();
if (SmackConfiguration.isDisabledSmackClass(classToLoad)) {
continue outerloop;
@@ -188,7 +184,7 @@ public final class SmackInitialization {
}
}
}
- while (!(eventType == XmlPullParser.END_TAG && startName.equals(name)));
+ while (!(eventType == XmlPullParser.Event.END_ELEMENT && startName.equals(parser.getName())));
}
private static void loadSmackClass(String className, boolean optional, ClassLoader classLoader) throws Exception {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/compress/provider/CompressedProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/compress/provider/CompressedProvider.java
index 8b02ef95b..fbed9abd3 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/compress/provider/CompressedProvider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/compress/provider/CompressedProvider.java
@@ -20,7 +20,7 @@ import org.jivesoftware.smack.compress.packet.Compressed;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.provider.NonzaProvider;
-import org.xmlpull.v1.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParser;
public final class CompressedProvider extends NonzaProvider {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/compress/provider/FailureProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/compress/provider/FailureProvider.java
index eaa9a980d..cf90f594b 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/compress/provider/FailureProvider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/compress/provider/FailureProvider.java
@@ -27,8 +27,8 @@ import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.provider.NonzaProvider;
import org.jivesoftware.smack.util.PacketParserUtils;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
+import org.jivesoftware.smack.xml.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParserException;
public final class FailureProvider extends NonzaProvider {
@@ -46,9 +46,9 @@ public final class FailureProvider extends NonzaProvider {
XmlEnvironment failureXmlEnvironment = XmlEnvironment.from(parser, xmlEnvironment);
outerloop: while (true) {
- int eventType = parser.next();
+ XmlPullParser.Event eventType = parser.next();
switch (eventType) {
- case XmlPullParser.START_TAG:
+ case START_ELEMENT:
String name = parser.getName();
String namespace = parser.getNamespace();
switch (namespace) {
@@ -72,11 +72,12 @@ public final class FailureProvider extends NonzaProvider {
break;
}
break;
- case XmlPullParser.END_TAG:
+ case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
+ default: // fall out
}
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/fsm/AbstractXmppStateMachineConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/fsm/AbstractXmppStateMachineConnection.java
index 99c8ac6b6..3330202d3 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/fsm/AbstractXmppStateMachineConnection.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/fsm/AbstractXmppStateMachineConnection.java
@@ -57,10 +57,10 @@ import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Challenge;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.Success;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.PacketParserUtils;
+import org.jivesoftware.smack.xml.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jxmpp.jid.parts.Resourcepart;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
public abstract class AbstractXmppStateMachineConnection extends AbstractXMPPConnection {
@@ -310,10 +310,10 @@ public abstract class AbstractXmppStateMachineConnection extends AbstractXMPPCon
// Skip the enclosing stream open what is guaranteed to be there.
parser.next();
- int event = parser.getEventType();
+ XmlPullParser.Event event = parser.getEventType();
outerloop: while (true) {
switch (event) {
- case XmlPullParser.START_TAG:
+ case START_ELEMENT:
final String name = parser.getName();
// Note that we don't handle "stream" here as it's done in the splitter.
switch (name) {
@@ -353,8 +353,9 @@ public abstract class AbstractXmppStateMachineConnection extends AbstractXMPPCon
break;
}
break;
- case XmlPullParser.END_DOCUMENT:
+ case END_DOCUMENT:
break outerloop;
+ default: // fall out
}
event = parser.next();
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/XmlEnvironment.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/XmlEnvironment.java
index da69cb240..0e713a04c 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/packet/XmlEnvironment.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/XmlEnvironment.java
@@ -19,7 +19,7 @@ package org.jivesoftware.smack.packet;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.util.StringUtils;
-import org.xmlpull.v1.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParser;
public class XmlEnvironment {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/parsing/StandardExtensionElementProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/parsing/StandardExtensionElementProvider.java
index 4b9f77acf..cceaf4216 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/parsing/StandardExtensionElementProvider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/parsing/StandardExtensionElementProvider.java
@@ -1,6 +1,6 @@
/**
*
- * Copyright 2015 Florian Schmaus.
+ * Copyright 2015-2019 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,8 +26,8 @@ import org.jivesoftware.smack.provider.ExtensionElementProvider;
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 parser for {@link StandardExtensionElement}s.
@@ -47,7 +47,7 @@ public class StandardExtensionElementProvider extends ExtensionElementProvider attributes = new LinkedHashMap<>(namespaceCount + attributeCount);
for (int i = 0; i < namespaceCount; i++) {
@@ -77,19 +77,22 @@ public class StandardExtensionElementProvider extends ExtensionElementProvider {
@@ -34,9 +34,9 @@ public class BindIQProvider extends IQProvider {
String name;
Bind bind = null;
outerloop: while (true) {
- int eventType = parser.next();
+ XmlPullParser.Event eventType = parser.next();
switch (eventType) {
- case XmlPullParser.START_TAG:
+ case START_ELEMENT:
name = parser.getName();
switch (name) {
case "resource":
@@ -49,11 +49,14 @@ public class BindIQProvider extends IQProvider {
break;
}
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 bind;
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/BodyElementProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/BodyElementProvider.java
index ad6cefdaf..df85d067c 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/BodyElementProvider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/BodyElementProvider.java
@@ -24,8 +24,8 @@ import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.XmlEnvironment;
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 BodyElementProvider extends ExtensionElementProvider {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/EmbeddedExtensionProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/EmbeddedExtensionProvider.java
index 6226d5d3d..f572d876d 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/EmbeddedExtensionProvider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/EmbeddedExtensionProvider.java
@@ -27,8 +27,8 @@ import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.util.PacketParserUtils;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
+import org.jivesoftware.smack.xml.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParserException;
/**
*
@@ -97,14 +97,14 @@ public abstract class EmbeddedExtensionProvider ext
}
List extensions = new ArrayList<>();
- int event;
+ XmlPullParser.Event event;
do {
event = parser.next();
- if (event == XmlPullParser.START_TAG)
+ if (event == XmlPullParser.Event.START_ELEMENT)
PacketParserUtils.addExtensionElement(extensions, parser, xmlEnvironment);
}
- while (!(event == XmlPullParser.END_TAG && parser.getDepth() == initialDepth));
+ while (!(event == XmlPullParser.Event.END_ELEMENT && parser.getDepth() == initialDepth));
return createReturnExtension(name, namespace, attMap, extensions);
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/IntrospectionProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/IntrospectionProvider.java
index 3c952bbf6..a4c58f406 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/IntrospectionProvider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/IntrospectionProvider.java
@@ -24,8 +24,8 @@ import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.XmlEnvironment;
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 IntrospectionProvider{
@@ -81,9 +81,9 @@ public class IntrospectionProvider{
ParserUtils.assertAtStartTag(parser);
Object object = objectClass.getConstructor().newInstance();
outerloop: while (true) {
- int eventType = parser.next();
+ XmlPullParser.Event eventType = parser.next();
switch (eventType) {
- case XmlPullParser.START_TAG:
+ case START_ELEMENT:
String name = parser.getName();
String stringValue = parser.nextText();
Class> propertyType = object.getClass().getMethod(
@@ -97,11 +97,14 @@ public class IntrospectionProvider{
propertyType).invoke(object, value);
break;
- case XmlPullParser.END_TAG:
+ case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
+ default:
+ // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
+ break;
}
}
ParserUtils.assertAtEndTag(parser);
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/Provider.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/Provider.java
index 46205fd6a..ef1a225d9 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/Provider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/Provider.java
@@ -26,8 +26,8 @@ import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
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;
/**
* Smack provider are the parsers used to deserialize raw XMPP into the according Java {@link Element}s.
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java
index c8b879306..e39f81d26 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/ProviderFileLoader.java
@@ -26,9 +26,8 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.IQ;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserFactory;
+import org.jivesoftware.smack.util.PacketParserUtils;
+import org.jivesoftware.smack.xml.XmlPullParser;
/**
* Loads the {@link IQProvider} and {@link ExtensionElementProvider} information from a standard provider file in preparation
@@ -54,12 +53,10 @@ public class ProviderFileLoader implements ProviderLoader {
public ProviderFileLoader(InputStream providerStream, ClassLoader classLoader) {
// Load processing providers.
try (InputStream is = providerStream) {
- XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
- parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- parser.setInput(is, "UTF-8");
- int eventType = parser.getEventType();
+ XmlPullParser parser = PacketParserUtils.getParserFor(is);
+ XmlPullParser.Event eventType = parser.getEventType();
do {
- if (eventType == XmlPullParser.START_TAG) {
+ if (eventType == XmlPullParser.Event.START_ELEMENT) {
final String typeName = parser.getName();
try {
@@ -134,7 +131,7 @@ public class ProviderFileLoader implements ProviderLoader {
}
eventType = parser.next();
}
- while (eventType != XmlPullParser.END_DOCUMENT);
+ while (eventType != XmlPullParser.Event.END_DOCUMENT);
}
catch (Exception e) {
LOGGER.log(Level.SEVERE, "Unknown error occurred while parsing provider file", e);
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/TlsFailureProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/TlsFailureProvider.java
index 6211e6cc0..2509d89c8 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/TlsFailureProvider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/TlsFailureProvider.java
@@ -19,7 +19,7 @@ package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.TlsProceed;
import org.jivesoftware.smack.packet.XmlEnvironment;
-import org.xmlpull.v1.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParser;
public final class TlsFailureProvider extends NonzaProvider {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/provider/TlsProceedProvider.java b/smack-core/src/main/java/org/jivesoftware/smack/provider/TlsProceedProvider.java
index 3be9f904f..f8e8b1158 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/provider/TlsProceedProvider.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/provider/TlsProceedProvider.java
@@ -19,7 +19,7 @@ package org.jivesoftware.smack.provider;
import org.jivesoftware.smack.packet.TlsFailure;
import org.jivesoftware.smack.packet.XmlEnvironment;
-import org.xmlpull.v1.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParser;
public final class TlsProceedProvider extends NonzaProvider {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
index dd065fe92..13ce501fb 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/PacketParserUtils.java
@@ -17,18 +17,19 @@
package org.jivesoftware.smack.util;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.logging.Level;
import java.util.logging.Logger;
-import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.compress.packet.Compress;
import org.jivesoftware.smack.packet.EmptyResultIQ;
import org.jivesoftware.smack.packet.ErrorIQ;
@@ -49,11 +50,11 @@ import org.jivesoftware.smack.provider.ExtensionElementProvider;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure;
+import org.jivesoftware.smack.xml.SmackXmlParser;
+import org.jivesoftware.smack.xml.XmlPullParser;
+import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jxmpp.jid.Jid;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlPullParserFactory;
/**
* Utility class that helps to parse packets. Any parsing packets method that must be shared
@@ -64,51 +65,27 @@ import org.xmlpull.v1.XmlPullParserFactory;
public class PacketParserUtils {
private static final Logger LOGGER = Logger.getLogger(PacketParserUtils.class.getName());
- public static final String FEATURE_XML_ROUNDTRIP = "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
-
- private static final XmlPullParserFactory XML_PULL_PARSER_FACTORY;
-
- /**
- * True if the XmlPullParser supports the XML_ROUNDTRIP feature.
- */
- public static final boolean XML_PULL_PARSER_SUPPORTS_ROUNDTRIP;
-
- static {
- // Ensure that Smack is initialized.
- SmackConfiguration.getVersion();
-
- XmlPullParser xmlPullParser;
- boolean roundtrip = false;
- try {
- XML_PULL_PARSER_FACTORY = XmlPullParserFactory.newInstance();
- xmlPullParser = XML_PULL_PARSER_FACTORY.newPullParser();
- try {
- xmlPullParser.setFeature(FEATURE_XML_ROUNDTRIP, true);
- // We could successfully set the feature
- roundtrip = true;
- } catch (XmlPullParserException e) {
- // Doesn't matter if FEATURE_XML_ROUNDTRIP isn't available
- LOGGER.log(Level.FINEST, "XmlPullParser does not support XML_ROUNDTRIP", e);
- }
- }
- catch (XmlPullParserException e) {
- // Something really bad happened
- throw new AssertionError(e);
- }
- XML_PULL_PARSER_SUPPORTS_ROUNDTRIP = roundtrip;
- }
-
// TODO: Rename argument name from 'stanza' to 'element'.
public static XmlPullParser getParserFor(String stanza) throws XmlPullParserException, IOException {
return getParserFor(new StringReader(stanza));
}
+ public static XmlPullParser getParserFor(InputStream inputStream) throws XmlPullParserException {
+ InputStreamReader inputStreamReader;
+ try {
+ inputStreamReader = new InputStreamReader(inputStream, StringUtils.UTF8);
+ } catch (UnsupportedEncodingException e) {
+ throw new AssertionError(e);
+ }
+ return SmackXmlParser.newXmlParser(inputStreamReader);
+ }
+
public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException {
- XmlPullParser parser = newXmppParser(reader);
+ XmlPullParser parser = SmackXmlParser.newXmlParser(reader);
// Wind the parser forward to the first start tag
- int event = parser.getEventType();
- while (event != XmlPullParser.START_TAG) {
- if (event == XmlPullParser.END_DOCUMENT) {
+ XmlPullParser.Event event = parser.getEventType();
+ while (event != XmlPullParser.Event.START_ELEMENT) {
+ if (event == XmlPullParser.Event.END_DOCUMENT) {
throw new IllegalArgumentException("Document contains no start tag");
}
event = parser.next();
@@ -116,26 +93,6 @@ public class PacketParserUtils {
return parser;
}
- public static XmlPullParser getParserFor(String stanza, String startTag)
- throws XmlPullParserException, IOException {
- XmlPullParser parser = getParserFor(stanza);
-
- while (true) {
- int event = parser.getEventType();
- String name = parser.getName();
- if (event == XmlPullParser.START_TAG && name.equals(startTag)) {
- break;
- }
- else if (event == XmlPullParser.END_DOCUMENT) {
- throw new IllegalArgumentException("Could not find start tag '" + startTag
- + "' in stanza: " + stanza);
- }
- parser.next();
- }
-
- return parser;
- }
-
@SuppressWarnings("unchecked")
public static S parseStanza(String stanza) throws Exception {
return (S) parseStanza(getParserFor(stanza), null);
@@ -166,53 +123,6 @@ public class PacketParserUtils {
}
}
- /**
- * Creates a new XmlPullParser suitable for parsing XMPP. This means in particular that
- * FEATURE_PROCESS_NAMESPACES is enabled.
- *
- * Note that not all XmlPullParser implementations will return a String on
- * getText() if the parser is on START_TAG or END_TAG. So you must not rely on this
- * behavior when using the parser.
- *
- *
- * @return A suitable XmlPullParser for XMPP parsing
- * @throws XmlPullParserException
- */
- public static XmlPullParser newXmppParser() throws XmlPullParserException {
- XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
- parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- if (XML_PULL_PARSER_SUPPORTS_ROUNDTRIP) {
- try {
- parser.setFeature(FEATURE_XML_ROUNDTRIP, true);
- }
- catch (XmlPullParserException e) {
- LOGGER.log(Level.SEVERE,
- "XmlPullParser does not support XML_ROUNDTRIP, although it was first determined to be supported",
- e);
- }
- }
- return parser;
- }
-
- /**
- * Creates a new XmlPullParser suitable for parsing XMPP. This means in particular that
- * FEATURE_PROCESS_NAMESPACES is enabled.
- *
- * Note that not all XmlPullParser implementations will return a String on
- * getText() if the parser is on START_TAG or END_TAG. So you must not rely on this
- * behavior when using the parser.
- *
- *
- * @param reader
- * @return A suitable XmlPullParser for XMPP parsing
- * @throws XmlPullParserException
- */
- public static XmlPullParser newXmppParser(Reader reader) throws XmlPullParserException {
- XmlPullParser parser = newXmppParser();
- parser.setInput(reader);
- return parser;
- }
-
public static Message parseMessage(XmlPullParser parser) throws XmlPullParserException, IOException, SmackParsingException {
return parseMessage(parser, null);
}
@@ -249,9 +159,9 @@ public class PacketParserUtils {
// in arbitrary sub-elements.
String thread = null;
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();
String namespace = parser.getNamespace();
switch (elementName) {
@@ -276,11 +186,12 @@ public class PacketParserUtils {
break;
}
break;
- case XmlPullParser.END_TAG:
+ case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
+ default: // fall out
}
}
@@ -295,9 +206,9 @@ public class PacketParserUtils {
/**
* Returns the textual content of an element as String. After this method returns the parser
- * position will be END_TAG, following the established pull parser calling convention.
+ * position will be END_ELEMENT, following the established pull parser calling convention.
*
- * The parser must be positioned on a START_TAG of an element which MUST NOT contain Mixed
+ * The parser must be positioned on a START_ELEMENT of an element which MUST NOT contain Mixed
* Content (as defined in XML 3.2.2), or else an XmlPullParserException will be thrown.
*
* This method is used for the parts where the XMPP specification requires elements that contain
@@ -309,41 +220,36 @@ public class PacketParserUtils {
* @throws IOException
*/
public static String parseElementText(XmlPullParser parser) throws XmlPullParserException, IOException {
- assert (parser.getEventType() == XmlPullParser.START_TAG);
+ assert (parser.getEventType() == XmlPullParser.Event.START_ELEMENT);
String res;
- if (parser.isEmptyElementTag()) {
- res = "";
- }
- else {
- // Advance to the text of the Element
- int event = parser.next();
- if (event != XmlPullParser.TEXT) {
- if (event == XmlPullParser.END_TAG) {
- // Assume this is the end tag of the start tag at the
- // beginning of this method. Typical examples where this
- // happens are body elements containing the empty string,
- // ie. , which appears to be valid XMPP, or a
- // least it's not explicitly forbidden by RFC 6121 5.2.3
- return "";
- } else {
- throw new XmlPullParserException(
- "Non-empty element tag not followed by text, while Mixed Content (XML 3.2.2) is disallowed");
- }
- }
- res = parser.getText();
- event = parser.next();
- if (event != XmlPullParser.END_TAG) {
+ // Advance to the text of the Element
+ XmlPullParser.Event event = parser.next();
+ if (event != XmlPullParser.Event.TEXT_CHARACTERS) {
+ if (event == XmlPullParser.Event.END_ELEMENT) {
+ // Assume this is the end tag of the start tag at the
+ // beginning of this method. Typical examples where this
+ // happens are body elements containing the empty string,
+ // ie. , which appears to be valid XMPP, or a
+ // least it's not explicitly forbidden by RFC 6121 5.2.3
+ return "";
+ } else {
throw new XmlPullParserException(
- "Non-empty element tag contains child-elements, while Mixed Content (XML 3.2.2) is disallowed");
+ "Non-empty element tag not followed by text, while Mixed Content (XML 3.2.2) is disallowed");
}
}
+ res = parser.getText();
+ event = parser.next();
+ if (event != XmlPullParser.Event.END_ELEMENT) {
+ throw new XmlPullParserException(
+ "Non-empty element tag contains child-elements, while Mixed Content (XML 3.2.2) is disallowed");
+ }
return res;
}
/**
* Returns the current element as string.
*
- * The parser must be positioned on START_TAG.
+ * The parser must be positioned on START_ELEMENT.
*
* Note that only the outermost namespace attributes ("xmlns") will be returned, not nested ones.
*
@@ -359,37 +265,10 @@ public class PacketParserUtils {
public static CharSequence parseElement(XmlPullParser parser,
boolean fullNamespaces) throws XmlPullParserException,
IOException {
- assert (parser.getEventType() == XmlPullParser.START_TAG);
+ assert (parser.getEventType() == XmlPullParser.Event.START_ELEMENT);
return parseContentDepth(parser, parser.getDepth(), fullNamespaces);
}
- /**
- * Returns the content of a element.
- *
- * The parser must be positioned on the START_TAG of the element which content is going to get
- * returned. If the current element is the empty element, then the empty string is returned. If
- * it is a element which contains just text, then just the text is returned. If it contains
- * nested elements (and text), then everything from the current opening tag to the corresponding
- * closing tag of the same depth is returned as String.
- *
- * Note that only the outermost namespace attributes ("xmlns") will be returned, not nested ones.
- *
- * @param parser the XML pull parser
- * @return the content of a tag
- * @throws XmlPullParserException if parser encounters invalid XML
- * @throws IOException if an IO error occurs
- */
- public static CharSequence parseContent(XmlPullParser parser)
- throws XmlPullParserException, IOException {
- assert (parser.getEventType() == XmlPullParser.START_TAG);
- if (parser.isEmptyElementTag()) {
- return "";
- }
- // Advance the parser, since we want to parse the content of the current element
- parser.next();
- return parseContentDepth(parser, parser.getDepth(), false);
- }
-
public static CharSequence parseContentDepth(XmlPullParser parser, int depth)
throws XmlPullParserException, IOException {
return parseContentDepth(parser, depth, false);
@@ -402,7 +281,7 @@ public class PacketParserUtils {
* parent elements will be added to child elements that don't define a different namespace.
*