Java 类org.jivesoftware.smackx.ReportedData.Row 实例源码

项目:AyoSunny    文件:XmppUtil.java   
/** 
   * 查询用户 
   *  
   * @param userName 
   * @return 
   * @throws XMPPException 
   */  
  public static List<Session> searchUsers(XMPPConnection mXMPPConnection,String userName) {  
    List<Session> listUser=new ArrayList<Session>();
      try{
    UserSearchManager search = new UserSearchManager(mXMPPConnection);
    //此处一定要加上 search.
    Form searchForm = search.getSearchForm("search."+mXMPPConnection.getServiceName());
    Form answerForm = searchForm.createAnswerForm();
    answerForm.setAnswer("Username", true);
    answerForm.setAnswer("search", userName);
    ReportedData data = search.getSearchResults(answerForm,"search."+mXMPPConnection.getServiceName());                 
    Iterator<Row> it = data.getRows();
    Row row=null;
    while(it.hasNext()){
        row=it.next();
        Session session=new Session();
        session.setFrom(row.getValues("Username").next().toString());
        listUser.add(session);
    }
}catch(Exception e){

}
      return listUser;  
  }
项目:android_chat    文件:AddContacts.java   
boolean userExist(String user, String jid) {
    if (ThreadHelper.xmppConnection.isAuthenticated()) {
        String service = "search."+ThreadHelper.xmppConnection.getServiceName();
        UserSearchManager search = new UserSearchManager(ThreadHelper.xmppConnection);
        try {
            Form queryForm = search.getSearchForm(service);
               Form searchForm = queryForm.createAnswerForm();
               searchForm.setAnswer("Username", true);
               searchForm.setAnswer("search", user);
               ReportedData data = search.getSearchResults(searchForm, service);

               Iterator<Row> rows = data.getRows();
               while (rows.hasNext()) {
                  Row row = rows.next();

                  Iterator<String> jids = row.getValues("jid");
                  while (jids.hasNext())
                   if (jids.next().equalsIgnoreCase(jid))
                       return true;
               }
        } catch (XMPPException e) {
            if (th.D) Log.e(TAG, e.getMessage(), e);
        }
    }
    return false;
}
项目:EIM    文件:XmppConnectionManager.java   
/**
 * �����û�
 * 
 * @param serverDomain
 * @param userName
 * @return
 */
public List<User> searchUsers(String serverDomain, String userName) {
    List<User> list = new ArrayList<User>();
    UserSearchManager userSearchManager = new UserSearchManager(connection);
    try {
        Form searchForm = userSearchManager.getSearchForm("search."
                + serverDomain);
        Form answerForm = searchForm.createAnswerForm();
        answerForm.setAnswer("Username", true);
        answerForm.setAnswer("Name", true);
        answerForm.setAnswer("search", userName);
        ReportedData data = userSearchManager.getSearchResults(answerForm,
                "search." + serverDomain);
        Iterator<Row> rows = data.getRows();
        while (rows.hasNext()) {
            User user = new User();
            Row row = rows.next();
            user.setUserName(row.getValues("Username").next().toString());
            user.setName(row.getValues("Name").next().toString());
            SLog.i(tag, user.toString());
            list.add(user);
        }
    } catch (XMPPException e) {
        SLog.e(tag, Log.getStackTraceString(e));
    }
    return list;
}
项目:spark-svn-mirror    文件:UserSearchResults.java   
/**
 * Returns the first value found in the ReportedData.Row.
 *
 * @param row the ReportedData.Row.
 * @param key the specified key in the ReportedData.Row.
 * @return the first value found in the ReportedData.Row
 */
public String getFirstValue(ReportedData.Row row, String key) {
    try {
        final Iterator<String> rows = row.getValues(key);
        while (rows.hasNext()) {
            return rows.next();
        }
    }
    catch (Exception e) {
        Log.error("Error retrieving the first value.", e);
    }
    return null;
}
项目:yiim_v2    文件:FriendAddActivity.java   
private void searchEjaaberd() {
    // 此处一定要加上 search.
    try {
        Connection connection = getXmppBinder().getXmppConnection();
        UserSearchManager search = new UserSearchManager(connection);
        Form searchForm = search.getSearchForm("vjud."
                + connection.getServiceName());
        Form answerForm = searchForm.createAnswerForm();
        // answerForm.setAnswer("nick", mSearchEditText.getText()
        // .toString().trim() + "*");
        answerForm.setAnswer("user", mSearchEditText.getText().toString()
                .trim() + "*");
        // answerForm.setAnswer("search", mSearchEditText.getText()
        // .toString().trim());
        ReportedData data = search.getSearchResults(answerForm, "vjud."
                + connection.getServiceName());
        Iterator<Row> it = data.getRows();
        Row row = null;

        ArrayList<FriendAddModel> list = new ArrayList<FriendAddModel>();
        while (it.hasNext()) {
            row = it.next();
            String userId = StringUtils.escapeUserResource(row
                    .getValues("jid").next().toString());
            FriendAddModel model = new FriendAddModel(userId);
            model.setMsg(userId);
            String nick = row.getValues("nick").next().toString();
            if (!YiUtils.isStringInvalid(nick)) {
                model.setName(nick);
            }

            XmppVcard vCard = new XmppVcard(getXmppBinder()
                    .getServiceContext());
            vCard.load(connection, model.getMsg());

            // 加载用户的个性签名
            String sign = vCard.getSign();
            if (sign != null && sign.length() > 0) {
                if (model.getSubMsg().length() > 1) {
                    sign = ' ' + sign;
                }
                model.setSubMsg(model.getSubMsg() + sign);
            }
            list.add(model);
        }
        Message message = getHandler().obtainMessage(MSG_ON_SEARCH_SUCCESS,
                list);
        message.sendToTarget();
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}
项目:yiim_v2    文件:FriendAddActivity.java   
private void searchOpenfire() {
    // 此处一定要加上 search.
    try {
        Connection connection = getXmppBinder().getXmppConnection();
        UserSearchManager search = new UserSearchManager(connection);
        Form searchForm = search.getSearchForm("search."
                + connection.getServiceName());
        Form answerForm = searchForm.createAnswerForm();
        answerForm.setAnswer("Username", true);
        answerForm.setAnswer("search", mSearchEditText.getText().toString()
                .trim());
        ReportedData data = search.getSearchResults(answerForm, "search."
                + connection.getServiceName());
        Iterator<Row> it = data.getRows();
        Row row = null;

        ArrayList<FriendAddModel> list = new ArrayList<FriendAddModel>();
        while (it.hasNext()) {
            row = it.next();
            String userId = row.getValues("Username").next().toString()
                    + "@" + XmppConnectionUtils.getXmppHost();
            FriendAddModel model = new FriendAddModel(userId);
            model.setMsg(userId);
            model.setName(row.getValues("Name").next().toString());

            XmppVcard vCard = new XmppVcard(getXmppBinder()
                    .getServiceContext());
            vCard.load(connection, userId);

            // 加载用户的个性签名
            String sign = vCard.getSign();
            if (sign != null && sign.length() > 0) {
                if (model.getSubMsg().length() > 1) {
                    sign = ' ' + sign;
                }
                model.setSubMsg(model.getSubMsg() + sign);
            }
            list.add(model);
        }
        Message message = getHandler().obtainMessage(MSG_ON_SEARCH_SUCCESS,
                list);
        message.sendToTarget();
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
}