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


Java RosterPacket.Item方法代码示例

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


在下文中一共展示了RosterPacket.Item方法的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: 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

示例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);
            	}
                          }
            synchronized (Roster.this) {
                rosterInitialized = true;
                Roster.this.notifyAll();
            }
            fireRosterChangedEvent(addedEntries,updatedEntries,deletedEntries);
	    }
	}
	connection.removePacketListener(this);
}
 
开发者ID:jtietema,项目名称:telegraph,代码行数:22,代码来源:Roster.java

示例5: 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

示例6: 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

示例7: setName

import org.jivesoftware.smack.packet.RosterPacket; //导入方法依赖的package包/类
/**
 * Sets the name of the group. Changing the group's name is like moving all the group entries
 * of the group to a new group specified by the new name. Since this group won't have entries 
 * it will be removed from the roster. This means that all the references to this object will 
 * be invalid and will need to be updated to the new group specified by the new name.
 *
 * @param name the name of the group.
 */
public void setName(String name) {
    synchronized (entries) {
        for (RosterEntry entry : entries) {
            RosterPacket packet = new RosterPacket();
            packet.setType(IQ.Type.SET);
            RosterPacket.Item item = RosterEntry.toRosterItem(entry);
            item.removeGroupName(this.name);
            item.addGroupName(name);
            packet.addRosterItem(item);
            connection.sendPacket(packet);
        }
    }
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:22,代码来源:RosterGroup.java

示例8: removeEntry

import org.jivesoftware.smack.packet.RosterPacket; //导入方法依赖的package包/类
/**
 * Removes a roster entry from this group. If the entry does not belong to any other group 
 * then it will be considered as unfiled, therefore it will be added to the list of unfiled 
 * entries.
 * Note that this is an asynchronous call -- Smack must wait for the server
 * to receive the updated roster.
 *
 * @param entry a roster entry.
 * @throws XMPPException if an error occured while trying to remove the entry from the group. 
 */
public void removeEntry(RosterEntry entry) throws XMPPException {
    PacketCollector collector = null;
    // Only remove the entry if it's in the entry list.
    // Remove the entry locally, if we wait for RosterPacketListenerprocess>>Packet(Packet)
    // to take place the entry will exist in the group until a packet is received from the 
    // server.
    synchronized (entries) {
        if (entries.contains(entry)) {
            RosterPacket packet = new RosterPacket();
            packet.setType(IQ.Type.SET);
            RosterPacket.Item item = RosterEntry.toRosterItem(entry);
            item.removeGroupName(this.getName());
            packet.addRosterItem(item);
            // Wait up to a certain number of seconds for a reply from the server.
            collector = connection
                    .createPacketCollector(new PacketIDFilter(packet.getPacketID()));
            connection.sendPacket(packet);
        }
    }
    if (collector != null) {
        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:CJC-ivotten,项目名称:androidPN-client.,代码行数:42,代码来源:RosterGroup.java

示例9: insertRosterItems

import org.jivesoftware.smack.packet.RosterPacket; //导入方法依赖的package包/类
private void insertRosterItems(List<RosterPacket.Item> items){
	 Collection<String> addedEntries = new ArrayList<String>();
     Collection<String> updatedEntries = new ArrayList<String>();
     Collection<String> deletedEntries = new ArrayList<String>();
     Iterator<RosterPacket.Item> iter = items.iterator();
     while(iter.hasNext()){
    	 insertRosterItem(iter.next(), addedEntries,updatedEntries,deletedEntries);
     }
     fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries);
}
 
开发者ID:CJC-ivotten,项目名称:androidPN-client.,代码行数:11,代码来源:Roster.java

示例10: addEntry

import org.jivesoftware.smack.packet.RosterPacket; //导入方法依赖的package包/类
/**
 * Adds a roster entry to this group. If the entry was unfiled then it will be removed from 
 * the unfiled list and will be added to this group.
 * Note that this is an asynchronous call -- Smack must wait for the server
 * to receive the updated roster.
 *
 * @param entry a roster entry.
 * @throws XMPPException if an error occured while trying to add the entry to the group.
 */
public void addEntry(RosterEntry entry) throws XMPPException {
    PacketCollector collector = null;
    // Only add the entry if it isn't already in the list.
    synchronized (entries) {
        if (!entries.contains(entry)) {
            RosterPacket packet = new RosterPacket();
            packet.setType(IQ.Type.SET);
            RosterPacket.Item item = RosterEntry.toRosterItem(entry);
            item.addGroupName(getName());
            packet.addRosterItem(item);
            // Wait up to a certain number of seconds for a reply from the server.
            collector = connection
                    .createPacketCollector(new PacketIDFilter(packet.getPacketID()));
            connection.sendPacket(packet);
        }
    }
    if (collector != null) {
        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:CJC-ivotten,项目名称:androidPN-client.,代码行数:38,代码来源:RosterGroup.java

示例11: removeSubscription

import org.jivesoftware.smack.packet.RosterPacket; //导入方法依赖的package包/类
/**
 * For unsubscription we have to create a packet like: <iq type="set" id="ab7ba" > <query xmlns="jabber:iq:roster"> <item subscription="remove" jid="[email protected]"
 * /> </query> </iq>
 * 
 * @param uname
 *            a valid username
 */
protected void removeSubscription(final String uname) {
    final RosterPacket rosterPacket = new RosterPacket();
    rosterPacket.setType(IQ.Type.SET);
    final RosterPacket.Item item = new RosterPacket.Item(uname + "@" + jabberServer, uname);
    item.setItemType(RosterPacket.ItemType.remove);
    rosterPacket.addRosterItem(item);
    try {
        connection.sendPacket(rosterPacket);
    } catch (final RuntimeException e) {
        log.warn("Error while trying to send Instant Messaging packet.", e);
    }
}
 
开发者ID:huihoo,项目名称:olat,代码行数:20,代码来源:InstantMessagingClient.java

示例12: 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:ikantech,项目名称:xmppsupport_v2,代码行数:12,代码来源:RosterEntry.java

示例13: insertRosterItems

import org.jivesoftware.smack.packet.RosterPacket; //导入方法依赖的package包/类
private void insertRosterItems(List<RosterPacket.Item> items) {
	Collection<String> addedEntries = new ArrayList<String>();
	Collection<String> updatedEntries = new ArrayList<String>();
	Collection<String> deletedEntries = new ArrayList<String>();
	Iterator<RosterPacket.Item> iter = items.iterator();
	while (iter.hasNext()) {
		insertRosterItem(iter.next(), addedEntries, updatedEntries,
				deletedEntries);
	}
	fireRosterChangedEvent(addedEntries, updatedEntries, deletedEntries);
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:12,代码来源:Roster.java

示例14: 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.
 * @throws IllegalStateException
 *             if connection is not logged in or logged in anonymously
 */
public void removeEntry(RosterEntry entry) 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.");
	}

	// 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:ikantech,项目名称:xmppsupport_v2,代码行数:50,代码来源:Roster.java

示例15: addEntry

import org.jivesoftware.smack.packet.RosterPacket; //导入方法依赖的package包/类
/**
 * Adds a roster entry to this group. If the entry was unfiled then it will
 * be removed from the unfiled list and will be added to this group. Note
 * that this is an asynchronous call -- Smack must wait for the server to
 * receive the updated roster.
 * 
 * @param entry
 *            a roster entry.
 * @throws XMPPException
 *             if an error occured while trying to add the entry to the
 *             group.
 */
public void addEntry(RosterEntry entry) throws XMPPException {
	PacketCollector collector = null;
	// Only add the entry if it isn't already in the list.
	synchronized (entries) {
		if (!entries.contains(entry)) {
			RosterPacket packet = new RosterPacket();
			packet.setType(IQ.Type.SET);
			RosterPacket.Item item = RosterEntry.toRosterItem(entry);
			item.addGroupName(getName());
			packet.addRosterItem(item);
			// Wait up to a certain number of seconds for a reply from the
			// server.
			collector = connection
					.createPacketCollector(new PacketIDFilter(packet
							.getPacketID()));
			connection.sendPacket(packet);
		}
	}
	if (collector != null) {
		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:ikantech,项目名称:xmppsupport_v2,代码行数:44,代码来源:RosterGroup.java


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