Search in sources :

Example 36 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class DataLayoutTest method testLayoutFromFile.

@Test
public void testLayoutFromFile() throws Exception {
    DataFormProvider pr = new DataFormProvider();
    InputStreamReader inputStreamReader = new InputStreamReader(this.getClass().getResourceAsStream(TEST_INPUT_1), "UTF-8");
    XmlPullParser parser = PacketParserUtils.getParserFor(inputStreamReader);
    DataForm form = pr.parse(parser);
    assertNotNull(form);
    assertEquals(1, form.getExtensionElements().size());
    DataLayout layout = (DataLayout) form.getExtensionElements().get(0);
    assertEquals(5, layout.getPageLayout().size());
    assertEquals("Label - & \u00E9 \u00E1 ", layout.getLabel());
    Section section = (Section) layout.getPageLayout().get(1);
    assertEquals("section Label - & \u00E9 \u00E1 ", section.getLabel());
    Text text = (Text) layout.getPageLayout().get(2);
    assertEquals("PageText - & \u00E9 \u00E1 ", text.getText());
    section = (Section) layout.getPageLayout().get(3);
    assertEquals("<html>Number of Persons by<br/> Nationality and Status</html>", section.getLabel());
    text = (Text) layout.getPageLayout().get(4);
    assertEquals("<html><font color='red'><em>DO NOT DELAY</em></font><br/>supply further information</html>", text.getText());
    assertNotNull(layout.toXML());
    String output = layout.toXML().toString();
    assertEquals(TEST_OUTPUT_SPECIAL, output);
}
Also used : InputStreamReader(java.io.InputStreamReader) DataFormProvider(org.jivesoftware.smackx.xdata.provider.DataFormProvider) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Text(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Text) Section(org.jivesoftware.smackx.xdatalayout.packet.DataLayout.Section) Test(org.junit.jupiter.api.Test)

Example 37 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class DataFormProviderTest method testRetrieveFieldWithEmptyLabel.

@Test
public void testRetrieveFieldWithEmptyLabel() throws XmlPullParserException, IOException, SmackParsingException {
    String form = "<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' label='' 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(form);
    DataForm dataForm = DataFormProvider.INSTANCE.parse(parser);
    FormField usernameFormField = dataForm.getField("FORM_TYPE");
    assertEquals(FormField.Type.hidden, usernameFormField.getType());
    assertEquals("", usernameFormField.getLabel());
}
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 38 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class FiltersTest method checkMultipleFilters.

@Test
public void checkMultipleFilters() throws Exception {
    Method methodAddStartDateFilter = MamManager.class.getDeclaredMethod("addStart", Date.class, DataForm.class);
    methodAddStartDateFilter.setAccessible(true);
    Method methodAddEndDateFilter = MamManager.class.getDeclaredMethod("addEnd", Date.class, DataForm.class);
    methodAddEndDateFilter.setAccessible(true);
    Method methodAddJidFilter = MamManager.class.getDeclaredMethod("addWithJid", Jid.class, DataForm.class);
    methodAddJidFilter.setAccessible(true);
    DataForm dataForm = getNewMamForm();
    Date date = new Date();
    String dateString = XmppDateTime.formatXEP0082Date(date);
    String jid = "test@jid.com";
    methodAddStartDateFilter.invoke(mamManager, date, dataForm);
    methodAddEndDateFilter.invoke(mamManager, date, dataForm);
    methodAddJidFilter.invoke(mamManager, JidCreate.from(jid), dataForm);
    String dataFormResult = dataForm.toXML().toString();
    List<String> fields = new ArrayList<>();
    List<String> values = new ArrayList<>();
    fields.add("start");
    values.add(dateString);
    Assert.assertNotEquals(dataFormResult, getMamXMemberWith(fields, values));
    fields.add("end");
    values.add(dateString);
    Assert.assertNotEquals(dataFormResult, getMamXMemberWith(fields, values));
    fields.clear();
    values.clear();
    fields.add("start");
    values.add(dateString);
    fields.add("with");
    values.add(jid);
    Assert.assertNotEquals(dataFormResult, getMamXMemberWith(fields, values));
    fields.clear();
    values.clear();
    fields.add("end");
    values.add(dateString);
    fields.add("with");
    values.add(jid);
    fields.add("start");
    values.add(dateString);
    Assert.assertNotEquals(dataFormResult, getMamXMemberWith(fields, values));
    fields.clear();
    values.clear();
    fields.add("start");
    values.add(dateString);
    fields.add("end");
    values.add(dateString);
    fields.add("with");
    values.add(jid);
    Assert.assertEquals(dataFormResult, getMamXMemberWith(fields, values));
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Date(java.util.Date) Test(org.junit.Test)

Example 39 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class StreamInitiationProvider method parse.

@Override
public StreamInitiation parse(XmlPullParser parser, int initialDepth) throws Exception {
    boolean done = false;
    // si
    String id = parser.getAttributeValue("", "id");
    String mimeType = parser.getAttributeValue("", "mime-type");
    StreamInitiation initiation = new StreamInitiation();
    // file
    String name = null;
    String size = null;
    String hash = null;
    String date = null;
    String desc = null;
    boolean isRanged = false;
    // feature
    DataForm form = null;
    DataFormProvider dataFormProvider = new DataFormProvider();
    int eventType;
    String elementName;
    String namespace;
    while (!done) {
        eventType = parser.next();
        elementName = parser.getName();
        namespace = parser.getNamespace();
        if (eventType == XmlPullParser.START_TAG) {
            if (elementName.equals("file")) {
                name = parser.getAttributeValue("", "name");
                size = parser.getAttributeValue("", "size");
                hash = parser.getAttributeValue("", "hash");
                date = parser.getAttributeValue("", "date");
            } else if (elementName.equals("desc")) {
                desc = parser.nextText();
            } else if (elementName.equals("range")) {
                isRanged = true;
            } else if (elementName.equals("x") && namespace.equals("jabber:x:data")) {
                form = dataFormProvider.parse(parser);
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (elementName.equals("si")) {
                done = true;
            } else if (elementName.equals("file")) {
                long fileSize = 0;
                if (size != null && size.trim().length() != 0) {
                    try {
                        fileSize = Long.parseLong(size);
                    } catch (NumberFormatException e) {
                        LOGGER.log(Level.SEVERE, "Failed to parse file size from " + fileSize, e);
                    }
                }
                Date fileDate = new Date();
                if (date != null) {
                    try {
                        fileDate = XmppDateTime.parseDate(date);
                    } catch (ParseException e) {
                    // couldn't parse date, use current date-time
                    }
                }
                File file = new File(name, fileSize);
                file.setHash(hash);
                file.setDate(fileDate);
                file.setDesc(desc);
                file.setRanged(isRanged);
                initiation.setFile(file);
            }
        }
    }
    initiation.setSessionID(id);
    initiation.setMimeType(mimeType);
    initiation.setFeatureNegotiationForm(form);
    return initiation;
}
Also used : StreamInitiation(org.jivesoftware.smackx.si.packet.StreamInitiation) DataFormProvider(org.jivesoftware.smackx.xdata.provider.DataFormProvider) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) ParseException(java.text.ParseException) File(org.jivesoftware.smackx.si.packet.StreamInitiation.File) Date(java.util.Date)

Example 40 with DataForm

use of org.jivesoftware.smackx.xdata.packet.DataForm in project Smack by igniterealtime.

the class MamManager method pageAfter.

/**
     * Obtain page after the last message saved (specific chat).
     * <p>
     * Note that the messageUid is the XEP-0313 UID and <b>not</> the stanza ID of the message.
     * </p>
     *
     * @param chatJid
     * @param messageUid the UID of the message of which messages after should be received.
     * @param max
     * @return the MAM query result
     * @throws XMPPErrorException
     * @throws NotLoggedInException
     * @throws NotConnectedException
     * @throws InterruptedException
     * @throws NoResponseException
     */
public MamQueryResult pageAfter(Jid chatJid, String messageUid, int max) throws XMPPErrorException, NotLoggedInException, NotConnectedException, InterruptedException, NoResponseException {
    RSMSet rsmSet = new RSMSet(messageUid, null, -1, -1, null, max, null, -1);
    DataForm dataForm = getNewMamForm();
    addWithJid(chatJid, dataForm);
    return page(null, dataForm, rsmSet);
}
Also used : RSMSet(org.jivesoftware.smackx.rsm.packet.RSMSet) 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