use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class RoomInfoTest method validateRoomWithForm.
@Test
public void validateRoomWithForm() {
DataForm.Builder dataForm = DataForm.builder(DataForm.Type.result);
TextSingleFormField.Builder desc = FormField.builder("muc#roominfo_description");
desc.setValue("The place for all good witches!");
dataForm.addField(desc.build());
TextSingleFormField.Builder subject = FormField.builder("muc#roominfo_subject");
subject.setValue("Spells");
dataForm.addField(subject.build());
TextSingleFormField.Builder occupants = FormField.builder("muc#roominfo_occupants");
occupants.setValue("3");
dataForm.addField(occupants.build());
DiscoverInfo discoInfo = DiscoverInfo.builder("disco1").addExtension(dataForm.build()).build();
RoomInfo roomInfo = new RoomInfo(discoInfo);
assertEquals("The place for all good witches!", roomInfo.getDescription());
assertEquals("Spells", roomInfo.getSubject());
assertEquals(3, roomInfo.getOccupantsCount());
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class DataValidationTest method testNamespacePrefix.
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testNamespacePrefix(SmackTestUtil.XmlPullParserKind parserKind) throws Exception {
String formFieldUsingNamespacePrefix = "<x xmlns='jabber:x:data'" + " xmlns:xdv='http://jabber.org/protocol/xdata-validate'" + " type='form'>" + " <title>Sample Form</title>" + " <instructions>" + " Please provide information for the following fields..." + " </instructions>" + " <field type='text-single' var='name' label='Event Name'/>" + " <field type='text-single' var='date/start' label='Starting Date'>" + " <xdv:validate datatype='xs:date'>" + " <basic/>" + " </xdv:validate>" + " </field>" + " <field type='text-single' var='date/end' label='Ending Date'>" + " <xdv:validate datatype='xs:date'>" + " <basic/>" + " </xdv:validate>" + " </field>" + "</x>";
DataForm dataForm = SmackTestUtil.parse(formFieldUsingNamespacePrefix, DataFormProvider.class, parserKind);
assertEquals("Sample Form", dataForm.getTitle());
FormField nameField = dataForm.getField("name");
assertEquals("Event Name", nameField.getLabel());
FormField dataStartField = dataForm.getField("date/start");
ValidateElement dataStartValidateElement = ValidateElement.from(dataStartField);
assertEquals("xs:date", dataStartValidateElement.getDatatype());
assertTrue(dataStartValidateElement instanceof BasicValidateElement);
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class DataFormProviderTest method testRetrieveFieldTypeFromReported.
@Test
public void testRetrieveFieldTypeFromReported() throws XmlPullParserException, IOException, SmackParsingException {
String firstForm = "<x xmlns='jabber:x:data' type='form'>" + " <title>Advanced User Search</title>" + " <instructions>The following fields are available for searching. Wildcard (*) characters are allowed as part of the query.</instructions>" + " <field var='FORM_TYPE' type='hidden'>" + " <value>jabber:iq:search</value>" + " </field>" + " <field label='Search' var='search'>" + " <required/>" + " </field>" + " <field label='Username' var='Username' type='boolean'>" + " <value>true</value>" + " </field>" + " <field label='Name' var='Name' type='boolean'>" + " <value>true</value>" + " </field>" + " <field label='Email' var='Email' type='boolean'>" + " <value>true</value>" + " </field>" + "</x>";
XmlPullParser parser = PacketParserUtils.getParserFor(firstForm);
DataForm firstDataForm = DataFormProvider.INSTANCE.parse(parser);
FormField usernameFormField = firstDataForm.getField("Username");
assertEquals(FormField.Type.bool, usernameFormField.getType());
String secondForm = "<x xmlns='jabber:x:data' type='result'>" + " <field var='FORM_TYPE' type='hidden'/>" + " <reported>" + " <field var='jid' type='jid-single' label='JID'/>" + " <field var='Username' type='text-single' label='Username'/>" + " <field var='Name' type='text-single' label='Name'/>" + " <field var='Email' type='text-single' label='Email'/>" + " </reported>" + " <item>" + " <field var='Email'>" + " <value>" + " 0" + " </value>" + " </field>" + " <field var='jid'>" + " <value>frank@orphu</value>" + " </field>" + " <field var='Username'>" + " <value>" + " frank" + " </value>" + " </field>" + " <field var='Name'>" + " <value>" + " 0" + " </value>" + " </field>" + " </item>" + " <item>" + " <field var='Email'>" + " <value>" + " </value>" + " </field>" + " <field var='jid'>" + " <value>frank2@orphu</value>" + " </field>" + " <field var='Username'>" + " <value>" + " frank2" + " </value>" + " </field>" + " <field var='Name'>" + " <value>" + " </value>" + " </field>" + " </item>" + "</x>";
parser = PacketParserUtils.getParserFor(secondForm);
DataForm secondDataForm = DataFormProvider.INSTANCE.parse(parser);
List<DataForm.Item> items = secondDataForm.getItems();
assertEquals(2, items.size());
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class MultiUserChat method getConfigurationForm.
/**
* Returns the room's configuration form that the room's owner can use.
* The configuration form allows to set the room's language,
* enable logging, specify room's type, etc..
*
* @return the Form that contains the fields to complete together with the instrucions or
* <code>null</code> if no configuration is possible.
* @throws XMPPErrorException if an error occurs asking the configuration form for the room.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
public Form getConfigurationForm() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
MUCOwner iq = new MUCOwner();
iq.setTo(room);
iq.setType(IQ.Type.get);
IQ answer = connection.sendIqRequestAndWaitForResponse(iq);
DataForm dataForm = DataForm.from(answer, MucConfigFormManager.FORM_TYPE);
return new Form(dataForm);
}
use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.
the class MultiUserChat method getRegistrationForm.
/**
* Returns the room's registration form that an unaffiliated user, can use to become a member
* of the room or <code>null</code> if no registration is possible. Some rooms may restrict the
* privilege to register members and allow only room admins to add new members.<p>
*
* If the user requesting registration requirements is not allowed to register with the room
* (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
* error to the user (error code 405).
*
* @return the registration Form that contains the fields to complete together with the
* instrucions or <code>null</code> if no registration is possible.
* @throws XMPPErrorException if an error occurs asking the registration form for the room or a
* 405 error if the user is not allowed to register with the room.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
public Form getRegistrationForm() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
Registration reg = new Registration();
reg.setType(IQ.Type.get);
reg.setTo(room);
IQ result = connection.sendIqRequestAndWaitForResponse(reg);
DataForm dataForm = DataForm.from(result);
return new Form(dataForm);
}
Aggregations