1/**
2 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 *     http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14package org.jivesoftware.smackx.pubsub;
15
16/**
17 * Represents a request to subscribe to a node.
18 *
19 * @author Robin Collier
20 */
21public class GetItemsRequest extends NodeExtension
22{
23	protected String subId;
24	protected int maxItems;
25
26	public GetItemsRequest(String nodeId)
27	{
28		super(PubSubElementType.ITEMS, nodeId);
29	}
30
31	public GetItemsRequest(String nodeId, String subscriptionId)
32	{
33		super(PubSubElementType.ITEMS, nodeId);
34		subId = subscriptionId;
35	}
36
37	public GetItemsRequest(String nodeId, int maxItemsToReturn)
38	{
39		super(PubSubElementType.ITEMS, nodeId);
40		maxItems = maxItemsToReturn;
41	}
42
43	public GetItemsRequest(String nodeId, String subscriptionId, int maxItemsToReturn)
44	{
45		this(nodeId, maxItemsToReturn);
46		subId = subscriptionId;
47	}
48
49	public String getSubscriptionId()
50	{
51		return subId;
52	}
53
54	public int getMaxItems()
55	{
56		return maxItems;
57	}
58
59	@Override
60	public String toXML()
61	{
62		StringBuilder builder = new StringBuilder("<");
63		builder.append(getElementName());
64
65		builder.append(" node='");
66		builder.append(getNode());
67		builder.append("'");
68
69		if (getSubscriptionId() != null)
70		{
71			builder.append(" subid='");
72			builder.append(getSubscriptionId());
73			builder.append("'");
74		}
75
76		if (getMaxItems() > 0)
77		{
78			builder.append(" max_items='");
79			builder.append(getMaxItems());
80			builder.append("'");
81		}
82		builder.append("/>");
83		return builder.toString();
84	}
85}
86