1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

SMACK-330 Added missing node attribute in the item element for pubsub.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@12303 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2011-04-29 02:36:16 +00:00
parent f90b43a87c
commit 1df6aaadf3
5 changed files with 87 additions and 13 deletions

View file

@ -16,6 +16,8 @@ package org.jivesoftware.smackx.pubsub;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
/**
* This class represents an item that has been, or will be published to a
* pubsub node. An <tt>Item</tt> has several properties that are dependent
@ -43,6 +45,20 @@ public class PayloadItem<E extends PacketExtension> extends Item
{
private E payload;
/**
* Create an <tt>Item</tt> with no id and a payload The id will be set by the server.
*
* @param payloadExt A {@link PacketExtension} which represents the payload data.
*/
public PayloadItem(E payloadExt)
{
super();
if (payloadExt == null)
throw new IllegalArgumentException("payload cannot be 'null'");
payload = payloadExt;
}
/**
* Create an <tt>Item</tt> with an id and payload.
*
@ -58,6 +74,28 @@ public class PayloadItem<E extends PacketExtension> extends Item
payload = payloadExt;
}
/**
* Create an <tt>Item</tt> with an id, node id and payload.
*
* <p>
* <b>Note:</b> This is not valid for publishing an item to a node, only receiving from
* one as part of {@link Message}. If used to create an Item to publish
* (via {@link LeafNode#publish(Item)}, the server <i>may</i> return an
* error for an invalid packet.
*
* @param itemId The id of this item.
* @param nodeId The id of the node the item was published to.
* @param payloadExt A {@link PacketExtension} which represents the payload data.
*/
public PayloadItem(String itemId, String nodeId, E payloadExt)
{
super(itemId, nodeId);
if (payloadExt == null)
throw new IllegalArgumentException("payload cannot be 'null'");
payload = payloadExt;
}
/**
* Get the payload associated with this <tt>Item</tt>. Customising the payload
* parsing from the server can be accomplished as described in {@link ItemProvider}.
@ -69,6 +107,7 @@ public class PayloadItem<E extends PacketExtension> extends Item
return payload;
}
@Override
public String toXML()
{
StringBuilder builder = new StringBuilder("<item");
@ -80,6 +119,11 @@ public class PayloadItem<E extends PacketExtension> extends Item
builder.append("'");
}
if (getNode() != null) {
builder.append(" node='");
builder.append(getNode());
builder.append("'");
}
builder.append(">");
builder.append(payload.toXML());
builder.append("</item>");
@ -92,4 +136,4 @@ public class PayloadItem<E extends PacketExtension> extends Item
{
return getClass().getName() + " | Content [" + toXML() + "]";
}
}
}