mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Add support for (custom) data form extensions
Fixes SMACK-605
This commit is contained in:
parent
d57fecfcc9
commit
9016120d71
3 changed files with 20 additions and 1 deletions
|
@ -609,7 +609,7 @@ public class PacketParserUtils {
|
|||
return iqPacket;
|
||||
}
|
||||
|
||||
private static RosterPacket parseRoster(XmlPullParser parser) throws Exception {
|
||||
public static RosterPacket parseRoster(XmlPullParser parser) throws Exception {
|
||||
RosterPacket roster = new RosterPacket();
|
||||
boolean done = false;
|
||||
RosterPacket.Item item = null;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.jivesoftware.smackx.xdata.packet;
|
||||
|
||||
import org.jivesoftware.smack.packet.Element;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smackx.xdata.FormField;
|
||||
|
@ -42,6 +43,7 @@ public class DataForm implements PacketExtension {
|
|||
private ReportedData reportedData;
|
||||
private final List<Item> items = new ArrayList<Item>();
|
||||
private final List<FormField> fields = new ArrayList<FormField>();
|
||||
private final List<Element> extensionElements = new ArrayList<Element>();
|
||||
|
||||
public DataForm(String type) {
|
||||
this.type = type;
|
||||
|
@ -195,6 +197,14 @@ public class DataForm implements PacketExtension {
|
|||
}
|
||||
}
|
||||
|
||||
public void addExtensionElement(Element element) {
|
||||
extensionElements.add(element);
|
||||
}
|
||||
|
||||
public List<Element> getExtensionElements() {
|
||||
return Collections.unmodifiableList(extensionElements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this DataForm has at least one FORM_TYPE field which is
|
||||
* hidden. This method is used for sanity checks.
|
||||
|
@ -232,6 +242,9 @@ public class DataForm implements PacketExtension {
|
|||
for (FormField field : getFields()) {
|
||||
buf.append(field.toXML());
|
||||
}
|
||||
for (Element element : extensionElements) {
|
||||
buf.append(element.toXML());
|
||||
}
|
||||
buf.closeElement(this);
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,9 @@
|
|||
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;
|
||||
|
@ -61,6 +63,10 @@ public class DataFormProvider implements PacketExtensionProvider {
|
|||
else if (parser.getName().equals("reported")) {
|
||||
dataForm.setReportedData(parseReported(parser));
|
||||
}
|
||||
// See XEP-133 Example 32 for a corner case where the data form contains this extension.
|
||||
else if (parser.getName().equals(RosterPacket.ELEMENT) && parser.getNamespace().equals(RosterPacket.NAMESPACE)) {
|
||||
dataForm.addExtensionElement(PacketParserUtils.parseRoster(parser));
|
||||
}
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals(dataForm.getElementName())) {
|
||||
done = true;
|
||||
|
|
Loading…
Reference in a new issue