001/**
002 *
003 * Copyright the original author or authors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.pubsub;
018
019import org.jivesoftware.smack.util.XmlStringBuilder;
020
021/**
022 * Represents a request to subscribe to a node.
023 *
024 * @author Robin Collier
025 */
026public class GetItemsRequest extends NodeExtension {
027    protected final String subId;
028    protected final int maxItems;
029
030    public GetItemsRequest(String nodeId) {
031        this(nodeId, null, -1);
032    }
033
034    public GetItemsRequest(String nodeId, String subscriptionId) {
035        this(nodeId, subscriptionId, -1);
036    }
037
038    public GetItemsRequest(String nodeId, int maxItemsToReturn) {
039        this(nodeId, null, maxItemsToReturn);
040    }
041
042    public GetItemsRequest(String nodeId, String subscriptionId, int maxItemsToReturn) {
043        super(PubSubElementType.ITEMS, nodeId);
044        maxItems = maxItemsToReturn;
045        subId = subscriptionId;
046    }
047
048    public String getSubscriptionId() {
049        return subId;
050    }
051
052    public int getMaxItems() {
053        return maxItems;
054    }
055
056    @Override
057    protected void addXml(XmlStringBuilder xml) {
058        xml.optAttribute("subid", getSubscriptionId());
059        xml.optIntAttribute("max_items", getMaxItems());
060        xml.closeEmptyElement();
061    }
062}