Package org.jivesoftware.smackx

Examples of org.jivesoftware.smackx.Form


   * @return The configuration form
   */
  public static ConfigureForm getFormFromPacket(Packet packet, PubSubElementType elem)
  {
    FormNode config = (FormNode)packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
    Form formReply = config.getForm();
    return new ConfigureForm(formReply);

  }
View Full Code Here


            //System.out.println(muc);
            muc.create(chatRoom);
            // Send an empty room configuration form which indicates that we
            // want
            // an instant room
            muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
            for (String user : users) {
                muc.invite(user, reason);
            }

            System.out.println("Created Chat Room :" + roomName + " with " + users);
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

        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) {
            this.description =
                    form.getField("muc#roominfo_description").getValues().next();
            Iterator<String> values = form.getField("muc#roominfo_subject").getValues();
            if (values.hasNext()) {
                this.subject = values.next();
            }
            else {
                this.subject = "";
            }
            this.occupantsCount =
                    Integer.parseInt(form.getField("muc#roominfo_occupants").getValues()
                    .next());
        }
    }
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) {
            this.description =
                    form.getField("muc#roominfo_description").getValues().next();
            Iterator<String> values = form.getField("muc#roominfo_subject").getValues();
            if (values.hasNext()) {
                this.subject = values.next();
            }
            else {
                this.subject = "";
            }
            this.occupantsCount =
                    Integer.parseInt(form.getField("muc#roominfo_occupants").getValues()
                    .next());
        }
    }
View Full Code Here

              regInfo.getAttributes().put(m.getKey(), inputStr);
          }
      }
      else {
        //TODO 重构注册信息的显示,要更清晰,可考虑独立出一个方法
        Form formToSend = regForm.createAnswerForm();
        for(Iterator<FormField> itr =regForm.getFields();itr.hasNext();){
          FormField field = itr.next();
          writer.append(field.getDescription() + "\n");
          writer.append(field.getLabel() + "\n");
          writer.append(field.isRequired()?"Required":"No required");
          Iterator<String> formFielditr = field.getValues();
          if(formFielditr != null){
            writer.append("Options:\n");
            while(formFielditr.hasNext()){
              writer.append(formFielditr.next() + "\n");
            }
          }
          writer.flush();
          inputStr = reader.readLine();
          formToSend.setAnswer(field.getVariable(), inputStr);
        }//end for
        //将填写好的表单附加到regInfo后面
        regInfo.addExtension(formToSend.getDataFormToSend());
        regInfo.setType(IQ.Type.SET);
      }
    }catch (IOException e) {
//      e.printStackTrace();
      System.err.println("getRegInfo exception.\n" + e.getMessage());
View Full Code Here

                        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 {
                            //
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

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.