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:
parent
d04517cd08
commit
6980c8e63d
137 changed files with 1101 additions and 841 deletions
|
|
@ -17,11 +17,14 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc.packet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* A group chat invitation packet extension, which is used to invite other
|
||||
|
|
@ -125,8 +128,12 @@ public class GroupChatInvitation implements PacketExtension {
|
|||
return packet.getExtension(ELEMENT, NAMESPACE);
|
||||
}
|
||||
|
||||
public static class Provider implements PacketExtensionProvider {
|
||||
public PacketExtension parseExtension (XmlPullParser parser) throws Exception {
|
||||
public static class Provider extends PacketExtensionProvider<GroupChatInvitation> {
|
||||
|
||||
@Override
|
||||
public GroupChatInvitation parse(XmlPullParser parser,
|
||||
int initialDepth) throws XmlPullParserException,
|
||||
IOException {
|
||||
String roomAddress = parser.getAttributeValue("", "jid");
|
||||
// Advance to end of extension.
|
||||
parser.next();
|
||||
|
|
|
|||
|
|
@ -17,19 +17,23 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc.provider;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smackx.muc.packet.MUCAdmin;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* The MUCAdminProvider parses MUCAdmin packets. (@see MUCAdmin)
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class MUCAdminProvider implements IQProvider {
|
||||
public class MUCAdminProvider extends IQProvider<MUCAdmin> {
|
||||
|
||||
public IQ parseIQ(XmlPullParser parser) throws Exception {
|
||||
@Override
|
||||
public MUCAdmin parse(XmlPullParser parser, int initialDepth)
|
||||
throws XmlPullParserException, IOException {
|
||||
MUCAdmin mucAdmin = new MUCAdmin();
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
|
|
|
|||
|
|
@ -17,20 +17,25 @@
|
|||
|
||||
package org.jivesoftware.smackx.muc.provider;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.muc.packet.MUCOwner;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* The MUCOwnerProvider parses MUCOwner packets. (@see MUCOwner)
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class MUCOwnerProvider implements IQProvider {
|
||||
public class MUCOwnerProvider extends IQProvider<MUCOwner> {
|
||||
|
||||
public IQ parseIQ(XmlPullParser parser) throws Exception {
|
||||
@Override
|
||||
public MUCOwner parse(XmlPullParser parser, int initialDepth)
|
||||
throws XmlPullParserException, IOException, SmackException {
|
||||
MUCOwner mucOwner = new MUCOwner();
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
|
|
|
|||
|
|
@ -16,14 +16,17 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.muc.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smackx.muc.MUCAffiliation;
|
||||
import org.jivesoftware.smackx.muc.MUCRole;
|
||||
import org.jivesoftware.smackx.muc.packet.Destroy;
|
||||
import org.jivesoftware.smackx.muc.packet.MUCItem;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class MUCParserUtils {
|
||||
public static MUCItem parseItem(XmlPullParser parser) throws Exception {
|
||||
public static MUCItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
int initialDepth = parser.getDepth();
|
||||
MUCAffiliation affiliation = MUCAffiliation.fromString(parser.getAttributeValue("", "affiliation"));
|
||||
String nick = parser.getAttributeValue("", "nick");
|
||||
|
|
@ -54,7 +57,7 @@ public class MUCParserUtils {
|
|||
return new MUCItem(affiliation, role, actor, reason, jid, nick);
|
||||
}
|
||||
|
||||
public static Destroy parseDestroy(XmlPullParser parser) throws Exception {
|
||||
public static Destroy parseDestroy(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
boolean done = false;
|
||||
Destroy destroy = new Destroy();
|
||||
destroy.setJid(parser.getAttributeValue("", "jid"));
|
||||
|
|
|
|||
|
|
@ -18,10 +18,12 @@
|
|||
package org.jivesoftware.smackx.muc.provider;
|
||||
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smackx.muc.packet.MUCUser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* The MUCUserProvider parses packets with extended presence information about
|
||||
|
|
@ -29,17 +31,18 @@ import org.xmlpull.v1.XmlPullParser;
|
|||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class MUCUserProvider implements PacketExtensionProvider {
|
||||
public class MUCUserProvider extends PacketExtensionProvider<MUCUser> {
|
||||
|
||||
/**
|
||||
* Parses a MUCUser packet (extension sub-packet).
|
||||
*
|
||||
* @param parser the XML parser, positioned at the starting element of the extension.
|
||||
* @return a PacketExtension.
|
||||
* @throws Exception if a parsing error occurs.
|
||||
* @throws IOException
|
||||
* @throws XmlPullParserException
|
||||
*/
|
||||
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
|
||||
final int initialDepth = parser.getDepth();
|
||||
@Override
|
||||
public MUCUser parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
|
||||
MUCUser mucUser = new MUCUser();
|
||||
outerloop: while (true) {
|
||||
switch (parser.next()) {
|
||||
|
|
@ -77,7 +80,7 @@ public class MUCUserProvider implements PacketExtensionProvider {
|
|||
return mucUser;
|
||||
}
|
||||
|
||||
private static MUCUser.Invite parseInvite(XmlPullParser parser) throws Exception {
|
||||
private static MUCUser.Invite parseInvite(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
boolean done = false;
|
||||
MUCUser.Invite invite = new MUCUser.Invite();
|
||||
invite.setFrom(parser.getAttributeValue("", "from"));
|
||||
|
|
@ -98,7 +101,7 @@ public class MUCUserProvider implements PacketExtensionProvider {
|
|||
return invite;
|
||||
}
|
||||
|
||||
private static MUCUser.Decline parseDecline(XmlPullParser parser) throws Exception {
|
||||
private static MUCUser.Decline parseDecline(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
boolean done = false;
|
||||
MUCUser.Decline decline = new MUCUser.Decline();
|
||||
decline.setFrom(parser.getAttributeValue("", "from"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue