diff --git a/source/org/jivesoftware/smackx/pubsub/Item.java b/source/org/jivesoftware/smackx/pubsub/Item.java index 9d627abfe..117463f9e 100644 --- a/source/org/jivesoftware/smackx/pubsub/Item.java +++ b/source/org/jivesoftware/smackx/pubsub/Item.java @@ -13,9 +13,10 @@ */ 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 Item has several properties that are dependent @@ -39,7 +40,7 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider; * * @author Robin Collier */ -public class Item implements PacketExtension +public class Item extends NodeExtension { private String id; @@ -52,6 +53,7 @@ public class Item implements PacketExtension */ public Item() { + super(PubSubElementType.ITEM); } /** @@ -63,8 +65,27 @@ public class Item implements PacketExtension */ public Item(String itemId) { + // The element type is actually irrelevant since we override getNamespace() to return null + super(PubSubElementType.ITEM); id = itemId; } + + /** + * Create an Item 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 {@link Message}. If used to create an Item to publish + * (via {@link LeafNode#publish(Item)}, the server may return an + * error for an invalid packet. + * + * @param itemId The id of the item. + * @param nodeId The id of the node which the item was published to. + */ + public Item(String itemId, String nodeId) + { + super(PubSubElementType.ITEM_EVENT, nodeId); + id = itemId; + } /** * Get the item id. Unique to the node it is associated with. @@ -76,16 +97,13 @@ public class Item implements PacketExtension return id; } - public String getElementName() - { - return "item"; - } - + @Override public String getNamespace() { return null; } + @Override public String toXML() { StringBuilder builder = new StringBuilder(""); return builder.toString(); diff --git a/source/org/jivesoftware/smackx/pubsub/PayloadItem.java b/source/org/jivesoftware/smackx/pubsub/PayloadItem.java index e147e6102..6ebd430c1 100644 --- a/source/org/jivesoftware/smackx/pubsub/PayloadItem.java +++ b/source/org/jivesoftware/smackx/pubsub/PayloadItem.java @@ -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 Item has several properties that are dependent @@ -43,6 +45,20 @@ public class PayloadItem extends Item { private E payload; + /** + * Create an Item 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 Item with an id and payload. * @@ -58,6 +74,28 @@ public class PayloadItem extends Item payload = payloadExt; } + /** + * Create an Item with an id, node id and payload. + * + *

+ * Note: 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 may 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 Item. Customising the payload * parsing from the server can be accomplished as described in {@link ItemProvider}. @@ -69,6 +107,7 @@ public class PayloadItem extends Item return payload; } + @Override public String toXML() { StringBuilder builder = new StringBuilder(" extends Item builder.append("'"); } + if (getNode() != null) { + builder.append(" node='"); + builder.append(getNode()); + builder.append("'"); + } builder.append(">"); builder.append(payload.toXML()); builder.append(""); @@ -92,4 +136,4 @@ public class PayloadItem extends Item { return getClass().getName() + " | Content [" + toXML() + "]"; } -} +} \ No newline at end of file diff --git a/source/org/jivesoftware/smackx/pubsub/PubSubElementType.java b/source/org/jivesoftware/smackx/pubsub/PubSubElementType.java index 78fa9c193..a887ca2ba 100644 --- a/source/org/jivesoftware/smackx/pubsub/PubSubElementType.java +++ b/source/org/jivesoftware/smackx/pubsub/PubSubElementType.java @@ -32,6 +32,9 @@ public enum PubSubElementType OPTIONS("options", PubSubNamespace.BASIC), DEFAULT("default", PubSubNamespace.OWNER), ITEMS("items", PubSubNamespace.BASIC), + ITEMS_EVENT("items", PubSubNamespace.EVENT), + ITEM("item", PubSubNamespace.BASIC), + ITEM_EVENT("item", PubSubNamespace.EVENT), PUBLISH("publish", PubSubNamespace.BASIC), PUBLISH_OPTIONS("publish-options", PubSubNamespace.BASIC), PURGE_OWNER("purge", PubSubNamespace.OWNER), @@ -41,7 +44,7 @@ public enum PubSubElementType SUBSCRIBE("subscribe", PubSubNamespace.BASIC), SUBSCRIPTION("subscription", PubSubNamespace.BASIC), SUBSCRIPTIONS("subscriptions", PubSubNamespace.BASIC), - UNSUBSCRIBE("unsubscribe", PubSubNamespace.BASIC); + UNSUBSCRIBE("unsubscribe", PubSubNamespace.BASIC); private String eName; private PubSubNamespace nSpace; diff --git a/source/org/jivesoftware/smackx/pubsub/PubSubManager.java b/source/org/jivesoftware/smackx/pubsub/PubSubManager.java index 4e67b315e..e3eeae4b4 100644 --- a/source/org/jivesoftware/smackx/pubsub/PubSubManager.java +++ b/source/org/jivesoftware/smackx/pubsub/PubSubManager.java @@ -48,13 +48,15 @@ final public class PubSubManager private Map nodeMap = new ConcurrentHashMap(); /** - * Create a pubsub manager associated to the specified connection. + * Create a pubsub manager associated to the specified connection. Defaults the service + * name to pubsub * * @param connection The XMPP connection */ public PubSubManager(Connection connection) { con = connection; + to = "pubsub." + connection.getServiceName(); } /** diff --git a/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java b/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java index f8b59427e..aabd4cb2f 100644 --- a/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java +++ b/source/org/jivesoftware/smackx/pubsub/provider/ItemProvider.java @@ -35,13 +35,14 @@ public class ItemProvider implements PacketExtensionProvider public PacketExtension parseExtension(XmlPullParser parser) throws Exception { String id = parser.getAttributeValue(null, "id"); + String node = parser.getAttributeValue(null, "node"); String elem = parser.getName(); int tag = parser.next(); if (tag == XmlPullParser.END_TAG) { - return new Item(id); + return new Item(id, node); } else { @@ -63,11 +64,11 @@ public class ItemProvider implements PacketExtensionProvider if (!done) tag = parser.next(); } - return new PayloadItem(id, new SimplePayload(payloadElemName, payloadNS, payloadText.toString())); + return new PayloadItem(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText.toString())); } else { - return new PayloadItem(id, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser)); + return new PayloadItem(id, node, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser)); } } }