Search in sources :

Example 21 with FormField

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

the class SimpleUserSearch method getItemsToSearch.

private String getItemsToSearch() {
    StringBuilder buf = new StringBuilder();
    if (form == null) {
        form = Form.getFormFrom(this);
    }
    if (form == null) {
        return "";
    }
    for (FormField field : form.getFields()) {
        String name = field.getVariable();
        String value = getSingleValue(field);
        if (value.trim().length() > 0) {
            buf.append('<').append(name).append('>').append(value).append("</").append(name).append('>');
        }
    }
    return buf.toString();
}
Also used : FormField(org.jivesoftware.smackx.xdata.FormField)

Example 22 with FormField

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

the class UserSearch method buildDataForm.

private static void buildDataForm(SimpleUserSearch search, String instructions, XmlPullParser parser) throws Exception {
    DataForm dataForm = new DataForm(DataForm.Type.form);
    boolean done = false;
    dataForm.setTitle("User Search");
    dataForm.addInstruction(instructions);
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG && !parser.getNamespace().equals("jabber:x:data")) {
            String name = parser.getName();
            FormField field = new FormField(name);
            // Handle hard coded values.
            if (name.equals("first")) {
                field.setLabel("First Name");
            } else if (name.equals("last")) {
                field.setLabel("Last Name");
            } else if (name.equals("email")) {
                field.setLabel("Email Address");
            } else if (name.equals("nick")) {
                field.setLabel("Nickname");
            }
            field.setType(FormField.Type.text_single);
            dataForm.addField(field);
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        } else if (eventType == XmlPullParser.START_TAG && parser.getNamespace().equals("jabber:x:data")) {
            PacketParserUtils.addExtensionElement(search, parser);
            done = true;
        }
    }
    if (search.getExtension("x", "jabber:x:data") == null) {
        search.addExtension(dataForm);
    }
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField)

Example 23 with FormField

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

the class ConfigureForm method toString.

@Override
public String toString() {
    StringBuilder result = new StringBuilder(getClass().getName() + " Content [");
    for (FormField formField : getFields()) {
        result.append('(');
        result.append(formField.getVariable());
        result.append(':');
        StringBuilder valuesBuilder = new StringBuilder();
        for (String value : formField.getValues()) {
            if (valuesBuilder.length() > 0)
                result.append(',');
            valuesBuilder.append(value);
        }
        if (valuesBuilder.length() == 0)
            valuesBuilder.append("NOT SET");
        result.append(valuesBuilder);
        result.append(')');
    }
    result.append(']');
    return result.toString();
}
Also used : FormField(org.jivesoftware.smackx.xdata.FormField)

Example 24 with FormField

use of org.jivesoftware.smackx.xdata.FormField in project xabber-android by redsolution.

the class Feature method createDataForm.

public static DataForm createDataForm(DataForm.Type type) {
    DataForm dataForm = new DataForm(type);
    FormField typeField = new FormField(FORM_TYPE_FIELD);
    typeField.addValue(FORM_TYPE_VALUE);
    typeField.setType(FormField.Type.hidden);
    dataForm.addField(typeField);
    return dataForm;
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField)

Example 25 with FormField

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

the class MamQueryIQProviderTest method checkMamQueryIQProvider.

@Test
public void checkMamQueryIQProvider() throws Exception {
    // example 1
    IQ iq1 = (IQ) PacketParserUtils.parseStanza(exampleMamQueryIQ1);
    MamQueryIQ mamQueryIQ1 = (MamQueryIQ) iq1;
    Assert.assertEquals(mamQueryIQ1.getType(), Type.set);
    Assert.assertEquals(mamQueryIQ1.getQueryId(), "test");
    DataForm dataForm1 = (DataForm) mamQueryIQ1.getExtension(DataForm.NAMESPACE);
    Assert.assertEquals(dataForm1.getType(), DataForm.Type.submit);
    List<FormField> fields1 = dataForm1.getFields();
    Assert.assertEquals(fields1.get(0).getType(), FormField.Type.hidden);
    Assert.assertEquals(fields1.get(1).getType(), FormField.Type.text_single);
    Assert.assertEquals(fields1.get(1).getValues().get(0), "Where arth thou, my Juliet?");
    Assert.assertEquals(fields1.get(2).getValues().get(0), "{http://jabber.org/protocol/mood}mood/lonely");
    // example2
    IQ iq2 = (IQ) PacketParserUtils.parseStanza(exampleMamQueryIQ2);
    MamQueryIQ mamQueryIQ2 = (MamQueryIQ) iq2;
    Assert.assertEquals(mamQueryIQ2.getType(), Type.result);
    Assert.assertNull(mamQueryIQ2.getQueryId());
    DataForm dataForm2 = (DataForm) mamQueryIQ2.getExtension(DataForm.NAMESPACE);
    Assert.assertEquals(dataForm2.getType(), DataForm.Type.form);
    List<FormField> fields2 = dataForm2.getFields();
    Assert.assertEquals(fields2.get(0).getValues().get(0), "urn:xmpp:mam:1");
    Assert.assertTrue(fields2.get(0).getValues().size() == 1);
    Assert.assertEquals(fields2.get(1).getType(), FormField.Type.jid_single);
    Assert.assertEquals(fields2.get(2).getType(), FormField.Type.text_single);
    Assert.assertEquals(fields2.get(2).getValues(), new ArrayList<>());
    Assert.assertEquals(fields2.get(4).getVariable(), "urn:example:xmpp:free-text-search");
}
Also used : MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ) IQ(org.jivesoftware.smack.packet.IQ) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ) Test(org.junit.Test)

Aggregations

FormField (org.jivesoftware.smackx.xdata.FormField)46 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)18 Test (org.junit.Test)10 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)6 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)3 Element (org.jivesoftware.smack.packet.Element)3 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)3 Form (org.jivesoftware.smackx.xdata.Form)3 RangeValidateElement (org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement.RangeValidateElement)3 XmlPullParser (org.xmlpull.v1.XmlPullParser)3 LinkedList (java.util.LinkedList)2 IQ (org.jivesoftware.smack.packet.IQ)2 RemoteCommand (org.jivesoftware.smackx.commands.RemoteCommand)2 StreamInitiation (org.jivesoftware.smackx.si.packet.StreamInitiation)2 ValidateElement (org.jivesoftware.smackx.xdatavalidation.packet.ValidateElement)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Method (java.lang.reflect.Method)1 MessageDigest (java.security.MessageDigest)1 HashMap (java.util.HashMap)1