本文整理汇总了Java中org.jivesoftware.smack.Roster类的典型用法代码示例。如果您正苦于以下问题:Java Roster类的具体用法?Java Roster怎么用?Java Roster使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Roster类属于org.jivesoftware.smack包,在下文中一共展示了Roster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transEntryToUser
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
/**
* ����RosterEntry����һ��User
*
* @param entry
* @return
*/
public static User transEntryToUser(RosterEntry entry, Roster roster) {
User user = new User();
if (entry.getName() == null) {
user.setName(StringUtil.getUserNameByJid(entry.getUser()));
} else {
user.setName(entry.getName());
}
user.setJID(entry.getUser());
System.out.println(entry.getUser());
Presence presence = roster.getPresence(entry.getUser());
user.setFrom(presence.getFrom());
user.setStatus(presence.getStatus());
user.setSize(entry.getGroups().size());
user.setAvailable(presence.isAvailable());
user.setType(entry.getType());
return user;
}
示例2: perform
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
@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;
}
示例3: addUserToGroup
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
/**
* 添加到分组
*
* @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));
}
}
}
示例4: getEntrysByGroup
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
/**
* 获取某一个分组的成员
*
* @param
* @param groupName
* @return
*/
public List<RosterEntry> getEntrysByGroup(String groupName) {
Roster roster = getCon().getRoster();
List<RosterEntry> list = new ArrayList<RosterEntry>();
RosterGroup group = roster.getGroup(groupName);
Collection<RosterEntry> rosterEntiry = group.getEntries();
Iterator<RosterEntry> iter = rosterEntiry.iterator();
while (iter.hasNext()) {
RosterEntry entry = iter.next();
SLog.i("xmpptool", entry.getUser() + "\t" + entry.getName() + entry.getType().toString());
if (entry.getType().toString().equals("both")) {
list.add(entry);
}
}
return list;
}
示例5: isFriendly
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
/**
* 判断是否是好友
*
* @param
* @param user
* @return
*/
public boolean isFriendly(String user) {
Roster roster = getCon().getRoster();
List<RosterEntry> list = new ArrayList<RosterEntry>();
list.addAll(roster.getEntries());
for (int i = 0; i < list.size(); i++) {
Log.i("xmppttttttttt", list.get(i).getUser().toUpperCase() + "\t" + user);
if (list.get(i).getUser().contains(user.toLowerCase())) {
if (list.get(i).getType().toString().equals("both")) {
return true;
} else {
return false;
}
}
}
return false;
}
示例6: enableUser
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
/**
* This method sends a friend request to the user if he isn't already in the bots {@link Roster}
* . {@inheritDoc}
*/
@Override
public void enableUser(String username) {
if (!connection.isConnected()) {
return;
}
Roster roster = connection.getRoster();
if (roster != null && roster.getEntry(username) != null) {
return;
}
try {
String clientId = ClientAndChannelContextHolder.getClient().getClientId();
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setFrom(sender);
subscribe.setTo(username + "." + clientId + XMPPPatternUtils.getUserSuffix());
connection.sendPacket(subscribe);
Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setFrom(sender);
subscribed.setTo(username + "." + clientId + XMPPPatternUtils.getUserSuffix());
connection.sendPacket(subscribed);
} catch (NotConnectedException e) {
LOG.debug("Could not send friendship request because XMPP connector is disconnected");
}
}
示例7: isAvailable
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @param username
* Has to be in the messagers format.
*/
@Override
public boolean isAvailable(String username) {
if (connection.isConnected()) {
Roster roster = connection.getRoster();
if (roster != null) {
Presence presence = roster.getPresence(username + XMPPPatternUtils.getUserSuffix());
return presence.isAvailable();
} else {
LOG.debug("XMPP connection did not return a roster for communote bot");
}
} else {
LOG.debug("Cannot check availability of user because XMPP connector is disconnected");
}
return false;
}
示例8: findFriends
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
public void findFriends() {
try {
listGroup=new ArrayList<Group>();
XMPPConnection conn = QQApplication.xmppConnection;
Roster roster = conn.getRoster();
Collection<RosterGroup> groups = roster.getGroups();
for (RosterGroup group : groups) {
Group mygroup=new Group();
mygroup.setGroupName(group.getName());
Collection<RosterEntry> entries = group.getEntries();
List<Child> childList=new ArrayList<Child>();
for (RosterEntry entry : entries) {
if(entry.getType().name().equals("both")){
Child child=new Child();
child.setUsername(entry.getUser().split("@")[0]);
childList.add(child);
}
}
mygroup.setChildList(childList);
listGroup.add(mygroup);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: showDialog
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
void showDialog(final String toUser){
Builder bd=new Builder(AddFriendActivity.this);
bd.setItems(new String[] {"添加为好友"}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Roster roster=QQApplication.xmppConnection.getRoster();
XmppUtil.addGroup(roster, "我的好友");//先默认创建一个分组
XmppUtil.addUsers(roster,toUser+"@"+QQApplication.xmppConnection.getServiceName(), toUser,"我的好友");
//注意消息的协议格式 =》接收者卍发送者卍消息类型卍消息内容卍发送时间
String message=toUser+Const.SPLIT+I+Const.SPLIT+Const.MSG_TYPE_ADD_FRIEND+Const.SPLIT+"你好"+Const.SPLIT+new SimpleDateFormat("MM-dd HH:mm").format(new Date());
XmppUtil.sendMessage(QQApplication.xmppConnection, message,toUser);
sendInviteUser=toUser;
mHandler.sendEmptyMessage(2);
} catch (XMPPException e) {
e.printStackTrace();
}
}
}).start();
}
});
bd.create().show();
}
示例10: init
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
public XMPPConnection init() {
Connection.DEBUG_ENABLED = false;
ProviderManager pm = ProviderManager.getInstance();
configure(pm);
ConnectionConfiguration connectionConfig = new ConnectionConfiguration(Const.XMPP_HOST, Const.XMPP_PORT);
// connectionConfig.setSASLAuthenticationEnabled(false);//
// 不使用SASL验证,设置为false
// connectionConfig
// .setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
// 允许自动连接
connectionConfig.setReconnectionAllowed(true);
// 允许登陆成功后更新在线状态
connectionConfig.setSendPresence(true);
// 收到好友邀请后manual表示需要经过同意,accept_all表示不经同意自动为好友
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
XMPPConnection connection = new XMPPConnection(connectionConfig);
return connection;
}
示例11: getGroups
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
/**
* ������з�����ϵ��
*
* @return
*/
public static List<MRosterGroup> getGroups(Roster roster) {
if (contacters == null)
throw new RuntimeException("contacters is null");
List<MRosterGroup> groups = new ArrayList<ContacterManager.MRosterGroup>();
groups.add(new MRosterGroup(Constant.ALL_FRIEND, getContacterList()));
for (RosterGroup group : roster.getGroups()) {
List<User> groupUsers = new ArrayList<User>();
for (RosterEntry entry : group.getEntries()) {
groupUsers.add(contacters.get(entry.getUser()));
}
groups.add(new MRosterGroup(group.getName(), groupUsers));
}
groups.add(new MRosterGroup(Constant.NO_GROUP_FRIEND,
getNoGroupUserList(roster)));
return groups;
}
示例12: getByUserJid
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
/**
* �����û�jid�õ��û�
*
* @param userJid
* @param nickname
*/
public static User getByUserJid(String userJId, XMPPConnection connection) {
Roster roster = connection.getRoster();
RosterEntry entry = connection.getRoster().getEntry(userJId);
if (null == entry) {
return null;
}
User user = new User();
if (entry.getName() == null) {
user.setName(StringUtil.getUserNameByJid(entry.getUser()));
} else {
user.setName(entry.getName());
}
user.setJID(entry.getUser());
System.out.println(entry.getUser());
Presence presence = roster.getPresence(entry.getUser());
user.setFrom(presence.getFrom());
user.setStatus(presence.getStatus());
user.setSize(entry.getGroups().size());
user.setAvailable(presence.isAvailable());
user.setType(entry.getType());
return user;
}
示例13: displayfrndslist
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
public void displayfrndslist()
{
Roster rster = conn.getRoster();
Collection<RosterEntry> records = rster.getEntries();
System.out.println("\nTotal friends: "+records.size());
int i = 1;
String status = null;
for(RosterEntry r:records)
{
Presence presence = rster.getPresence(r.getUser());
if ((presence != null)){
if(rster.getPresence(r.getUser()).toString().contains("away"))
status = "idle";
else if (rster.getPresence(r.getUser()).toString().contains("unavailable"))
status = "offline";
else if (rster.getPresence(r.getUser()).toString().contains("dnd"))
status = "busy";
else
status = "available";
System.out.println("(#" + i + ")"+r.getUser()+"---"+status);
i++;
}
}
}
示例14: init
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
/**
* 初始化连接
* @param loginConfig
* @return
*/
public XMPPConnection init(IMConfig loginConfig) {
Connection.DEBUG_ENABLED = false;
ProviderManager pm = ProviderManager.getInstance();
configure(pm);
connectionConfig = new ConnectionConfiguration(
loginConfig.getXmppHost(), loginConfig.getXmppPort(),
loginConfig.getXmppServiceName());
//connectionConfig.setSASLAuthenticationEnabled(false);// 不使用SASL验证,设置为false
connectionConfig
.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
// 允许自动连接
connectionConfig.setReconnectionAllowed(false);
// 允许登陆成功后更新在线状态
connectionConfig.setSendPresence(true);
// 收到好友邀请后manual表示需要经过同意,accept_all表示不经同意自动为好友
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);
connection = new XMPPConnection(connectionConfig);
return connection;
}
示例15: initContacter
import org.jivesoftware.smack.Roster; //导入依赖的package包/类
public void initContacter(){
mGroupNames.clear();
mIMRosterGroups.clear();
//增加分组
try {
Roster mRoster = IMUtil.getRoster();
mGroupNames.addAll(IMUtil.getGroupNames(mRoster));
mIMRosterGroups.addAll(IMUtil.getRosterGroups(mRoster));
} catch (Exception e) {
e.printStackTrace();
mGroupNames.clear();
mIMRosterGroups.clear();
}
mContacterListAdapter.notifyDataSetChanged();
if(mGroupNames.size()>0){
mListView.expandGroup(0);
}
}