use of org.jivesoftware.smackx.FormField in project ecf by eclipse.
the class XMPPUserSearchManager method getUserPropertiesFields.
/**
* Returns the user properties fields available on the XMPP server
*
* @param form
* @return String[] fields for form
* @throws ECFException
*/
public String[] getUserPropertiesFields() throws ECFException {
try {
if (form == null)
form = manager.getSearchForm(ecfConnection.getXMPPConnection(), SERVICE_SEARCH + ecfConnection.getXMPPConnection().getServiceName());
Set fields = new HashSet();
Iterator userProperties = form.getFields();
while (userProperties.hasNext()) {
FormField field = (FormField) userProperties.next();
String variable = field.getVariable();
// ignore these fields
if (!variable.equalsIgnoreCase(FORM_TYPE) && !variable.equalsIgnoreCase(SEARCH_ACTION))
fields.add(variable);
}
return (String[]) fields.toArray(new String[0]);
} catch (final XMPPException e) {
String message = null;
if (e.getXMPPError() != null && e.getXMPPError().getCode() == 404) {
message = Messages.XMPPContainer_UNRECOGONIZED_SEARCH_SERVICE;
} else {
message = e.getLocalizedMessage();
}
throw new ECFException(message, e);
}
}
use of org.jivesoftware.smackx.FormField in project Smack by igniterealtime.
the class AdHocCommandDiscoTest method testAdHocCommands.
public void testAdHocCommands() {
try {
AdHocCommandManager manager1 = AdHocCommandManager.getAddHocCommandsManager(getConnection(0));
manager1.registerCommand("test", "test node", LocalCommand.class);
manager1.registerCommand("test2", "test node", new LocalCommandFactory() {
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
return new LocalCommand() {
public boolean isLastStage() {
return true;
}
public boolean hasPermission(String jid) {
return true;
}
public void execute() throws XMPPException {
Form result = new Form(Form.TYPE_RESULT);
FormField resultField = new FormField("test2");
resultField.setLabel("test node");
resultField.addValue("it worked");
result.addField(resultField);
setForm(result);
}
public void next(Form response) throws XMPPException {
//
}
public void complete(Form response) throws XMPPException {
//
}
public void prev() throws XMPPException {
//
}
public void cancel() throws XMPPException {
//
}
};
}
});
AdHocCommandManager manager2 = AdHocCommandManager.getAddHocCommandsManager(getConnection(1));
DiscoverItems items = manager2.discoverCommands(getFullJID(0));
assertTrue("Disco for command test failed", items.getItems().next().getNode().equals("test"));
RemoteCommand command = manager2.getRemoteCommand(getFullJID(0), "test2");
command.execute();
assertEquals("Disco for command test failed", command.getForm().getField("test2").getValues().next(), "it worked");
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.jivesoftware.smackx.FormField in project Smack by igniterealtime.
the class MultiUserChatTest method setUp.
protected void setUp() throws Exception {
// SmackConfiguration.DEBUG = false;
super.setUp();
room = "fruta124@" + getMUCDomain();
try {
// User1 creates the room
muc = new MultiUserChat(getConnection(0), room);
muc.create("testbot");
// User1 sends an empty room configuration form which indicates that we want
// an instant room
Form form = new Form(Form.TYPE_SUBMIT);
FormField field = new FormField("muc#roomconfig_whois");
field.setType("list-single");
form.addField(field);
form.setAnswer("muc#roomconfig_whois", Arrays.asList("moderators"));
muc.sendConfigurationForm(form);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.jivesoftware.smackx.FormField in project Smack by igniterealtime.
the class SubscriberUseCases method testSubscribeConfigRequired.
public void testSubscribeConfigRequired() throws Exception {
ConfigureForm form = new ConfigureForm(FormType.submit);
form.setAccessModel(AccessModel.open);
// Openfire specific field - nothing in the spec yet
FormField required = new FormField("pubsub#subscription_required");
required.setType(FormField.TYPE_BOOLEAN);
form.addField(required);
form.setAnswer("pubsub#subscription_required", true);
LeafNode node = (LeafNode) getManager().createNode("Pubnode" + System.currentTimeMillis(), form);
Subscription sub = node.subscribe(getJid());
assertEquals(getJid(), sub.getJid());
assertNotNull(sub.getId());
assertEquals(node.getId(), sub.getNode());
assertEquals(true, sub.isConfigRequired());
}
Aggregations