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{
028    protected final String subId;
029    protected final int maxItems;
030
031    public GetItemsRequest(String nodeId)
032    {
033        this(nodeId, null, -1);
034    }
035
036    public GetItemsRequest(String nodeId, String subscriptionId)
037    {
038        this(nodeId, subscriptionId, -1);
039    }
040
041    public GetItemsRequest(String nodeId, int maxItemsToReturn)
042    {
043        this(nodeId, null, maxItemsToReturn);
044    }
045
046    public GetItemsRequest(String nodeId, String subscriptionId, int maxItemsToReturn)
047    {
048        super(PubSubElementType.ITEMS, nodeId);
049        maxItems = maxItemsToReturn;
050        subId = subscriptionId;
051    }
052
053    public String getSubscriptionId()
054    {
055        return subId;
056    }
057
058    public int getMaxItems()
059    {
060        return maxItems;
061    }
062
063    @Override
064    public XmlStringBuilder toXML() {
065        XmlStringBuilder xml = new XmlStringBuilder();
066        xml.halfOpenElement(getElementName());
067        xml.attribute("node", getNode());
068        xml.optAttribute("subid", getSubscriptionId());
069        xml.optIntAttribute("max_items", getMaxItems());
070        xml.closeEmptyElement();
071        return xml;
072    }
073}