Package org.jivesoftware.smackx

Examples of org.jivesoftware.smackx.Form


                    // Set the new data to the command.
                    command.setData(response);

                    if (Action.next.equals(action)) {
                        command.incrementStage();
                        command.next(new Form(requestData.getForm()));
                        if (command.isLastStage()) {
                            // If it is the last stage then the command is
                            // completed
                            response.setStatus(Status.completed);
                        }
                        else {
                            // Otherwise it is still executing
                            response.setStatus(Status.executing);
                        }
                    }
                    else if (Action.complete.equals(action)) {
                        command.incrementStage();
                        command.complete(new Form(requestData.getForm()));
                        response.setStatus(Status.completed);
                        // Remove the completed session
                        executingCommands.remove(sessionId);
                    }
                    else if (Action.prev.equals(action)) {
View Full Code Here


    public Form getForm() {
        if (data.getForm() == null) {
            return null;
        }
        else {
            return new Form(data.getForm());
        }
    }
View Full Code Here

        if (inQueue) {
            throw new IllegalStateException("Already in queue " + workgroupJID);
        }

        // Build dataform from metadata
        Form form = new Form(Form.TYPE_SUBMIT);
        Iterator iter = metadata.keySet().iterator();
        while (iter.hasNext()) {
            String name = (String)iter.next();
            String value = (String)metadata.get(name).toString();

            String escapedName = StringUtils.escapeForXML(name);
            String escapedValue = StringUtils.escapeForXML(value);

            FormField field = new FormField(escapedName);
            field.setType(FormField.TYPE_TEXT_SINGLE);
            form.addField(field);
            form.setAnswer(escapedName, escapedValue);
        }
        joinQueue(form, userID);
    }
View Full Code Here

        try {
            // Create the room
            muc.create("testbot1");

            // Get the the room's configuration form
            Form form = muc.getConfigurationForm();
            assertNotNull("No room configuration form", form);
            // Create a new form to submit based on the original form
            Form submitForm = form.createAnswerForm();
            // Add default answers to the form to submit
            for (Iterator<FormField> fields = form.getFields(); fields.hasNext();) {
                FormField field = fields.next();
                if (!FormField.TYPE_HIDDEN.equals(field.getType())
                    && field.getVariable() != null) {
                    // Sets the default value as the answer
                    submitForm.setDefaultAnswer(field.getVariable());
                }
            }
            List<String> owners = new ArrayList<String>();
            owners.add(getBareJID(0));
            submitForm.setAnswer("muc#roomconfig_roomowners", owners);

            // Update the new room's configuration
            muc.sendConfigurationForm(submitForm);

            // Destroy the new room
View Full Code Here

            // Create the room
            muc.create("testbot");

            // Send an empty room configuration form which indicates that we want
            // an instant room
            muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));

            // Destroy the new room
            muc.destroy("The room has almost no activity...", null);
        }
        catch (XMPPException e) {
View Full Code Here

            // Check that user2 doesn't have a reserved nickname yet
            String reservedNickname = muc2.getReservedNickname();
            assertNull("Reserved nickname is not null", reservedNickname);

            // User2 registers with the room and reserves a nickname
            Form registrationForm = muc2.getRegistrationForm();
            Form answerForm = registrationForm.createAnswerForm();
            answerForm.setAnswer("muc#register_first", "MyFirstName");
            answerForm.setAnswer("muc#register_last", "MyLastName");
            answerForm.setAnswer("muc#register_roomnick", "MyNick");
            muc2.sendRegistrationForm(answerForm);

            // Check that user2 has a reserved nickname
            reservedNickname = muc2.getReservedNickname();
            assertEquals("Reserved nickname is wrong", "MyNick", reservedNickname);

            // Check that user2 can join the room using his reserved nickname
            muc2.join("MyNick");
            muc2.leave();

            // Check that other users cannot join the room with user2's reserved nickname
            MultiUserChat muc3 = new MultiUserChat(getConnection(2), room);
            try {
                muc3.join("MyNick");
                fail("Other user was able to join with other user's reserved nickname");
            }
            catch (XMPPException e) {
                XMPPError xmppError = e.getXMPPError();
                assertNotNull(
                    "No XMPPError was received when joining with other user's reserved nickname",
                    xmppError);
                assertEquals(
                    "Different error code was received while joining with other user's reserved nickname",
                    409,
                    xmppError.getCode());
            }

            // Check that user3 can join the room using his own nickname (not reserved)
            muc3.join("MyNotReservedNick");
            muc3.leave();

            // Check that another user cannot reserve an already reserved nickname
            registrationForm = muc3.getRegistrationForm();
            answerForm = registrationForm.createAnswerForm();
            answerForm.setAnswer("muc#register_first", "MyFirstName 2");
            answerForm.setAnswer("muc#register_last", "MyLastName 2");
            answerForm.setAnswer("muc#register_roomnick", "MyNick");
            try {
                muc3.sendRegistrationForm(answerForm);
            }
            catch (XMPPException e) {
                XMPPError xmppError = e.getXMPPError();
                assertNotNull(
                    "No XMPPError was received when reserving an already reserved nickname",
                    xmppError);
                assertEquals(
                    "Different error code was received while reserving an already reserved nickname",
                    409,
                    xmppError.getCode());
            }

            // Check that another user can reserve a new nickname
            registrationForm = muc3.getRegistrationForm();
            answerForm = registrationForm.createAnswerForm();
            answerForm.setAnswer("muc#register_first", "MyFirstName 2");
            answerForm.setAnswer("muc#register_last", "MyLastName 2");
            answerForm.setAnswer("muc#register_roomnick", "MyNick 2");
            muc3.sendRegistrationForm(answerForm);

        }
        catch (XMPPException e) {
            e.printStackTrace();
View Full Code Here

        }
    }

    private void makeRoomModerated() throws XMPPException {
        // User1 (which is the room owner) converts the instant room into a moderated room
        Form form = muc.getConfigurationForm();
        Form answerForm = form.createAnswerForm();
        answerForm.setAnswer("muc#roomconfig_moderatedroom", true);
        answerForm.setAnswer("muc#roomconfig_whois", Arrays.asList("moderators"));
        // Keep the room owner
        try {
            List<String> owners = new ArrayList<String>();
            owners.add(getBareJID(0));
            answerForm.setAnswer("muc#roomconfig_roomowners", owners);
        }
        catch (IllegalArgumentException e) {
            // Do nothing
        }
        muc.sendConfigurationForm(answerForm);
View Full Code Here

            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());
View Full Code Here

        this.moderated = info.containsFeature("muc_moderated");
        this.nonanonymous = info.containsFeature("muc_nonanonymous");
        this.passwordProtected = info.containsFeature("muc_passwordprotected");
        this.persistent = info.containsFeature("muc_persistent");
        // Get the information based on the discovered extended information
        Form form = Form.getFormFrom(info);
        if (form != null) {
            FormField descField = form.getField("muc#roominfo_description");
            this.description = descField == null ? "" : descField.getValues().next();

            FormField subjField = form.getField("muc#roominfo_subject");
            this.subject = subjField == null ? "" : subjField.getValues().next();

            FormField occCountField = form.getField("muc#roominfo_occupants");
            this.occupantsCount = occCountField == null ? -1 : Integer.parseInt(occCountField.getValues()
                    .next());
        }
    }
View Full Code Here

public class FormNodeProvider extends EmbeddedExtensionProvider
{
  @Override
  protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends PacketExtension> content)
  {
        return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm)content.iterator().next()));
  }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smackx.Form

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.