Java Code Examples for org.jivesoftware.smack.Roster#getEntry()

The following examples show how to use org.jivesoftware.smack.Roster#getEntry() . 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: RosterAction.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    Action action = Action.valueOf(sampler.getPropertyAsString(ACTION, Action.get_roster.toString()));
    Roster roster = sampler.getXMPPConnection().getRoster();
    String entry = sampler.getPropertyAsString(ENTRY);
    res.setSamplerData(action.toString() + ": " + entry);
    if (action == Action.get_roster) {
        res.setResponseData(rosterToString(roster).getBytes());
    } else if (action == Action.add_item) {
        roster.createEntry(entry, entry, new String[0]);
    } else if (action == Action.delete_item) {
        RosterEntry rosterEntry = roster.getEntry(entry);
        if (rosterEntry != null) {
            roster.removeEntry(rosterEntry);
        }
    }

    return res;
}
 
Example 2
Source File: XmppTool.java    From xmpp with Apache License 2.0 6 votes vote down vote up
/**
 * 添加到分组
 *
 * @param
 * @param userName
 * @param groupName
 */
public void addUserToGroup(String userName, String groupName) {
    Roster roster = con.getRoster();
    RosterGroup group = roster.getGroup(groupName);
    if (null == group) {
        group = roster.createGroup(groupName);
    }
    RosterEntry entry = roster.getEntry(userName);
    if (entry != null) {
        try {
            group.addEntry(entry);
        } catch (XMPPException e) {
            SLog.e(tag, Log.getStackTraceString(e));
        }
    }

}
 
Example 3
Source File: XmppManager.java    From weixin with Apache License 2.0 6 votes vote down vote up
/**
 * 删除好友
 * 
 * @param roster
 * @param userName
 * @return
 */
public boolean removeUser(Roster roster, String userName) {
	try {
		if (userName.contains("@")) {
			userName = userName.split("@")[0];
		}
		RosterEntry entry = roster.getEntry(userName);
		L.i(LOGTAG, "删除好友--->" + userName);
		L.d(LOGTAG, "User." + (roster.getEntry(userName) == null));
		roster.removeEntry(entry);
		return true;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return false;
}
 
Example 4
Source File: XmppTool.java    From xmpp with Apache License 2.0 5 votes vote down vote up
/**
 * 删除好友
 *
 * @param userName
 * @return
 */
public boolean removeUser(String userName) {
    Roster roster = con.getRoster();
    try {
        RosterEntry entry = roster.getEntry(userName);
        if (null != entry) {
            roster.removeEntry(entry);
        }
        return true;
    } catch (XMPPException e) {
        SLog.e(tag, Log.getStackTraceString(e));
    }
    return false;
}
 
Example 5
Source File: SarosView.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getNickname(JID jid) throws RemoteException {
  Roster roster = getConnectionService().getRoster();

  if (roster == null) throw new IllegalStateException("not connected to a xmpp server");

  if (roster.getEntry(jid.getBase()) == null) return null;
  if (roster.getEntry(jid.getBase()).getName() == null) return jid.getBase();
  else return roster.getEntry(jid.getBase()).getName();
}
 
Example 6
Source File: XmppDeleteEntryRunnable.java    From yiim_v2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public XmppResult execute() {
	// TODO Auto-generated method stub
	XmppResult result = createResult();

	Cursor mCursor = null;
	try {
		// 删除关系表
		if (mRosterId != -1) {
			mCursor = mContext.getContentResolver().query(
					ContentUris.withAppendedId(RosterColumns.CONTENT_URI,
							mRosterId),
					new String[] { RosterColumns.USERID,
							RosterColumns.GROUP_ID }, null, null, null);
			if (mCursor != null && mCursor.getCount() == 1) {
				mCursor.moveToFirst();
				mUserId = mCursor.getString(0);
				mGroupId = mCursor.getInt(1);
			}
		}

		Roster roster = XmppConnectionUtils.getInstance().getConnection()
				.getRoster();
		RosterEntry rosterEntry = roster.getEntry(mUserId);
		if (rosterEntry != null) {
			roster.removeEntry(rosterEntry);
		}

		mContext.getContentResolver().delete(
				RosterColumns.CONTENT_URI,
				RosterColumns.USERID + "='"+mUserId+"' and " + RosterColumns.GROUP_ID
						+ "=" + mGroupId,
				null);

		// 删除本地聊天记录
		YiIMUtils.deleteChatRecord(mContext, mUserId);

		// 删除本地会话记录
		YiIMUtils.deleteConversation(mContext, mUserId);

		result.status = Status.SUCCESS;
	} catch (Exception e) {
		YiLog.getInstance().e(e, "delete friend failed.");
		result.obj = e.getMessage();
	} finally {
		if (mCursor != null) {
			mCursor.close();
			mCursor = null;
		}
	}

	return result;
}
 
Example 7
Source File: XMPPUtils.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param connectionService network component that should be used to resolve the nickname or
 *     <code>null</code> to use the default one
 * @param jid the JID to resolve the nickname for
 * @param alternative nickname to return if no nickname is available, can be <code>null</code>
 * @return The nickname associated with the given JID in the current roster or the
 *     <tt>alternative</tt> representation if the current roster is not available or the nickname
 *     has not been set.
 */
public static String getNickname(
    XMPPConnectionService connectionService, final JID jid, final String alternative) {

  if (connectionService == null) connectionService = defaultConnectionService;

  if (connectionService == null) return alternative;

  Connection connection = connectionService.getConnection();

  if (connection == null) return alternative;

  Roster roster = connection.getRoster();

  if (roster == null) return alternative;

  RosterEntry entry = roster.getEntry(jid.getBase());

  if (entry == null) return alternative;

  String nickName = entry.getName();

  if (nickName != null && nickName.trim().length() > 0) return nickName;

  return alternative;
}