1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-16 20:22:05 +01: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

@ -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 <tt>Item</tt> 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 <tt>Item</tt> with an id and a node id.
* <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 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("<item");
@ -96,6 +114,12 @@ public class Item implements PacketExtension
builder.append(id);
builder.append("'");
}
if (getNode() != null) {
builder.append(" node='");
builder.append(getNode());
builder.append("'");
}
builder.append("/>");
return builder.toString();

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() + "]";
}
}
}

View file

@ -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;

View file

@ -48,13 +48,15 @@ final public class PubSubManager
private Map<String, Node> nodeMap = new ConcurrentHashMap<String, Node>();
/**
* Create a pubsub manager associated to the specified connection.
* Create a pubsub manager associated to the specified connection. Defaults the service
* name to <i>pubsub</i>
*
* @param connection The XMPP connection
*/
public PubSubManager(Connection connection)
{
con = connection;
to = "pubsub." + connection.getServiceName();
}
/**

View file

@ -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<SimplePayload>(id, new SimplePayload(payloadElemName, payloadNS, payloadText.toString()));
return new PayloadItem<SimplePayload>(id, node, new SimplePayload(payloadElemName, payloadNS, payloadText.toString()));
}
else
{
return new PayloadItem<PacketExtension>(id, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser));
return new PayloadItem<PacketExtension>(id, node, PacketParserUtils.parsePacketExtension(payloadElemName, payloadNS, parser));
}
}
}