Search in sources :

Example 11 with FormField

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

the class SubscribeForm method addField.

private void addField(SubscribeOptionFields nodeField, FormField.Type type) {
    String fieldName = nodeField.getFieldName();
    if (getField(fieldName) == null) {
        FormField field = new FormField(fieldName);
        field.setType(type);
        addField(field);
    }
}
Also used : FormField(org.jivesoftware.smackx.xdata.FormField)

Example 12 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 13 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 14 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 15 with FormField

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

the class MamManager method getNewMamForm.

private static DataForm getNewMamForm() {
    FormField field = new FormField(FormField.FORM_TYPE);
    field.setType(FormField.Type.hidden);
    field.addValue(MamElements.NAMESPACE);
    DataForm form = new DataForm(DataForm.Type.submit);
    form.addField(field);
    return form;
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField)

Aggregations

FormField (org.jivesoftware.smackx.xdata.FormField)45 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)17 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