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,14 +17,15 @@
|
|||
|
||||
package org.jivesoftware.smackx.xdata.provider;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.packet.RosterPacket;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.xdata.FormField;
|
||||
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -33,16 +34,10 @@ import java.util.List;
|
|||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class DataFormProvider implements PacketExtensionProvider {
|
||||
public class DataFormProvider extends PacketExtensionProvider<DataForm> {
|
||||
|
||||
/**
|
||||
* Creates a new DataFormProvider.
|
||||
* ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor
|
||||
*/
|
||||
public DataFormProvider() {
|
||||
}
|
||||
|
||||
public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
|
||||
@Override
|
||||
public DataForm parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
|
||||
boolean done = false;
|
||||
DataForm dataForm = new DataForm(parser.getAttributeValue("", "type"));
|
||||
while (!done) {
|
||||
|
|
@ -76,7 +71,7 @@ public class DataFormProvider implements PacketExtensionProvider {
|
|||
return dataForm;
|
||||
}
|
||||
|
||||
private FormField parseField(XmlPullParser parser) throws Exception {
|
||||
private FormField parseField(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
boolean done = false;
|
||||
FormField formField = new FormField(parser.getAttributeValue("", "var"));
|
||||
formField.setLabel(parser.getAttributeValue("", "label"));
|
||||
|
|
@ -105,7 +100,7 @@ public class DataFormProvider implements PacketExtensionProvider {
|
|||
return formField;
|
||||
}
|
||||
|
||||
private DataForm.Item parseItem(XmlPullParser parser) throws Exception {
|
||||
private DataForm.Item parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
boolean done = false;
|
||||
List<FormField> fields = new ArrayList<FormField>();
|
||||
while (!done) {
|
||||
|
|
@ -123,7 +118,7 @@ public class DataFormProvider implements PacketExtensionProvider {
|
|||
return new DataForm.Item(fields);
|
||||
}
|
||||
|
||||
private DataForm.ReportedData parseReported(XmlPullParser parser) throws Exception {
|
||||
private DataForm.ReportedData parseReported(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
boolean done = false;
|
||||
List<FormField> fields = new ArrayList<FormField>();
|
||||
while (!done) {
|
||||
|
|
@ -141,7 +136,7 @@ public class DataFormProvider implements PacketExtensionProvider {
|
|||
return new DataForm.ReportedData(fields);
|
||||
}
|
||||
|
||||
private FormField.Option parseOption(XmlPullParser parser) throws Exception {
|
||||
private FormField.Option parseOption(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
boolean done = false;
|
||||
FormField.Option option = null;
|
||||
String label = parser.getAttributeValue("", "label");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue