Search in sources :

Example 16 with FormField

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);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ECFException(org.eclipse.ecf.core.util.ECFException) Iterator(java.util.Iterator) XMPPException(org.jivesoftware.smack.XMPPException) FormField(org.jivesoftware.smackx.FormField) HashSet(java.util.HashSet)

Example 17 with FormField

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());
    }
}
Also used : Form(org.jivesoftware.smackx.Form) DiscoverItems(org.jivesoftware.smackx.packet.DiscoverItems) XMPPException(org.jivesoftware.smack.XMPPException) FormField(org.jivesoftware.smackx.FormField) XMPPException(org.jivesoftware.smack.XMPPException)

Example 18 with FormField

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());
    }
}
Also used : Form(org.jivesoftware.smackx.Form) FormField(org.jivesoftware.smackx.FormField) XMPPException(org.jivesoftware.smack.XMPPException)

Example 19 with FormField

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());
}
Also used : FormField(org.jivesoftware.smackx.FormField)

Aggregations

FormField (org.jivesoftware.smackx.FormField)19 XMPPException (org.jivesoftware.smack.XMPPException)5 DataForm (org.jivesoftware.smackx.packet.DataForm)5 Form (org.jivesoftware.smackx.Form)4 StreamInitiation (org.jivesoftware.smackx.packet.StreamInitiation)2 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IQ (org.jivesoftware.smack.packet.IQ)1 XMPPError (org.jivesoftware.smack.packet.XMPPError)1 DiscoverInfo (org.jivesoftware.smackx.packet.DiscoverInfo)1 Feature (org.jivesoftware.smackx.packet.DiscoverInfo.Feature)1 Identity (org.jivesoftware.smackx.packet.DiscoverInfo.Identity)1 DiscoverItems (org.jivesoftware.smackx.packet.DiscoverItems)1 PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)1 WorkgroupForm (org.jivesoftware.smackx.workgroup.ext.forms.WorkgroupForm)1