1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-14 06:51:08 +01:00

Rework Smack Provider design

this is the first stop towards fixing "SMACK-65: parsing should look for
depth", by providing the initial parsing depth to the provider. Some
methods (.e.g parseMessage) now use the depth as abort condition,
instead of a unclean String equals check.

parseIQ() and parseExtension() where both renamed to parse.

This also restricts the Exceptions thrown by the parse method, to just
XmlPullParserException, IOException and SmackException (not really a big
victory, but nevertheless a slight improvement).

StreamFeatureProvider is now gone, we simply use PacketExtensionProvider
for stream features.
This commit is contained in:
Florian Schmaus 2014-10-07 21:15:20 +02:00
parent d04517cd08
commit 6980c8e63d
137 changed files with 1101 additions and 841 deletions

View file

@ -17,15 +17,18 @@
package org.jivesoftware.smackx.iqversion.provider;
import java.io.IOException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smackx.iqversion.packet.Version;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class VersionProvider implements IQProvider {
public IQ parseIQ(XmlPullParser parser) throws Exception {
assert (parser.getEventType() == XmlPullParser.START_TAG);
final int initalDepth = parser.getDepth();
public class VersionProvider extends IQProvider<Version> {
@Override
public Version parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
String name = null, version = null, os = null;
outerloop: while (true) {
@ -46,7 +49,7 @@ public class VersionProvider implements IQProvider {
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == initalDepth && parser.getName().equals(IQ.QUERY_ELEMENT)) {
if (parser.getDepth() == initialDepth && parser.getName().equals(IQ.QUERY_ELEMENT)) {
break outerloop;
}
}