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