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();
}
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);
}
}
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();
}
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;
}
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");
}
Aggregations