当前位置: 首页>>代码示例>>Java>>正文


Java RosterPacket类代码示例

本文整理汇总了Java中org.jivesoftware.smack.packet.RosterPacket的典型用法代码示例。如果您正苦于以下问题:Java RosterPacket类的具体用法?Java RosterPacket怎么用?Java RosterPacket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RosterPacket类属于org.jivesoftware.smack.packet包,在下文中一共展示了RosterPacket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeEntry

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
/**
 * Removes a roster entry from the roster. The roster entry will also be removed from the
 * unfiled entries or from any roster group where it could belong and will no longer be part
 * of the roster. Note that this is an asynchronous call -- Smack must wait for the server
 * to send an updated subscription status.
 *
 * @param entry a roster entry.
 * @throws XMPPException if an XMPP error occurs.
 */
public void removeEntry(RosterEntry entry) throws XMPPException {
    // Only remove the entry if it's in the entry list.
    // The actual removal logic takes place in RosterPacketListenerprocess>>Packet(Packet)
    if (!entries.containsKey(entry.getUser())) {
        return;
    }
    RosterPacket packet = new RosterPacket();
    packet.setType(IQ.Type.SET);
    RosterPacket.Item item = RosterEntry.toRosterItem(entry);
    // Set the item type as REMOVE so that the server will delete the entry
    item.setItemType(RosterPacket.ItemType.remove);
    packet.addRosterItem(item);
    PacketCollector collector = connection.createPacketCollector(
            new PacketIDFilter(packet.getPacketID()));
    connection.sendPacket(packet);
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from the server.");
    }
    // If the server replied with an error, throw an exception.
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
}
 
开发者ID:samuelhehe,项目名称:androidpn_enhanced_client,代码行数:35,代码来源:Roster.java

示例2: processPacket

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
public void processPacket(Packet packet) {
	if(packet instanceof IQ){
		IQ result = (IQ)packet;
		if(result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()){
			Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if(persistentStorage!=null){
            	for(RosterPacket.Item item : persistentStorage.getEntries()){
            		insertRosterItem(item,addedEntries,updatedEntries,deletedEntries);
            	}
            	synchronized (Roster.this) {
                    rosterInitialized = true;
                    Roster.this.notifyAll();
                }
            	fireRosterChangedEvent(addedEntries,updatedEntries,deletedEntries);
            }
		}
	}
	connection.removePacketListener(this);
}
 
开发者ID:samuelhehe,项目名称:androidpn_enhanced_client,代码行数:22,代码来源:Roster.java

示例3: reload

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 * 
 * @throws IllegalStateException if connection is not logged in or logged in anonymously
 */
public void reload() {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Not logged in to server.");
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException("Anonymous users can't have a roster.");
    }

	RosterPacket packet = new RosterPacket();
	if(persistentStorage!=null){
		packet.setVersion(persistentStorage.getRosterVersion());
	}
	requestPacketId = packet.getPacketID();
	PacketFilter idFilter = new PacketIDFilter(requestPacketId);
	connection.addPacketListener(new RosterResultListener(), idFilter);
    connection.sendPacket(packet);
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:25,代码来源:Roster.java

示例4: processPacket

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
public void processPacket(Packet packet) {
    if (packet instanceof IQ) {
        IQ result = (IQ) packet;
        if (result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()) {
            Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if (persistentStorage != null) {
                for (RosterPacket.Item item : persistentStorage.getEntries()) {
                    insertRosterItem(item, addedEntries, updatedEntries, deletedEntries);
                }
            }
            fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries);
        }
    }
    connection.removePacketListener(this);
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:18,代码来源:Roster.java

示例5: subscribeToUser

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
/**
 * Sends a subscription request to the username answers are handled by the method
 * 
 * @param uname
 * @param groupname
 */
protected void subscribeToUser(final String uname, final String groupname) {
    final Presence presence = new Presence(Presence.Type.subscribe);
    presence.setTo(uname + "@" + jabberServer);
    try {
        connection.sendPacket(presence);

        final RosterPacket rosterPacket = new RosterPacket();
        rosterPacket.setType(IQ.Type.SET);
        final RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname);
        item.addGroupName(groupname);
        item.setItemType(RosterPacket.ItemType.both);
        rosterPacket.addRosterItem(item);
        connection.sendPacket(rosterPacket);
    } catch (final RuntimeException e) {
        log.warn("Error while trying to send Instant Messaging packet.", e);
    }
}
 
开发者ID:huihoo,项目名称:olat,代码行数:24,代码来源:InstantMessagingClient.java

示例6: reload

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
/**
 * Reloads the entire roster from the server. This is an asynchronous
 * operation, which means the method will return immediately, and the roster
 * will be reloaded at a later point when the server responds to the reload
 * request.
 * 
 * @throws IllegalStateException
 *             if connection is not logged in or logged in anonymously
 */
public void reload() {
	if (!connection.isAuthenticated()) {
		throw new IllegalStateException("Not logged in to server.");
	}
	if (connection.isAnonymous()) {
		throw new IllegalStateException(
				"Anonymous users can't have a roster.");
	}

	RosterPacket packet = new RosterPacket();
	if (persistentStorage != null) {
		packet.setVersion(persistentStorage.getRosterVersion());
	}
	requestPacketId = packet.getPacketID();
	PacketFilter idFilter = new PacketIDFilter(requestPacketId);
	connection.addPacketListener(new RosterResultListener(), idFilter);
	connection.sendPacket(packet);
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:28,代码来源:Roster.java

示例7: processPacket

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
public void processPacket(Packet packet) {
	if (packet instanceof IQ) {
		IQ result = (IQ) packet;
		if (result.getType().equals(IQ.Type.RESULT)
				&& result.getExtensions().isEmpty()) {
			Collection<String> addedEntries = new ArrayList<String>();
			Collection<String> updatedEntries = new ArrayList<String>();
			Collection<String> deletedEntries = new ArrayList<String>();
			if (persistentStorage != null) {
				for (RosterPacket.Item item : persistentStorage
						.getEntries()) {
					insertRosterItem(item, addedEntries,
							updatedEntries, deletedEntries);
				}
			}
			synchronized (Roster.this) {
				rosterInitialized = true;
				Roster.this.notifyAll();
			}
			fireRosterChangedEvent(addedEntries, updatedEntries,
					deletedEntries);
		}
	}
	connection.removePacketListener(this);
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:26,代码来源:Roster.java

示例8: processPacket

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
@Override
public void processPacket(Packet packet) {
    RosterPacket p = (RosterPacket) packet;
    Intent i = new Intent(ACTION_ROSTER);
    i.putExtra(EXTRA_FROM, p.getFrom());
    i.putExtra(EXTRA_TO, p.getTo());
    // here we are not using() because Type is a class, not an enum
    i.putExtra(EXTRA_TYPE, p.getType().toString());
    i.putExtra(EXTRA_PACKET_ID, p.getPacketID());

    Collection<RosterPacket.Item> items = p.getRosterItems();
    String[] list = new String[items.size()];

    int index = 0;
    for (Iterator<RosterPacket.Item> iter = items.iterator(); iter.hasNext(); ) {
        RosterPacket.Item item = iter.next();
        list[index] = item.getUser();
        index++;
    }

    i.putExtra(EXTRA_JIDLIST, list);

    sendBroadcast(i);
}
 
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:25,代码来源:RosterListener.java

示例9: rosterEntry2Buddy

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
public Buddy rosterEntry2Buddy(RosterEntry entry, String ownerJid, Context context, byte serviceId){
	if (entry == null){
		return null;
	}
	Buddy buddy = new Buddy(normalizeJID(entry.getUser()), ownerJid, XMPPApiConstants.PROTOCOL_NAME, serviceId);
	buddy.setName(entry.getName());
	buddy.setId(entry.getUser().hashCode());
	buddy.setGroupId((entry.getGroups() != null && entry.getGroups().size() > 0) ? entry.getGroups().iterator().next().getName() : ApiConstants.NO_GROUP_ID);
	//buddy.clientId = getClientId(entry.getUser());
	
	if (entry.getStatus()!=null && entry.getStatus().equals(RosterPacket.ItemStatus.SUBSCRIPTION_PENDING)){
		//buddy.visibility = Buddy.VIS_NOT_AUTHORIZED;
	}
	
	return buddy;
}
 
开发者ID:snuk182,项目名称:aceim,代码行数:17,代码来源:XMPPEntityAdapter.java

示例10: processPacket

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
public void processPacket(Packet packet) {
	if(packet instanceof IQ){
		IQ result = (IQ)packet;
		if(result.getType().equals(IQ.Type.RESULT) && result.getExtensions().isEmpty()){
			Collection<String> addedEntries = new ArrayList<String>();
            Collection<String> updatedEntries = new ArrayList<String>();
            Collection<String> deletedEntries = new ArrayList<String>();
            if(persistentStorage!=null){
            	for(RosterPacket.Item item : persistentStorage.getEntries()){
            		insertRosterItem(item,addedEntries,updatedEntries,deletedEntries);
            	}
                          }
            synchronized (Roster.this) {
                rosterInitialized = true;
                Roster.this.notifyAll();
            }
            fireRosterChangedEvent(addedEntries,updatedEntries,deletedEntries);
	    }
	}
	connection.removePacketListener(this);
}
 
开发者ID:jtietema,项目名称:telegraph,代码行数:22,代码来源:Roster.java

示例11: RosterEntry

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
/**
 * Creates a new roster entry.
 *
 * @param user the user.
 * @param name the nickname for the entry.
 * @param type the subscription type.
 * @param status the subscription status (related to subscriptions pending to be approbed).
 * @param connection a connection to the XMPP server.
 */
RosterEntry(String user, String name, RosterPacket.ItemType type,
            RosterPacket.ItemStatus status, Roster roster, Connection connection) {
    this.user = user;
    this.name = name;
    this.type = type;
    this.status = status;
    this.roster = roster;
    this.connection = connection;
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:19,代码来源:RosterEntry.java

示例12: setName

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
/**
 * Sets the name associated with this entry.
 *
 * @param name the name.
 */
public void setName(String name) {
    // Do nothing if the name hasn't changed.
    if (name != null && name.equals(this.name)) {
        return;
    }
    this.name = name;
    RosterPacket packet = new RosterPacket();
    packet.setType(IQ.Type.SET);
    packet.addRosterItem(toRosterItem(this));
    connection.sendPacket(packet);
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:17,代码来源:RosterEntry.java

示例13: toRosterItem

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
static RosterPacket.Item toRosterItem(RosterEntry entry) {
    RosterPacket.Item item = new RosterPacket.Item(entry.getUser(), entry.getName());
    item.setItemType(entry.getType());
    item.setItemStatus(entry.getStatus());
    // Set the correct group names for the item.
    for (RosterGroup group : entry.getGroups()) {
        item.addGroupName(group.getName());
    }
    return item;
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:11,代码来源:RosterEntry.java

示例14: reload

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
/**
 * Reloads the entire roster from the server. This is an asynchronous operation,
 * which means the method will return immediately, and the roster will be
 * reloaded at a later point when the server responds to the reload request.
 * 
 * @throws IllegalStateException if connection is not logged in or logged in anonymously
 */
public void reload() {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Not logged in to server.");
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException("Anonymous users can't have a roster.");
    }

    connection.sendPacket(new RosterPacket());
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:18,代码来源:Roster.java

示例15: createEntry

import org.jivesoftware.smack.packet.RosterPacket; //导入依赖的package包/类
/**
 * Creates a new roster entry and presence subscription. The server will asynchronously
 * update the roster with the subscription status.
 *
 * @param user   the user. (e.g. [email protected])
 * @param name   the nickname of the user.
 * @param groups the list of group names the entry will belong to, or <tt>null</tt> if the
 *               the roster entry won't belong to a group.
 * @throws XMPPException if an XMPP exception occurs.
 * @throws IllegalStateException if connection is not logged in or logged in anonymously
 */
public void createEntry(String user, String name, String[] groups) throws XMPPException {
    if (!connection.isAuthenticated()) {
        throw new IllegalStateException("Not logged in to server.");
    }
    if (connection.isAnonymous()) {
        throw new IllegalStateException("Anonymous users can't have a roster.");
    }

    // Create and send roster entry creation packet.
    RosterPacket rosterPacket = new RosterPacket();
    rosterPacket.setType(IQ.Type.SET);
    RosterPacket.Item item = new RosterPacket.Item(user, name);
    if (groups != null) {
        for (String group : groups) {
            if (group != null && group.trim().length() > 0) {
                item.addGroupName(group);
            }
        }
    }
    rosterPacket.addRosterItem(item);
    // Wait up to a certain number of seconds for a reply from the server.
    PacketCollector collector = connection.createPacketCollector(
            new PacketIDFilter(rosterPacket.getPacketID()));
    connection.sendPacket(rosterPacket);
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from the server.");
    }
    // If the server replied with an error, throw an exception.
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }

    // Create a presence subscription packet and send.
    Presence presencePacket = new Presence(Presence.Type.subscribe);
    presencePacket.setTo(user);
    connection.sendPacket(presencePacket);
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:51,代码来源:Roster.java


注:本文中的org.jivesoftware.smack.packet.RosterPacket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。