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,9 +17,12 @@
|
|||
|
||||
package org.jivesoftware.smackx.offline.packet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
/**
|
||||
* OfflineMessageInfo is an extension included in the retrieved offline messages requested by
|
||||
|
|
@ -85,25 +88,20 @@ public class OfflineMessageInfo implements PacketExtension {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
public static class Provider implements PacketExtensionProvider {
|
||||
|
||||
/**
|
||||
* Creates a new Provider.
|
||||
* ProviderManager requires that every PacketExtensionProvider has a public,
|
||||
* no-argument constructor
|
||||
*/
|
||||
public Provider() {
|
||||
}
|
||||
public static class Provider extends PacketExtensionProvider<OfflineMessageInfo> {
|
||||
|
||||
/**
|
||||
* Parses a OfflineMessageInfo 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 {
|
||||
@Override
|
||||
public OfflineMessageInfo parse(XmlPullParser parser,
|
||||
int initialDepth) throws XmlPullParserException,
|
||||
IOException {
|
||||
OfflineMessageInfo info = new OfflineMessageInfo();
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ package org.jivesoftware.smackx.offline.packet;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.provider.IQProvider;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -187,9 +189,12 @@ public class OfflineMessageRequest extends IQ {
|
|||
}
|
||||
}
|
||||
|
||||
public static class Provider implements IQProvider {
|
||||
public static class Provider extends IQProvider<OfflineMessageRequest> {
|
||||
|
||||
public IQ parseIQ(XmlPullParser parser) throws Exception {
|
||||
@Override
|
||||
public OfflineMessageRequest parse(XmlPullParser parser,
|
||||
int initialDepth) throws XmlPullParserException,
|
||||
IOException {
|
||||
OfflineMessageRequest request = new OfflineMessageRequest();
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
|
|
@ -214,7 +219,8 @@ public class OfflineMessageRequest extends IQ {
|
|||
return request;
|
||||
}
|
||||
|
||||
private Item parseItem(XmlPullParser parser) throws Exception {
|
||||
private Item parseItem(XmlPullParser parser)
|
||||
throws XmlPullParserException, IOException {
|
||||
boolean done = false;
|
||||
Item item = new Item(parser.getAttributeValue("", "node"));
|
||||
item.setAction(parser.getAttributeValue("", "action"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue