mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-21 11:32:05 +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:
parent
b3646abecd
commit
4133eb175c
414 changed files with 3855 additions and 2041 deletions
57
build.gradle
57
build.gradle
|
@ -24,6 +24,7 @@ apply from: 'version.gradle'
|
|||
|
||||
allprojects {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'java-library'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'jacoco'
|
||||
|
@ -80,6 +81,8 @@ allprojects {
|
|||
':smack-omemo',
|
||||
':smack-omemo-signal',
|
||||
':smack-openpgp',
|
||||
':smack-xmlparser',
|
||||
':smack-xmlparser-xpp3',
|
||||
].collect{ project(it) }
|
||||
androidBootClasspathProjects = [
|
||||
':smack-android',
|
||||
|
@ -97,13 +100,37 @@ allprojects {
|
|||
':smack-omemo-signal',
|
||||
':smack-omemo-signal-integration-test',
|
||||
].collect{ project(it) }
|
||||
// When this list is empty, then move the according javadoc
|
||||
// tool Werror option into the global configure section.
|
||||
nonStrictJavadocProjects = [
|
||||
':smack-bosh',
|
||||
':smack-core',
|
||||
':smack-experimental',
|
||||
':smack-extensions',
|
||||
':smack-im',
|
||||
':smack-integration-test',
|
||||
':smack-jingle-old',
|
||||
':smack-legacy',
|
||||
':smack-omemo',
|
||||
':smack-tcp',
|
||||
].collect{ project(it) }
|
||||
// Lazily evaluate the Android bootClasspath and offline
|
||||
// Javadoc using a closure, so that targets which do not
|
||||
// require it are still able to succeed without an Android
|
||||
// SDK.
|
||||
androidBootClasspath = { getAndroidRuntimeJar() }
|
||||
androidJavadocOffline = { getAndroidJavadocOffline() }
|
||||
junitVersion = '5.2.0'
|
||||
junit4Projects = [
|
||||
':smack-core',
|
||||
':smack-extensions',
|
||||
':smack-im',
|
||||
':smack-integration-test',
|
||||
':smack-omemo',
|
||||
':smack-omemo-signal',
|
||||
':smack-openpgp',
|
||||
].collect { project(it) }
|
||||
junitVersion = '5.4.2'
|
||||
powerMockVersion = '1.7.3'
|
||||
}
|
||||
group = 'org.igniterealtime.smack'
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
|
@ -114,6 +141,12 @@ allprojects {
|
|||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
|
||||
// Enable once the tests are fixed that sometimes break if
|
||||
// they are executed in parallel (.e.g Socks5)
|
||||
// maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
|
||||
|
||||
// Enable full stacktraces of failed tests. Especially handy
|
||||
// for environments like Travis.
|
||||
testLogging {
|
||||
|
@ -232,6 +265,10 @@ allprojects {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||||
|
||||
errorprone 'com.google.errorprone:error_prone_core:2.3.2'
|
||||
errorproneJavac('com.google.errorprone:javac:9+181-r4173-1')
|
||||
}
|
||||
|
@ -241,6 +278,15 @@ allprojects {
|
|||
test { dependsOn javadoc }
|
||||
}
|
||||
|
||||
configure (junit4Projects) {
|
||||
dependencies {
|
||||
testImplementation "org.junit.vintage:junit-vintage-engine:$junitVersion"
|
||||
testImplementation "org.powermock:powermock-module-junit4:$powerMockVersion"
|
||||
testImplementation "org.powermock:powermock-module-junit4-rule:$powerMockVersion"
|
||||
testImplementation "org.powermock:powermock-api-mockito2:$powerMockVersion"
|
||||
}
|
||||
}
|
||||
|
||||
gradle.taskGraph.whenReady { taskGraph ->
|
||||
if (signingRequired
|
||||
&& taskGraph.allTasks.any { it instanceof Sign }) {
|
||||
|
@ -532,6 +578,15 @@ subprojects*.jar {
|
|||
}
|
||||
}
|
||||
|
||||
configure(subprojects - nonStrictJavadocProjects) {
|
||||
tasks.withType(Javadoc) {
|
||||
// Abort on javadoc warnings.
|
||||
// See JDK-8200363 (https://bugs.openjdk.java.net/browse/JDK-8200363)
|
||||
// for information about the -Xwerror option.
|
||||
options.addStringOption('Xwerror', '-quiet')
|
||||
}
|
||||
}
|
||||
|
||||
configure(subprojects - gplLicensedProjects) {
|
||||
checkstyle {
|
||||
configProperties.checkstyleLicenseHeader = "header"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,14 +169,10 @@ recommended when using Smack.
|
|||
</p>
|
||||
|
||||
<p>
|
||||
If you dont' use a
|
||||
dependency resolution system, like gradle or maven, then you will need
|
||||
to download at least
|
||||
the <a href="http://www.extreme.indiana.edu/xgws/xsoap/xpp/mxp1/">Xml
|
||||
Pull Parser 3rd Edition (XPP3) library</a> or any other library that
|
||||
implements the XmlPullParser interface
|
||||
(like <a href="http://kxml.org/">kXML</a>) and the set of
|
||||
<a href="http://jxmpp.org">jXMPP libraries</a>.
|
||||
Smack tries to depend on as few as possible libraries. The only
|
||||
requirement is <a href="http://jxmpp.org">jXMPP</a>. For DNS
|
||||
resolution we recommend to
|
||||
use <a href="http://minidns.org">MiniDNS</a>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Exception> 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<Exception> 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 {
|
||||
|
|
|
@ -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<Compressed> {
|
||||
|
||||
|
|
|
@ -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<Failure> {
|
||||
|
||||
|
@ -46,9 +46,9 @@ public final class FailureProvider extends NonzaProvider<Failure> {
|
|||
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<Failure> {
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
case END_ELEMENT:
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
default: // fall out
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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<S
|
|||
String name = parser.getName();
|
||||
String namespace = parser.getNamespace();
|
||||
StandardExtensionElement.Builder builder = StandardExtensionElement.builder(name, namespace);
|
||||
final int namespaceCount = parser.getNamespaceCount(initialDepth);
|
||||
final int namespaceCount = parser.getNamespaceCount();
|
||||
final int attributeCount = parser.getAttributeCount();
|
||||
final Map<String, String> attributes = new LinkedHashMap<>(namespaceCount + attributeCount);
|
||||
for (int i = 0; i < namespaceCount; i++) {
|
||||
|
@ -77,19 +77,22 @@ public class StandardExtensionElementProvider extends ExtensionElementProvider<S
|
|||
builder.addAttributes(attributes);
|
||||
|
||||
outerloop: while (true) {
|
||||
int event = parser.next();
|
||||
XmlPullParser.Event event = parser.next();
|
||||
switch (event) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
builder.addElement(parse(parser, parser.getDepth(), xmlEnvironment));
|
||||
break;
|
||||
case XmlPullParser.TEXT:
|
||||
case TEXT_CHARACTERS:
|
||||
builder.setText(parser.getText());
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
case END_ELEMENT:
|
||||
if (initialDepth == parser.getDepth()) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,12 @@ import java.io.IOException;
|
|||
|
||||
import org.jivesoftware.smack.packet.Bind;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jxmpp.jid.EntityFullJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.jid.parts.Resourcepart;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class BindIQProvider extends IQProvider<Bind> {
|
||||
|
||||
|
@ -34,9 +34,9 @@ public class BindIQProvider extends IQProvider<Bind> {
|
|||
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<Bind> {
|
|||
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;
|
||||
|
|
|
@ -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<Message.Body> {
|
||||
|
||||
|
|
|
@ -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<PE extends ExtensionElement> ext
|
|||
}
|
||||
|
||||
List<ExtensionElement> 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<TlsProceed> {
|
||||
|
||||
|
|
|
@ -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<TlsFailure> {
|
||||
|
||||
|
|
|
@ -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 extends Stanza> 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.
|
||||
* <p>
|
||||
* Note that not all XmlPullParser implementations will return a String on
|
||||
* <code>getText()</code> if the parser is on START_TAG or END_TAG. So you must not rely on this
|
||||
* behavior when using the parser.
|
||||
* </p>
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* Note that not all XmlPullParser implementations will return a String on
|
||||
* <code>getText()</code> if the parser is on START_TAG or END_TAG. So you must not rely on this
|
||||
* behavior when using the parser.
|
||||
* </p>
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
* 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. <body></body>, 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. <body></body>, 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.
|
||||
* <p>
|
||||
* The parser must be positioned on START_TAG.
|
||||
* The parser must be positioned on START_ELEMENT.
|
||||
* </p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
* 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.
|
||||
* <p>
|
||||
* This method is able to parse the content with MX- and KXmlParser. KXmlParser does not support
|
||||
* xml-roundtrip. i.e. return a String on getText() on START_TAG and END_TAG. We check for the
|
||||
* xml-roundtrip. i.e. return a String on getText() on START_ELEMENT and END_ELEMENT. We check for the
|
||||
* XML_ROUNDTRIP feature. If it's not found we are required to work around this limitation, which
|
||||
* results in only partial support for XML namespaces ("xmlns"): Only the outermost namespace of
|
||||
* elements will be included in the resulting String, if <code>fullNamespaces</code> is set to false.
|
||||
|
@ -419,7 +298,7 @@ public class PacketParserUtils {
|
|||
* @throws IOException
|
||||
*/
|
||||
public static CharSequence parseContentDepth(XmlPullParser parser, int depth, boolean fullNamespaces) throws XmlPullParserException, IOException {
|
||||
if (parser.getFeature(FEATURE_XML_ROUNDTRIP)) {
|
||||
if (parser.supportsRoundtrip()) {
|
||||
return parseContentDepthWithRoundtrip(parser, depth, fullNamespaces);
|
||||
} else {
|
||||
return parseContentDepthWithoutRoundtrip(parser, depth, fullNamespaces);
|
||||
|
@ -429,15 +308,21 @@ public class PacketParserUtils {
|
|||
private static CharSequence parseContentDepthWithoutRoundtrip(XmlPullParser parser, int depth,
|
||||
boolean fullNamespaces) throws XmlPullParserException, IOException {
|
||||
XmlStringBuilder xml = new XmlStringBuilder();
|
||||
int event = parser.getEventType();
|
||||
boolean isEmptyElement = false;
|
||||
XmlPullParser.Event event = parser.getEventType();
|
||||
// XmlPullParser reports namespaces in nested elements even if *only* the outer ones defines
|
||||
// it. This 'flag' ensures that when a namespace is set for an element, it won't be set again
|
||||
// in a nested element. It's an ugly workaround that has the potential to break things.
|
||||
String namespaceElement = null;
|
||||
boolean startElementJustSeen = false;
|
||||
outerloop: while (true) {
|
||||
switch (event) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
if (startElementJustSeen) {
|
||||
xml.rightAngleBracket();
|
||||
}
|
||||
else {
|
||||
startElementJustSeen = true;
|
||||
}
|
||||
xml.halfOpenElement(parser.getName());
|
||||
if (namespaceElement == null || fullNamespaces) {
|
||||
String namespace = parser.getNamespace();
|
||||
|
@ -449,18 +334,11 @@ public class PacketParserUtils {
|
|||
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
||||
xml.attribute(parser.getAttributeName(i), parser.getAttributeValue(i));
|
||||
}
|
||||
if (parser.isEmptyElementTag()) {
|
||||
xml.closeEmptyElement();
|
||||
isEmptyElement = true;
|
||||
}
|
||||
else {
|
||||
xml.rightAngleBracket();
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
if (isEmptyElement) {
|
||||
// Do nothing as the element was already closed, just reset the flag
|
||||
isEmptyElement = false;
|
||||
case END_ELEMENT:
|
||||
if (startElementJustSeen) {
|
||||
xml.closeEmptyElement();
|
||||
startElementJustSeen = false;
|
||||
}
|
||||
else {
|
||||
xml.closeElement(parser.getName());
|
||||
|
@ -474,9 +352,16 @@ public class PacketParserUtils {
|
|||
break outerloop;
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.TEXT:
|
||||
case TEXT_CHARACTERS:
|
||||
if (startElementJustSeen) {
|
||||
startElementJustSeen = false;
|
||||
xml.rightAngleBracket();
|
||||
}
|
||||
xml.escape(parser.getText());
|
||||
break;
|
||||
default:
|
||||
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
||||
break;
|
||||
}
|
||||
event = parser.next();
|
||||
}
|
||||
|
@ -485,20 +370,39 @@ public class PacketParserUtils {
|
|||
|
||||
private static CharSequence parseContentDepthWithRoundtrip(XmlPullParser parser, int depth, boolean fullNamespaces)
|
||||
throws XmlPullParserException, IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int event = parser.getEventType();
|
||||
XmlStringBuilder sb = new XmlStringBuilder();
|
||||
XmlPullParser.Event event = parser.getEventType();
|
||||
boolean startElementJustSeen = false;
|
||||
outerloop: while (true) {
|
||||
// Only append the text if the parser is not on on an empty element' start tag. Empty elements are reported
|
||||
// twice, so in order to prevent duplication we only add their text when we are on their end tag.
|
||||
if (!(event == XmlPullParser.START_TAG && parser.isEmptyElementTag())) {
|
||||
switch (event) {
|
||||
case START_ELEMENT:
|
||||
if (startElementJustSeen) {
|
||||
sb.rightAngleBracket();
|
||||
}
|
||||
startElementJustSeen = true;
|
||||
break;
|
||||
case END_ELEMENT:
|
||||
boolean isEmptyElement = false;
|
||||
if (startElementJustSeen) {
|
||||
isEmptyElement = true;
|
||||
startElementJustSeen = false;
|
||||
}
|
||||
if (!isEmptyElement) {
|
||||
String text = parser.getText();
|
||||
sb.append(text);
|
||||
}
|
||||
if (parser.getDepth() <= depth) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
startElementJustSeen = false;
|
||||
CharSequence text = parser.getText();
|
||||
if (event == XmlPullParser.TEXT) {
|
||||
text = StringUtils.escapeForXmlText(text);
|
||||
if (event == XmlPullParser.Event.TEXT_CHARACTERS) {
|
||||
text = StringUtils.escapeForXml(text);
|
||||
}
|
||||
sb.append(text);
|
||||
}
|
||||
if (event == XmlPullParser.END_TAG && parser.getDepth() <= depth) {
|
||||
break outerloop;
|
||||
break;
|
||||
}
|
||||
event = parser.next();
|
||||
}
|
||||
|
@ -543,9 +447,9 @@ public class PacketParserUtils {
|
|||
|
||||
// Parse sub-elements
|
||||
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) {
|
||||
|
@ -587,11 +491,14 @@ public class PacketParserUtils {
|
|||
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 presence;
|
||||
|
@ -622,10 +529,10 @@ public class PacketParserUtils {
|
|||
final IQ.Type type = IQ.Type.fromString(parser.getAttributeValue("", "type"));
|
||||
|
||||
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) {
|
||||
|
@ -640,7 +547,7 @@ public class PacketParserUtils {
|
|||
iqPacket = provider.parse(parser, outerXmlEnvironment);
|
||||
}
|
||||
// Note that if we reach this code, it is guranteed that the result IQ contained a child element
|
||||
// (RFC 6120 § 8.2.3 6) because otherwhise we would have reached the END_TAG first.
|
||||
// (RFC 6120 § 8.2.3 6) because otherwhise we would have reached the END_ELEMENT first.
|
||||
else {
|
||||
// No Provider found for the IQ stanza, parse it to an UnparsedIQ instance
|
||||
// so that the content of the IQ can be examined later on
|
||||
|
@ -649,11 +556,14 @@ public class PacketParserUtils {
|
|||
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;
|
||||
}
|
||||
}
|
||||
// Decide what to do when an IQ packet was not understood
|
||||
|
@ -694,15 +604,15 @@ public class PacketParserUtils {
|
|||
List<String> mechanisms = new ArrayList<String>();
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
String elementName = parser.getName();
|
||||
if (elementName.equals("mechanism")) {
|
||||
mechanisms.add(parser.nextText());
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getName().equals("mechanisms")) {
|
||||
done = true;
|
||||
}
|
||||
|
@ -721,14 +631,14 @@ public class PacketParserUtils {
|
|||
*/
|
||||
public static Compress.Feature parseCompressionFeature(XmlPullParser parser)
|
||||
throws IOException, XmlPullParserException {
|
||||
assert (parser.getEventType() == XmlPullParser.START_TAG);
|
||||
assert (parser.getEventType() == XmlPullParser.Event.START_ELEMENT);
|
||||
String name;
|
||||
final int initialDepth = parser.getDepth();
|
||||
List<String> methods = new LinkedList<>();
|
||||
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 "method":
|
||||
|
@ -736,7 +646,7 @@ public class PacketParserUtils {
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
case END_ELEMENT:
|
||||
name = parser.getName();
|
||||
switch (name) {
|
||||
case Compress.Feature.ELEMENT:
|
||||
|
@ -744,9 +654,13 @@ public class PacketParserUtils {
|
|||
break outerloop;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert (parser.getEventType() == XmlPullParser.END_TAG);
|
||||
assert (parser.getEventType() == XmlPullParser.Event.END_ELEMENT);
|
||||
assert (parser.getDepth() == initialDepth);
|
||||
return new Compress.Feature(methods);
|
||||
}
|
||||
|
@ -782,9 +696,9 @@ public class PacketParserUtils {
|
|||
String condition = null;
|
||||
Map<String, String> descriptiveTexts = null;
|
||||
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();
|
||||
if (name.equals("text")) {
|
||||
descriptiveTexts = parseDescriptiveTexts(parser, descriptiveTexts);
|
||||
|
@ -794,11 +708,14 @@ public class PacketParserUtils {
|
|||
condition = parser.getName();
|
||||
}
|
||||
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 new SASLFailure(condition, descriptiveTexts);
|
||||
|
@ -826,9 +743,9 @@ public class PacketParserUtils {
|
|||
String conditionText = null;
|
||||
XmlEnvironment streamErrorXmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);
|
||||
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) {
|
||||
|
@ -841,8 +758,9 @@ public class PacketParserUtils {
|
|||
// If it's not a text element, that is qualified by the StreamError.NAMESPACE,
|
||||
// then it has to be the stream error code
|
||||
condition = StreamError.Condition.fromString(name);
|
||||
if (!parser.isEmptyElementTag()) {
|
||||
conditionText = parser.nextText();
|
||||
conditionText = parser.nextText();
|
||||
if (conditionText.isEmpty()) {
|
||||
conditionText = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -852,11 +770,14 @@ public class PacketParserUtils {
|
|||
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 new StreamError(condition, conditionText, descriptiveTexts, extensions);
|
||||
|
@ -888,9 +809,9 @@ public class PacketParserUtils {
|
|||
builder.setErrorGenerator(parser.getAttributeValue("", "by"));
|
||||
|
||||
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) {
|
||||
|
@ -901,8 +822,9 @@ public class PacketParserUtils {
|
|||
break;
|
||||
default:
|
||||
builder.setCondition(StanzaError.Condition.fromString(name));
|
||||
if (!parser.isEmptyElementTag()) {
|
||||
builder.setConditionText(parser.nextText());
|
||||
String conditionText = parser.nextText();
|
||||
if (!conditionText.isEmpty()) {
|
||||
builder.setConditionText(conditionText);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -911,10 +833,14 @@ public class PacketParserUtils {
|
|||
PacketParserUtils.addExtensionElement(extensions, parser, name, namespace, stanzaErrorXmlEnvironment);
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
case END_ELEMENT:
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
||||
break;
|
||||
}
|
||||
}
|
||||
builder.setExtensions(extensions).setDescriptiveTexts(descriptiveTexts);
|
||||
|
@ -949,14 +875,14 @@ public class PacketParserUtils {
|
|||
|
||||
public static StartTls parseStartTlsFeature(XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException {
|
||||
assert (parser.getEventType() == XmlPullParser.START_TAG);
|
||||
assert (parser.getEventType() == XmlPullParser.Event.START_ELEMENT);
|
||||
assert (parser.getNamespace().equals(StartTls.NAMESPACE));
|
||||
int initalDepth = parser.getDepth();
|
||||
boolean required = false;
|
||||
outerloop: while (true) {
|
||||
int event = parser.next();
|
||||
XmlPullParser.Event event = parser.next();
|
||||
switch (event) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
String name = parser.getName();
|
||||
switch (name) {
|
||||
case "required":
|
||||
|
@ -964,13 +890,17 @@ public class PacketParserUtils {
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
case END_ELEMENT:
|
||||
if (parser.getDepth() == initalDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert (parser.getEventType() == XmlPullParser.END_TAG);
|
||||
assert (parser.getEventType() == XmlPullParser.Event.END_ELEMENT);
|
||||
return new StartTls(required);
|
||||
}
|
||||
|
||||
|
@ -978,14 +908,11 @@ public class PacketParserUtils {
|
|||
ParserUtils.assertAtStartTag(parser);
|
||||
final int initialDepth = parser.getDepth();
|
||||
boolean optional = false;
|
||||
if (parser.isEmptyElementTag()) {
|
||||
return new Session.Feature(optional);
|
||||
}
|
||||
|
||||
outerloop: while (true) {
|
||||
int event = parser.next();
|
||||
XmlPullParser.Event event = parser.next();
|
||||
switch (event) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
String name = parser.getName();
|
||||
switch (name) {
|
||||
case Session.Feature.OPTIONAL_ELEMENT:
|
||||
|
@ -993,10 +920,14 @@ public class PacketParserUtils {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ import javax.xml.namespace.QName;
|
|||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException.SmackTextParseException;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException.SmackUriSyntaxParsingException;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.jxmpp.jid.EntityFullJid;
|
||||
|
@ -38,8 +40,6 @@ import org.jxmpp.jid.impl.JidCreate;
|
|||
import org.jxmpp.jid.parts.Resourcepart;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.jxmpp.util.XmppDateTime;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class ParserUtils {
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class ParserUtils {
|
|||
public static final String JID = "jid";
|
||||
|
||||
public static void assertAtStartTag(XmlPullParser parser) throws XmlPullParserException {
|
||||
assert (parser.getEventType() == XmlPullParser.START_TAG);
|
||||
assert (parser.getEventType() == XmlPullParser.Event.START_ELEMENT);
|
||||
}
|
||||
|
||||
public static void assertAtStartTag(XmlPullParser parser, String name) throws XmlPullParserException {
|
||||
|
@ -58,13 +58,13 @@ public class ParserUtils {
|
|||
}
|
||||
|
||||
public static void assertAtEndTag(XmlPullParser parser) throws XmlPullParserException {
|
||||
assert (parser.getEventType() == XmlPullParser.END_TAG);
|
||||
assert (parser.getEventType() == XmlPullParser.Event.END_ELEMENT);
|
||||
}
|
||||
|
||||
public static void forwardToEndTagOfDepth(XmlPullParser parser, int depth)
|
||||
throws XmlPullParserException, IOException {
|
||||
int event = parser.getEventType();
|
||||
while (!(event == XmlPullParser.END_TAG && parser.getDepth() == depth)) {
|
||||
XmlPullParser.Event event = parser.getEventType();
|
||||
while (!(event == XmlPullParser.Event.END_ELEMENT && parser.getDepth() == depth)) {
|
||||
event = parser.next();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 Florian Schmaus
|
||||
* Copyright 2018-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.
|
||||
|
@ -22,9 +22,9 @@ import org.jivesoftware.smack.compress.packet.Failure;
|
|||
import org.jivesoftware.smack.packet.StanzaError;
|
||||
import org.jivesoftware.smack.packet.StanzaError.Condition;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class FailureProviderTest {
|
||||
|
||||
|
|
|
@ -18,19 +18,25 @@ package org.jivesoftware.smack.packet;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.packet.StreamError.Condition;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.test.util.SmackTestUtil;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
public class StreamErrorTest {
|
||||
|
||||
@Test
|
||||
public void testParsingOfSimpleStreamError() {
|
||||
StreamError error = null;
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testParsingOfSimpleStreamError(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
final String xml =
|
||||
// Usually the stream:stream element has more attributes (to, version, ...)
|
||||
// We omit those, since they are not relevant for testing
|
||||
|
@ -39,19 +45,17 @@ public class StreamErrorTest {
|
|||
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-streams' /> +" +
|
||||
"</stream:error>" +
|
||||
"</stream:stream>";
|
||||
try {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error");
|
||||
error = PacketParserUtils.parseStreamError(parser);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(xml, "error", parserKind);
|
||||
StreamError error = PacketParserUtils.parseStreamError(parser);
|
||||
|
||||
assertNotNull(error);
|
||||
assertEquals(Condition.conflict, error.getCondition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingOfStreamErrorWithText() {
|
||||
StreamError error = null;
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testParsingOfStreamErrorWithText(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
final String xml =
|
||||
// Usually the stream:stream element has more attributes (to, version, ...)
|
||||
// We omit those, since they are not relevant for testing
|
||||
|
@ -63,20 +67,19 @@ public class StreamErrorTest {
|
|||
"</text>" +
|
||||
"</stream:error>" +
|
||||
"</stream:stream>";
|
||||
try {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error");
|
||||
error = PacketParserUtils.parseStreamError(parser);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(xml, "error", parserKind);
|
||||
StreamError error = PacketParserUtils.parseStreamError(parser);
|
||||
|
||||
assertNotNull(error);
|
||||
assertEquals(Condition.conflict, error.getCondition());
|
||||
assertEquals("Replaced by new connection", error.getDescriptiveText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingOfStreamErrorWithTextAndOptionalElement() {
|
||||
StreamError error = null;
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testParsingOfStreamErrorWithTextAndOptionalElement(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
final String xml =
|
||||
// Usually the stream:stream element has more attributes (to, version, ...)
|
||||
// We omit those, since they are not relevant for testing
|
||||
|
@ -91,12 +94,10 @@ public class StreamErrorTest {
|
|||
"</appSpecificElement>" +
|
||||
"</stream:error>" +
|
||||
"</stream:stream>";
|
||||
try {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error");
|
||||
error = PacketParserUtils.parseStreamError(parser);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(xml, "error", parserKind);
|
||||
StreamError error = PacketParserUtils.parseStreamError(parser);
|
||||
|
||||
assertNotNull(error);
|
||||
assertEquals(Condition.conflict, error.getCondition());
|
||||
assertEquals("Replaced by new connection", error.getDescriptiveText());
|
||||
|
@ -104,21 +105,20 @@ public class StreamErrorTest {
|
|||
assertNotNull(appSpecificElement);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamErrorXmlNotWellFormed() {
|
||||
StreamError error = null;
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testStreamErrorXmlNotWellFormed(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
final String xml =
|
||||
// Usually the stream:stream element has more attributes (to, version, ...)
|
||||
// We omit those, since they are not relevant for testing
|
||||
"<stream:stream from='im.example.com' id='++TR84Sm6A3hnt3Q065SnAbbk3Y=' xmlns:stream='http://etherx.jabber.org/streams'>" +
|
||||
"<stream:error><xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>" +
|
||||
"</stream:stream>";
|
||||
try {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(xml, "error");
|
||||
error = PacketParserUtils.parseStreamError(parser);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(xml, "error", parserKind);
|
||||
StreamError error = PacketParserUtils.parseStreamError(parser);
|
||||
|
||||
assertNotNull(error);
|
||||
assertEquals(Condition.not_well_formed, error.getCondition());
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
|||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class ParsingExceptionTest {
|
||||
|
||||
|
@ -39,6 +39,7 @@ public class ParsingExceptionTest {
|
|||
"<extension2 xmlns='namespace'>" +
|
||||
"<bar node='testNode'>" +
|
||||
"<i id='testid1'>" +
|
||||
"text content" +
|
||||
"</i>" +
|
||||
"</bar>" +
|
||||
"</extension2>";
|
||||
|
@ -57,8 +58,7 @@ public class ParsingExceptionTest {
|
|||
public void consumeUnparsedInput() throws Exception {
|
||||
final String MESSAGE_EXCEPTION_ELEMENT =
|
||||
"<" + ThrowException.ELEMENT + " xmlns='" + ThrowException.NAMESPACE + "'>" +
|
||||
"<nothingInHere>" +
|
||||
"</nothingInHere>" +
|
||||
"<nothingInHere/>" +
|
||||
"</" + ThrowException.ELEMENT + ">";
|
||||
XmlPullParser parser = TestUtils.getMessageParser(
|
||||
"<message from='user@server.example' to='francisco@denmark.lit' id='foo'>" +
|
||||
|
|
|
@ -22,10 +22,10 @@ import java.util.Collection;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.FileUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class ProviderConfigTest {
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ import static org.junit.Assert.assertTrue;
|
|||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class ProviderManagerTest {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014-2017 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.
|
||||
|
@ -16,8 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.sasl;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
|
|
|
@ -0,0 +1,165 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 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.
|
||||
* 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.smack.test.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.Element;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.Provider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserFactory;
|
||||
import org.jivesoftware.smack.xml.stax.StaxXmlPullParserFactory;
|
||||
import org.jivesoftware.smack.xml.xpp3.Xpp3XmlPullParserFactory;
|
||||
|
||||
public class SmackTestUtil {
|
||||
|
||||
@SuppressWarnings("ImmutableEnumChecker")
|
||||
public enum XmlPullParserKind {
|
||||
StAX(StaxXmlPullParserFactory.class),
|
||||
XPP3(Xpp3XmlPullParserFactory.class),
|
||||
;
|
||||
|
||||
public final XmlPullParserFactory factory;
|
||||
|
||||
XmlPullParserKind(Class<? extends XmlPullParserFactory> factoryClass) {
|
||||
try {
|
||||
factory = factoryClass.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <E extends Element, P extends Provider<E>> E parse(CharSequence xml, Class<P> providerClass, XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
P provider = providerClassToProvider(providerClass);
|
||||
return parse(xml, provider, parserKind);
|
||||
}
|
||||
|
||||
public static <E extends Element, P extends Provider<E>> E parse(InputStream inputStream, Class<P> providerClass, XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
P provider = providerClassToProvider(providerClass);
|
||||
return parse(inputStream, provider, parserKind);
|
||||
}
|
||||
|
||||
public static <E extends Element, P extends Provider<E>> E parse(Reader reader, Class<P> providerClass, XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
P provider = providerClassToProvider(providerClass);
|
||||
return parse(reader, provider, parserKind);
|
||||
}
|
||||
|
||||
public static <E extends Element> E parse(CharSequence xml, Provider<E> provider, XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
String xmlString = xml.toString();
|
||||
Reader reader = new StringReader(xmlString);
|
||||
return parse(reader, provider, parserKind);
|
||||
}
|
||||
|
||||
public static <E extends Element> E parse(InputStream inputStream, Provider<E> provider, XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||
return parse(inputStreamReader, provider, parserKind);
|
||||
}
|
||||
|
||||
public static <E extends Element> E parse(Reader reader, Provider<E> provider, XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException, SmackParsingException {
|
||||
XmlPullParser parser = getParserFor(reader, parserKind);
|
||||
E element = provider.parse(parser);
|
||||
return element;
|
||||
}
|
||||
|
||||
public static XmlPullParser getParserFor(String xml, XmlPullParserKind parserKind) throws XmlPullParserException, IOException {
|
||||
Reader reader = new StringReader(xml);
|
||||
return getParserFor(reader, parserKind);
|
||||
}
|
||||
|
||||
public static XmlPullParser getParserFor(InputStream inputStream, XmlPullParserKind parserKind) throws XmlPullParserException, IOException {
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||
return getParserFor(inputStreamReader, parserKind);
|
||||
}
|
||||
|
||||
public static XmlPullParser getParserFor(Reader reader, XmlPullParserKind parserKind) throws XmlPullParserException, IOException {
|
||||
XmlPullParser parser = parserKind.factory.newXmlPullParser(reader);
|
||||
forwardParserToStartElement(parser);
|
||||
return parser;
|
||||
}
|
||||
|
||||
public static XmlPullParser getParserFor(String xml, QName startTagQName, XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
XmlPullParser parser = getParserFor(xml, parserKind);
|
||||
forwardParserToStartElement(parser, (p) -> p.getQName().equals(startTagQName));
|
||||
return parser;
|
||||
}
|
||||
|
||||
public static XmlPullParser getParserFor(String xml, String startTagLocalpart, XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
XmlPullParser parser = getParserFor(xml, parserKind);
|
||||
forwardParserToStartElement(parser, (p) -> p.getName().equals(startTagLocalpart));
|
||||
return parser;
|
||||
}
|
||||
|
||||
private static <E extends Element, P extends Provider<E>> P providerClassToProvider(Class<P> providerClass) {
|
||||
P provider;
|
||||
// TODO: Consider adding a shortcut in case there is a static INSTANCE field holding an instance of the
|
||||
// requested provider.
|
||||
try {
|
||||
provider = providerClass.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| NoSuchMethodException | SecurityException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
private static void forwardParserToStartElement(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
forwardParserToStartElement(parser, p -> true);
|
||||
}
|
||||
|
||||
private static void forwardParserToStartElement(XmlPullParser parser,
|
||||
Predicate<XmlPullParser> doneForwarding) throws XmlPullParserException, IOException {
|
||||
outerloop: while (true) {
|
||||
XmlPullParser.Event event = parser.getEventType();
|
||||
switch (event) {
|
||||
case START_ELEMENT:
|
||||
if (doneForwarding.test(parser)) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
case END_DOCUMENT:
|
||||
throw new IllegalArgumentException("Not matching START_ELEMENT found");
|
||||
default:
|
||||
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
||||
break;
|
||||
}
|
||||
parser.next();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,14 +20,11 @@ import java.io.IOException;
|
|||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.jivesoftware.smack.xml.SmackXmlParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
// TODO: Remove this class and replace it with SmackTestUtil.
|
||||
public final class TestUtils {
|
||||
private TestUtils() {
|
||||
}
|
||||
|
@ -52,12 +49,12 @@ public final class TestUtils {
|
|||
return getParser(new StringReader(string), startTag);
|
||||
}
|
||||
|
||||
public static XmlPullParser getParser(Reader reader, String startTag) {
|
||||
private static XmlPullParser getParser(Reader reader, String startTag) {
|
||||
XmlPullParser parser;
|
||||
try {
|
||||
parser = PacketParserUtils.newXmppParser(reader);
|
||||
parser = SmackXmlParser.newXmlParser(reader);
|
||||
if (startTag == null) {
|
||||
while (parser.getEventType() != XmlPullParser.START_TAG) {
|
||||
while (parser.getEventType() != XmlPullParser.Event.START_ELEMENT) {
|
||||
parser.next();
|
||||
}
|
||||
return parser;
|
||||
|
@ -65,7 +62,7 @@ public final class TestUtils {
|
|||
boolean found = false;
|
||||
|
||||
while (!found) {
|
||||
if ((parser.next() == XmlPullParser.START_TAG) && parser.getName().equals(startTag))
|
||||
if ((parser.next() == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals(startTag))
|
||||
found = true;
|
||||
}
|
||||
|
||||
|
@ -79,17 +76,4 @@ public final class TestUtils {
|
|||
return parser;
|
||||
}
|
||||
|
||||
public static <EE extends ExtensionElement> EE parseExtensionElement(String elementString)
|
||||
throws Exception {
|
||||
return parseExtensionElement(getParser(elementString), null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <EE extends ExtensionElement> EE parseExtensionElement(XmlPullParser parser, XmlEnvironment outerXmlEnvironment)
|
||||
throws Exception {
|
||||
ParserUtils.assertAtStartTag(parser);
|
||||
final String elementName = parser.getName();
|
||||
final String namespace = parser.getNamespace();
|
||||
return (EE) PacketParserUtils.parseExtensionElement(elementName, namespace, parser, outerXmlEnvironment);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.util.HashMap;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
@ -42,15 +44,18 @@ import org.jivesoftware.smack.packet.StreamOpen;
|
|||
import org.jivesoftware.smack.sasl.SASLError;
|
||||
import org.jivesoftware.smack.sasl.packet.SaslStreamElements;
|
||||
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure;
|
||||
import org.jivesoftware.smack.test.util.SmackTestUtil;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smack.test.util.XmlUnitUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class PacketParserUtilsTest {
|
||||
|
||||
|
@ -59,8 +64,9 @@ public class PacketParserUtilsTest {
|
|||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleMessageBodyTest() throws Exception {
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void singleMessageBodyTest(SmackTestUtil.XmlPullParserKind parserKind) throws Exception {
|
||||
String defaultLanguage = Stanza.getDefaultLanguage();
|
||||
String otherLanguage = determineNonDefaultLanguage();
|
||||
|
||||
|
@ -79,7 +85,7 @@ public class PacketParserUtilsTest {
|
|||
.asString(outputProperties);
|
||||
|
||||
Message message = PacketParserUtils
|
||||
.parseMessage(PacketParserUtils.getParserFor(control));
|
||||
.parseMessage(SmackTestUtil.getParserFor(control, parserKind));
|
||||
|
||||
assertEquals(defaultLanguage, message.getBody());
|
||||
assertTrue(message.getBodyLanguages().isEmpty());
|
||||
|
@ -99,7 +105,7 @@ public class PacketParserUtilsTest {
|
|||
.t(otherLanguage)
|
||||
.asString(outputProperties);
|
||||
|
||||
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||
message = PacketParserUtils.parseMessage(SmackTestUtil.getParserFor(control, parserKind));
|
||||
|
||||
assertEquals(otherLanguage, message.getBody());
|
||||
assertTrue(message.getBodyLanguages().isEmpty());
|
||||
|
@ -118,7 +124,7 @@ public class PacketParserUtilsTest {
|
|||
.t(defaultLanguage)
|
||||
.asString(outputProperties);
|
||||
|
||||
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||
message = PacketParserUtils.parseMessage(SmackTestUtil.getParserFor(control, parserKind));
|
||||
|
||||
assertEquals(defaultLanguage, message.getBody());
|
||||
assertTrue(message.getBodyLanguages().isEmpty());
|
||||
|
@ -138,7 +144,7 @@ public class PacketParserUtilsTest {
|
|||
.t(defaultLanguage)
|
||||
.asString(outputProperties);
|
||||
|
||||
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||
message = PacketParserUtils.parseMessage(SmackTestUtil.getParserFor(control, parserKind));
|
||||
|
||||
assertNull(message.getBody());
|
||||
assertFalse(message.getBodyLanguages().isEmpty());
|
||||
|
@ -159,7 +165,7 @@ public class PacketParserUtilsTest {
|
|||
.t(otherLanguage)
|
||||
.asString(outputProperties);
|
||||
|
||||
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||
message = PacketParserUtils.parseMessage(SmackTestUtil.getParserFor(control, parserKind));
|
||||
|
||||
assertNull(message.getBody());
|
||||
assertFalse(message.getBodyLanguages().isEmpty());
|
||||
|
@ -181,7 +187,7 @@ public class PacketParserUtilsTest {
|
|||
.t(otherLanguage)
|
||||
.asString(outputProperties);
|
||||
|
||||
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||
message = PacketParserUtils.parseMessage(SmackTestUtil.getParserFor(control, parserKind));
|
||||
|
||||
assertNull(message.getBody());
|
||||
assertFalse(message.getBodyLanguages().isEmpty());
|
||||
|
@ -203,7 +209,7 @@ public class PacketParserUtilsTest {
|
|||
.t(defaultLanguage)
|
||||
.asString(outputProperties);
|
||||
|
||||
message = PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(control));
|
||||
message = PacketParserUtils.parseMessage(SmackTestUtil.getParserFor(control, parserKind));
|
||||
|
||||
assertNull(message.getBody());
|
||||
assertFalse(message.getBodyLanguages().isEmpty());
|
||||
|
@ -708,13 +714,18 @@ public class PacketParserUtilsTest {
|
|||
.t("Good Message Body")
|
||||
.asString(outputProperties);
|
||||
|
||||
// XPP3 writes "end tag", StAX writes "end-tag".
|
||||
Supplier<Stream<String>> expectedContentOfExceptionMessage = () -> Stream.of("end tag", "end-tag");
|
||||
|
||||
String invalidControl = validControl.replace("Good Message Body", "Bad </span> Body");
|
||||
|
||||
try {
|
||||
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||
fail("Exception should be thrown");
|
||||
} catch (XmlPullParserException e) {
|
||||
assertTrue(e.getMessage().contains("end tag name </span>"));
|
||||
String exceptionMessage = e.getMessage();
|
||||
boolean expectedContentFound = expectedContentOfExceptionMessage.get().anyMatch((expected) -> exceptionMessage.contains(expected));
|
||||
assertTrue(expectedContentFound);
|
||||
}
|
||||
|
||||
invalidControl = validControl.replace("Good Message Body", "Bad </body> Body");
|
||||
|
@ -723,7 +734,9 @@ public class PacketParserUtilsTest {
|
|||
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||
fail("Exception should be thrown");
|
||||
} catch (XmlPullParserException e) {
|
||||
assertTrue(e.getMessage().contains("end tag name </body>"));
|
||||
String exceptionMessage = e.getMessage();
|
||||
boolean expectedContentFound = expectedContentOfExceptionMessage.get().anyMatch((expected) -> exceptionMessage.contains(expected));
|
||||
assertTrue(expectedContentFound);
|
||||
}
|
||||
|
||||
invalidControl = validControl.replace("Good Message Body", "Bad </message> Body");
|
||||
|
@ -732,9 +745,10 @@ public class PacketParserUtilsTest {
|
|||
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||
fail("Exception should be thrown");
|
||||
} catch (XmlPullParserException e) {
|
||||
assertTrue(e.getMessage().contains("end tag name </message>"));
|
||||
String exceptionMessage = e.getMessage();
|
||||
boolean expectedContentFound = expectedContentOfExceptionMessage.get().anyMatch((expected) -> exceptionMessage.contains(expected));
|
||||
assertTrue(expectedContentFound);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -808,13 +822,13 @@ public class PacketParserUtilsTest {
|
|||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseContentDepthTest() throws Exception {
|
||||
final String stanza = "<iq type='result' to='foo@bar.com' from='baz.com' id='42'/>";
|
||||
XmlPullParser parser = TestUtils.getParser(stanza, "iq");
|
||||
CharSequence content = PacketParserUtils.parseContent(parser);
|
||||
assertEquals("", content.toString());
|
||||
}
|
||||
// @Test
|
||||
// public void parseContentDepthTest() throws Exception {
|
||||
// final String stanza = "<iq type='result' to='foo@bar.com' from='baz.com' id='42'/>";
|
||||
// XmlPullParser parser = TestUtils.getParser(stanza, "iq");
|
||||
// CharSequence content = PacketParserUtils.parseContent(parser);
|
||||
// assertEquals("", content.toString());
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void parseElementMultipleNamespace()
|
||||
|
|
|
@ -0,0 +1,231 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 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.
|
||||
* 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.smack.xml;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestUtil;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
public class XmlPullParserTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testSimpleEmptyElement(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
Reader reader = new StringReader("<empty-element/>");
|
||||
XmlPullParser parser = parserKind.factory.newXmlPullParser(reader);
|
||||
|
||||
assertEquals(XmlPullParser.Event.START_DOCUMENT, parser.getEventType());
|
||||
assertEquals(XmlPullParser.Event.START_ELEMENT, parser.next());
|
||||
QName qname = parser.getQName();
|
||||
assertEquals(qname.getLocalPart(), "empty-element");
|
||||
assertEquals(qname.getPrefix(), XMLConstants.DEFAULT_NS_PREFIX);
|
||||
assertEquals(qname.getNamespaceURI(), XMLConstants.NULL_NS_URI);
|
||||
assertEquals(XmlPullParser.Event.END_ELEMENT, parser.next());
|
||||
assertEquals(XmlPullParser.Event.END_DOCUMENT, parser.next());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testQNameSimpleElement(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
String simpleElement = "<outer-element xmlns='outer-namespace'><inner-element/></outer-element>";
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(simpleElement, parserKind);
|
||||
QName qname = parser.getQName();
|
||||
assertEquals("outer-element", qname.getLocalPart());
|
||||
assertEquals("outer-namespace", qname.getNamespaceURI());
|
||||
assertEquals(XmlPullParser.Event.START_ELEMENT, parser.next());
|
||||
qname = parser.getQName();
|
||||
assertEquals("inner-element", qname.getLocalPart());
|
||||
assertEquals("outer-namespace", qname.getNamespaceURI());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testQNamePrefixElement(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
String prefixElement = "<outer-element xmlns='outer-namespace' xmlns:inner-prefix='inner-namespace'><inner-prefix:inner-element></outer-element>";
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(prefixElement, parserKind);
|
||||
QName qname = parser.getQName();
|
||||
assertEquals("outer-element", qname.getLocalPart());
|
||||
assertEquals("outer-namespace", qname.getNamespaceURI());
|
||||
assertEquals(XmlPullParser.Event.START_ELEMENT, parser.next());
|
||||
qname = parser.getQName();
|
||||
assertEquals("inner-element", qname.getLocalPart());
|
||||
assertEquals("inner-namespace", qname.getNamespaceURI());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testAttributesElementWithOneAttribute(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
String elementWithOneAttribute = "<element attribute-one='attribute-one-value'/>";
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(elementWithOneAttribute, parserKind);
|
||||
assertAttributeHolds(parser, 0, "attribute-one", "", "");
|
||||
assertThrows(NullPointerException.class, () ->
|
||||
assertAttributeHolds(parser, 1, "attribute-one", "", ""));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testAttributesNamespacedElementWithOneAttribute(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
String namespacedElementWithOneAttribute = "<element xmlns='element-namespace' attribute-one='attribute-one-value'/>";
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(namespacedElementWithOneAttribute, parserKind);
|
||||
assertAttributeHolds(parser, 0, "attribute-one", "", "");
|
||||
assertThrows(NullPointerException.class, () ->
|
||||
assertAttributeHolds(parser, 1, "attribute-one", "", ""));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testAttributesNamespacedElementWithOneNamespacedAttribute(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
String namespacedElementWithOneNamespacedAttribute = "<element xmlns='element-namespace' xmlns:attribute-namespace='attribute-namespace-value' attribute-namespace:attribute-one='attribute-one-value'/>";
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(namespacedElementWithOneNamespacedAttribute, parserKind);
|
||||
assertAttributeHolds(parser, 0, "attribute-one", "attribute-namespace", "attribute-namespace-value");
|
||||
assertThrows(NullPointerException.class, () ->
|
||||
assertAttributeHolds(parser, 1, "attribute-one", "", ""));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testNamespacedAttributes(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
String element = "<element xmlns:attr='attribute-namespace' attr:attributeOneName='attributeOneValue'/>";
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(element, parserKind);
|
||||
assertEquals(1, parser.getAttributeCount());
|
||||
|
||||
assertEquals("attributeOneName", parser.getAttributeName(0));
|
||||
assertEquals("attr", parser.getAttributePrefix(0));
|
||||
assertEquals("attribute-namespace", parser.getAttributeNamespace(0));
|
||||
QName attributeZeroQname = parser.getAttributeQName(0);
|
||||
assertEquals("attributeOneName", attributeZeroQname.getLocalPart());
|
||||
assertEquals("attr", attributeZeroQname.getPrefix());
|
||||
assertEquals("attribute-namespace", attributeZeroQname.getNamespaceURI());
|
||||
|
||||
// Test how parser handle non-existent attributes.
|
||||
assertNull(parser.getAttributeName(1));
|
||||
assertNull(parser.getAttributePrefix(1));
|
||||
assertNull(parser.getAttributeNamespace(1));
|
||||
QName attributeOneQname = parser.getAttributeQName(1);
|
||||
assertNull(attributeOneQname);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testAttributeType(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
String element = "<element xmlns:attr='attribute-namespace' attr:attributeOneName='attributeOneValue'/>";
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(element, parserKind);
|
||||
|
||||
assertEquals("CDATA", parser.getAttributeType(0));
|
||||
|
||||
assertNull(parser.getAttributeType(1));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testNextText(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
XmlPullParser parser;
|
||||
|
||||
String simpleElement = "<element>Element text</element>";
|
||||
parser = SmackTestUtil.getParserFor(simpleElement, parserKind);
|
||||
assertEquals("Element text", parser.nextText());
|
||||
|
||||
String complexElement = "<outer-elment><element1>Element 1 ' text</element1><element2>Element 2 text</element2></outer-element>";
|
||||
parser = SmackTestUtil.getParserFor(complexElement, parserKind);
|
||||
assertEquals(XmlPullParser.Event.START_ELEMENT, parser.next());
|
||||
assertEquals("element1", parser.getName());
|
||||
assertEquals(0, parser.getAttributeCount());
|
||||
assertEquals("Element 1 ' text", parser.nextText());
|
||||
|
||||
assertEquals(XmlPullParser.Event.START_ELEMENT, parser.next());
|
||||
assertEquals("element2", parser.getName());
|
||||
assertEquals(0, parser.getAttributeCount());
|
||||
assertEquals("Element 2 text", parser.nextText());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testNextTextMixedContent(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
String element = "<element>Mixed content element text<inner-element>Inner element text</inner-element></element>";
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(element, parserKind);
|
||||
assertThrows(XmlPullParserException.class, () -> parser.nextText());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testNextTextOnEndElement(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
String element = "<element>Element text</element>";
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(element, parserKind);
|
||||
assertEquals(XmlPullParser.Event.START_ELEMENT, parser.getEventType());
|
||||
assertEquals(XmlPullParser.Event.TEXT_CHARACTERS, parser.next());
|
||||
assertEquals(XmlPullParser.Event.END_ELEMENT, parser.next());
|
||||
assertThrows(XmlPullParserException.class, () -> parser.nextText());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
|
||||
public void testNextTextOnEmptyElement(SmackTestUtil.XmlPullParserKind parserKind)
|
||||
throws XmlPullParserException, IOException {
|
||||
String[] emptyElementStream = Stream.of().toArray(String[]::new);
|
||||
for (String emptyElement : emptyElementStream) {
|
||||
XmlPullParser parser = SmackTestUtil.getParserFor(emptyElement, parserKind);
|
||||
assertEquals(XmlPullParser.Event.START_ELEMENT, parser.getEventType());
|
||||
assertEquals("", parser.nextText());
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertAttributeHolds(XmlPullParser parser, int attributeIndex, String expectedLocalpart,
|
||||
String expectedPrefix, String expectedNamespace) {
|
||||
QName qname = parser.getAttributeQName(attributeIndex);
|
||||
String qnameNamespaceUri = qname.getNamespaceURI();
|
||||
|
||||
assertEquals(expectedLocalpart, qname.getLocalPart());
|
||||
assertEquals(expectedPrefix, qname.getPrefix());
|
||||
assertEquals(expectedNamespace, qnameNamespaceUri);
|
||||
|
||||
assertEquals(qname.getLocalPart(), parser.getAttributeName(attributeIndex));
|
||||
assertEquals(qname.getPrefix(), parser.getAttributePrefix(attributeIndex));
|
||||
|
||||
final String expectedGetAttributeNamespace;
|
||||
if (qnameNamespaceUri.equals(XMLConstants.NULL_NS_URI)) {
|
||||
expectedGetAttributeNamespace = null;
|
||||
}
|
||||
else {
|
||||
expectedGetAttributeNamespace = qnameNamespaceUri;
|
||||
}
|
||||
assertEquals(expectedGetAttributeNamespace, parser.getAttributeNamespace(attributeIndex));
|
||||
}
|
||||
}
|
|
@ -21,15 +21,14 @@ import java.io.IOException;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
|
||||
import org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction;
|
||||
import org.jivesoftware.smackx.forward.packet.Forwarded;
|
||||
import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* This class implements the {@link ExtensionElementProvider} to parse
|
||||
* carbon copied messages from a packet. It will return a {@link CarbonExtension} stanza extension.
|
||||
|
@ -48,11 +47,11 @@ public class CarbonManagerProvider extends ExtensionElementProvider<CarbonExtens
|
|||
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("forwarded")) {
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT && parser.getName().equals("forwarded")) {
|
||||
fwd = FORWARDED_PROVIDER.parse(parser);
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG && dir == Direction.valueOf(parser.getName()))
|
||||
else if (eventType == XmlPullParser.Event.END_ELEMENT && dir == Direction.valueOf(parser.getName()))
|
||||
done = true;
|
||||
}
|
||||
if (fwd == null) {
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.jivesoftware.smack.filter.StanzaExtensionFilter;
|
|||
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements;
|
||||
import org.jivesoftware.smackx.chat_markers.filter.ChatMarkersFilter;
|
||||
import org.jivesoftware.smackx.chat_markers.filter.EligibleForChatMarkerFilter;
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.jivesoftware.smack.packet.ExtensionElement;
|
|||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import org.jivesoftware.smackx.chat_markers.ChatMarkersState;
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.jivesoftware.smackx.chat_markers.filter;
|
|||
|
||||
import org.jivesoftware.smack.filter.StanzaExtensionFilter;
|
||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements;
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.chat_markers.filter;
|
|||
import org.jivesoftware.smack.filter.StanzaExtensionFilter;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
import org.jivesoftware.smackx.chatstates.ChatState;
|
||||
import org.jivesoftware.smackx.chatstates.ChatStateManager;
|
||||
|
||||
|
|
|
@ -18,11 +18,10 @@ package org.jivesoftware.smackx.chat_markers.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.AcknowledgedExtension;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Acknowledged extension provider class (XEP-0333).
|
||||
*
|
||||
|
|
|
@ -18,11 +18,10 @@ package org.jivesoftware.smackx.chat_markers.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.DisplayedExtension;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Displayed extension provider class (XEP-0333).
|
||||
*
|
||||
|
|
|
@ -18,11 +18,10 @@ package org.jivesoftware.smackx.chat_markers.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.MarkableExtension;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Markable extension provider class (XEP-0333).
|
||||
*
|
||||
|
|
|
@ -18,11 +18,10 @@ package org.jivesoftware.smackx.chat_markers.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.ReceivedExtension;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Received extension provider class (XEP-0333).
|
||||
*
|
||||
|
|
|
@ -20,12 +20,11 @@ import java.io.IOException;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.csi.packet.ClientStateIndication;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class ClientStateIndicationFeatureProvider extends ExtensionElementProvider<ClientStateIndication.Feature> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.jivesoftware.smack.packet.StanzaError;
|
|||
import org.jivesoftware.smack.packet.StanzaError.Condition;
|
||||
import org.jivesoftware.smack.packet.StanzaError.Type;
|
||||
import org.jivesoftware.smack.util.RandomUtil;
|
||||
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.dox.element.DnsIq;
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@ import java.io.IOException;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smackx.dox.element.DnsIq;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.jivesoftware.smackx.dox.element.DnsIq;
|
||||
|
||||
public class DnsIqProvider extends IQProvider<DnsIq> {
|
||||
|
||||
|
|
|
@ -18,11 +18,10 @@ package org.jivesoftware.smackx.eme.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.eme.element.ExplicitMessageEncryptionElement;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class ExplicitMessageEncryptionProvider extends ExtensionElementProvider<ExplicitMessageEncryptionElement> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2017 Paul Schaub
|
||||
* Copyright © 2017 Paul Schaub, 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.
|
||||
|
@ -20,18 +20,19 @@ import java.io.IOException;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.hashes.HashManager;
|
||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Provider for HashElements.
|
||||
*/
|
||||
public class HashElementProvider extends ExtensionElementProvider<HashElement> {
|
||||
|
||||
public static final HashElementProvider INSTANCE = new HashElementProvider();
|
||||
|
||||
@Override
|
||||
public HashElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
|
||||
String algo = parser.getAttributeValue(null, HashElement.ATTR_ALGO);
|
||||
|
|
|
@ -18,11 +18,10 @@ package org.jivesoftware.smackx.hints.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.hints.element.MessageProcessingHint;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public abstract class MessageProcessingHintProvider<H extends MessageProcessingHint> extends ExtensionElementProvider<H> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,14 +22,13 @@ import org.jivesoftware.smack.packet.NamedElement;
|
|||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
|
||||
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
|
||||
import org.jivesoftware.smackx.shim.provider.HeadersProvider;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Abstract parent for Req and Resp stanza providers.
|
||||
*
|
||||
|
@ -63,7 +62,7 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
|||
protected HeadersExtension parseHeaders(XmlPullParser parser) throws IOException, XmlPullParserException, SmackParsingException {
|
||||
HeadersExtension headersExtension = null;
|
||||
/* We are either at start of headers, start of data or end of req/res */
|
||||
if (parser.next() == XmlPullParser.START_TAG && parser.getName().equals(HeadersExtension.ELEMENT)) {
|
||||
if (parser.next() == XmlPullParser.Event.START_ELEMENT && parser.getName().equals(HeadersExtension.ELEMENT)) {
|
||||
headersExtension = HeadersProvider.INSTANCE.parse(parser);
|
||||
parser.next();
|
||||
}
|
||||
|
@ -85,11 +84,11 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
|||
boolean done = false;
|
||||
AbstractHttpOverXmpp.Data data = null;
|
||||
/* We are either at start of data or end of req/res */
|
||||
if (parser.getEventType() == XmlPullParser.START_TAG) {
|
||||
if (parser.getEventType() == XmlPullParser.Event.START_ELEMENT) {
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
switch (parser.getName()) {
|
||||
case ELEMENT_TEXT:
|
||||
child = parseText(parser);
|
||||
|
@ -118,7 +117,7 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
|||
// other elements are not allowed
|
||||
throw new IllegalArgumentException("unsupported child tag: " + parser.getName());
|
||||
}
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getName().equals(ELEMENT_DATA)) {
|
||||
done = true;
|
||||
}
|
||||
|
@ -134,15 +133,15 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
|||
boolean done = false;
|
||||
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.END_TAG) {
|
||||
if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getName().equals(ELEMENT_TEXT)) {
|
||||
done = true;
|
||||
} else {
|
||||
throw new IllegalArgumentException("unexpected end tag of: " + parser.getName());
|
||||
}
|
||||
} else if (eventType == XmlPullParser.TEXT) {
|
||||
} else if (eventType == XmlPullParser.Event.TEXT_CHARACTERS) {
|
||||
text = parser.getText();
|
||||
} else {
|
||||
throw new IllegalArgumentException("unexpected eventType: " + eventType);
|
||||
|
@ -159,13 +158,13 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
|||
boolean startClosed = true;
|
||||
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if ((eventType == XmlPullParser.END_TAG) && parser.getName().equals(ELEMENT_XML)) {
|
||||
if ((eventType == XmlPullParser.Event.END_ELEMENT) && parser.getName().equals(ELEMENT_XML)) {
|
||||
done = true;
|
||||
} else { // just write everything else as text
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
|
||||
if (!startClosed) {
|
||||
builder.append('>');
|
||||
|
@ -175,7 +174,7 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
|||
builder.append(parser.getName());
|
||||
appendXmlAttributes(parser, builder);
|
||||
startClosed = false;
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
|
||||
if (startClosed) {
|
||||
builder.append("</");
|
||||
|
@ -185,7 +184,7 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
|||
builder.append("/>");
|
||||
startClosed = true;
|
||||
}
|
||||
} else if (eventType == XmlPullParser.TEXT) {
|
||||
} else if (eventType == XmlPullParser.Event.TEXT_CHARACTERS) {
|
||||
|
||||
if (!startClosed) {
|
||||
builder.append('>');
|
||||
|
@ -223,16 +222,16 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
|||
boolean done = false;
|
||||
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.END_TAG) {
|
||||
if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
|
||||
if (parser.getName().equals(ELEMENT_BASE_64)) {
|
||||
done = true;
|
||||
} else {
|
||||
throw new IllegalArgumentException("unexpected end tag of: " + parser.getName());
|
||||
}
|
||||
} else if (eventType == XmlPullParser.TEXT) {
|
||||
} else if (eventType == XmlPullParser.Event.TEXT_CHARACTERS) {
|
||||
text = parser.getText();
|
||||
} else {
|
||||
throw new IllegalArgumentException("unexpected eventType: " + eventType);
|
||||
|
@ -249,9 +248,9 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
|||
boolean done = false;
|
||||
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.END_TAG) {
|
||||
if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getName().equals(ELEMENT_CHUNKED_BASE_64)) {
|
||||
done = true;
|
||||
} else {
|
||||
|
@ -270,9 +269,9 @@ public abstract class AbstractHttpOverXmppProvider<H extends AbstractHttpOverXmp
|
|||
boolean done = false;
|
||||
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.END_TAG) {
|
||||
if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getName().equals(ELEMENT_IBB)) {
|
||||
done = true;
|
||||
} else {
|
||||
|
|
|
@ -20,12 +20,11 @@ import java.io.IOException;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Stanza provider for base64 binary chunks.
|
||||
*
|
||||
|
@ -50,15 +49,15 @@ public class Base64BinaryChunkProvider extends ExtensionElementProvider<Base64Bi
|
|||
boolean done = false;
|
||||
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.END_TAG) {
|
||||
if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getName().equals(Base64BinaryChunk.ELEMENT_CHUNK)) {
|
||||
done = true;
|
||||
} else {
|
||||
throw new IllegalArgumentException("unexpected end tag of: " + parser.getName());
|
||||
}
|
||||
} else if (eventType == XmlPullParser.TEXT) {
|
||||
} else if (eventType == XmlPullParser.Event.TEXT_CHARACTERS) {
|
||||
text = parser.getText();
|
||||
} else {
|
||||
throw new IllegalArgumentException("unexpected eventType: " + eventType);
|
||||
|
|
|
@ -21,13 +21,12 @@ import java.io.IOException;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.hoxt.packet.HttpMethod;
|
||||
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Req stanza provider.
|
||||
*
|
||||
|
|
|
@ -20,13 +20,13 @@ import java.io.IOException;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
|
||||
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp;
|
||||
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Resp stanza provider.
|
||||
*
|
||||
|
|
|
@ -20,13 +20,12 @@ import java.io.IOException;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.httpfileupload.element.FileTooLargeError;
|
||||
import org.jivesoftware.smackx.httpfileupload.element.FileTooLargeError_V0_2;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Provider for File Too Large error extension.
|
||||
*
|
||||
|
@ -41,10 +40,10 @@ public class FileTooLargeErrorProvider extends ExtensionElementProvider<FileTooL
|
|||
Long maxFileSize = null;
|
||||
|
||||
outerloop: while (true) {
|
||||
int event = parser.next();
|
||||
XmlPullParser.Event event = parser.next();
|
||||
|
||||
switch (event) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
String name = parser.getName();
|
||||
switch (name) {
|
||||
case "max-file-size":
|
||||
|
@ -52,11 +51,14 @@ public class FileTooLargeErrorProvider extends ExtensionElementProvider<FileTooL
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,15 +24,14 @@ import java.util.Map;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.httpfileupload.HttpFileUploadManager;
|
||||
import org.jivesoftware.smackx.httpfileupload.UploadService;
|
||||
import org.jivesoftware.smackx.httpfileupload.element.Slot;
|
||||
import org.jivesoftware.smackx.httpfileupload.element.Slot_V0_2;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Provider for Slot.
|
||||
*
|
||||
|
@ -53,10 +52,10 @@ public class SlotProvider extends IQProvider<Slot> {
|
|||
PutElement_V0_4_Content putElementV04Content = null;
|
||||
|
||||
outerloop: while (true) {
|
||||
int event = parser.next();
|
||||
XmlPullParser.Event event = parser.next();
|
||||
|
||||
switch (event) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
String name = parser.getName();
|
||||
switch (name) {
|
||||
case "put": {
|
||||
|
@ -89,11 +88,14 @@ public class SlotProvider extends IQProvider<Slot> {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,9 +117,9 @@ public class SlotProvider extends IQProvider<Slot> {
|
|||
|
||||
Map<String, String> headers = null;
|
||||
outerloop: while (true) {
|
||||
int next = parser.next();
|
||||
XmlPullParser.Event next = parser.next();
|
||||
switch (next) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
String name = parser.getName();
|
||||
switch (name) {
|
||||
case "header":
|
||||
|
@ -132,11 +134,14 @@ public class SlotProvider extends IQProvider<Slot> {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ import java.util.List;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.iot.control.element.IoTSetRequest;
|
||||
import org.jivesoftware.smackx.iot.control.element.SetBoolData;
|
||||
|
@ -30,19 +32,16 @@ import org.jivesoftware.smackx.iot.control.element.SetDoubleData;
|
|||
import org.jivesoftware.smackx.iot.control.element.SetIntData;
|
||||
import org.jivesoftware.smackx.iot.control.element.SetLongData;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class IoTSetRequestProvider extends IQProvider<IoTSetRequest> {
|
||||
|
||||
@Override
|
||||
public IoTSetRequest parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
|
||||
List<SetData> data = new ArrayList<>(4);
|
||||
outerloop: while (true) {
|
||||
final int eventType = parser.next();
|
||||
final XmlPullParser.Event eventType = parser.next();
|
||||
final String name = parser.getName();
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
switch (name) {
|
||||
case "bool": {
|
||||
String valueName = parser.getAttributeValue(null, "name");
|
||||
|
@ -74,11 +73,14 @@ public class IoTSetRequestProvider extends IQProvider<IoTSetRequest> {
|
|||
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 new IoTSetRequest(data);
|
||||
|
|
|
@ -18,11 +18,10 @@ package org.jivesoftware.smackx.iot.control.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.control.element.IoTSetResponse;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTSetResponseProvider extends IQProvider<IoTSetResponse> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,11 +21,10 @@ import java.io.IOException;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.data.element.IoTDataReadOutAccepted;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTDataReadOutAcceptedProvider extends IQProvider<IoTDataReadOutAccepted> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,11 +21,10 @@ import java.io.IOException;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.data.element.IoTDataRequest;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTDataRequestProvider extends IQProvider<IoTDataRequest> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,6 +28,8 @@ import org.jivesoftware.smack.parsing.SmackParsingException;
|
|||
import org.jivesoftware.smack.parsing.SmackParsingException.SmackTextParseException;
|
||||
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.iot.data.element.IoTDataField;
|
||||
import org.jivesoftware.smackx.iot.data.element.IoTFieldsExtension;
|
||||
|
@ -37,8 +39,6 @@ import org.jivesoftware.smackx.iot.element.NodeInfo;
|
|||
import org.jivesoftware.smackx.iot.parser.NodeInfoParser;
|
||||
|
||||
import org.jxmpp.util.XmppDateTime;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class IoTFieldsExtensionProvider extends ExtensionElementProvider<IoTFieldsExtension> {
|
||||
|
||||
|
@ -50,10 +50,10 @@ public class IoTFieldsExtensionProvider extends ExtensionElementProvider<IoTFiel
|
|||
boolean done = ParserUtils.getBooleanAttribute(parser, "done", false);
|
||||
List<NodeElement> nodes = new ArrayList<>();
|
||||
outerloop: while (true) {
|
||||
final int eventType = parser.next();
|
||||
final XmlPullParser.Event eventType = parser.next();
|
||||
final String name = parser.getName();
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
switch (name) {
|
||||
case NodeElement.ELEMENT:
|
||||
NodeElement node = parseNode(parser);
|
||||
|
@ -61,11 +61,14 @@ public class IoTFieldsExtensionProvider extends ExtensionElementProvider<IoTFiel
|
|||
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 new IoTFieldsExtension(seqNr, done, nodes);
|
||||
|
@ -76,10 +79,10 @@ public class IoTFieldsExtensionProvider extends ExtensionElementProvider<IoTFiel
|
|||
final NodeInfo nodeInfo = NodeInfoParser.parse(parser);
|
||||
List<TimestampElement> timestampElements = new ArrayList<>();
|
||||
outerloop: while (true) {
|
||||
final int eventType = parser.next();
|
||||
final XmlPullParser.Event eventType = parser.next();
|
||||
final String name = parser.getName();
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
switch (name){
|
||||
case TimestampElement.ELEMENT:
|
||||
TimestampElement timestampElement = parseTimestampElement(parser);
|
||||
|
@ -87,11 +90,14 @@ public class IoTFieldsExtensionProvider extends ExtensionElementProvider<IoTFiel
|
|||
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 new NodeElement(nodeInfo, timestampElements);
|
||||
|
@ -108,10 +114,10 @@ public class IoTFieldsExtensionProvider extends ExtensionElementProvider<IoTFiel
|
|||
}
|
||||
List<IoTDataField> fields = new ArrayList<>();
|
||||
outerloop: while (true) {
|
||||
final int eventType = parser.next();
|
||||
final XmlPullParser.Event eventType = parser.next();
|
||||
final String name = parser.getName();
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
IoTDataField field = null;
|
||||
final String fieldName = parser.getAttributeValue(null, "name");
|
||||
final String fieldValue = parser.getAttributeValue(null, "value");
|
||||
|
@ -134,11 +140,14 @@ public class IoTFieldsExtensionProvider extends ExtensionElementProvider<IoTFiel
|
|||
fields.add(field);
|
||||
}
|
||||
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 new TimestampElement(date, fields);
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.iot.discovery.provider;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.discovery.element.IoTClaimed;
|
||||
import org.jivesoftware.smackx.iot.element.NodeInfo;
|
||||
|
@ -26,7 +27,6 @@ import org.jivesoftware.smackx.iot.parser.NodeInfoParser;
|
|||
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTClaimedProvider extends IQProvider<IoTClaimed> {
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.iot.discovery.provider;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.discovery.element.IoTDisown;
|
||||
import org.jivesoftware.smackx.iot.element.NodeInfo;
|
||||
|
@ -26,7 +27,6 @@ import org.jivesoftware.smackx.iot.parser.NodeInfoParser;
|
|||
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTDisownProvider extends IQProvider<IoTDisown> {
|
||||
|
||||
|
|
|
@ -18,13 +18,12 @@ package org.jivesoftware.smackx.iot.discovery.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.discovery.element.IoTDisowned;
|
||||
import org.jivesoftware.smackx.iot.element.NodeInfo;
|
||||
import org.jivesoftware.smackx.iot.parser.NodeInfoParser;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTDisownedProvider extends IQProvider<IoTDisowned> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,15 +23,14 @@ import java.util.List;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.iot.discovery.element.IoTRegister;
|
||||
import org.jivesoftware.smackx.iot.discovery.element.Tag;
|
||||
import org.jivesoftware.smackx.iot.element.NodeInfo;
|
||||
import org.jivesoftware.smackx.iot.parser.NodeInfoParser;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class IoTRegisterProvider extends IQProvider<IoTRegister> {
|
||||
|
||||
@Override
|
||||
|
@ -40,8 +39,8 @@ public class IoTRegisterProvider extends IQProvider<IoTRegister> {
|
|||
NodeInfo nodeInfo = NodeInfoParser.parse(parser);
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
while (parser.getDepth() != initialDepth) {
|
||||
int event = parser.next();
|
||||
if (event != XmlPullParser.START_TAG) {
|
||||
XmlPullParser.Event event = parser.next();
|
||||
if (event != XmlPullParser.Event.START_ELEMENT) {
|
||||
continue;
|
||||
}
|
||||
final String element = parser.getName();
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.discovery.element.IoTRemove;
|
||||
import org.jivesoftware.smackx.iot.element.NodeInfo;
|
||||
|
@ -28,7 +29,6 @@ import org.jivesoftware.smackx.iot.parser.NodeInfoParser;
|
|||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTRemoveProvider extends IQProvider<IoTRemove> {
|
||||
|
||||
|
|
|
@ -18,13 +18,12 @@ package org.jivesoftware.smackx.iot.discovery.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.discovery.element.IoTRemoved;
|
||||
import org.jivesoftware.smackx.iot.element.NodeInfo;
|
||||
import org.jivesoftware.smackx.iot.parser.NodeInfoParser;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTRemovedProvider extends IQProvider<IoTRemoved> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,13 +18,12 @@ package org.jivesoftware.smackx.iot.discovery.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.discovery.element.IoTUnregister;
|
||||
import org.jivesoftware.smackx.iot.element.NodeInfo;
|
||||
import org.jivesoftware.smackx.iot.parser.NodeInfoParser;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTUnregisterProvider extends IQProvider<IoTUnregister> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,9 +18,9 @@ package org.jivesoftware.smackx.iot.parser;
|
|||
|
||||
import static org.jivesoftware.smack.util.StringUtils.isNullOrEmpty;
|
||||
|
||||
import org.jivesoftware.smackx.iot.element.NodeInfo;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.jivesoftware.smackx.iot.element.NodeInfo;
|
||||
|
||||
public class NodeInfoParser {
|
||||
|
||||
|
|
|
@ -18,11 +18,10 @@ package org.jivesoftware.smackx.iot.provisioning.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.provisioning.element.ClearCache;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class ClearCacheProvider extends IQProvider<ClearCache> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,11 +18,10 @@ package org.jivesoftware.smackx.iot.provisioning.provider;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.provisioning.element.ClearCacheResponse;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class ClearCacheResponseProvider extends IQProvider<ClearCacheResponse> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,12 +19,12 @@ package org.jivesoftware.smackx.iot.provisioning.provider;
|
|||
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.iot.provisioning.element.Friend;
|
||||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class FriendProvider extends ExtensionElementProvider<Friend> {
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ package org.jivesoftware.smackx.iot.provisioning.provider;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.provisioning.element.IoTIsFriend;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTIsFriendProvider extends IQProvider<IoTIsFriend> {
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@ package org.jivesoftware.smackx.iot.provisioning.provider;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
import org.jivesoftware.smackx.iot.provisioning.element.IoTIsFriendResponse;
|
||||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class IoTIsFriendResponseProvider extends IQProvider<IoTIsFriendResponse> {
|
||||
|
||||
|
|
|
@ -19,12 +19,12 @@ package org.jivesoftware.smackx.iot.provisioning.provider;
|
|||
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.iot.provisioning.element.Unfriend;
|
||||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class UnfriendProvider extends ExtensionElementProvider<Unfriend> {
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.jingle_filetransfer.element;
|
|||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.io.File;
|
|||
import java.util.Date;
|
||||
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2017 Paul Schaub
|
||||
* Copyright © 2017 Paul Schaub, 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.
|
||||
|
@ -18,6 +18,7 @@ package org.jivesoftware.smackx.jingle_filetransfer.element;
|
|||
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||
|
||||
/**
|
||||
|
@ -29,14 +30,14 @@ public class Range implements NamedElement {
|
|||
public static final String ATTR_OFFSET = "offset";
|
||||
public static final String ATTR_LENGTH = "length";
|
||||
|
||||
private final int offset, length;
|
||||
private final Integer offset, length;
|
||||
private final HashElement hash;
|
||||
|
||||
/**
|
||||
* Create a Range element with default values.
|
||||
*/
|
||||
public Range() {
|
||||
this(0, -1, null);
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,7 +45,7 @@ public class Range implements NamedElement {
|
|||
* @param length length of the transmitted data in bytes.
|
||||
*/
|
||||
public Range(int length) {
|
||||
this(0, length, null);
|
||||
this(null, length, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +63,7 @@ public class Range implements NamedElement {
|
|||
* @param length number of bytes that shall be transferred.
|
||||
* @param hash hash of the bytes in the specified range.
|
||||
*/
|
||||
public Range(int offset, int length, HashElement hash) {
|
||||
public Range(Integer offset, Integer length, HashElement hash) {
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
this.hash = hash;
|
||||
|
@ -102,10 +103,11 @@ public class Range implements NamedElement {
|
|||
public CharSequence toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder sb = new XmlStringBuilder(this);
|
||||
|
||||
if (offset > 0) {
|
||||
// TODO: (Introduce and) use XmlStringBuilder.optXmlAttribute(name, Number).
|
||||
if (offset != null) {
|
||||
sb.attribute(ATTR_OFFSET, offset);
|
||||
}
|
||||
if (length > 0) {
|
||||
if (length != null) {
|
||||
sb.attribute(ATTR_LENGTH, length);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,14 +16,14 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle_filetransfer.provider;
|
||||
|
||||
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
||||
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||
import org.jivesoftware.smackx.hashes.provider.HashElementProvider;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
|
@ -31,9 +31,6 @@ import org.jivesoftware.smackx.jingle_filetransfer.element.Checksum;
|
|||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.element.Range;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Provider for the Checksum element.
|
||||
*/
|
||||
|
@ -54,10 +51,11 @@ public class ChecksumProvider extends ExtensionElementProvider<Checksum> {
|
|||
|
||||
boolean go = true;
|
||||
while (go) {
|
||||
int tag = parser.nextTag();
|
||||
XmlPullParser.TagEvent tag = parser.nextTag();
|
||||
String n = parser.getText();
|
||||
|
||||
if (tag == START_TAG) {
|
||||
switch (tag) {
|
||||
case START_ELEMENT:
|
||||
switch (n) {
|
||||
case HashElement.ELEMENT:
|
||||
hashElement = new HashElementProvider().parse(parser);
|
||||
|
@ -70,7 +68,8 @@ public class ChecksumProvider extends ExtensionElementProvider<Checksum> {
|
|||
int l = length == null ? -1 : Integer.parseInt(length);
|
||||
range = new Range(o, l);
|
||||
}
|
||||
} else if (tag == END_TAG) {
|
||||
break;
|
||||
case END_ELEMENT:
|
||||
switch (n) {
|
||||
case Range.ELEMENT:
|
||||
if (hashElement != null && range != null) {
|
||||
|
@ -88,6 +87,7 @@ public class ChecksumProvider extends ExtensionElementProvider<Checksum> {
|
|||
}
|
||||
go = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new Checksum(creator, name, cb.build());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Paul Schaub
|
||||
* Copyright 2017 Paul Schaub, 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.
|
||||
|
@ -16,15 +16,16 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jingle_filetransfer.provider;
|
||||
|
||||
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
||||
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.hashes.element.HashElement;
|
||||
import org.jivesoftware.smackx.hashes.provider.HashElementProvider;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||
|
@ -34,8 +35,6 @@ import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChi
|
|||
import org.jivesoftware.smackx.jingle_filetransfer.element.Range;
|
||||
|
||||
import org.jxmpp.util.XmppDateTime;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Provider for JingleContentDescriptionFileTransfer elements.
|
||||
|
@ -46,20 +45,18 @@ public class JingleFileTransferProvider
|
|||
@Override
|
||||
public JingleFileTransfer parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
|
||||
ArrayList<JingleContentDescriptionChildElement> payloads = new ArrayList<>();
|
||||
boolean inRange = false;
|
||||
JingleFileTransferChild.Builder builder = JingleFileTransferChild.getBuilder();
|
||||
HashElement inRangeHash = null;
|
||||
|
||||
int offset = 0;
|
||||
int length = -1;
|
||||
|
||||
String elementName;
|
||||
while (true) {
|
||||
|
||||
int tag = parser.nextTag();
|
||||
String elem = parser.getName();
|
||||
XmlPullParser.TagEvent tag = parser.nextTag();
|
||||
|
||||
if (tag == START_TAG) {
|
||||
switch (elem) {
|
||||
switch (tag) {
|
||||
case START_ELEMENT:
|
||||
elementName = parser.getName();
|
||||
switch (elementName) {
|
||||
case JingleFileTransferChild.ELEM_DATE:
|
||||
try {
|
||||
builder.setDate(XmppDateTime.parseXEP0082Date(parser.nextText()));
|
||||
|
@ -85,36 +82,20 @@ public class JingleFileTransferProvider
|
|||
break;
|
||||
|
||||
case Range.ELEMENT:
|
||||
inRange = true;
|
||||
String offsetString = parser.getAttributeValue(null, Range.ATTR_OFFSET);
|
||||
String lengthString = parser.getAttributeValue(null, Range.ATTR_LENGTH);
|
||||
offset = (offsetString != null ? Integer.parseInt(offsetString) : 0);
|
||||
length = (lengthString != null ? Integer.parseInt(lengthString) : -1);
|
||||
Range range = parseRangeElement(parser);
|
||||
builder.setRange(range);
|
||||
|
||||
if (parser.isEmptyElementTag()) {
|
||||
inRange = false;
|
||||
builder.setRange(new Range(offset, length));
|
||||
}
|
||||
break;
|
||||
|
||||
case HashElement.ELEMENT:
|
||||
if (inRange) {
|
||||
inRangeHash = new HashElementProvider().parse(parser);
|
||||
} else {
|
||||
builder.setHash(new HashElementProvider().parse(parser));
|
||||
}
|
||||
HashElement hashElement = HashElementProvider.INSTANCE.parse(parser);
|
||||
builder.setHash(hashElement);
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (tag == END_TAG) {
|
||||
switch (elem) {
|
||||
|
||||
case Range.ELEMENT:
|
||||
inRange = false;
|
||||
builder.setRange(new Range(offset, length, inRangeHash));
|
||||
inRangeHash = null;
|
||||
break;
|
||||
|
||||
break;
|
||||
case END_ELEMENT:
|
||||
elementName = parser.getName();
|
||||
switch (elementName) {
|
||||
case JingleFileTransferChild.ELEMENT:
|
||||
payloads.add(builder.build());
|
||||
builder = JingleFileTransferChild.getBuilder();
|
||||
|
@ -123,7 +104,42 @@ public class JingleFileTransferProvider
|
|||
case JingleFileTransfer.ELEMENT:
|
||||
return new JingleFileTransfer(payloads);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Range parseRangeElement(XmlPullParser parser) throws IOException, XmlPullParserException, SmackParsingException {
|
||||
final int initialDepth = parser.getDepth();
|
||||
final Integer offset = ParserUtils.getIntegerAttribute(parser, Range.ATTR_OFFSET);
|
||||
final Integer length = ParserUtils.getIntegerAttribute(parser, Range.ATTR_LENGTH);
|
||||
|
||||
HashElement hashElement = null;
|
||||
outerloop: while (true) {
|
||||
String element;
|
||||
XmlPullParser.Event event = parser.next();
|
||||
switch (event) {
|
||||
case START_ELEMENT:
|
||||
element = parser.getName();
|
||||
switch (element) {
|
||||
case HashElement.ELEMENT:
|
||||
hashElement = HashElementProvider.INSTANCE.parse(parser);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case END_ELEMENT:
|
||||
element = parser.getName();
|
||||
if (element.equals(Range.ELEMENT) && parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new Range(offset, length, hashElement);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,12 +21,11 @@ import java.io.IOException;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.json.packet.AbstractJsonPacketExtension;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public abstract class AbstractJsonExtensionProvider<J extends AbstractJsonPacketExtension> extends ExtensionElementProvider<J> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,14 +22,13 @@ import org.jivesoftware.smack.packet.XmlEnvironment;
|
|||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.mam.element.MamFinIQ;
|
||||
import org.jivesoftware.smackx.rsm.packet.RSMSet;
|
||||
import org.jivesoftware.smackx.rsm.provider.RSMSetProvider;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* MAM Fin IQ Provider class.
|
||||
*
|
||||
|
@ -48,18 +47,21 @@ public class MamFinIQProvider extends IQProvider<MamFinIQ> {
|
|||
RSMSet rsmSet = null;
|
||||
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
if (parser.getName().equals(RSMSet.ELEMENT)) {
|
||||
rsmSet = RSMSetProvider.INSTANCE.parse(parser);
|
||||
}
|
||||
break;
|
||||
case XmlPullParser.END_TAG:
|
||||
case END_ELEMENT:
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,14 +22,14 @@ import java.util.List;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.mam.element.MamPrefsIQ;
|
||||
import org.jivesoftware.smackx.mam.element.MamPrefsIQ.DefaultBehavior;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* MAM Preferences IQ Provider class.
|
||||
|
@ -58,10 +58,10 @@ public class MamPrefsIQProvider extends IQProvider<MamPrefsIQ> {
|
|||
List<Jid> neverJids = null;
|
||||
|
||||
outerloop: while (true) {
|
||||
final int eventType = parser.next();
|
||||
final XmlPullParser.Event eventType = parser.next();
|
||||
final String name = parser.getName();
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
switch (name) {
|
||||
case "always":
|
||||
alwaysJids = iterateJids(parser);
|
||||
|
@ -71,11 +71,14 @@ public class MamPrefsIQProvider extends IQProvider<MamPrefsIQ> {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,10 +91,10 @@ public class MamPrefsIQProvider extends IQProvider<MamPrefsIQ> {
|
|||
int initialDepth = parser.getDepth();
|
||||
|
||||
outerloop: while (true) {
|
||||
final int eventType = parser.next();
|
||||
final XmlPullParser.Event eventType = parser.next();
|
||||
final String name = parser.getName();
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
switch (name) {
|
||||
case "jid":
|
||||
parser.next();
|
||||
|
@ -99,11 +102,14 @@ public class MamPrefsIQProvider extends IQProvider<MamPrefsIQ> {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,14 +21,13 @@ import java.io.IOException;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.mam.element.MamQueryIQ;
|
||||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||
import org.jivesoftware.smackx.xdata.provider.DataFormProvider;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* MAM Query IQ Provider class.
|
||||
*
|
||||
|
@ -47,22 +46,25 @@ public class MamQueryIQProvider extends IQProvider<MamQueryIQ> {
|
|||
String node = parser.getAttributeValue("", "node");
|
||||
|
||||
outerloop: while (true) {
|
||||
final int eventType = parser.next();
|
||||
final XmlPullParser.Event eventType = parser.next();
|
||||
final String name = parser.getName();
|
||||
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
switch (name) {
|
||||
case DataForm.ELEMENT:
|
||||
dataForm = DataFormProvider.INSTANCE.parse(parser);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,14 +21,13 @@ import java.io.IOException;
|
|||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.forward.packet.Forwarded;
|
||||
import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
|
||||
import org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* MAM Result Provider class.
|
||||
*
|
||||
|
@ -46,21 +45,24 @@ public class MamResultProvider extends ExtensionElementProvider<MamResultExtensi
|
|||
String id = parser.getAttributeValue("", "id");
|
||||
|
||||
outerloop: while (true) {
|
||||
final int eventType = parser.next();
|
||||
final XmlPullParser.Event eventType = parser.next();
|
||||
final String name = parser.getName();
|
||||
switch (eventType) {
|
||||
case XmlPullParser.START_TAG:
|
||||
case START_ELEMENT:
|
||||
switch (name) {
|
||||
case Forwarded.ELEMENT:
|
||||
forwarded = ForwardedProvider.INSTANCE.parse(parser);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.message_markup.provider;
|
||||
|
||||
import static org.xmlpull.v1.XmlPullParser.END_TAG;
|
||||
import static org.xmlpull.v1.XmlPullParser.START_TAG;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
@ -28,15 +25,15 @@ import java.util.Set;
|
|||
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.message_markup.element.BlockQuoteElement;
|
||||
import org.jivesoftware.smackx.message_markup.element.CodeBlockElement;
|
||||
import org.jivesoftware.smackx.message_markup.element.ListElement;
|
||||
import org.jivesoftware.smackx.message_markup.element.MarkupElement;
|
||||
import org.jivesoftware.smackx.message_markup.element.SpanElement;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class MarkupElementProvider extends ExtensionElementProvider<MarkupElement> {
|
||||
|
||||
@Override
|
||||
|
@ -51,11 +48,11 @@ public class MarkupElementProvider extends ExtensionElementProvider<MarkupElemen
|
|||
List<ListElement.ListEntryElement> lis = new ArrayList<>();
|
||||
|
||||
while (true) {
|
||||
int tag = parser.next();
|
||||
XmlPullParser.Event tag = parser.next();
|
||||
String name = parser.getName();
|
||||
int start, end;
|
||||
switch (tag) {
|
||||
case START_TAG:
|
||||
case START_ELEMENT:
|
||||
switch (name) {
|
||||
case BlockQuoteElement.ELEMENT:
|
||||
start = ParserUtils.getIntegerAttributeOrThrow(parser, BlockQuoteElement.ATTR_START,
|
||||
|
@ -109,7 +106,7 @@ public class MarkupElementProvider extends ExtensionElementProvider<MarkupElemen
|
|||
}
|
||||
break;
|
||||
|
||||
case END_TAG:
|
||||
case END_ELEMENT:
|
||||
switch (name) {
|
||||
case SpanElement.ELEMENT:
|
||||
markup.addSpan(spanStart, spanEnd, spanStyles);
|
||||
|
@ -134,7 +131,11 @@ public class MarkupElementProvider extends ExtensionElementProvider<MarkupElemen
|
|||
case MarkupElement.ELEMENT:
|
||||
return markup.build();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,14 +21,14 @@ import java.util.HashMap;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
|
||||
import org.jivesoftware.smackx.muclight.element.MUCLightElements.AffiliationsChangeExtension;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* MUC Light Affiliations Change Provider class.
|
||||
|
@ -45,9 +45,9 @@ public class MUCLightAffiliationsChangeProvider extends ExtensionElementProvider
|
|||
String version = null;
|
||||
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
|
||||
if (parser.getName().equals("prev-version")) {
|
||||
prevVersion = parser.nextText();
|
||||
|
@ -64,7 +64,7 @@ public class MUCLightAffiliationsChangeProvider extends ExtensionElementProvider
|
|||
affiliations.put(jid, mucLightAffiliation);
|
||||
}
|
||||
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
|
|
|
@ -21,14 +21,14 @@ import java.util.HashMap;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
|
||||
import org.jivesoftware.smackx.muclight.element.MUCLightAffiliationsIQ;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* MUC Light affiliations IQ provider class.
|
||||
|
@ -44,9 +44,9 @@ public class MUCLightAffiliationsIQProvider extends IQProvider<MUCLightAffiliati
|
|||
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
|
||||
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
|
||||
if (parser.getName().equals("version")) {
|
||||
version = parser.nextText();
|
||||
|
@ -58,7 +58,7 @@ public class MUCLightAffiliationsIQProvider extends IQProvider<MUCLightAffiliati
|
|||
occupants.put(JidCreate.from(parser.nextText()), affiliation);
|
||||
}
|
||||
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@ import java.util.HashMap;
|
|||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.muclight.element.MUCLightBlockingIQ;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* MUC Light blocking IQ provider class.
|
||||
|
@ -45,9 +45,9 @@ public class MUCLightBlockingIQProvider extends IQProvider<MUCLightBlockingIQ> {
|
|||
HashMap<Jid, Boolean> users = null;
|
||||
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
|
||||
if (parser.getName().equals("room")) {
|
||||
rooms = parseBlocking(parser, rooms);
|
||||
|
@ -57,7 +57,7 @@ public class MUCLightBlockingIQProvider extends IQProvider<MUCLightBlockingIQ> {
|
|||
users = parseBlocking(parser, users);
|
||||
}
|
||||
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
|
|
|
@ -21,13 +21,12 @@ import java.util.HashMap;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
|
||||
import org.jivesoftware.smackx.muclight.element.MUCLightConfigurationIQ;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* MUC Light configuration IQ provider class.
|
||||
*
|
||||
|
@ -44,9 +43,9 @@ public class MUCLightConfigurationIQProvider extends IQProvider<MUCLightConfigur
|
|||
HashMap<String, String> customConfigs = null;
|
||||
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
|
||||
if (parser.getName().equals("version")) {
|
||||
version = parser.nextText();
|
||||
|
@ -61,7 +60,7 @@ public class MUCLightConfigurationIQProvider extends IQProvider<MUCLightConfigur
|
|||
customConfigs.put(parser.getName(), parser.nextText());
|
||||
}
|
||||
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
|
|
|
@ -21,12 +21,11 @@ import java.util.HashMap;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.muclight.element.MUCLightElements.ConfigurationsChangeExtension;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* MUC Light configurations change provider class.
|
||||
*
|
||||
|
@ -44,9 +43,9 @@ public class MUCLightConfigurationsChangeProvider extends ExtensionElementProvid
|
|||
HashMap<String, String> customConfigs = null;
|
||||
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
|
||||
if (parser.getName().equals("prev-version")) {
|
||||
prevVersion = parser.nextText();
|
||||
|
@ -63,7 +62,7 @@ public class MUCLightConfigurationsChangeProvider extends ExtensionElementProvid
|
|||
customConfigs.put(parser.getName(), parser.nextText());
|
||||
}
|
||||
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.util.HashMap;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.muclight.MUCLightAffiliation;
|
||||
import org.jivesoftware.smackx.muclight.MUCLightRoomConfiguration;
|
||||
|
@ -28,8 +30,6 @@ import org.jivesoftware.smackx.muclight.element.MUCLightInfoIQ;
|
|||
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* MUC Light info IQ provider class.
|
||||
|
@ -48,9 +48,9 @@ public class MUCLightInfoIQProvider extends IQProvider<MUCLightInfoIQ> {
|
|||
HashMap<Jid, MUCLightAffiliation> occupants = new HashMap<>();
|
||||
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
|
||||
if (parser.getName().equals("version")) {
|
||||
version = parser.nextText();
|
||||
|
@ -62,7 +62,7 @@ public class MUCLightInfoIQProvider extends IQProvider<MUCLightInfoIQ> {
|
|||
outerloop2: while (true) {
|
||||
eventType = parser.next();
|
||||
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
if (parser.getName().equals("roomname")) {
|
||||
roomName = parser.nextText();
|
||||
} else if (parser.getName().equals("subject")) {
|
||||
|
@ -74,7 +74,7 @@ public class MUCLightInfoIQProvider extends IQProvider<MUCLightInfoIQ> {
|
|||
customConfigs.put(parser.getName(), parser.nextText());
|
||||
}
|
||||
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getDepth() == depth) {
|
||||
break outerloop2;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public class MUCLightInfoIQProvider extends IQProvider<MUCLightInfoIQ> {
|
|||
occupants = iterateOccupants(parser);
|
||||
}
|
||||
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
|
@ -101,14 +101,14 @@ public class MUCLightInfoIQProvider extends IQProvider<MUCLightInfoIQ> {
|
|||
int depth = parser.getDepth();
|
||||
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
if (parser.getName().equals("user")) {
|
||||
MUCLightAffiliation affiliation = MUCLightAffiliation
|
||||
.fromString(parser.getAttributeValue("", "affiliation"));
|
||||
occupants.put(JidCreate.from(parser.nextText()), affiliation);
|
||||
}
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getDepth() == depth) {
|
||||
break outerloop;
|
||||
}
|
||||
|
|
|
@ -20,13 +20,13 @@ import java.io.IOException;
|
|||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.jivesoftware.smackx.push_notifications.element.PushNotificationsElements.RemoteDisablingExtension;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* Push Notifications Remote Disabling Provider class.
|
||||
|
@ -43,8 +43,8 @@ public class RemoteDisablingProvider extends ExtensionElementProvider<RemoteDisa
|
|||
String node = parser.getAttributeValue("", "node");
|
||||
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
if (parser.getName().equals("affiliation")) {
|
||||
userJid = JidCreate.from(parser.getAttributeValue("", "jid"));
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class RemoteDisablingProvider extends ExtensionElementProvider<RemoteDisa
|
|||
return null;
|
||||
}
|
||||
}
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
if (parser.getDepth() == initialDepth) {
|
||||
break outerloop;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.jivesoftware.smack.ConnectionCreationListener;
|
|||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
|
||||
public final class ReferenceManager extends Manager {
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.jivesoftware.smack.packet.ExtensionElement;
|
|||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
import org.jivesoftware.smackx.reference.ReferenceManager;
|
||||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
|
|
|
@ -26,10 +26,10 @@ import org.jivesoftware.smack.parsing.SmackParsingException;
|
|||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
import org.jivesoftware.smack.util.ParserUtils;
|
||||
import org.jivesoftware.smackx.reference.element.ReferenceElement;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.jivesoftware.smackx.reference.element.ReferenceElement;
|
||||
|
||||
public class ReferenceProvider extends ExtensionElementProvider<ReferenceElement> {
|
||||
|
||||
|
@ -53,8 +53,8 @@ public class ReferenceProvider extends ExtensionElementProvider<ReferenceElement
|
|||
}
|
||||
ExtensionElement child = null;
|
||||
outerloop: while (true) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
XmlPullParser.Event eventType = parser.next();
|
||||
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
||||
String elementName = parser.getName();
|
||||
String namespace = parser.getNamespace();
|
||||
ExtensionElementProvider<?> provider = ProviderManager.getExtensionProvider(elementName, namespace);
|
||||
|
@ -62,7 +62,7 @@ public class ReferenceProvider extends ExtensionElementProvider<ReferenceElement
|
|||
child = provider.parse(parser);
|
||||
}
|
||||
}
|
||||
if (eventType == XmlPullParser.END_TAG) {
|
||||
else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
break outerloop;
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue