org.jivesoftware.smackx.ReportedData.Row Java Examples
The following examples show how to use
org.jivesoftware.smackx.ReportedData.Row.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmppConnection.java From weixin with Apache License 2.0 | 5 votes |
/** * 查询用户 * * @param userName * @return * @throws XMPPException */ public List<HashMap<String, String>> searchUsers(String userName) { if (getConnection() == null) return null; HashMap<String, String> user = null; List<HashMap<String, String>> results = new ArrayList<HashMap<String, String>>(); try { new ServiceDiscoveryManager(getConnection()); UserSearchManager usm = new UserSearchManager(getConnection()); Form searchForm = usm.getSearchForm(getConnection().getServiceName()); Form answerForm = searchForm.createAnswerForm(); answerForm.setAnswer("userAccount", true); answerForm.setAnswer("userPhote", userName); ReportedData data = usm.getSearchResults(answerForm, "search" + getConnection().getServiceName()); Iterator<Row> it = data.getRows(); Row row = null; while (it.hasNext()) { user = new HashMap<String, String>(); row = it.next(); user.put("userAccount", row.getValues("userAccount").next().toString()); user.put("userPhote", row.getValues("userPhote").next().toString()); results.add(user); // 若存在,则有返回,UserName一定非空,其他两个若是有设,一定非空 } } catch (XMPPException e) { e.printStackTrace(); } return results; }
Example #2
Source File: FriendAddActivity.java From yiim_v2 with GNU General Public License v2.0 | 4 votes |
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(); } }
Example #3
Source File: FriendAddActivity.java From yiim_v2 with GNU General Public License v2.0 | 4 votes |
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(); } }
Example #4
Source File: XMPPUtils.java From saros with GNU General Public License v2.0 | 2 votes |
/** * Tries to find the user in the user directory of the server. This method may fail for different * XMPP Server implementation, because the 'user' variable is not mandatory neither that it must * be named 'user'. Currently works with ejabberd XMPP servers. */ // TODO: remove this method, add more logic and let the GUI handle search // stuff private static boolean isListedInUserDirectory(Connection connection, JID jid) { String userDirectoryService = null; try { userDirectoryService = getUserDirectoryService(connection, connection.getServiceName()); if (userDirectoryService == null) return false; UserSearch search = new UserSearch(); Form form = search.getSearchForm(connection, userDirectoryService); String userFieldVariable = null; for (Iterator<FormField> it = form.getFields(); it.hasNext(); ) { FormField formField = it.next(); if ("user".equalsIgnoreCase(formField.getVariable())) { userFieldVariable = formField.getVariable(); break; } } if (userFieldVariable == null) return false; Form answerForm = form.createAnswerForm(); answerForm.setAnswer(userFieldVariable, jid.getName()); ReportedData data = search.sendSearchForm(connection, answerForm, userDirectoryService); for (Iterator<Row> it = data.getRows(); it.hasNext(); ) { Row row = it.next(); Iterator<String> vit = row.getValues("jid"); if (vit == null) continue; while (vit.hasNext()) { JID returnedJID = new JID(vit.next()); if (jid.equals(returnedJID)) return true; } } return false; } catch (XMPPException e) { log.error("searching in the user directory + '" + userDirectoryService + "' failed", e); return false; } }