Search in sources :

Example 56 with DataForm

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());
}
Also used : TextSingleFormField(org.jivesoftware.smackx.xdata.TextSingleFormField) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Test(org.junit.jupiter.api.Test)

Example 57 with DataForm

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);
}
Also used : ValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement) RangeValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement) BasicValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.BasicValidateElement) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField) BasicValidateElement(org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.BasicValidateElement) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 58 with DataForm

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());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField) Test(org.junit.jupiter.api.Test)

Example 59 with DataForm

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);
}
Also used : Form(org.jivesoftware.smackx.xdata.form.Form) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FillableForm(org.jivesoftware.smackx.xdata.form.FillableForm) IQ(org.jivesoftware.smack.packet.IQ) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MUCOwner(org.jivesoftware.smackx.muc.packet.MUCOwner)

Example 60 with 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);
}
Also used : Form(org.jivesoftware.smackx.xdata.form.Form) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FillableForm(org.jivesoftware.smackx.xdata.form.FillableForm) Registration(org.jivesoftware.smackx.iqregister.packet.Registration) IQ(org.jivesoftware.smack.packet.IQ) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm)

Aggregations

DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)65 FormField (org.jivesoftware.smackx.xdata.FormField)23 Test (org.junit.jupiter.api.Test)13 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)12 Feature (com.xabber.xmpp.ssn.Feature)7 MamQueryIQ (org.jivesoftware.smackx.mam.element.MamQueryIQ)7 Date (java.util.Date)5 MamQueryArgs (org.jivesoftware.smackx.mam.MamManager.MamQueryArgs)5 OtrMode (com.xabber.xmpp.archive.OtrMode)4 LoggingValue (com.xabber.xmpp.ssn.LoggingValue)4 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)4 FillableForm (org.jivesoftware.smackx.xdata.form.FillableForm)4 LinkedList (java.util.LinkedList)3 IQ (org.jivesoftware.smack.packet.IQ)3 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)3 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)3 DiscoverInfoBuilder (org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder)3 Form (org.jivesoftware.smackx.xdata.form.Form)3 DisclosureValue (com.xabber.xmpp.ssn.DisclosureValue)2