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
019/**
020 * Represents a request to subscribe to a node.
021 * 
022 * @author Robin Collier
023 */
024public class GetItemsRequest extends NodeExtension
025{
026        protected String subId;
027        protected int maxItems;
028        
029        public GetItemsRequest(String nodeId)
030        {
031                super(PubSubElementType.ITEMS, nodeId);
032        }
033        
034        public GetItemsRequest(String nodeId, String subscriptionId)
035        {
036                super(PubSubElementType.ITEMS, nodeId);
037                subId = subscriptionId;
038        }
039
040        public GetItemsRequest(String nodeId, int maxItemsToReturn)
041        {
042                super(PubSubElementType.ITEMS, nodeId);
043                maxItems = maxItemsToReturn;
044        }
045
046        public GetItemsRequest(String nodeId, String subscriptionId, int maxItemsToReturn)
047        {
048                this(nodeId, maxItemsToReturn);
049                subId = subscriptionId;
050        }
051
052        public String getSubscriptionId()
053        {
054                return subId;
055        }
056
057        public int getMaxItems()
058        {
059                return maxItems;
060        }
061
062        @Override
063        public String toXML()
064        {
065                StringBuilder builder = new StringBuilder("<");
066                builder.append(getElementName());
067                
068                builder.append(" node='");
069                builder.append(getNode());
070                builder.append("'");
071
072                if (getSubscriptionId() != null)
073                {
074                        builder.append(" subid='");
075                        builder.append(getSubscriptionId());
076                        builder.append("'");
077                }
078
079                if (getMaxItems() > 0)
080                {
081                        builder.append(" max_items='");
082                        builder.append(getMaxItems());
083                        builder.append("'");
084                }
085                builder.append("/>");
086                return builder.toString();
087        }
088}