1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 07:22:07 +01:00

Enabling additional and returned extensions in getItems()

This commit is contained in:
Abmar Barros 2014-09-26 11:06:04 -03:00 committed by Florian Schmaus
parent 47dd63e6b2
commit ae385e6b44

View file

@ -25,6 +25,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.IQ.Type;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.pubsub.packet.PubSub;
@ -70,8 +71,7 @@ public class LeafNode extends Node
*/
public <T extends Item> List<T> getItems() throws NoResponseException, XMPPErrorException, NotConnectedException
{
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId()));
return getItems(request);
return getItems((List<PacketExtension>) null, (List<PacketExtension>) null);
}
/**
@ -153,10 +153,44 @@ public class LeafNode extends Node
return getItems(request);
}
/**
* Get items persisted on the node.
* <p>
* {@code additionalExtensions} can be used e.g. to add a "Result Set Management" extension.
* {@code returnedExtensions} will be filled with the packet extensions found in the answer.
* </p>
*
* @param additionalExtensions additional {@code PacketExtensions} to be added to the request.
* This is an optional argument, if provided as null no extensions will be added.
* @param returnedExtensions a collection that will be filled with the returned packet
* extensions. This is an optional argument, if provided as null it won't be populated.
* @return List of {@link Item}
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
*/
public <T extends Item> List<T> getItems(List<PacketExtension> additionalExtensions,
List<PacketExtension> returnedExtensions) throws NoResponseException,
XMPPErrorException, NotConnectedException {
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId()));
request.addExtensions(additionalExtensions);
return getItems(request, returnedExtensions);
}
private <T extends Item> List<T> getItems(PubSub request) throws NoResponseException,
XMPPErrorException, NotConnectedException {
return getItems(request, null);
}
@SuppressWarnings("unchecked")
private <T extends Item> List<T> getItems(PubSub request) throws NoResponseException, XMPPErrorException, NotConnectedException {
private <T extends Item> List<T> getItems(PubSub request,
List<PacketExtension> returnedExtensions) throws NoResponseException,
XMPPErrorException, NotConnectedException {
PubSub result = con.createPacketCollectorAndSend(request).nextResultOrThrow();
ItemsExtension itemsElem = result.getExtension(PubSubElementType.ITEMS);
if (returnedExtensions != null) {
returnedExtensions.addAll(result.getExtensions());
}
return (List<T>) itemsElem.getItems();
}