diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java index d5eb713f8..ee9aa2777 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/LeafNode.java @@ -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 List getItems() throws NoResponseException, XMPPErrorException, NotConnectedException { - PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId())); - return getItems(request); + return getItems((List) null, (List) null); } /** @@ -153,10 +153,44 @@ public class LeafNode extends Node return getItems(request); } + /** + * Get items persisted on the node. + *

+ * {@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. + *

+ * + * @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 List getItems(List additionalExtensions, + List returnedExtensions) throws NoResponseException, + XMPPErrorException, NotConnectedException { + PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId())); + request.addExtensions(additionalExtensions); + return getItems(request, returnedExtensions); + } + + private List getItems(PubSub request) throws NoResponseException, + XMPPErrorException, NotConnectedException { + return getItems(request, null); + } + @SuppressWarnings("unchecked") - private List getItems(PubSub request) throws NoResponseException, XMPPErrorException, NotConnectedException { + private List getItems(PubSub request, + List 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) itemsElem.getItems(); }