/**
   * 修改会议室 当前该函数只能修改会议室名称和成员
   *
   * @param roomName
   * @param memberList
   */
  public static boolean modifyRoom(
      ImConnection talkConnection, String roomName, String newRoomName, List<String> memberList) {
    try {
      MultiUserChat muc = getMultiUserChat(talkConnection, roomName);
      if (muc != null) {
        muc.join(talkConnection.getXMPPConnection().getUser());
        // 获得聊天室的配置表单
        Form form = muc.getConfigurationForm();
        // 根据原始表单创建一个要提交的新表单。
        Form submitForm = form.createAnswerForm();
        submitForm.setAnswer("muc#roomconfig_roomname", newRoomName); // 设置房间的新名称
        // form.setAnswer();
        // 先删除所以的群成员
        List<Affiliate> delMembers = (List<Affiliate>) muc.getMembers();
        if (delMembers != null && delMembers.size() > 0) {
          for (Affiliate affiliate : delMembers) {
            muc.revokeMembership(affiliate.getJid());
          }
        }

        if (memberList != null && memberList.size() > 0) {
          for (String member : memberList) {
            muc.grantMembership(member);
          }
        }

        muc.sendConfigurationForm(submitForm);
      }
    } catch (XMPPException e) {
      e.printStackTrace();
    }
    return true;
  }
Exemplo n.º 2
0
 /**
  * Returns a new Form to submit the completed values. The new Form will include all the fields of
  * the original form except for the fields of type FIXED. Only the HIDDEN fields will include the
  * same value of the original form. The other fields of the new form MUST be completed. If a field
  * remains with no answer when sending the completed form, then it won't be included as part of
  * the completed form.
  *
  * <p>The reason why the fields with variables are included in the new form is to provide a model
  * for binding with any UI. This means that the UIs will use the original form (of type "form") to
  * learn how to render the form, but the UIs will bind the fields to the form of type submit.
  *
  * @return a Form to submit the completed values.
  */
 public Form createAnswerForm() {
   if (!isFormType()) {
     throw new IllegalStateException("Only forms of type \"form\" could be answered");
   }
   // Create a new Form
   final Form form = new Form(TYPE_SUBMIT);
   for (final Iterator<FormField> fields = getFields(); fields.hasNext(); ) {
     final FormField field = fields.next();
     // Add to the new form any type of field that includes a variable.
     // Note: The fields of type FIXED are the only ones that don't
     // specify a variable
     if (field.getVariable() != null) {
       final FormField newField = new FormField(field.getVariable());
       newField.setType(field.getType());
       form.addField(newField);
       // Set the answer ONLY to the hidden fields
       if (FormField.TYPE_HIDDEN.equals(field.getType())) {
         // Since a hidden field could have many values we need to
         // collect them
         // in a list
         final List<String> values = new ArrayList<String>();
         for (final Iterator<String> it = field.getValues(); it.hasNext(); ) {
           values.add(it.next());
         }
         form.setAnswer(field.getVariable(), values);
       }
     }
   }
   return form;
 }
Exemplo n.º 3
0
 /**
  * Returns the number of offline messages for the user of the connection.
  *
  * @return the number of offline messages for the user of the connection.
  * @throws XMPPException If the user is not allowed to make this request or the server does not
  *     support offline message retrieval.
  */
 public int getMessageCount() throws XMPPException {
   DiscoverInfo info =
       ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(null, namespace);
   Form extendedInfo = Form.getFormFrom(info);
   if (extendedInfo != null) {
     String value = (String) extendedInfo.getField("number_of_messages").getValues().next();
     return Integer.parseInt(value);
   }
   return 0;
 }
Exemplo n.º 4
0
 RoomInfo(DiscoverInfo info) {
   super();
   this.room = info.getFrom();
   // Get the information based on the discovered features
   this.membersOnly = info.containsFeature("muc_membersonly");
   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());
   }
 }
Exemplo n.º 5
0
  /**
   * Creates a node with specified configuration.
   *
   * <p>Note: This is the only way to create a collection node.
   *
   * @param name The name of the node, which must be unique within the pubsub service
   * @param config The configuration for the node
   * @return The node that was created
   * @exception XMPPException
   */
  public Node createNode(String name, Form config) throws XMPPException {
    PubSub request =
        createPubsubPacket(to, Type.SET, new NodeExtension(PubSubElementType.CREATE, name));
    boolean isLeafNode = true;

    if (config != null) {
      request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
      FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());

      if (nodeTypeField != null)
        isLeafNode = nodeTypeField.getValues().next().equals(NodeType.leaf.toString());
    }

    // Errors will cause exceptions in getReply, so it only returns
    // on success.
    sendPubsubPacket(con, to, Type.SET, request);
    Node newNode = isLeafNode ? new LeafNode(con, name) : new CollectionNode(con, name);
    newNode.setTo(to);
    nodeMap.put(newNode.getId(), newNode);

    return newNode;
  }
Exemplo n.º 6
0
  public String getJid() {
    try {
      System.out.println("getJid method executed");
      ConnectionConfiguration config = new ConnectionConfiguration(DOMAIN, PORT);
      config.setSASLAuthenticationEnabled(true);
      XMPPConnection con = new XMPPConnection(config);
      con.connect();
      System.out.println("Connection ok");
      con.login("searchuser", "search");
      System.out.println("Logged in");
      UserSearchManager search = new UserSearchManager(con);
      System.out.println("User Search created");
      Collection services = search.getSearchServices();
      System.out.println("Search Services found:");
      Iterator it = services.iterator();
      while (it.hasNext()) {
        System.out.println(it.next());
      }
      Form searchForm = search.getSearchForm("search." + "cuopencomm");
      System.out.println("Available search fields:");
      Iterator<FormField> fields = searchForm.getFields();
      while (fields.hasNext()) {
        FormField field = fields.next();
        System.out.println(field.getVariable() + " : " + field.getType());
      }

      Form answerForm = searchForm.createAnswerForm();
      answerForm.setAnswer("search", email);
      answerForm.setAnswer("Email", true);

      ReportedData data = search.getSearchResults(answerForm, "search." + "cuopencomm");

      System.out.println("\nColumns that are included as part of the search results:");
      Iterator<Column> columns = data.getColumns();
      while (columns.hasNext()) {
        System.out.println(columns.next().getVariable());
      }

      System.out.println("\nThe jids and emails from our each of our hits:");
      Iterator<Row> rows = data.getRows();
      while (rows.hasNext()) {
        Row row = rows.next();

        Iterator<String> jids = row.getValues("jid");
        Iterator<String> emails = row.getValues("email");
        String jidFound = null;
        String emailFound = null;

        while (emails.hasNext() && jids.hasNext()) {
          jidFound = jids.next();
          emailFound = emails.next();
          System.out.println(jidFound);
          System.out.println(emailFound);
          if (emailFound.equalsIgnoreCase(email)) {
            jid = jidFound;
            String[] jidCleaned = jid.split("@");
            jid = jidCleaned[0];
            System.out.println(jid);
          }
        }
      }
      con.disconnect();
      return jid;
    } catch (Exception ex) {
      System.out.println("Caught Exception :" + ex.getMessage());
      return jid;
    }
  }
 /**
  * Sets the form of the current stage. This should be used when setting a response. It could be a
  * form to fill out the information needed to go to the next stage or the result of an execution.
  *
  * @param form the form of the current stage to fill out or the result of the execution.
  */
 protected void setForm(Form form) {
   data.setForm(form.getDataFormToSend());
 }
 public static MultiUserChat createConferenceRoom(
     ImConnection talkConnection, String roomName, List<String> memberList) throws XMPPException {
   try {
     MultiUserChat muc = getMultiUserChat(talkConnection, roomName);
     if (muc != null) {
       // 创建聊天室
       muc.join(talkConnection.getXMPPConnection().getUser());
       //                muc.create(roomName); // roomName房间的名字
       // 获得聊天室的配置表单
       Form form = muc.getConfigurationForm();
       // 根据原始表单创建一个要提交的新表单。
       Form submitForm = form.createAnswerForm();
       // 向要提交的表单添加默认答复
       for (Iterator<FormField> fields = form.getFields(); fields.hasNext(); ) {
         FormField field = (FormField) fields.next();
         if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
           // 设置默认值作为答复
           submitForm.setDefaultAnswer(field.getVariable());
         }
       }
       // 设置聊天室的新拥有者
       List<String> owners = new ArrayList<String>();
       owners.add(talkConnection.getXMPPConnection().getUser()); // 用户JID
       submitForm.setAnswer("muc#roomconfig_roomowners", owners);
       // 设置聊天室是持久聊天室,即将要被保存下来
       submitForm.setAnswer("muc#roomconfig_persistentroom", true);
       // 房间仅对成员开放
       submitForm.setAnswer("muc#roomconfig_membersonly", false);
       // 允许占有者邀请其他人
       submitForm.setAnswer("muc#roomconfig_allowinvites", true);
       // 登录房间对话
       submitForm.setAnswer("muc#roomconfig_enablelogging", true);
       // 仅允许注册的昵称登录
       submitForm.setAnswer("x-muc#roomconfig_reservednick", true);
       // 允许使用者修改昵称
       submitForm.setAnswer("x-muc#roomconfig_canchangenick", false);
       // 允许用户注册房间
       submitForm.setAnswer("x-muc#roomconfig_registration", false);
       // 发送已完成的表单(有默认值)到服务器来配置聊天室
       submitForm.setAnswer("muc#roomconfig_passwordprotectedroom", true);
       // 添加群成员
       for (String tempMember : memberList) {
         muc.grantMembership(tempMember);
       }
       // 发送已完成的表单(有默认值)到服务器来配置聊天室
       muc.sendConfigurationForm(submitForm);
     }
     return muc;
   } catch (XMPPException e) {
     e.printStackTrace();
     throw new XMPPException("");
   }
 }
Exemplo n.º 9
0
  public static void createMucChannel(
      String channelname, String channeltopic, int userid, int channelid) {
    try {
      if (!Application.mucchannels.containsKey(channelid)) {
        // create MUC
        MultiUserChat muc =
            new MultiUserChat(Application.conn, channelname + "@conference.webchat");
        System.out.println("Channelname: " + channelname);
        muc.create(channelname);

        Application.mucchannels.put(channelid, muc);

        Form form = muc.getConfigurationForm();
        Form submitForm = form.createAnswerForm();

        for (Iterator<FormField> fields = form.getFields(); fields.hasNext(); ) {
          FormField field = (FormField) fields.next();
          if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
            submitForm.setDefaultAnswer(field.getVariable());
          }
        }

        List<String> owners = new ArrayList<String>();
        owners.add("webchat@webchat");
        submitForm.setAnswer("muc#roomconfig_roomowners", owners);
        muc.sendConfigurationForm(submitForm);
        muc.invite(
            models.User.find.byId(userid).username + "@webchat/Smack",
            "Einladung in Channel " + channelname);
        final int chanid = channelid;
        muc.sendMessage("Willkommen: Topic lautet " + channeltopic + "!");
        muc.addMessageListener(
            new PacketListener() {
              @Override
              public void processPacket(Packet packet) {
                if (packet instanceof Message) {
                  String[] temp;
                  temp = ((Message) packet).getFrom().split("/");
                  if (!temp[1].equals(models.Channel.find.byId(chanid).name)) {
                    System.out.println("Received user: "******"@webchat/Smack",
            "Einladung in Channel " + channelname);
        muc.sendMessage("Willkommen: Topic lautet" + channeltopic + "!");
      }
    } catch (XMPPException exp) {
      exp.printStackTrace();
    }
  }