use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class NodeUtils method getFormFromPacket.
/**
* Get a {@link ConfigureForm} from a packet.
*
* @param packet TODO javadoc me please
* @param elem TODO javadoc me please
* @return The configuration form
*/
public static ConfigureForm getFormFromPacket(Stanza packet, PubSubElementType elem) {
FormNode config = (FormNode) packet.getExtensionElement(elem.getElementName(), elem.getNamespace().getXmlns());
DataForm dataForm = config.getForm();
return new ConfigureForm(dataForm);
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class DataFormProvider method parse.
@Override
public DataForm parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
DataForm.Type dataFormType = DataForm.Type.fromString(parser.getAttributeValue("", "type"));
DataForm.Builder dataForm = DataForm.builder(dataFormType);
String formType = null;
DataForm.ReportedData reportedData = null;
outerloop: while (true) {
XmlPullParser.Event eventType = parser.next();
switch(eventType) {
case START_ELEMENT:
String name = parser.getName();
String namespace = parser.getNamespace();
XmlEnvironment elementXmlEnvironment = XmlEnvironment.from(parser, xmlEnvironment);
switch(name) {
case "instructions":
dataForm.addInstruction(parser.nextText());
break;
case "title":
dataForm.setTitle(parser.nextText());
break;
case "field":
// Note that we parse this form field without any potential reportedData. We only use reportedData
// to lookup form field types of fields under <item/>.
FormField formField = parseField(parser, elementXmlEnvironment, formType);
TextSingleFormField hiddenFormTypeField = formField.asHiddenFormTypeFieldIfPossible();
if (hiddenFormTypeField != null) {
if (formType != null) {
throw new SmackParsingException("Multiple hidden form type fields");
}
formType = hiddenFormTypeField.getValue();
}
dataForm.addField(formField);
break;
case "item":
DataForm.Item item = parseItem(parser, elementXmlEnvironment, formType, reportedData);
dataForm.addItem(item);
break;
case "reported":
if (reportedData != null) {
throw new SmackParsingException("Data form with multiple <reported/> elements");
}
reportedData = parseReported(parser, elementXmlEnvironment, formType);
dataForm.setReportedData(reportedData);
break;
// See XEP-133 Example 32 for a corner case where the data form contains this extension.
case RosterPacket.ELEMENT:
if (namespace.equals(RosterPacket.NAMESPACE)) {
dataForm.addExtensionElement(RosterPacketProvider.INSTANCE.parse(parser));
}
break;
// See XEP-141 Data Forms Layout
case DataLayout.ELEMENT:
if (namespace.equals(DataLayout.NAMESPACE)) {
dataForm.addExtensionElement(DataLayoutProvider.parse(parser));
}
break;
}
break;
case END_ELEMENT:
if (parser.getDepth() == initialDepth) {
break outerloop;
}
break;
default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
}
}
return dataForm.build();
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class RoomInfoTest method validateRoomWithEmptyForm.
@Test
public void validateRoomWithEmptyForm() {
DataForm dataForm = DataForm.builder(DataForm.Type.result).build();
DiscoverInfo discoInfo = DiscoverInfo.builder("disco1").addExtension(dataForm).build();
RoomInfo roomInfo = new RoomInfo(discoInfo);
assertTrue(roomInfo.getDescription().isEmpty());
assertTrue(roomInfo.getSubject().isEmpty());
assertEquals(-1, roomInfo.getOccupantsCount());
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class EntityCapsManagerTest method createComplexSamplePacket.
private static DiscoverInfo createComplexSamplePacket() throws XmppStringprepException {
DiscoverInfoBuilder di = DiscoverInfo.builder("disco1");
di.from(JidCreate.from("benvolio@capulet.lit/230193"));
di.to(JidCreate.from("juliet@capulet.lit/chamber"));
di.ofType(IQ.Type.result);
Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
DiscoverInfo.Identity i = new DiscoverInfo.Identity("client", "pc", "Psi 0.11", "en");
identities.add(i);
i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");
identities.add(i);
di.addIdentities(identities);
di.addFeature("http://jabber.org/protocol/disco#items");
di.addFeature(EntityCapsManager.NAMESPACE);
di.addFeature("http://jabber.org/protocol/muc");
di.addFeature("http://jabber.org/protocol/disco#info");
DataForm softwareInfoDataForm = createSampleSoftwareInfoDataForm();
di.addExtension(softwareInfoDataForm);
return di.build();
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class EntityCapsManagerTest method createMalformedDiscoverInfo.
private static DiscoverInfo createMalformedDiscoverInfo() throws XmppStringprepException {
DiscoverInfoBuilder di = DiscoverInfo.builder("disco1");
di.from("benvolio@capulet.lit/230193");
di.to(")juliet@capulet.lit/chamber");
di.ofType(IQ.Type.result);
Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
DiscoverInfo.Identity i = new DiscoverInfo.Identity("client", "pc", "Psi 0.11", "en");
identities.add(i);
i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");
identities.add(i);
di.addIdentities(identities);
// Failure 1: Duplicate identities
i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");
identities.add(i);
di.addIdentities(identities);
di.addFeature("http://jabber.org/protocol/disco#items");
di.addFeature(EntityCapsManager.NAMESPACE);
di.addFeature("http://jabber.org/protocol/muc");
di.addFeature("http://jabber.org/protocol/disco#info");
// Failure 2: Duplicate features
di.addFeature("http://jabber.org/protocol/disco#info");
DataForm softwareInfoDataForm = createSampleSoftwareInfoDataForm();
di.addExtension(softwareInfoDataForm);
DiscoverInfo discoverInfo = di.buildWithoutValidiation();
return discoverInfo;
}
Aggregations