Package org.jivesoftware.smackx.pubsub
Class Item
- java.lang.Object
-
- org.jivesoftware.smackx.pubsub.NodeExtension
-
- org.jivesoftware.smackx.pubsub.Item
-
- All Implemented Interfaces:
Element
,ExtensionElement
,FullyQualifiedElement
,NamedElement
,XmlLangElement
- Direct Known Subclasses:
PayloadItem
public class Item extends NodeExtension
This class represents an item that has been, or will be published to a PubSub node. AnItem
has several properties that are dependent on the configuration of the node to which it has been or will be published.An Item received from a node (via
LeafNode.getItems()
orNode.addItemEventListener(org.jivesoftware.smackx.pubsub.listener.ItemEventListener)
- Will always have an id (either user or server generated) unless node configuration has both
ConfigureFormReader.isPersistItems()
andConfigureFormReader.isDeliverPayloads()
set to false. - Will have a payload if the node configuration has
ConfigureFormReader.isDeliverPayloads()
set to true, otherwise it will be null.
An Item created to send to a node (via
LeafNode.publish()
orLeafNode.publish()
- The id is optional, since the server will generate one if necessary, but should be used if it is meaningful in the context of the node. This value must be unique within the node that it is sent to, since resending an item with the same id will overwrite the one that already exists if the items are persisted.
- Will require payload if the node configuration has
ConfigureFormReader.isDeliverPayloads()
set to true.
To customise the payload object being returned from the
PayloadItem.getPayload()
method, you can add a custom parser as explained inItemProvider
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Item.ItemNamespace
-
Constructor Summary
Constructors Constructor Description Item()
Create an emptyItem
with no id.Item(String itemId)
Create anItem
with an id but no payload.Item(String itemId, String nodeId)
Create anItem
with an id and a node id.Item(Item.ItemNamespace itemNamespace, String itemId)
Create anItem
with an id but no payload.Item(Item.ItemNamespace itemNamespace, String itemId, String nodeId)
Create anItem
with an id and a node id.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addXml(XmlStringBuilder xml)
String
getId()
Get the item id.String
toString()
-
Methods inherited from class org.jivesoftware.smackx.pubsub.NodeExtension
getElementName, getNamespace, getNode, getPubSubNamespace, toXML
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.packet.FullyQualifiedElement
getLanguage, getQName
-
-
-
-
Constructor Detail
-
Item
public Item()
Create an emptyItem
with no id. This is a valid item for nodes which are configured so thatConfigureFormReader.isDeliverPayloads()
is false. In most cases an id will be generated by the server. For nodes configured withConfigureFormReader.isDeliverPayloads()
andConfigureFormReader.isPersistItems()
set to false, noItem
is sent to the node, you have to use theLeafNode.publish()
method in this case.
-
Item
public Item(String itemId)
Create anItem
with an id but no payload. This is a valid item for nodes which are configured so thatConfigureFormReader.isDeliverPayloads()
is false.- Parameters:
itemId
- The id if the item. It must be unique within the node unless overwriting and existing item. Passing null is the equivalent of callingItem()
.
-
Item
public Item(Item.ItemNamespace itemNamespace, String itemId)
Create anItem
with an id but no payload. This is a valid item for nodes which are configured so thatConfigureFormReader.isDeliverPayloads()
is false.- Parameters:
itemNamespace
- the namespace of the item.itemId
- The id if the item. It must be unique within the node unless overwriting and existing item. Passing null is the equivalent of callingItem()
.
-
Item
public Item(String itemId, String nodeId)
Create anItem
with an id and a node id.Note: This is not valid for publishing an item to a node, only receiving from one as part of
Message
. If used to create an Item to publish (viaLeafNode.publish(Item)
, the server may return an error for an invalid packet.- Parameters:
itemId
- The id of the item.nodeId
- The id of the node which the item was published to.
-
Item
public Item(Item.ItemNamespace itemNamespace, String itemId, String nodeId)
Create anItem
with an id and a node id.Note: This is not valid for publishing an item to a node, only receiving from one as part of
Message
. If used to create an Item to publish (viaLeafNode.publish(Item)
, the server may return an error for an invalid packet.- Parameters:
itemNamespace
- the namespace of the item.itemId
- The id of the item.nodeId
- The id of the node which the item was published to.
-
-
Method Detail
-
getId
public String getId()
Get the item id. Unique to the node it is associated with.- Returns:
- The id
-
addXml
protected void addXml(XmlStringBuilder xml)
- Overrides:
addXml
in classNodeExtension
-
toString
public String toString()
- Overrides:
toString
in classNodeExtension
-
-