1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-18 02:51:08 +01:00

Enfore spaces for indentation

Although I'm in the tabs camp, Smack uses mostly spaces. Therefore it
is the logical choice for the indentation style.
This commit is contained in:
Florian Schmaus 2017-02-07 22:02:40 +01:00
parent ffe9397e66
commit ef0af66b21
125 changed files with 5336 additions and 5344 deletions

View file

@ -24,18 +24,18 @@ package org.jivesoftware.smackx.pubsub;
*/
public enum AccessModel
{
/** Anyone may subscribe and retrieve items. */
open,
/** Anyone may subscribe and retrieve items. */
open,
/** Subscription request must be approved and only subscribers may retrieve items. */
authorize,
/** Subscription request must be approved and only subscribers may retrieve items. */
authorize,
/** Anyone with a presence subscription of both or from may subscribe and retrieve items. */
presence,
/** Anyone with a presence subscription of both or from may subscribe and retrieve items. */
presence,
/** Anyone in the specified roster group(s) may subscribe and retrieve items. */
roster,
/** Anyone in the specified roster group(s) may subscribe and retrieve items. */
roster,
/** Only those on a whitelist may subscribe and retrieve items. */
whitelist;
/** Only those on a whitelist may subscribe and retrieve items. */
whitelist;
}

View file

@ -42,17 +42,17 @@ public class Affiliation implements ExtensionElement
private final Type affiliation;
private final PubSubNamespace namespace;
public enum Type
{
member, none, outcast, owner, publisher
}
public enum Type
{
member, none, outcast, owner, publisher
}
/**
* Constructs an affiliation.
*
* @param node The node the user is affiliated with.
* @param affiliation the optional affiliation.
*/
/**
* Constructs an affiliation.
*
* @param node The node the user is affiliated with.
* @param affiliation the optional affiliation.
*/
public Affiliation(String node, Type affiliation) {
this.node = StringUtils.requireNotNullOrEmpty(node, "node must not be null or empty");
this.affiliation = affiliation;

View file

@ -30,8 +30,8 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*/
public class AffiliationsExtension extends NodeExtension
{
protected List<Affiliation> items = Collections.emptyList();
private final String node;
protected List<Affiliation> items = Collections.emptyList();
private final String node;
public AffiliationsExtension() {
this(null, null);
@ -47,20 +47,20 @@ public class AffiliationsExtension extends NodeExtension
this.node = node;
}
public List<Affiliation> getAffiliations()
{
return items;
}
public List<Affiliation> getAffiliations()
{
return items;
}
@Override
public CharSequence toXML()
{
if ((items == null) || (items.size() == 0))
{
return super.toXML();
}
else
{
@Override
public CharSequence toXML()
{
if ((items == null) || (items.size() == 0))
{
return super.toXML();
}
else
{
// Can't use XmlStringBuilder(this), because we don't want the namespace to be included
XmlStringBuilder xml = new XmlStringBuilder();
xml.openElement(getElementName());
@ -69,6 +69,6 @@ public class AffiliationsExtension extends NodeExtension
xml.append(items);
xml.closeElement(this);
return xml;
}
}
}
}
}

View file

@ -24,12 +24,12 @@ package org.jivesoftware.smackx.pubsub;
*/
public enum ChildrenAssociationPolicy
{
/** Anyone may associate leaf nodes with the collection. */
all,
/** Anyone may associate leaf nodes with the collection. */
all,
/** Only collection node owners may associate leaf nodes with the collection. */
owners,
/** Only collection node owners may associate leaf nodes with the collection. */
owners,
/** Only those on a whitelist may associate leaf nodes with the collection. */
whitelist;
/** Only those on a whitelist may associate leaf nodes with the collection. */
whitelist;
}

View file

@ -18,9 +18,9 @@ package org.jivesoftware.smackx.pubsub;
public class CollectionNode extends Node
{
CollectionNode(PubSubManager pubSubManager, String nodeId)
{
super(pubSubManager, nodeId);
}
CollectionNode(PubSubManager pubSubManager, String nodeId)
{
super(pubSubManager, nodeId);
}
}

View file

@ -31,29 +31,29 @@ import org.jivesoftware.smack.packet.ExtensionElement;
*/
public class ConfigurationEvent extends NodeExtension implements EmbeddedPacketExtension
{
private ConfigureForm form;
private ConfigureForm form;
public ConfigurationEvent(String nodeId)
{
super(PubSubElementType.CONFIGURATION, nodeId);
}
public ConfigurationEvent(String nodeId)
{
super(PubSubElementType.CONFIGURATION, nodeId);
}
public ConfigurationEvent(String nodeId, ConfigureForm configForm)
{
super(PubSubElementType.CONFIGURATION, nodeId);
form = configForm;
}
public ConfigurationEvent(String nodeId, ConfigureForm configForm)
{
super(PubSubElementType.CONFIGURATION, nodeId);
form = configForm;
}
public ConfigureForm getConfiguration()
{
return form;
}
public ConfigureForm getConfiguration()
{
return form;
}
public List<ExtensionElement> getExtensions()
{
if (getConfiguration() == null)
return Collections.emptyList();
else
return Arrays.asList(((ExtensionElement)getConfiguration().getDataFormToSend()));
}
public List<ExtensionElement> getExtensions()
{
if (getConfiguration() == null)
return Collections.emptyList();
else
return Arrays.asList(((ExtensionElement)getConfiguration().getDataFormToSend()));
}
}

View file

@ -29,193 +29,193 @@ import org.jivesoftware.smackx.xdata.Form;
*/
public enum ConfigureNodeFields
{
/**
* Determines who may subscribe and retrieve items.
*
* <p><b>Value: {@link AccessModel}</b></p>
*/
access_model,
/**
* Determines who may subscribe and retrieve items.
*
* <p><b>Value: {@link AccessModel}</b></p>
*/
access_model,
/**
* The URL of an XSL transformation which can be applied to
* payloads in order to generate an appropriate message
* body element.
*
* <p><b>Value: {@link URL}</b></p>
*/
body_xslt,
/**
* The URL of an XSL transformation which can be applied to
* payloads in order to generate an appropriate message
* body element.
*
* <p><b>Value: {@link URL}</b></p>
*/
body_xslt,
/**
* The collection with which a node is affiliated.
*
* <p><b>Value: String</b></p>
*/
collection,
/**
* The collection with which a node is affiliated.
*
* <p><b>Value: String</b></p>
*/
collection,
/**
* The URL of an XSL transformation which can be applied to
* payload format in order to generate a valid Data Forms result
* that the client could display using a generic Data Forms
* rendering engine body element.
*
* <p><b>Value: {@link URL}</b></p>
*/
dataform_xslt,
/**
* The URL of an XSL transformation which can be applied to
* payload format in order to generate a valid Data Forms result
* that the client could display using a generic Data Forms
* rendering engine body element.
*
* <p><b>Value: {@link URL}</b></p>
*/
dataform_xslt,
/**
* Whether to deliver payloads with event notifications.
*
* <p><b>Value: boolean</b></p>
*/
deliver_payloads,
/**
* Whether to deliver payloads with event notifications.
*
* <p><b>Value: boolean</b></p>
*/
deliver_payloads,
/**
* Whether owners or publisher should receive replies to items.
*
* <p><b>Value: {@link ItemReply}</b></p>
*/
itemreply,
/**
* Whether owners or publisher should receive replies to items.
*
* <p><b>Value: {@link ItemReply}</b></p>
*/
itemreply,
/**
* Who may associate leaf nodes with a collection.
*
* <p><b>Value: {@link ChildrenAssociationPolicy}</b></p>
*/
children_association_policy,
/**
* Who may associate leaf nodes with a collection.
*
* <p><b>Value: {@link ChildrenAssociationPolicy}</b></p>
*/
children_association_policy,
/**
* The list of JIDs that may associate leaf nodes with a
* collection.
*
* <p><b>Value: List of JIDs as Strings</b></p>
*/
children_association_whitelist,
/**
* The list of JIDs that may associate leaf nodes with a
* collection.
*
* <p><b>Value: List of JIDs as Strings</b></p>
*/
children_association_whitelist,
/**
* The child nodes (leaf or collection) associated with a collection.
*
* <p><b>Value: List of Strings</b></p>
*/
children,
/**
* The child nodes (leaf or collection) associated with a collection.
*
* <p><b>Value: List of Strings</b></p>
*/
children,
/**
* The maximum number of child nodes that can be associated with a
* collection.
*
* <p><b>Value: int</b></p>
*/
children_max,
/**
* The maximum number of child nodes that can be associated with a
* collection.
*
* <p><b>Value: int</b></p>
*/
children_max,
/**
* The maximum number of items to persist.
*
* <p><b>Value: int</b></p>
*/
max_items,
/**
* The maximum number of items to persist.
*
* <p><b>Value: int</b></p>
*/
max_items,
/**
* The maximum payload size in bytes.
*
* <p><b>Value: int</b></p>
*/
max_payload_size,
/**
* The maximum payload size in bytes.
*
* <p><b>Value: int</b></p>
*/
max_payload_size,
/**
* Whether the node is a leaf (default) or collection.
*
* <p><b>Value: {@link NodeType}</b></p>
*/
node_type,
/**
* Whether the node is a leaf (default) or collection.
*
* <p><b>Value: {@link NodeType}</b></p>
*/
node_type,
/**
* Whether to notify subscribers when the node configuration changes.
*
* <p><b>Value: boolean</b></p>
*/
notify_config,
/**
* Whether to notify subscribers when the node configuration changes.
*
* <p><b>Value: boolean</b></p>
*/
notify_config,
/**
* Whether to notify subscribers when the node is deleted.
*
* <p><b>Value: boolean</b></p>
*/
notify_delete,
/**
* Whether to notify subscribers when the node is deleted.
*
* <p><b>Value: boolean</b></p>
*/
notify_delete,
/**
* Whether to notify subscribers when items are removed from the node.
*
* <p><b>Value: boolean</b></p>
*/
notify_retract,
/**
* Whether to notify subscribers when items are removed from the node.
*
* <p><b>Value: boolean</b></p>
*/
notify_retract,
/**
* Whether to persist items to storage. This is required to have. multiple
* items in the node.
*
* <p><b>Value: boolean</b></p>
*/
persist_items,
/**
* Whether to persist items to storage. This is required to have. multiple
* items in the node.
*
* <p><b>Value: boolean</b></p>
*/
persist_items,
/**
* Whether to deliver notifications to available users only.
*
* <p><b>Value: boolean</b></p>
*/
presence_based_delivery,
/**
* Whether to deliver notifications to available users only.
*
* <p><b>Value: boolean</b></p>
*/
presence_based_delivery,
/**
* Defines who can publish to the node.
*
* <p><b>Value: {@link PublishModel}</b></p>
*/
publish_model,
/**
* Defines who can publish to the node.
*
* <p><b>Value: {@link PublishModel}</b></p>
*/
publish_model,
/**
* The specific multi-user chat rooms to specify for replyroom.
*
* <p><b>Value: List of JIDs as Strings</b></p>
*/
replyroom,
/**
* The specific multi-user chat rooms to specify for replyroom.
*
* <p><b>Value: List of JIDs as Strings</b></p>
*/
replyroom,
/**
* The specific JID(s) to specify for replyto.
*
* <p><b>Value: List of JIDs as Strings</b></p>
*/
replyto,
/**
* The specific JID(s) to specify for replyto.
*
* <p><b>Value: List of JIDs as Strings</b></p>
*/
replyto,
/**
* The roster group(s) allowed to subscribe and retrieve items.
*
* <p><b>Value: List of strings</b></p>
*/
roster_groups_allowed,
/**
* The roster group(s) allowed to subscribe and retrieve items.
*
* <p><b>Value: List of strings</b></p>
*/
roster_groups_allowed,
/**
* Whether to allow subscriptions.
*
* <p><b>Value: boolean</b></p>
*/
subscribe,
/**
* Whether to allow subscriptions.
*
* <p><b>Value: boolean</b></p>
*/
subscribe,
/**
* A friendly name for the node.
*
* <p><b>Value: String</b></p>
*/
title,
/**
* A friendly name for the node.
*
* <p><b>Value: String</b></p>
*/
title,
/**
* The type of node data, ussually specified by the namespace
* of the payload(if any);MAY be a list-single rather than a
* text single.
*
* <p><b>Value: String</b></p>
*/
type;
/**
* The type of node data, ussually specified by the namespace
* of the payload(if any);MAY be a list-single rather than a
* text single.
*
* <p><b>Value: String</b></p>
*/
type;
public String getFieldName()
{
return "pubsub#" + toString();
}
public String getFieldName()
{
return "pubsub#" + toString();
}
}

View file

@ -39,10 +39,10 @@ import org.jivesoftware.smack.util.PacketParserUtils;
*/
public interface EmbeddedPacketExtension extends ExtensionElement
{
/**
* Get the list of embedded {@link ExtensionElement} objects.
*
* @return List of embedded {@link ExtensionElement}
*/
List<ExtensionElement> getExtensions();
/**
* Get the list of embedded {@link ExtensionElement} objects.
*
* @return List of embedded {@link ExtensionElement}
*/
List<ExtensionElement> getExtensions();
}

View file

@ -44,39 +44,39 @@ public class EventElement implements EmbeddedPacketExtension
*/
public static final String NAMESPACE = PubSubNamespace.EVENT.getXmlns();
private EventElementType type;
private NodeExtension ext;
private EventElementType type;
private NodeExtension ext;
public EventElement(EventElementType eventType, NodeExtension eventExt)
{
type = eventType;
ext = eventExt;
}
public EventElement(EventElementType eventType, NodeExtension eventExt)
{
type = eventType;
ext = eventExt;
}
public EventElementType getEventType()
{
return type;
}
public EventElementType getEventType()
{
return type;
}
public List<ExtensionElement> getExtensions()
{
return Arrays.asList(new ExtensionElement[]{getEvent()});
}
public List<ExtensionElement> getExtensions()
{
return Arrays.asList(new ExtensionElement[]{getEvent()});
}
public NodeExtension getEvent()
{
return ext;
}
public NodeExtension getEvent()
{
return ext;
}
public String getElementName()
{
return "event";
}
public String getElementName()
{
return "event";
}
public String getNamespace()
{
return PubSubNamespace.EVENT.getXmlns();
}
public String getNamespace()
{
return PubSubNamespace.EVENT.getXmlns();
}
@Override
public XmlStringBuilder toXML() {

View file

@ -24,21 +24,21 @@ package org.jivesoftware.smackx.pubsub;
*/
public enum EventElementType
{
/** A node has been associated or dissassociated with a collection node. */
collection,
/** A node has been associated or dissassociated with a collection node. */
collection,
/** A node has had its configuration changed. */
configuration,
/** A node has had its configuration changed. */
configuration,
/** A node has been deleted. */
delete,
/** A node has been deleted. */
delete,
/** Items have been published to a node. */
items,
/** Items have been published to a node. */
items,
/** All items have been purged from a node. */
purge,
/** All items have been purged from a node. */
purge,
/** A node has been subscribed to. */
subscription
/** A node has been subscribed to. */
subscription
}

View file

@ -28,75 +28,75 @@ import org.jivesoftware.smackx.xdata.Form;
*/
public class FormNode extends NodeExtension
{
private Form configForm;
private Form configForm;
/**
* Create a {@link FormNode} which contains the specified form.
*
* @param formType The type of form being sent
* @param submitForm The form
*/
public FormNode(FormNodeType formType, Form submitForm)
{
super(formType.getNodeElement());
/**
* Create a {@link FormNode} which contains the specified form.
*
* @param formType The type of form being sent
* @param submitForm The form
*/
public FormNode(FormNodeType formType, Form submitForm)
{
super(formType.getNodeElement());
if (submitForm == null)
throw new IllegalArgumentException("Submit form cannot be null");
configForm = submitForm;
}
if (submitForm == null)
throw new IllegalArgumentException("Submit form cannot be null");
configForm = submitForm;
}
/**
* Create a {@link FormNode} which contains the specified form, which is
* associated with the specified node.
*
* @param formType The type of form being sent
* @param nodeId The node the form is associated with
* @param submitForm The form
*/
public FormNode(FormNodeType formType, String nodeId, Form submitForm)
{
super(formType.getNodeElement(), nodeId);
/**
* Create a {@link FormNode} which contains the specified form, which is
* associated with the specified node.
*
* @param formType The type of form being sent
* @param nodeId The node the form is associated with
* @param submitForm The form
*/
public FormNode(FormNodeType formType, String nodeId, Form submitForm)
{
super(formType.getNodeElement(), nodeId);
if (submitForm == null)
throw new IllegalArgumentException("Submit form cannot be null");
configForm = submitForm;
}
if (submitForm == null)
throw new IllegalArgumentException("Submit form cannot be null");
configForm = submitForm;
}
/**
* Get the Form that is to be sent, or was retrieved from the server.
*
* @return The form
*/
public Form getForm()
{
return configForm;
}
/**
* Get the Form that is to be sent, or was retrieved from the server.
*
* @return The form
*/
public Form getForm()
{
return configForm;
}
@Override
public CharSequence toXML()
{
if (configForm == null)
{
return super.toXML();
}
else
{
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
@Override
public CharSequence toXML()
{
if (configForm == null)
{
return super.toXML();
}
else
{
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
if (getNode() != null)
{
builder.append(" node='");
builder.append(getNode());
builder.append("'>");
}
else
builder.append('>');
builder.append(configForm.getDataFormToSend().toXML());
builder.append("</");
builder.append(getElementName() + '>');
return builder.toString();
}
}
if (getNode() != null)
{
builder.append(" node='");
builder.append(getNode());
builder.append("'>");
}
else
builder.append('>');
builder.append(configForm.getDataFormToSend().toXML());
builder.append("</");
builder.append(getElementName() + '>');
return builder.toString();
}
}
}

View file

@ -27,29 +27,29 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
*/
public enum FormNodeType
{
/** Form for configuring an existing node. */
CONFIGURE_OWNER,
/** Form for configuring an existing node. */
CONFIGURE_OWNER,
/** Form for configuring a node during creation. */
CONFIGURE,
/** Form for configuring a node during creation. */
CONFIGURE,
/** Form for configuring subscription options. */
OPTIONS,
/** Form for configuring subscription options. */
OPTIONS,
/** Form which represents the default node configuration options. */
DEFAULT;
/** Form which represents the default node configuration options. */
DEFAULT;
public PubSubElementType getNodeElement()
{
return PubSubElementType.valueOf(toString());
}
public PubSubElementType getNodeElement()
{
return PubSubElementType.valueOf(toString());
}
public static FormNodeType valueOfFromElementName(String elem, String configNamespace)
{
if ("configure".equals(elem) && PubSubNamespace.OWNER.getXmlns().equals(configNamespace))
{
return CONFIGURE_OWNER;
}
return valueOf(elem.toUpperCase(Locale.US));
}
public static FormNodeType valueOfFromElementName(String elem, String configNamespace)
{
if ("configure".equals(elem) && PubSubNamespace.OWNER.getXmlns().equals(configNamespace))
{
return CONFIGURE_OWNER;
}
return valueOf(elem.toUpperCase(Locale.US));
}
}

View file

@ -25,42 +25,42 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*/
public class GetItemsRequest extends NodeExtension
{
protected final String subId;
protected final int maxItems;
protected final String subId;
protected final int maxItems;
public GetItemsRequest(String nodeId)
{
this(nodeId, null, -1);
}
public GetItemsRequest(String nodeId)
{
this(nodeId, null, -1);
}
public GetItemsRequest(String nodeId, String subscriptionId)
{
public GetItemsRequest(String nodeId, String subscriptionId)
{
this(nodeId, subscriptionId, -1);
}
}
public GetItemsRequest(String nodeId, int maxItemsToReturn)
{
public GetItemsRequest(String nodeId, int maxItemsToReturn)
{
this(nodeId, null, maxItemsToReturn);
}
}
public GetItemsRequest(String nodeId, String subscriptionId, int maxItemsToReturn)
{
public GetItemsRequest(String nodeId, String subscriptionId, int maxItemsToReturn)
{
super(PubSubElementType.ITEMS, nodeId);
maxItems = maxItemsToReturn;
subId = subscriptionId;
}
subId = subscriptionId;
}
public String getSubscriptionId()
{
return subId;
}
public String getSubscriptionId()
{
return subId;
}
public int getMaxItems()
{
return maxItems;
}
public int getMaxItems()
{
return maxItems;
}
@Override
@Override
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder();
xml.halfOpenElement(getElementName());

View file

@ -50,94 +50,92 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
*/
public class Item extends NodeExtension
{
private String id;
private String id;
/**
* Create an empty <tt>Item</tt> with no id. This is a valid item for nodes which are configured
* so that {@link ConfigureForm#isDeliverPayloads()} is false. In most cases an id will be generated by the server.
* For nodes configured with {@link ConfigureForm#isDeliverPayloads()} and {@link ConfigureForm#isPersistItems()}
* set to false, no <tt>Item</tt> is sent to the node, you have to use {@link LeafNode#send()} or {@link LeafNode#publish()}
* methods in this case.
*/
public Item()
{
super(PubSubElementType.ITEM);
}
/**
* Create an <tt>Item</tt> with an id but no payload. This is a valid item for nodes which are configured
* so that {@link ConfigureForm#isDeliverPayloads()} is false.
*
* @param itemId The id if the item. It must be unique within the node unless overwriting and existing item.
* Passing null is the equivalent of calling {@link #Item()}.
*/
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)
/**
* Create an empty <tt>Item</tt> with no id. This is a valid item for nodes which are configured
* so that {@link ConfigureForm#isDeliverPayloads()} is false. In most cases an id will be generated by the server.
* For nodes configured with {@link ConfigureForm#isDeliverPayloads()} and {@link ConfigureForm#isPersistItems()}
* set to false, no <tt>Item</tt> is sent to the node, you have to use {@link LeafNode#send()} or {@link LeafNode#publish()}
* methods in this case.
*/
public Item()
{
// CHECKSTYLE:OFF
super(PubSubElementType.ITEM_EVENT, nodeId);
// CHECKSTYLE:ON
super(PubSubElementType.ITEM);
}
/**
* Create an <tt>Item</tt> with an id but no payload. This is a valid item for nodes which are configured
* so that {@link ConfigureForm#isDeliverPayloads()} is false.
*
* @param itemId The id if the item. It must be unique within the node unless overwriting and existing item.
* Passing null is the equivalent of calling {@link #Item()}.
*/
public Item(String itemId)
{
// The element type is actually irrelevant since we override getNamespace() to return null
super(PubSubElementType.ITEM);
id = itemId;
}
/**
* Get the item id. Unique to the node it is associated with.
*
* @return The id
*/
public String getId()
{
return id;
}
/**
* 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;
}
@Override
public String getNamespace()
{
return null;
}
/**
* Get the item id. Unique to the node it is associated with.
*
* @return The id
*/
public String getId()
{
return id;
}
@Override
public String toXML()
{
StringBuilder builder = new StringBuilder("<item");
@Override
public String getNamespace()
{
return null;
}
if (id != null)
{
builder.append(" id='");
builder.append(id);
builder.append('\'');
}
@Override
public String toXML()
{
StringBuilder builder = new StringBuilder("<item");
if (id != null)
{
builder.append(" id='");
builder.append(id);
builder.append('\'');
}
if (getNode() != null) {
builder.append(" node='");
builder.append(getNode());
builder.append('\'');
}
builder.append("/>");
builder.append("/>");
return builder.toString();
}
return builder.toString();
}
@Override
public String toString()
{
return getClass().getName() + " | Content [" + toXML() + "]";
}
@Override
public String toString()
{
return getClass().getName() + " | Content [" + toXML() + "]";
}
}

View file

@ -26,40 +26,40 @@ import java.util.List;
*/
public class ItemDeleteEvent extends SubscriptionEvent
{
private List<String> itemIds = Collections.emptyList();
private List<String> itemIds = Collections.emptyList();
/**
* Constructs an <tt>ItemDeleteEvent</tt> that indicates the the supplied
* items (by id) have been deleted, and that the event matches the listed
* subscriptions. The subscriptions would have been created by calling
* {@link LeafNode#subscribe(String)}.
*
* @param nodeId The id of the node the event came from
* @param deletedItemIds The item ids of the items that were deleted.
* @param subscriptionIds The subscriptions that match the event.
*/
public ItemDeleteEvent(String nodeId, List<String> deletedItemIds, List<String> subscriptionIds)
{
super(nodeId, subscriptionIds);
/**
* Constructs an <tt>ItemDeleteEvent</tt> that indicates the the supplied
* items (by id) have been deleted, and that the event matches the listed
* subscriptions. The subscriptions would have been created by calling
* {@link LeafNode#subscribe(String)}.
*
* @param nodeId The id of the node the event came from
* @param deletedItemIds The item ids of the items that were deleted.
* @param subscriptionIds The subscriptions that match the event.
*/
public ItemDeleteEvent(String nodeId, List<String> deletedItemIds, List<String> subscriptionIds)
{
super(nodeId, subscriptionIds);
if (deletedItemIds == null)
throw new IllegalArgumentException("deletedItemIds cannot be null");
itemIds = deletedItemIds;
}
if (deletedItemIds == null)
throw new IllegalArgumentException("deletedItemIds cannot be null");
itemIds = deletedItemIds;
}
/**
* Get the item id's of the items that have been deleted.
*
* @return List of item id's
*/
public List<String> getItemIds()
{
return Collections.unmodifiableList(itemIds);
}
/**
* Get the item id's of the items that have been deleted.
*
* @return List of item id's
*/
public List<String> getItemIds()
{
return Collections.unmodifiableList(itemIds);
}
@Override
public String toString()
{
return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Deleted Items: " + itemIds + ']';
}
@Override
public String toString()
{
return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Deleted Items: " + itemIds + ']';
}
}

View file

@ -27,98 +27,98 @@ import java.util.List;
*/
public class ItemPublishEvent<T extends Item> extends SubscriptionEvent
{
private List<T> items;
private Date originalDate;
private List<T> items;
private Date originalDate;
/**
* Constructs an <tt>ItemPublishEvent</tt> with the provided list
* of {@link Item} that were published.
*
* @param nodeId The id of the node the event came from
* @param eventItems The list of {@link Item} that were published
*/
public ItemPublishEvent(String nodeId, List<T> eventItems)
{
super(nodeId);
items = eventItems;
}
/**
* Constructs an <tt>ItemPublishEvent</tt> with the provided list
* of {@link Item} that were published.
*
* @param nodeId The id of the node the event came from
* @param eventItems The list of {@link Item} that were published
*/
public ItemPublishEvent(String nodeId, List<T> eventItems)
{
super(nodeId);
items = eventItems;
}
/**
* Constructs an <tt>ItemPublishEvent</tt> with the provided list
* of {@link Item} that were published. The list of subscription ids
* represents the subscriptions that matched the event, in the case
* of the user having multiple subscriptions.
*
* @param nodeId The id of the node the event came from
* @param eventItems The list of {@link Item} that were published
* @param subscriptionIds The list of subscriptionIds
*/
public ItemPublishEvent(String nodeId, List<T> eventItems, List<String> subscriptionIds)
{
super(nodeId, subscriptionIds);
items = eventItems;
}
/**
* Constructs an <tt>ItemPublishEvent</tt> with the provided list
* of {@link Item} that were published. The list of subscription ids
* represents the subscriptions that matched the event, in the case
* of the user having multiple subscriptions.
*
* @param nodeId The id of the node the event came from
* @param eventItems The list of {@link Item} that were published
* @param subscriptionIds The list of subscriptionIds
*/
public ItemPublishEvent(String nodeId, List<T> eventItems, List<String> subscriptionIds)
{
super(nodeId, subscriptionIds);
items = eventItems;
}
/**
* Constructs an <tt>ItemPublishEvent</tt> with the provided list
* of {@link Item} that were published in the past. The published
* date signifies that this is delayed event. The list of subscription ids
* represents the subscriptions that matched the event, in the case
* of the user having multiple subscriptions.
*
* @param nodeId The id of the node the event came from
* @param eventItems The list of {@link Item} that were published
* @param subscriptionIds The list of subscriptionIds
*/
public ItemPublishEvent(String nodeId, List<T> eventItems, List<String> subscriptionIds, Date publishedDate)
{
super(nodeId, subscriptionIds);
items = eventItems;
/**
* Constructs an <tt>ItemPublishEvent</tt> with the provided list
* of {@link Item} that were published in the past. The published
* date signifies that this is delayed event. The list of subscription ids
* represents the subscriptions that matched the event, in the case
* of the user having multiple subscriptions.
*
* @param nodeId The id of the node the event came from
* @param eventItems The list of {@link Item} that were published
* @param subscriptionIds The list of subscriptionIds
*/
public ItemPublishEvent(String nodeId, List<T> eventItems, List<String> subscriptionIds, Date publishedDate)
{
super(nodeId, subscriptionIds);
items = eventItems;
if (publishedDate != null)
originalDate = publishedDate;
}
if (publishedDate != null)
originalDate = publishedDate;
}
/**
* Get the list of {@link Item} that were published.
*
* @return The list of published {@link Item}
*/
public List<T> getItems()
{
return Collections.unmodifiableList(items);
}
/**
* Get the list of {@link Item} that were published.
*
* @return The list of published {@link Item}
*/
public List<T> getItems()
{
return Collections.unmodifiableList(items);
}
/**
* Indicates whether this event was delayed. That is, the items
* were published to the node at some time in the past. This will
* typically happen if there is an item already published to the node
* before a user subscribes to it. In this case, when the user
* subscribes, the server may send the last item published to the node
* with a delay date showing its time of original publication.
*
* @return true if the items are delayed, false otherwise.
*/
public boolean isDelayed()
{
return (originalDate != null);
}
/**
* Indicates whether this event was delayed. That is, the items
* were published to the node at some time in the past. This will
* typically happen if there is an item already published to the node
* before a user subscribes to it. In this case, when the user
* subscribes, the server may send the last item published to the node
* with a delay date showing its time of original publication.
*
* @return true if the items are delayed, false otherwise.
*/
public boolean isDelayed()
{
return (originalDate != null);
}
/**
* Gets the original date the items were published. This is only
* valid if {@link #isDelayed()} is true.
*
*/
public Date getPublishedDate()
{
return originalDate;
}
/**
* Gets the original date the items were published. This is only
* valid if {@link #isDelayed()} is true.
*
*/
public Date getPublishedDate()
{
return originalDate;
}
@Override
public String toString()
{
return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Delayed: " +
(isDelayed() ? originalDate.toString() : "false") + ']';
}
@Override
public String toString()
{
return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Delayed: " +
(isDelayed() ? originalDate.toString() : "false") + ']';
}
}

View file

@ -24,9 +24,9 @@ package org.jivesoftware.smackx.pubsub;
*/
public enum ItemReply
{
/** The node owner. */
owner,
/** The node owner. */
owner,
/** The item publisher. */
publisher;
/** The item publisher. */
publisher;
}

View file

@ -36,168 +36,168 @@ import org.jivesoftware.smack.packet.ExtensionElement;
*/
public class ItemsExtension extends NodeExtension implements EmbeddedPacketExtension
{
protected ItemsElementType type;
protected Boolean notify;
protected List<? extends ExtensionElement> items;
protected ItemsElementType type;
protected Boolean notify;
protected List<? extends ExtensionElement> items;
public enum ItemsElementType
{
/** An items element, which has an optional <b>max_items</b> attribute when requesting items. */
items(PubSubElementType.ITEMS, "max_items"),
public enum ItemsElementType
{
/** An items element, which has an optional <b>max_items</b> attribute when requesting items. */
items(PubSubElementType.ITEMS, "max_items"),
/** A retract element, which has an optional <b>notify</b> attribute when publishing deletions. */
retract(PubSubElementType.RETRACT, "notify");
/** A retract element, which has an optional <b>notify</b> attribute when publishing deletions. */
retract(PubSubElementType.RETRACT, "notify");
private PubSubElementType elem;
private String att;
private PubSubElementType elem;
private String att;
private ItemsElementType(PubSubElementType nodeElement, String attribute)
{
elem = nodeElement;
att = attribute;
}
private ItemsElementType(PubSubElementType nodeElement, String attribute)
{
elem = nodeElement;
att = attribute;
}
public PubSubElementType getNodeElement()
{
return elem;
}
public PubSubElementType getNodeElement()
{
return elem;
}
public String getElementAttribute()
{
return att;
}
}
public String getElementAttribute()
{
return att;
}
}
/**
* Construct an instance with a list representing items that have been published or deleted.
*
* <p>Valid scenarios are:</p>
* <ul>
* <li>Request items from node - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and an
* optional value for the <b>max_items</b> attribute.
* <li>Request to delete items - itemsType = {@link ItemsElementType#retract}, items = list of {@link Item} containing
* only id's and an optional value for the <b>notify</b> attribute.
* <li>Items published event - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and
* attributeValue = <code>null</code>
* <li>Items deleted event - itemsType = {@link ItemsElementType#items}, items = list of {@link RetractItem} and
* attributeValue = <code>null</code>
* </ul>
*
* @param itemsType Type of representation
* @param nodeId The node to which the items are being sent or deleted
* @param items The list of {@link Item} or {@link RetractItem}
*/
public ItemsExtension(ItemsElementType itemsType, String nodeId, List<? extends ExtensionElement> items)
{
super(itemsType.getNodeElement(), nodeId);
type = itemsType;
this.items = items;
}
/**
* Construct an instance with a list representing items that have been published or deleted.
*
* <p>Valid scenarios are:</p>
* <ul>
* <li>Request items from node - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and an
* optional value for the <b>max_items</b> attribute.
* <li>Request to delete items - itemsType = {@link ItemsElementType#retract}, items = list of {@link Item} containing
* only id's and an optional value for the <b>notify</b> attribute.
* <li>Items published event - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and
* attributeValue = <code>null</code>
* <li>Items deleted event - itemsType = {@link ItemsElementType#items}, items = list of {@link RetractItem} and
* attributeValue = <code>null</code>
* </ul>
*
* @param itemsType Type of representation
* @param nodeId The node to which the items are being sent or deleted
* @param items The list of {@link Item} or {@link RetractItem}
*/
public ItemsExtension(ItemsElementType itemsType, String nodeId, List<? extends ExtensionElement> items)
{
super(itemsType.getNodeElement(), nodeId);
type = itemsType;
this.items = items;
}
/**
* Construct an instance with a list representing items that have been published or deleted.
*
* <p>Valid scenarios are:</p>
* <ul>
* <li>Request items from node - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and an
* optional value for the <b>max_items</b> attribute.
* <li>Request to delete items - itemsType = {@link ItemsElementType#retract}, items = list of {@link Item} containing
* only id's and an optional value for the <b>notify</b> attribute.
* <li>Items published event - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and
* attributeValue = <code>null</code>
* <li>Items deleted event - itemsType = {@link ItemsElementType#items}, items = list of {@link RetractItem} and
* attributeValue = <code>null</code>
* </ul>
*
* @param nodeId The node to which the items are being sent or deleted
* @param items The list of {@link Item} or {@link RetractItem}
*/
public ItemsExtension(String nodeId, List<? extends ExtensionElement> items, boolean notify)
{
super(ItemsElementType.retract.getNodeElement(), nodeId);
type = ItemsElementType.retract;
this.items = items;
this.notify = notify;
}
/**
* Construct an instance with a list representing items that have been published or deleted.
*
* <p>Valid scenarios are:</p>
* <ul>
* <li>Request items from node - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and an
* optional value for the <b>max_items</b> attribute.
* <li>Request to delete items - itemsType = {@link ItemsElementType#retract}, items = list of {@link Item} containing
* only id's and an optional value for the <b>notify</b> attribute.
* <li>Items published event - itemsType = {@link ItemsElementType#items}, items = list of {@link Item} and
* attributeValue = <code>null</code>
* <li>Items deleted event - itemsType = {@link ItemsElementType#items}, items = list of {@link RetractItem} and
* attributeValue = <code>null</code>
* </ul>
*
* @param nodeId The node to which the items are being sent or deleted
* @param items The list of {@link Item} or {@link RetractItem}
*/
public ItemsExtension(String nodeId, List<? extends ExtensionElement> items, boolean notify)
{
super(ItemsElementType.retract.getNodeElement(), nodeId);
type = ItemsElementType.retract;
this.items = items;
this.notify = notify;
}
/**
* Get the type of element.
*
* @return The element type
*/
public ItemsElementType getItemsElementType()
{
return type;
}
/**
* Get the type of element.
*
* @return The element type
*/
public ItemsElementType getItemsElementType()
{
return type;
}
@SuppressWarnings("unchecked")
public List<ExtensionElement> getExtensions()
{
return (List<ExtensionElement>)getItems();
}
@SuppressWarnings("unchecked")
public List<ExtensionElement> getExtensions()
{
return (List<ExtensionElement>)getItems();
}
/**
* Gets the items related to the type of request or event.
*
* return List of {@link Item}, {@link RetractItem}, or null
*/
public List<? extends ExtensionElement> getItems()
{
return items;
}
/**
* Gets the items related to the type of request or event.
*
* return List of {@link Item}, {@link RetractItem}, or null
*/
public List<? extends ExtensionElement> getItems()
{
return items;
}
/**
* Gets the value of the optional attribute related to the {@link ItemsElementType}.
*
* @return The attribute value
*/
public boolean getNotify()
{
return notify;
}
/**
* Gets the value of the optional attribute related to the {@link ItemsElementType}.
*
* @return The attribute value
*/
public boolean getNotify()
{
return notify;
}
@Override
public CharSequence toXML()
{
if ((items == null) || (items.size() == 0))
{
return super.toXML();
}
else
{
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
builder.append(" node='");
builder.append(getNode());
@Override
public CharSequence toXML()
{
if ((items == null) || (items.size() == 0))
{
return super.toXML();
}
else
{
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
builder.append(" node='");
builder.append(getNode());
if (notify != null)
{
builder.append("' ");
builder.append(type.getElementAttribute());
builder.append("='");
builder.append(notify.equals(Boolean.TRUE) ? 1 : 0);
builder.append("'>");
}
else
{
builder.append("'>");
for (ExtensionElement item : items)
{
builder.append(item.toXML());
}
}
if (notify != null)
{
builder.append("' ");
builder.append(type.getElementAttribute());
builder.append("='");
builder.append(notify.equals(Boolean.TRUE) ? 1 : 0);
builder.append("'>");
}
else
{
builder.append("'>");
for (ExtensionElement item : items)
{
builder.append(item.toXML());
}
}
builder.append("</");
builder.append(getElementName());
builder.append('>');
return builder.toString();
}
}
builder.append("</");
builder.append(getElementName());
builder.append('>');
return builder.toString();
}
}
@Override
public String toString()
{
return getClass().getName() + "Content [" + toXML() + "]";
}
@Override
public String toString()
{
return getClass().getName() + "Content [" + toXML() + "]";
}
}

View file

@ -38,125 +38,125 @@ import org.jivesoftware.smackx.pubsub.packet.PubSub;
*/
public class LeafNode extends Node
{
LeafNode(PubSubManager pubSubManager, String nodeId)
{
super(pubSubManager, nodeId);
}
LeafNode(PubSubManager pubSubManager, String nodeId)
{
super(pubSubManager, nodeId);
}
/**
* Get information on the items in the node in standard
* {@link DiscoverItems} format.
*
* @return The item details in {@link DiscoverItems} format
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverItems discoverItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
DiscoverItems items = new DiscoverItems();
items.setTo(pubSubManager.getServiceJid());
items.setNode(getId());
/**
* Get information on the items in the node in standard
* {@link DiscoverItems} format.
*
* @return The item details in {@link DiscoverItems} format
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverItems discoverItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
DiscoverItems items = new DiscoverItems();
items.setTo(pubSubManager.getServiceJid());
items.setNode(getId());
return pubSubManager.getConnection().createStanzaCollectorAndSend(items).nextResultOrThrow();
}
}
/**
* Get the current items stored in the node.
*
* @return List of {@link Item} in the node
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
/**
* Get the current items stored in the node.
*
* @return List of {@link Item} in the node
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
return getItems((List<ExtensionElement>) null, (List<ExtensionElement>) null);
}
}
/**
* Get the current items stored in the node based
* on the subscription associated with the provided
* subscription id.
*
* @param subscriptionId - The subscription id for the
* associated subscription.
* @return List of {@link Item} in the node
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), subscriptionId));
/**
* Get the current items stored in the node based
* on the subscription associated with the provided
* subscription id.
*
* @param subscriptionId - The subscription id for the
* associated subscription.
* @return List of {@link Item} in the node
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), subscriptionId));
return getItems(request);
}
}
/**
* Get the items specified from the node. This would typically be
* used when the server does not return the payload due to size
* constraints. The user would be required to retrieve the payload
* after the items have been retrieved via {@link #getItems()} or an
* event, that did not include the payload.
*
* @param ids Item ids of the items to retrieve
*
* @return The list of {@link Item} with payload
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(Collection<String> ids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
List<Item> itemList = new ArrayList<Item>(ids.size());
/**
* Get the items specified from the node. This would typically be
* used when the server does not return the payload due to size
* constraints. The user would be required to retrieve the payload
* after the items have been retrieved via {@link #getItems()} or an
* event, that did not include the payload.
*
* @param ids Item ids of the items to retrieve
*
* @return The list of {@link Item} with payload
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(Collection<String> ids) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
List<Item> itemList = new ArrayList<Item>(ids.size());
for (String id : ids)
{
itemList.add(new Item(id));
}
PubSub request = createPubsubPacket(Type.get, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList));
for (String id : ids)
{
itemList.add(new Item(id));
}
PubSub request = createPubsubPacket(Type.get, new ItemsExtension(ItemsExtension.ItemsElementType.items, getId(), itemList));
return getItems(request);
}
}
/**
* Get items persisted on the node, limited to the specified number.
*
* @param maxItems Maximum number of items to return
*
* @return List of {@link Item}
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(int maxItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), maxItems));
/**
* Get items persisted on the node, limited to the specified number.
*
* @param maxItems Maximum number of items to return
*
* @return List of {@link Item}
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(int maxItems) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), maxItems));
return getItems(request);
}
}
/**
* Get items persisted on the node, limited to the specified number
* based on the subscription associated with the provided subscriptionId.
*
* @param maxItems Maximum number of items to return
* @param subscriptionId The subscription which the retrieval is based
* on.
*
* @return List of {@link Item}
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(int maxItems, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), subscriptionId, maxItems));
/**
* Get items persisted on the node, limited to the specified number
* based on the subscription associated with the provided subscriptionId.
*
* @param maxItems Maximum number of items to return
* @param subscriptionId The subscription which the retrieval is based
* on.
*
* @return List of {@link Item}
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> List<T> getItems(int maxItems, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = createPubsubPacket(Type.get, new GetItemsRequest(getId(), subscriptionId, maxItems));
return getItems(request);
}
}
/**
* Get items persisted on the node.
@ -200,206 +200,206 @@ public class LeafNode extends Node
return (List<T>) itemsElem.getItems();
}
/**
* Publishes an event to the node. This is an empty event
* with no item.
*
* This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false
* and {@link ConfigureForm#isDeliverPayloads()}=false.
*
* This is an asynchronous call which returns as soon as the
* stanza(/packet) has been sent.
*
* For synchronous calls use {@link #send() send()}.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void publish() throws NotConnectedException, InterruptedException
{
PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId()));
/**
* Publishes an event to the node. This is an empty event
* with no item.
*
* This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false
* and {@link ConfigureForm#isDeliverPayloads()}=false.
*
* This is an asynchronous call which returns as soon as the
* stanza(/packet) has been sent.
*
* For synchronous calls use {@link #send() send()}.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void publish() throws NotConnectedException, InterruptedException
{
PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId()));
pubSubManager.getConnection().sendStanza(packet);
}
pubSubManager.getConnection().sendStanza(packet);
}
/**
* Publishes an event to the node. This is a simple item
* with no payload.
*
* If the id is null, an empty item (one without an id) will be sent.
* Please note that this is not the same as {@link #send()}, which
* publishes an event with NO item.
*
* This is an asynchronous call which returns as soon as the
* stanza(/packet) has been sent.
*
* For synchronous calls use {@link #send(Item) send(Item))}.
*
* @param item - The item being sent
* @throws NotConnectedException
* @throws InterruptedException
*/
@SuppressWarnings("unchecked")
public <T extends Item> void publish(T item) throws NotConnectedException, InterruptedException
{
Collection<T> items = new ArrayList<T>(1);
items.add((T)(item == null ? new Item() : item));
publish(items);
}
/**
* Publishes an event to the node. This is a simple item
* with no payload.
*
* If the id is null, an empty item (one without an id) will be sent.
* Please note that this is not the same as {@link #send()}, which
* publishes an event with NO item.
*
* This is an asynchronous call which returns as soon as the
* stanza(/packet) has been sent.
*
* For synchronous calls use {@link #send(Item) send(Item))}.
*
* @param item - The item being sent
* @throws NotConnectedException
* @throws InterruptedException
*/
@SuppressWarnings("unchecked")
public <T extends Item> void publish(T item) throws NotConnectedException, InterruptedException
{
Collection<T> items = new ArrayList<T>(1);
items.add((T)(item == null ? new Item() : item));
publish(items);
}
/**
* Publishes multiple events to the node. Same rules apply as in {@link #publish(Item)}.
*
* In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input
* list will get stored on the node, assuming it stores the last sent item.
*
* This is an asynchronous call which returns as soon as the
* stanza(/packet) has been sent.
*
* For synchronous calls use {@link #send(Collection) send(Collection))}.
*
* @param items - The collection of items being sent
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> void publish(Collection<T> items) throws NotConnectedException, InterruptedException
{
PubSub packet = createPubsubPacket(Type.set, new PublishItem<T>(getId(), items));
/**
* Publishes multiple events to the node. Same rules apply as in {@link #publish(Item)}.
*
* In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input
* list will get stored on the node, assuming it stores the last sent item.
*
* This is an asynchronous call which returns as soon as the
* stanza(/packet) has been sent.
*
* For synchronous calls use {@link #send(Collection) send(Collection))}.
*
* @param items - The collection of items being sent
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Item> void publish(Collection<T> items) throws NotConnectedException, InterruptedException
{
PubSub packet = createPubsubPacket(Type.set, new PublishItem<T>(getId(), items));
pubSubManager.getConnection().sendStanza(packet);
}
pubSubManager.getConnection().sendStanza(packet);
}
/**
* Publishes an event to the node. This is an empty event
* with no item.
*
* This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false
* and {@link ConfigureForm#isDeliverPayloads()}=false.
*
* This is a synchronous call which will throw an exception
* on failure.
*
* For asynchronous calls, use {@link #publish() publish()}.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public void send() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId()));
/**
* Publishes an event to the node. This is an empty event
* with no item.
*
* This is only acceptable for nodes with {@link ConfigureForm#isPersistItems()}=false
* and {@link ConfigureForm#isDeliverPayloads()}=false.
*
* This is a synchronous call which will throw an exception
* on failure.
*
* For asynchronous calls, use {@link #publish() publish()}.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public void send() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub packet = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PUBLISH, getId()));
pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
/**
* Publishes an event to the node. This can be either a simple item
* with no payload, or one with it. This is determined by the Node
* configuration.
*
* If the node has <b>deliver_payload=false</b>, the Item must not
* have a payload.
*
* If the id is null, an empty item (one without an id) will be sent.
* Please note that this is not the same as {@link #send()}, which
* publishes an event with NO item.
*
* This is a synchronous call which will throw an exception
* on failure.
*
* For asynchronous calls, use {@link #publish(Item) publish(Item)}.
*
* @param item - The item being sent
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
@SuppressWarnings("unchecked")
public <T extends Item> void send(T item) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
Collection<T> items = new ArrayList<T>(1);
items.add((item == null ? (T)new Item() : item));
send(items);
}
/**
* Publishes an event to the node. This can be either a simple item
* with no payload, or one with it. This is determined by the Node
* configuration.
*
* If the node has <b>deliver_payload=false</b>, the Item must not
* have a payload.
*
* If the id is null, an empty item (one without an id) will be sent.
* Please note that this is not the same as {@link #send()}, which
* publishes an event with NO item.
*
* This is a synchronous call which will throw an exception
* on failure.
*
* For asynchronous calls, use {@link #publish(Item) publish(Item)}.
*
* @param item - The item being sent
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
@SuppressWarnings("unchecked")
public <T extends Item> void send(T item) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
Collection<T> items = new ArrayList<T>(1);
items.add((item == null ? (T)new Item() : item));
send(items);
}
/**
* Publishes multiple events to the node. Same rules apply as in {@link #send(Item)}.
*
* In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input
* list will get stored on the node, assuming it stores the last sent item.
*
* This is a synchronous call which will throw an exception
* on failure.
*
* For asynchronous calls, use {@link #publish(Collection) publish(Collection))}.
*
* @param items - The collection of {@link Item} objects being sent
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public <T extends Item> void send(Collection<T> items) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub packet = createPubsubPacket(Type.set, new PublishItem<T>(getId(), items));
/**
* Publishes multiple events to the node. Same rules apply as in {@link #send(Item)}.
*
* In addition, if {@link ConfigureForm#isPersistItems()}=false, only the last item in the input
* list will get stored on the node, assuming it stores the last sent item.
*
* This is a synchronous call which will throw an exception
* on failure.
*
* For asynchronous calls, use {@link #publish(Collection) publish(Collection))}.
*
* @param items - The collection of {@link Item} objects being sent
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public <T extends Item> void send(Collection<T> items) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub packet = createPubsubPacket(Type.set, new PublishItem<T>(getId(), items));
pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
/**
* Purges the node of all items.
*
* <p>Note: Some implementations may keep the last item
* sent.
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteAllItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PURGE_OWNER, getId()), PubSubElementType.PURGE_OWNER.getNamespace());
/**
* Purges the node of all items.
*
* <p>Note: Some implementations may keep the last item
* sent.
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteAllItems() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = createPubsubPacket(Type.set, new NodeExtension(PubSubElementType.PURGE_OWNER, getId()), PubSubElementType.PURGE_OWNER.getNamespace());
pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
}
pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
}
/**
* Delete the item with the specified id from the node.
*
* @param itemId The id of the item
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteItem(String itemId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
Collection<String> items = new ArrayList<String>(1);
items.add(itemId);
deleteItem(items);
}
/**
* Delete the item with the specified id from the node.
*
* @param itemId The id of the item
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteItem(String itemId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
Collection<String> items = new ArrayList<String>(1);
items.add(itemId);
deleteItem(items);
}
/**
* Delete the items with the specified id's from the node.
*
* @param itemIds The list of id's of items to delete
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteItem(Collection<String> itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
List<Item> items = new ArrayList<Item>(itemIds.size());
/**
* Delete the items with the specified id's from the node.
*
* @param itemIds The list of id's of items to delete
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteItem(Collection<String> itemIds) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
List<Item> items = new ArrayList<Item>(itemIds.size());
for (String id : itemIds)
{
items.add(new Item(id));
}
PubSub request = createPubsubPacket(Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items));
pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
}
for (String id : itemIds)
{
items.add(new Item(id));
}
PubSub request = createPubsubPacket(Type.set, new ItemsExtension(ItemsExtension.ItemsElementType.retract, getId(), items));
pubSubManager.getConnection().createStanzaCollectorAndSend(request).nextResultOrThrow();
}
}

View file

@ -48,97 +48,97 @@ abstract public class Node
protected final PubSubManager pubSubManager;
protected final String id;
protected ConcurrentHashMap<ItemEventListener<Item>, StanzaListener> itemEventToListenerMap = new ConcurrentHashMap<ItemEventListener<Item>, StanzaListener>();
protected ConcurrentHashMap<ItemDeleteListener, StanzaListener> itemDeleteToListenerMap = new ConcurrentHashMap<ItemDeleteListener, StanzaListener>();
protected ConcurrentHashMap<NodeConfigListener, StanzaListener> configEventToListenerMap = new ConcurrentHashMap<NodeConfigListener, StanzaListener>();
protected ConcurrentHashMap<ItemEventListener<Item>, StanzaListener> itemEventToListenerMap = new ConcurrentHashMap<ItemEventListener<Item>, StanzaListener>();
protected ConcurrentHashMap<ItemDeleteListener, StanzaListener> itemDeleteToListenerMap = new ConcurrentHashMap<ItemDeleteListener, StanzaListener>();
protected ConcurrentHashMap<NodeConfigListener, StanzaListener> configEventToListenerMap = new ConcurrentHashMap<NodeConfigListener, StanzaListener>();
/**
* Construct a node associated to the supplied connection with the specified
* node id.
*
* @param connection The connection the node is associated with
* @param nodeName The node id
*/
Node(PubSubManager pubSubManager, String nodeId)
{
this.pubSubManager = pubSubManager;
id = nodeId;
}
/**
* Construct a node associated to the supplied connection with the specified
* node id.
*
* @param connection The connection the node is associated with
* @param nodeName The node id
*/
Node(PubSubManager pubSubManager, String nodeId)
{
this.pubSubManager = pubSubManager;
id = nodeId;
}
/**
* Get the NodeId.
*
* @return the node id
*/
public String getId()
{
return id;
}
/**
* Returns a configuration form, from which you can create an answer form to be submitted
* via the {@link #sendConfigurationForm(Form)}.
*
* @return the configuration form
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public ConfigureForm getNodeConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
/**
* Get the NodeId.
*
* @return the node id
*/
public String getId()
{
return id;
}
/**
* Returns a configuration form, from which you can create an answer form to be submitted
* via the {@link #sendConfigurationForm(Form)}.
*
* @return the configuration form
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public ConfigureForm getNodeConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(
PubSubElementType.CONFIGURE_OWNER, getId()), PubSubNamespace.OWNER);
Stanza reply = sendPubsubPacket(pubSub);
return NodeUtils.getFormFromPacket(reply, PubSubElementType.CONFIGURE_OWNER);
}
Stanza reply = sendPubsubPacket(pubSub);
return NodeUtils.getFormFromPacket(reply, PubSubElementType.CONFIGURE_OWNER);
}
/**
* Update the configuration with the contents of the new {@link Form}.
*
* @param submitForm
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendConfigurationForm(Form submitForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
/**
* Update the configuration with the contents of the new {@link Form}.
*
* @param submitForm
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void sendConfigurationForm(Form submitForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub packet = createPubsubPacket(Type.set, new FormNode(FormNodeType.CONFIGURE_OWNER,
getId(), submitForm), PubSubNamespace.OWNER);
pubSubManager.getConnection().createStanzaCollectorAndSend(packet).nextResultOrThrow();
}
}
/**
* Discover node information in standard {@link DiscoverInfo} format.
*
* @return The discovery information about the node.
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverInfo discoverInfo() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
DiscoverInfo info = new DiscoverInfo();
info.setTo(pubSubManager.getServiceJid());
info.setNode(getId());
return pubSubManager.getConnection().createStanzaCollectorAndSend(info).nextResultOrThrow();
}
/**
* Discover node information in standard {@link DiscoverInfo} format.
*
* @return The discovery information about the node.
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverInfo discoverInfo() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
DiscoverInfo info = new DiscoverInfo();
info.setTo(pubSubManager.getServiceJid());
info.setNode(getId());
return pubSubManager.getConnection().createStanzaCollectorAndSend(info).nextResultOrThrow();
}
/**
* Get the subscriptions currently associated with this node.
*
* @return List of {@link Subscription}
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
/**
* Get the subscriptions currently associated with this node.
*
* @return List of {@link Subscription}
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
return getSubscriptions(null, null);
}
}
/**
* Get the subscriptions currently associated with this node.
@ -223,15 +223,15 @@ abstract public class Node
return subElem.getSubscriptions();
}
/**
* Get the affiliations of this node.
*
* @return List of {@link Affiliation}
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
/**
* Get the affiliations of this node.
*
* @return List of {@link Affiliation}
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Affiliation> getAffiliations() throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException {
return getAffiliations(null, null);
@ -346,398 +346,394 @@ abstract public class Node
return sendPubsubPacket(pubSub);
}
/**
* The user subscribes to the node using the supplied jid. The
* bare jid portion of this one must match the jid for the connection.
*
* Please note that the {@link Subscription.State} should be checked
* on return since more actions may be required by the caller.
* {@link Subscription.State#pending} - The owner must approve the subscription
* request before messages will be received.
* {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true,
* the caller must configure the subscription before messages will be received. If it is false
* the caller can configure it but is not required to do so.
* @param jid The jid to subscribe as.
* @return The subscription
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public Subscription subscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
// CHECKSTYLE:OFF
PubSub pubSub = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
// CHECKSTYLE:ON
PubSub reply = sendPubsubPacket(pubSub);
return reply.getExtension(PubSubElementType.SUBSCRIPTION);
}
/**
* The user subscribes to the node using the supplied jid. The
* bare jid portion of this one must match the jid for the connection.
*
* Please note that the {@link Subscription.State} should be checked
* on return since more actions may be required by the caller.
* {@link Subscription.State#pending} - The owner must approve the subscription
* request before messages will be received.
* {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true,
* the caller must configure the subscription before messages will be received. If it is false
* the caller can configure it but is not required to do so.
* @param jid The jid to subscribe as.
* @return The subscription
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public Subscription subscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub pubSub = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
PubSub reply = sendPubsubPacket(pubSub);
return reply.getExtension(PubSubElementType.SUBSCRIPTION);
}
/**
* The user subscribes to the node using the supplied jid and subscription
* options. The bare jid portion of this one must match the jid for the
* connection.
*
* Please note that the {@link Subscription.State} should be checked
* on return since more actions may be required by the caller.
* {@link Subscription.State#pending} - The owner must approve the subscription
* request before messages will be received.
* {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true,
* the caller must configure the subscription before messages will be received. If it is false
* the caller can configure it but is not required to do so.
* @param jid The jid to subscribe as.
* @return The subscription
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public Subscription subscribe(String jid, SubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
// CHECKSTYLE:OFF
PubSub request = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
// CHECKSTYLE:ON
request.addExtension(new FormNode(FormNodeType.OPTIONS, subForm));
PubSub reply = sendPubsubPacket(request);
return reply.getExtension(PubSubElementType.SUBSCRIPTION);
}
/**
* The user subscribes to the node using the supplied jid and subscription
* options. The bare jid portion of this one must match the jid for the
* connection.
*
* Please note that the {@link Subscription.State} should be checked
* on return since more actions may be required by the caller.
* {@link Subscription.State#pending} - The owner must approve the subscription
* request before messages will be received.
* {@link Subscription.State#unconfigured} - If the {@link Subscription#isConfigRequired()} is true,
* the caller must configure the subscription before messages will be received. If it is false
* the caller can configure it but is not required to do so.
* @param jid The jid to subscribe as.
* @return The subscription
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public Subscription subscribe(String jid, SubscribeForm subForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = createPubsubPacket(Type.set, new SubscribeExtension(jid, getId()));
request.addExtension(new FormNode(FormNodeType.OPTIONS, subForm));
PubSub reply = sendPubsubPacket(request);
return reply.getExtension(PubSubElementType.SUBSCRIPTION);
}
/**
* Remove the subscription related to the specified JID. This will only
* work if there is only 1 subscription. If there are multiple subscriptions,
* use {@link #unsubscribe(String, String)}.
*
* @param jid The JID used to subscribe to the node
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public void unsubscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
unsubscribe(jid, null);
}
/**
* Remove the subscription related to the specified JID. This will only
* work if there is only 1 subscription. If there are multiple subscriptions,
* use {@link #unsubscribe(String, String)}.
*
* @param jid The JID used to subscribe to the node
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public void unsubscribe(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
unsubscribe(jid, null);
}
/**
* Remove the specific subscription related to the specified JID.
*
* @param jid The JID used to subscribe to the node
* @param subscriptionId The id of the subscription being removed
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unsubscribe(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
sendPubsubPacket(createPubsubPacket(Type.set, new UnsubscribeExtension(jid, getId(), subscriptionId)));
}
/**
* Remove the specific subscription related to the specified JID.
*
* @param jid The JID used to subscribe to the node
* @param subscriptionId The id of the subscription being removed
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void unsubscribe(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
sendPubsubPacket(createPubsubPacket(Type.set, new UnsubscribeExtension(jid, getId(), subscriptionId)));
}
/**
* Returns a SubscribeForm for subscriptions, from which you can create an answer form to be submitted
* via the {@link #sendConfigurationForm(Form)}.
*
* @return A subscription options form
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public SubscribeForm getSubscriptionOptions(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
return getSubscriptionOptions(jid, null);
}
/**
* Returns a SubscribeForm for subscriptions, from which you can create an answer form to be submitted
* via the {@link #sendConfigurationForm(Form)}.
*
* @return A subscription options form
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public SubscribeForm getSubscriptionOptions(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
return getSubscriptionOptions(jid, null);
}
/**
* Get the options for configuring the specified subscription.
*
* @param jid JID the subscription is registered under
* @param subscriptionId The subscription id
*
* @return The subscription option form
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public SubscribeForm getSubscriptionOptions(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub packet = sendPubsubPacket(createPubsubPacket(Type.get, new OptionsExtension(jid, getId(), subscriptionId)));
FormNode ext = packet.getExtension(PubSubElementType.OPTIONS);
return new SubscribeForm(ext.getForm());
}
/**
* Get the options for configuring the specified subscription.
*
* @param jid JID the subscription is registered under
* @param subscriptionId The subscription id
*
* @return The subscription option form
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public SubscribeForm getSubscriptionOptions(String jid, String subscriptionId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub packet = sendPubsubPacket(createPubsubPacket(Type.get, new OptionsExtension(jid, getId(), subscriptionId)));
FormNode ext = packet.getExtension(PubSubElementType.OPTIONS);
return new SubscribeForm(ext.getForm());
}
/**
* Register a listener for item publication events. This
* listener will get called whenever an item is published to
* this node.
*
* @param listener The handler for the event
*/
@SuppressWarnings("unchecked")
/**
* Register a listener for item publication events. This
* listener will get called whenever an item is published to
* this node.
*
* @param listener The handler for the event
*/
@SuppressWarnings("unchecked")
public void addItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener)
{
StanzaListener conListener = new ItemEventTranslator(listener);
itemEventToListenerMap.put(listener, conListener);
pubSubManager.getConnection().addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.items.toString(), "item"));
}
{
StanzaListener conListener = new ItemEventTranslator(listener);
itemEventToListenerMap.put(listener, conListener);
pubSubManager.getConnection().addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.items.toString(), "item"));
}
/**
* Unregister a listener for publication events.
*
* @param listener The handler to unregister
*/
public void removeItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener)
{
StanzaListener conListener = itemEventToListenerMap.remove(listener);
/**
* Unregister a listener for publication events.
*
* @param listener The handler to unregister
*/
public void removeItemEventListener(@SuppressWarnings("rawtypes") ItemEventListener listener)
{
StanzaListener conListener = itemEventToListenerMap.remove(listener);
if (conListener != null)
pubSubManager.getConnection().removeSyncStanzaListener(conListener);
}
if (conListener != null)
pubSubManager.getConnection().removeSyncStanzaListener(conListener);
}
/**
* Register a listener for configuration events. This listener
* will get called whenever the node's configuration changes.
*
* @param listener The handler for the event
*/
public void addConfigurationListener(NodeConfigListener listener)
{
StanzaListener conListener = new NodeConfigTranslator(listener);
configEventToListenerMap.put(listener, conListener);
pubSubManager.getConnection().addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.configuration.toString()));
}
/**
* Register a listener for configuration events. This listener
* will get called whenever the node's configuration changes.
*
* @param listener The handler for the event
*/
public void addConfigurationListener(NodeConfigListener listener)
{
StanzaListener conListener = new NodeConfigTranslator(listener);
configEventToListenerMap.put(listener, conListener);
pubSubManager.getConnection().addSyncStanzaListener(conListener, new EventContentFilter(EventElementType.configuration.toString()));
}
/**
* Unregister a listener for configuration events.
*
* @param listener The handler to unregister
*/
public void removeConfigurationListener(NodeConfigListener listener)
{
StanzaListener conListener = configEventToListenerMap .remove(listener);
/**
* Unregister a listener for configuration events.
*
* @param listener The handler to unregister
*/
public void removeConfigurationListener(NodeConfigListener listener)
{
StanzaListener conListener = configEventToListenerMap .remove(listener);
if (conListener != null)
pubSubManager.getConnection().removeSyncStanzaListener(conListener);
}
if (conListener != null)
pubSubManager.getConnection().removeSyncStanzaListener(conListener);
}
/**
* Register an listener for item delete events. This listener
* gets called whenever an item is deleted from the node.
*
* @param listener The handler for the event
*/
public void addItemDeleteListener(ItemDeleteListener listener)
{
StanzaListener delListener = new ItemDeleteTranslator(listener);
itemDeleteToListenerMap.put(listener, delListener);
EventContentFilter deleteItem = new EventContentFilter(EventElementType.items.toString(), "retract");
EventContentFilter purge = new EventContentFilter(EventElementType.purge.toString());
/**
* Register an listener for item delete events. This listener
* gets called whenever an item is deleted from the node.
*
* @param listener The handler for the event
*/
public void addItemDeleteListener(ItemDeleteListener listener)
{
StanzaListener delListener = new ItemDeleteTranslator(listener);
itemDeleteToListenerMap.put(listener, delListener);
EventContentFilter deleteItem = new EventContentFilter(EventElementType.items.toString(), "retract");
EventContentFilter purge = new EventContentFilter(EventElementType.purge.toString());
pubSubManager.getConnection().addSyncStanzaListener(delListener, new OrFilter(deleteItem, purge));
}
pubSubManager.getConnection().addSyncStanzaListener(delListener, new OrFilter(deleteItem, purge));
}
/**
* Unregister a listener for item delete events.
*
* @param listener The handler to unregister
*/
public void removeItemDeleteListener(ItemDeleteListener listener)
{
StanzaListener conListener = itemDeleteToListenerMap .remove(listener);
/**
* Unregister a listener for item delete events.
*
* @param listener The handler to unregister
*/
public void removeItemDeleteListener(ItemDeleteListener listener)
{
StanzaListener conListener = itemDeleteToListenerMap .remove(listener);
if (conListener != null)
pubSubManager.getConnection().removeSyncStanzaListener(conListener);
}
if (conListener != null)
pubSubManager.getConnection().removeSyncStanzaListener(conListener);
}
@Override
public String toString()
{
return super.toString() + " " + getClass().getName() + " id: " + id;
}
@Override
public String toString()
{
return super.toString() + " " + getClass().getName() + " id: " + id;
}
protected PubSub createPubsubPacket(Type type, ExtensionElement ext)
{
return createPubsubPacket(type, ext, null);
}
protected PubSub createPubsubPacket(Type type, ExtensionElement ext)
{
return createPubsubPacket(type, ext, null);
}
protected PubSub createPubsubPacket(Type type, ExtensionElement ext, PubSubNamespace ns)
{
protected PubSub createPubsubPacket(Type type, ExtensionElement ext, PubSubNamespace ns)
{
return PubSub.createPubsubPacket(pubSubManager.getServiceJid(), type, ext, ns);
}
}
protected PubSub sendPubsubPacket(PubSub packet) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
return pubSubManager.sendPubsubPacket(packet);
}
protected PubSub sendPubsubPacket(PubSub packet) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
return pubSubManager.sendPubsubPacket(packet);
}
private static List<String> getSubscriptionIds(Stanza packet)
{
HeadersExtension headers = (HeadersExtension)packet.getExtension("headers", "http://jabber.org/protocol/shim");
List<String> values = null;
private static List<String> getSubscriptionIds(Stanza packet)
{
HeadersExtension headers = (HeadersExtension)packet.getExtension("headers", "http://jabber.org/protocol/shim");
List<String> values = null;
if (headers != null)
{
values = new ArrayList<String>(headers.getHeaders().size());
if (headers != null)
{
values = new ArrayList<String>(headers.getHeaders().size());
for (Header header : headers.getHeaders())
{
values.add(header.getValue());
}
}
return values;
}
for (Header header : headers.getHeaders())
{
values.add(header.getValue());
}
}
return values;
}
/**
* This class translates low level item publication events into api level objects for
* user consumption.
*
* @author Robin Collier
*/
public class ItemEventTranslator implements StanzaListener
{
@SuppressWarnings("rawtypes")
/**
* This class translates low level item publication events into api level objects for
* user consumption.
*
* @author Robin Collier
*/
public class ItemEventTranslator implements StanzaListener
{
@SuppressWarnings("rawtypes")
private ItemEventListener listener;
public ItemEventTranslator(@SuppressWarnings("rawtypes") ItemEventListener eventListener)
{
listener = eventListener;
}
public ItemEventTranslator(@SuppressWarnings("rawtypes") ItemEventListener eventListener)
{
listener = eventListener;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({ "rawtypes", "unchecked" })
public void processStanza(Stanza packet)
{
{
// CHECKSTYLE:OFF
EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
// CHECKSTYLE:ON
ItemsExtension itemsElem = (ItemsExtension)event.getEvent();
ItemsExtension itemsElem = (ItemsExtension)event.getEvent();
ItemPublishEvent eventItems = new ItemPublishEvent(itemsElem.getNode(), itemsElem.getItems(), getSubscriptionIds(packet), DelayInformationManager.getDelayTimestamp(packet));
listener.handlePublishedItems(eventItems);
}
}
listener.handlePublishedItems(eventItems);
}
}
/**
* This class translates low level item deletion events into api level objects for
* user consumption.
*
* @author Robin Collier
*/
public class ItemDeleteTranslator implements StanzaListener
{
private ItemDeleteListener listener;
/**
* This class translates low level item deletion events into api level objects for
* user consumption.
*
* @author Robin Collier
*/
public class ItemDeleteTranslator implements StanzaListener
{
private ItemDeleteListener listener;
public ItemDeleteTranslator(ItemDeleteListener eventListener)
{
listener = eventListener;
}
public ItemDeleteTranslator(ItemDeleteListener eventListener)
{
listener = eventListener;
}
public void processStanza(Stanza packet)
{
public void processStanza(Stanza packet)
{
// CHECKSTYLE:OFF
EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
List<ExtensionElement> extList = event.getExtensions();
List<ExtensionElement> extList = event.getExtensions();
if (extList.get(0).getElementName().equals(PubSubElementType.PURGE_EVENT.getElementName()))
{
listener.handlePurge();
}
else
{
ItemsExtension itemsElem = (ItemsExtension)event.getEvent();
@SuppressWarnings("unchecked")
if (extList.get(0).getElementName().equals(PubSubElementType.PURGE_EVENT.getElementName()))
{
listener.handlePurge();
}
else
{
ItemsExtension itemsElem = (ItemsExtension)event.getEvent();
@SuppressWarnings("unchecked")
Collection<RetractItem> pubItems = (Collection<RetractItem>) itemsElem.getItems();
List<String> items = new ArrayList<String>(pubItems.size());
List<String> items = new ArrayList<String>(pubItems.size());
for (RetractItem item : pubItems)
{
items.add(item.getId());
}
for (RetractItem item : pubItems)
{
items.add(item.getId());
}
ItemDeleteEvent eventItems = new ItemDeleteEvent(itemsElem.getNode(), items, getSubscriptionIds(packet));
listener.handleDeletedItems(eventItems);
}
ItemDeleteEvent eventItems = new ItemDeleteEvent(itemsElem.getNode(), items, getSubscriptionIds(packet));
listener.handleDeletedItems(eventItems);
}
// CHECKSTYLE:ON
}
}
}
}
/**
* This class translates low level node configuration events into api level objects for
* user consumption.
*
* @author Robin Collier
*/
public class NodeConfigTranslator implements StanzaListener
{
private NodeConfigListener listener;
/**
* This class translates low level node configuration events into api level objects for
* user consumption.
*
* @author Robin Collier
*/
public class NodeConfigTranslator implements StanzaListener
{
private NodeConfigListener listener;
public NodeConfigTranslator(NodeConfigListener eventListener)
{
listener = eventListener;
}
public NodeConfigTranslator(NodeConfigListener eventListener)
{
listener = eventListener;
}
public void processStanza(Stanza packet)
{
public void processStanza(Stanza packet)
{
// CHECKSTYLE:OFF
EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
ConfigurationEvent config = (ConfigurationEvent)event.getEvent();
EventElement event = (EventElement)packet.getExtension("event", PubSubNamespace.EVENT.getXmlns());
ConfigurationEvent config = (ConfigurationEvent)event.getEvent();
// CHECKSTYLE:ON
listener.handleNodeConfiguration(config);
}
}
listener.handleNodeConfiguration(config);
}
}
/**
* Filter for {@link StanzaListener} to filter out events not specific to the
* event type expected for this node.
*
* @author Robin Collier
*/
class EventContentFilter extends FlexibleStanzaTypeFilter<Message>
{
/**
* Filter for {@link StanzaListener} to filter out events not specific to the
* event type expected for this node.
*
* @author Robin Collier
*/
class EventContentFilter extends FlexibleStanzaTypeFilter<Message>
{
private final String firstElement;
private final String secondElement;
private final boolean allowEmpty;
EventContentFilter(String elementName)
{
EventContentFilter(String elementName)
{
this(elementName, null);
}
}
EventContentFilter(String firstLevelEelement, String secondLevelElement)
{
firstElement = firstLevelEelement;
secondElement = secondLevelElement;
EventContentFilter(String firstLevelEelement, String secondLevelElement)
{
firstElement = firstLevelEelement;
secondElement = secondLevelElement;
allowEmpty = firstElement.equals(EventElementType.items.toString())
&& "item".equals(secondLevelElement);
}
}
public boolean acceptSpecific(Message message) {
EventElement event = EventElement.from(message);
if (event == null)
return false;
if (event == null)
return false;
NodeExtension embedEvent = event.getEvent();
NodeExtension embedEvent = event.getEvent();
if (embedEvent == null)
return false;
if (embedEvent == null)
return false;
if (embedEvent.getElementName().equals(firstElement))
{
if (!embedEvent.getNode().equals(getId()))
return false;
if (embedEvent.getElementName().equals(firstElement))
{
if (!embedEvent.getNode().equals(getId()))
return false;
if (secondElement == null)
return true;
if (secondElement == null)
return true;
if (embedEvent instanceof EmbeddedPacketExtension)
{
List<ExtensionElement> secondLevelList = ((EmbeddedPacketExtension)embedEvent).getExtensions();
if (embedEvent instanceof EmbeddedPacketExtension)
{
List<ExtensionElement> secondLevelList = ((EmbeddedPacketExtension)embedEvent).getExtensions();
// XEP-0060 allows no elements on second level for notifications. See schema or
// for example § 4.3:
@ -746,11 +742,11 @@ abstract public class Node
return true;
}
if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement))
return true;
}
}
return false;
}
}
if (secondLevelList.size() > 0 && secondLevelList.get(0).getElementName().equals(secondElement))
return true;
}
}
return false;
}
}
}

View file

@ -18,15 +18,15 @@ package org.jivesoftware.smackx.pubsub;
abstract public class NodeEvent
{
private String nodeId;
private String nodeId;
protected NodeEvent(String id)
{
nodeId = id;
}
protected NodeEvent(String id)
{
nodeId = id;
}
public String getNodeId()
{
return nodeId;
}
public String getNodeId()
{
return nodeId;
}
}

View file

@ -28,61 +28,61 @@ import org.jivesoftware.smack.packet.ExtensionElement;
*/
public class NodeExtension implements ExtensionElement
{
private final PubSubElementType element;
private final String node;
private final PubSubElementType element;
private final String node;
/**
* Constructs a <tt>NodeExtension</tt> with an element name specified
* by {@link PubSubElementType} and the specified node id.
*
* @param elem Defines the element name and namespace
* @param nodeId Specifies the id of the node
*/
public NodeExtension(PubSubElementType elem, String nodeId)
{
element = elem;
this.node = nodeId;
}
/**
* Constructs a <tt>NodeExtension</tt> with an element name specified
* by {@link PubSubElementType} and the specified node id.
*
* @param elem Defines the element name and namespace
* @param nodeId Specifies the id of the node
*/
public NodeExtension(PubSubElementType elem, String nodeId)
{
element = elem;
this.node = nodeId;
}
/**
* Constructs a <tt>NodeExtension</tt> with an element name specified
* by {@link PubSubElementType}.
*
* @param elem Defines the element name and namespace
*/
public NodeExtension(PubSubElementType elem)
{
this(elem, null);
}
/**
* Constructs a <tt>NodeExtension</tt> with an element name specified
* by {@link PubSubElementType}.
*
* @param elem Defines the element name and namespace
*/
public NodeExtension(PubSubElementType elem)
{
this(elem, null);
}
/**
* Gets the node id.
*
* @return The node id
*/
public String getNode()
{
return node;
}
/**
* Gets the node id.
*
* @return The node id
*/
public String getNode()
{
return node;
}
public String getElementName()
{
return element.getElementName();
}
public String getElementName()
{
return element.getElementName();
}
public String getNamespace()
{
return element.getNamespace().getXmlns();
}
public String getNamespace()
{
return element.getNamespace().getXmlns();
}
public CharSequence toXML()
{
return '<' + getElementName() + (node == null ? "" : " node='" + node + '\'') + "/>";
}
public CharSequence toXML()
{
return '<' + getElementName() + (node == null ? "" : " node='" + node + '\'') + "/>";
}
@Override
public String toString()
{
return getClass().getName() + " - content [" + toXML() + "]";
}
@Override
public String toString()
{
return getClass().getName() + " - content [" + toXML() + "]";
}
}

View file

@ -23,6 +23,6 @@ package org.jivesoftware.smackx.pubsub;
*/
public enum NodeType
{
leaf,
collection;
leaf,
collection;
}

View file

@ -25,35 +25,35 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*/
public class OptionsExtension extends NodeExtension
{
protected String jid;
protected String id;
protected String jid;
protected String id;
public OptionsExtension(String subscriptionJid)
{
this(subscriptionJid, null, null);
}
public OptionsExtension(String subscriptionJid)
{
this(subscriptionJid, null, null);
}
public OptionsExtension(String subscriptionJid, String nodeId)
{
this(subscriptionJid, nodeId, null);
}
public OptionsExtension(String subscriptionJid, String nodeId)
{
this(subscriptionJid, nodeId, null);
}
public OptionsExtension(String jid, String nodeId, String subscriptionId)
{
super(PubSubElementType.OPTIONS, nodeId);
this.jid = jid;
id = subscriptionId;
}
public OptionsExtension(String jid, String nodeId, String subscriptionId)
{
super(PubSubElementType.OPTIONS, nodeId);
this.jid = jid;
id = subscriptionId;
}
public String getJid()
{
return jid;
}
public String getJid()
{
return jid;
}
public String getId()
{
return id;
}
public String getId()
{
return id;
}
@Override
public XmlStringBuilder toXML() {

View file

@ -49,98 +49,98 @@ import org.jivesoftware.smackx.pubsub.provider.ItemProvider;
*/
public class PayloadItem<E extends ExtensionElement> extends Item
{
private E payload;
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 ExtensionElement} which represents the payload data.
*/
public PayloadItem(E payloadExt)
{
super();
/**
* Create an <tt>Item</tt> with no id and a payload The id will be set by the server.
*
* @param payloadExt A {@link ExtensionElement} which represents the payload data.
*/
public PayloadItem(E payloadExt)
{
super();
if (payloadExt == null)
throw new IllegalArgumentException("payload cannot be 'null'");
payload = payloadExt;
}
if (payloadExt == null)
throw new IllegalArgumentException("payload cannot be 'null'");
payload = payloadExt;
}
/**
* Create an <tt>Item</tt> with an id and payload.
*
* @param itemId The id of this item. It can be null if we want the server to set the id.
* @param payloadExt A {@link ExtensionElement} which represents the payload data.
*/
public PayloadItem(String itemId, E payloadExt)
{
super(itemId);
/**
* Create an <tt>Item</tt> with an id and payload.
*
* @param itemId The id of this item. It can be null if we want the server to set the id.
* @param payloadExt A {@link ExtensionElement} which represents the payload data.
*/
public PayloadItem(String itemId, E payloadExt)
{
super(itemId);
if (payloadExt == null)
throw new IllegalArgumentException("payload cannot be 'null'");
payload = payloadExt;
}
if (payloadExt == null)
throw new IllegalArgumentException("payload cannot be 'null'");
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.
* </p>
*
* @param itemId The id of this item.
* @param nodeId The id of the node the item was published to.
* @param payloadExt A {@link ExtensionElement} which represents the payload data.
*/
public PayloadItem(String itemId, String nodeId, E payloadExt)
{
super(itemId, nodeId);
/**
* 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.
* </p>
*
* @param itemId The id of this item.
* @param nodeId The id of the node the item was published to.
* @param payloadExt A {@link ExtensionElement} 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;
}
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}.
*
* @return The payload as a {@link ExtensionElement}.
*/
public E getPayload()
{
return payload;
}
/**
* Get the payload associated with this <tt>Item</tt>. Customising the payload
* parsing from the server can be accomplished as described in {@link ItemProvider}.
*
* @return The payload as a {@link ExtensionElement}.
*/
public E getPayload()
{
return payload;
}
@Override
public String toXML()
{
StringBuilder builder = new StringBuilder("<item");
@Override
public String toXML()
{
StringBuilder builder = new StringBuilder("<item");
if (getId() != null)
{
builder.append(" id='");
builder.append(getId());
builder.append('\'');
}
if (getId() != null)
{
builder.append(" id='");
builder.append(getId());
builder.append('\'');
}
if (getNode() != null) {
builder.append(" node='");
builder.append(getNode());
builder.append('\'');
}
builder.append('>');
builder.append(payload.toXML());
builder.append("</item>");
builder.append('>');
builder.append(payload.toXML());
builder.append("</item>");
return builder.toString();
}
return builder.toString();
}
@Override
public String toString()
{
return getClass().getName() + " | Content [" + toXML() + "]";
}
@Override
public String toString()
{
return getClass().getName() + " | Content [" + toXML() + "]";
}
}

View file

@ -24,5 +24,5 @@ package org.jivesoftware.smackx.pubsub;
*/
public enum PresenceState
{
chat, online, away, xa, dnd
chat, online, away, xa, dnd
}

View file

@ -28,58 +28,58 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
*/
public enum PubSubElementType
{
CREATE("create", PubSubNamespace.BASIC),
DELETE("delete", PubSubNamespace.OWNER),
DELETE_EVENT("delete", PubSubNamespace.EVENT),
CONFIGURE("configure", PubSubNamespace.BASIC),
CONFIGURE_OWNER("configure", PubSubNamespace.OWNER),
CONFIGURATION("configuration", PubSubNamespace.EVENT),
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),
PURGE_EVENT("purge", PubSubNamespace.EVENT),
RETRACT("retract", PubSubNamespace.BASIC),
AFFILIATIONS("affiliations", PubSubNamespace.BASIC),
SUBSCRIBE("subscribe", PubSubNamespace.BASIC),
SUBSCRIPTION("subscription", PubSubNamespace.BASIC),
SUBSCRIPTIONS("subscriptions", PubSubNamespace.BASIC),
UNSUBSCRIBE("unsubscribe", PubSubNamespace.BASIC);
CREATE("create", PubSubNamespace.BASIC),
DELETE("delete", PubSubNamespace.OWNER),
DELETE_EVENT("delete", PubSubNamespace.EVENT),
CONFIGURE("configure", PubSubNamespace.BASIC),
CONFIGURE_OWNER("configure", PubSubNamespace.OWNER),
CONFIGURATION("configuration", PubSubNamespace.EVENT),
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),
PURGE_EVENT("purge", PubSubNamespace.EVENT),
RETRACT("retract", PubSubNamespace.BASIC),
AFFILIATIONS("affiliations", PubSubNamespace.BASIC),
SUBSCRIBE("subscribe", PubSubNamespace.BASIC),
SUBSCRIPTION("subscription", PubSubNamespace.BASIC),
SUBSCRIPTIONS("subscriptions", PubSubNamespace.BASIC),
UNSUBSCRIBE("unsubscribe", PubSubNamespace.BASIC);
private String eName;
private PubSubNamespace nSpace;
private String eName;
private PubSubNamespace nSpace;
private PubSubElementType(String elemName, PubSubNamespace ns)
{
eName = elemName;
nSpace = ns;
}
private PubSubElementType(String elemName, PubSubNamespace ns)
{
eName = elemName;
nSpace = ns;
}
public PubSubNamespace getNamespace()
{
return nSpace;
}
public PubSubNamespace getNamespace()
{
return nSpace;
}
public String getElementName()
{
return eName;
}
public String getElementName()
{
return eName;
}
public static PubSubElementType valueOfFromElemName(String elemName, String namespace)
{
int index = namespace.lastIndexOf('#');
String fragment = (index == -1 ? null : namespace.substring(index+1));
public static PubSubElementType valueOfFromElemName(String elemName, String namespace)
{
int index = namespace.lastIndexOf('#');
String fragment = (index == -1 ? null : namespace.substring(index+1));
if (fragment != null)
{
return valueOf((elemName + '_' + fragment).toUpperCase(Locale.US));
}
return valueOf(elemName.toUpperCase(Locale.US).replace('-', '_'));
}
if (fragment != null)
{
return valueOf((elemName + '_' + fragment).toUpperCase(Locale.US));
}
return valueOf(elemName.toUpperCase(Locale.US).replace('-', '_'));
}
}

View file

@ -127,114 +127,114 @@ public final class PubSubManager extends Manager {
return pubSubManager;
}
/**
* Create a pubsub manager associated to the specified connection where
* the pubsub requests require a specific to address for packets.
*
* @param connection The XMPP connection
* @param toAddress The pubsub specific to address (required for some servers)
*/
PubSubManager(XMPPConnection connection, BareJid toAddress)
{
super(connection);
pubSubService = toAddress;
}
/**
* Create a pubsub manager associated to the specified connection where
* the pubsub requests require a specific to address for packets.
*
* @param connection The XMPP connection
* @param toAddress The pubsub specific to address (required for some servers)
*/
PubSubManager(XMPPConnection connection, BareJid toAddress)
{
super(connection);
pubSubService = toAddress;
}
/**
* Creates an instant node, if supported.
*
* @return The node that was created
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public LeafNode createNode() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub reply = sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.CREATE), null);
NodeExtension elem = reply.getExtension("create", PubSubNamespace.BASIC.getXmlns());
/**
* Creates an instant node, if supported.
*
* @return The node that was created
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public LeafNode createNode() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub reply = sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.CREATE), null);
NodeExtension elem = reply.getExtension("create", PubSubNamespace.BASIC.getXmlns());
LeafNode newNode = new LeafNode(this, elem.getNode());
nodeMap.put(newNode.getId(), newNode);
LeafNode newNode = new LeafNode(this, elem.getNode());
nodeMap.put(newNode.getId(), newNode);
return newNode;
}
return newNode;
}
/**
* Creates a node with default configuration.
*
* @param nodeId The id of the node, which must be unique within the
* pubsub service
* @return The node that was created
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public LeafNode createNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
return (LeafNode) createNode(nodeId, null);
}
/**
* Creates a node with default configuration.
*
* @param nodeId The id of the node, which must be unique within the
* pubsub service
* @return The node that was created
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public LeafNode createNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
return (LeafNode) createNode(nodeId, null);
}
/**
* Creates a node with specified configuration.
*
* Note: This is the only way to create a collection node.
*
* @param nodeId The name of the node, which must be unique within the
* pubsub service
* @param config The configuration for the node
* @return The node that was created
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public Node createNode(String nodeId, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = PubSub.createPubsubPacket(pubSubService, Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId), null);
boolean isLeafNode = true;
/**
* Creates a node with specified configuration.
*
* Note: This is the only way to create a collection node.
*
* @param nodeId The name of the node, which must be unique within the
* pubsub service
* @param config The configuration for the node
* @return The node that was created
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public Node createNode(String nodeId, Form config) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub request = PubSub.createPubsubPacket(pubSubService, Type.set, new NodeExtension(PubSubElementType.CREATE, nodeId), null);
boolean isLeafNode = true;
if (config != null)
{
request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());
if (config != null)
{
request.addExtension(new FormNode(FormNodeType.CONFIGURE, config));
FormField nodeTypeField = config.getField(ConfigureNodeFields.node_type.getFieldName());
if (nodeTypeField != null)
isLeafNode = nodeTypeField.getValues().get(0).equals(NodeType.leaf.toString());
}
if (nodeTypeField != null)
isLeafNode = nodeTypeField.getValues().get(0).equals(NodeType.leaf.toString());
}
// Errors will cause exceptions in getReply, so it only returns
// on success.
sendPubsubPacket(request);
Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId);
nodeMap.put(newNode.getId(), newNode);
// Errors will cause exceptions in getReply, so it only returns
// on success.
sendPubsubPacket(request);
Node newNode = isLeafNode ? new LeafNode(this, nodeId) : new CollectionNode(this, nodeId);
nodeMap.put(newNode.getId(), newNode);
return newNode;
}
return newNode;
}
/**
* Retrieves the requested node, if it exists. It will throw an
* exception if it does not.
*
* @param id - The unique id of the node
* @return the node
* @throws XMPPErrorException The node does not exist
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
/**
* Retrieves the requested node, if it exists. It will throw an
* exception if it does not.
*
* @param id - The unique id of the node
* @return the node
* @throws XMPPErrorException The node does not exist
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public <T extends Node> T getNode(String id) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
Node node = nodeMap.get(id);
{
Node node = nodeMap.get(id);
if (node == null)
{
DiscoverInfo info = new DiscoverInfo();
info.setTo(pubSubService);
info.setNode(id);
if (node == null)
{
DiscoverInfo info = new DiscoverInfo();
info.setTo(pubSubService);
info.setNode(id);
DiscoverInfo infoReply = connection().createStanzaCollectorAndSend(info).nextResultOrThrow();
DiscoverInfo infoReply = connection().createStanzaCollectorAndSend(info).nextResultOrThrow();
if (infoReply.hasIdentity(PubSub.ELEMENT, "leaf")) {
node = new LeafNode(this, id);
@ -253,104 +253,104 @@ public final class PubSubManager extends Manager {
+ id
+ "', but it did not contain an Identity of type 'leaf' or 'collection' (and category 'pubsub'), which is not allowed according to XEP-60 5.3.");
}
nodeMap.put(id, node);
}
@SuppressWarnings("unchecked")
T res = (T) node;
return res;
}
nodeMap.put(id, node);
}
@SuppressWarnings("unchecked")
T res = (T) node;
return res;
}
/**
* Get all the nodes that currently exist as a child of the specified
* collection node. If the service does not support collection nodes
* then all nodes will be returned.
*
* To retrieve contents of the root collection node (if it exists),
* or there is no root collection node, pass null as the nodeId.
*
* @param nodeId - The id of the collection node for which the child
* nodes will be returned.
* @return {@link DiscoverItems} representing the existing nodes
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverItems discoverNodes(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
DiscoverItems items = new DiscoverItems();
/**
* Get all the nodes that currently exist as a child of the specified
* collection node. If the service does not support collection nodes
* then all nodes will be returned.
*
* To retrieve contents of the root collection node (if it exists),
* or there is no root collection node, pass null as the nodeId.
*
* @param nodeId - The id of the collection node for which the child
* nodes will be returned.
* @return {@link DiscoverItems} representing the existing nodes
* @throws XMPPErrorException
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverItems discoverNodes(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
DiscoverItems items = new DiscoverItems();
if (nodeId != null)
items.setNode(nodeId);
items.setTo(pubSubService);
DiscoverItems nodeItems = connection().createStanzaCollectorAndSend(items).nextResultOrThrow();
return nodeItems;
}
if (nodeId != null)
items.setNode(nodeId);
items.setTo(pubSubService);
DiscoverItems nodeItems = connection().createStanzaCollectorAndSend(items).nextResultOrThrow();
return nodeItems;
}
/**
* Gets the subscriptions on the root node.
*
* @return List of exceptions
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
Stanza reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS), null);
SubscriptionsExtension subElem = reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns());
return subElem.getSubscriptions();
}
/**
* Gets the subscriptions on the root node.
*
* @return List of exceptions
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public List<Subscription> getSubscriptions() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
Stanza reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS), null);
SubscriptionsExtension subElem = reply.getExtension(PubSubElementType.SUBSCRIPTIONS.getElementName(), PubSubElementType.SUBSCRIPTIONS.getNamespace().getXmlns());
return subElem.getSubscriptions();
}
/**
* Gets the affiliations on the root node.
*
* @return List of affiliations
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public List<Affiliation> getAffiliations() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS), null);
AffiliationsExtension listElem = reply.getExtension(PubSubElementType.AFFILIATIONS);
return listElem.getAffiliations();
}
/**
* Gets the affiliations on the root node.
*
* @return List of affiliations
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*
*/
public List<Affiliation> getAffiliations() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
PubSub reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.AFFILIATIONS), null);
AffiliationsExtension listElem = reply.getExtension(PubSubElementType.AFFILIATIONS);
return listElem.getAffiliations();
}
/**
* Delete the specified node.
*
* @param nodeId
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.DELETE, nodeId), PubSubElementType.DELETE.getNamespace());
nodeMap.remove(nodeId);
}
/**
* Delete the specified node.
*
* @param nodeId
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public void deleteNode(String nodeId) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
sendPubsubPacket(Type.set, new NodeExtension(PubSubElementType.DELETE, nodeId), PubSubElementType.DELETE.getNamespace());
nodeMap.remove(nodeId);
}
/**
* Returns the default settings for Node configuration.
*
* @return configuration form containing the default settings.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public ConfigureForm getDefaultConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
// Errors will cause exceptions in getReply, so it only returns
// on success.
PubSub reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.DEFAULT), PubSubElementType.DEFAULT.getNamespace());
return NodeUtils.getFormFromPacket(reply, PubSubElementType.DEFAULT);
}
/**
* Returns the default settings for Node configuration.
*
* @return configuration form containing the default settings.
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public ConfigureForm getDefaultConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
// Errors will cause exceptions in getReply, so it only returns
// on success.
PubSub reply = sendPubsubPacket(Type.get, new NodeExtension(PubSubElementType.DEFAULT), PubSubElementType.DEFAULT.getNamespace());
return NodeUtils.getFormFromPacket(reply, PubSubElementType.DEFAULT);
}
/**
* Get the JID of the PubSub service managed by this manager.
@ -361,21 +361,21 @@ public final class PubSubManager extends Manager {
return pubSubService;
}
/**
* Gets the supported features of the servers pubsub implementation
* as a standard {@link DiscoverInfo} instance.
*
* @return The supported features
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverInfo getSupportedFeatures() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
ServiceDiscoveryManager mgr = ServiceDiscoveryManager.getInstanceFor(connection());
return mgr.discoverInfo(pubSubService);
}
/**
* Gets the supported features of the servers pubsub implementation
* as a standard {@link DiscoverInfo} instance.
*
* @return The supported features
* @throws XMPPErrorException
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
*/
public DiscoverInfo getSupportedFeatures() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
ServiceDiscoveryManager mgr = ServiceDiscoveryManager.getInstanceFor(connection());
return mgr.discoverInfo(pubSubService);
}
/**
* Check if it is possible to create PubSub nodes on this service. It could be possible that the
@ -424,13 +424,13 @@ public final class PubSubManager extends Manager {
throws NoResponseException, XMPPErrorException, NotConnectedException,
InterruptedException {
// CHECKSTYLE:OFF
PubSub pubSub = new PubSub(to, type, ns);
for (ExtensionElement pe : extList) {
pubSub.addExtension(pe);
}
PubSub pubSub = new PubSub(to, type, ns);
for (ExtensionElement pe : extList) {
pubSub.addExtension(pe);
}
// CHECKSTYLE:ON
return sendPubsubPacket(pubSub);
}
}
PubSub sendPubsubPacket(PubSub packet) throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException {
@ -439,7 +439,7 @@ public final class PubSubManager extends Manager {
return null;
}
return (PubSub) resultIQ;
}
}
/**
* Get the "default" PubSub service for a given XMPP connection. The default PubSub service is

View file

@ -26,48 +26,48 @@ import java.util.Collection;
*/
public class PublishItem<T extends Item> extends NodeExtension
{
protected Collection<T> items;
protected Collection<T> items;
/**
* Construct a request to publish an item to a node.
*
* @param nodeId The node to publish to
* @param toPublish The {@link Item} to publish
*/
public PublishItem(String nodeId, T toPublish)
{
super(PubSubElementType.PUBLISH, nodeId);
items = new ArrayList<T>(1);
items.add(toPublish);
}
/**
* Construct a request to publish an item to a node.
*
* @param nodeId The node to publish to
* @param toPublish The {@link Item} to publish
*/
public PublishItem(String nodeId, T toPublish)
{
super(PubSubElementType.PUBLISH, nodeId);
items = new ArrayList<T>(1);
items.add(toPublish);
}
/**
* Construct a request to publish multiple items to a node.
*
* @param nodeId The node to publish to
* @param toPublish The list of {@link Item} to publish
*/
public PublishItem(String nodeId, Collection<T> toPublish)
{
super(PubSubElementType.PUBLISH, nodeId);
items = toPublish;
}
/**
* Construct a request to publish multiple items to a node.
*
* @param nodeId The node to publish to
* @param toPublish The list of {@link Item} to publish
*/
public PublishItem(String nodeId, Collection<T> toPublish)
{
super(PubSubElementType.PUBLISH, nodeId);
items = toPublish;
}
@Override
public String toXML()
{
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
builder.append(" node='");
builder.append(getNode());
builder.append("'>");
@Override
public String toXML()
{
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
builder.append(" node='");
builder.append(getNode());
builder.append("'>");
for (Item item : items)
{
builder.append(item.toXML());
}
builder.append("</publish>");
for (Item item : items)
{
builder.append(item.toXML());
}
builder.append("</publish>");
return builder.toString();
}
return builder.toString();
}
}

View file

@ -24,12 +24,12 @@ package org.jivesoftware.smackx.pubsub;
*/
public enum PublishModel
{
/** Only publishers may publish. */
publishers,
/** Only publishers may publish. */
publishers,
/** Only subscribers may publish. */
subscribers,
/** Only subscribers may publish. */
subscribers,
/** Anyone may publish. */
open;
/** Anyone may publish. */
open;
}

View file

@ -26,37 +26,37 @@ import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
*/
public class RetractItem implements ExtensionElement
{
private String id;
private String id;
/**
* Construct a <tt>RetractItem</tt> with the specified id.
*
* @param itemId The id if the item deleted
*/
public RetractItem(String itemId)
{
if (itemId == null)
throw new IllegalArgumentException("itemId must not be 'null'");
id = itemId;
}
/**
* Construct a <tt>RetractItem</tt> with the specified id.
*
* @param itemId The id if the item deleted
*/
public RetractItem(String itemId)
{
if (itemId == null)
throw new IllegalArgumentException("itemId must not be 'null'");
id = itemId;
}
public String getId()
{
return id;
}
public String getId()
{
return id;
}
public String getElementName()
{
return "retract";
}
public String getElementName()
{
return "retract";
}
public String getNamespace()
{
return PubSubNamespace.EVENT.getXmlns();
}
public String getNamespace()
{
return PubSubNamespace.EVENT.getXmlns();
}
public String toXML()
{
return "<retract id='" + id + "'/>";
}
public String toXML()
{
return "<retract id='" + id + "'/>";
}
}

View file

@ -26,44 +26,44 @@ import org.jivesoftware.smack.packet.ExtensionElement;
*/
public class SimplePayload implements ExtensionElement
{
private final String elemName;
private final String ns;
private final CharSequence payload;
private final String elemName;
private final String ns;
private final CharSequence payload;
/**
* Construct a <tt>SimplePayload</tt> object with the specified element name,
* namespace and content. The content must be well formed XML.
*
* @param elementName The root element name (of the payload)
* @param namespace The namespace of the payload, null if there is none
* @param xmlPayload The payload data
*/
public SimplePayload(String elementName, String namespace, CharSequence xmlPayload)
{
elemName = elementName;
payload = xmlPayload;
ns = namespace;
}
/**
* Construct a <tt>SimplePayload</tt> object with the specified element name,
* namespace and content. The content must be well formed XML.
*
* @param elementName The root element name (of the payload)
* @param namespace The namespace of the payload, null if there is none
* @param xmlPayload The payload data
*/
public SimplePayload(String elementName, String namespace, CharSequence xmlPayload)
{
elemName = elementName;
payload = xmlPayload;
ns = namespace;
}
public String getElementName()
{
return elemName;
}
public String getElementName()
{
return elemName;
}
public String getNamespace()
{
return ns;
}
public String getNamespace()
{
return ns;
}
@Override
public CharSequence toXML()
{
return payload;
}
@Override
public CharSequence toXML()
{
return payload;
}
@Override
public String toString()
{
return getClass().getName() + "payload [" + toXML() + "]";
}
@Override
public String toString()
{
return getClass().getName() + "payload [" + toXML() + "]";
}
}

View file

@ -23,41 +23,41 @@ package org.jivesoftware.smackx.pubsub;
*/
public class SubscribeExtension extends NodeExtension
{
protected String jid;
protected String jid;
public SubscribeExtension(String subscribeJid)
{
super(PubSubElementType.SUBSCRIBE);
jid = subscribeJid;
}
public SubscribeExtension(String subscribeJid)
{
super(PubSubElementType.SUBSCRIBE);
jid = subscribeJid;
}
public SubscribeExtension(String subscribeJid, String nodeId)
{
super(PubSubElementType.SUBSCRIBE, nodeId);
jid = subscribeJid;
}
public SubscribeExtension(String subscribeJid, String nodeId)
{
super(PubSubElementType.SUBSCRIBE, nodeId);
jid = subscribeJid;
}
public String getJid()
{
return jid;
}
public String getJid()
{
return jid;
}
@Override
public String toXML()
{
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
@Override
public String toXML()
{
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
if (getNode() != null)
{
builder.append(" node='");
builder.append(getNode());
builder.append('\'');
}
builder.append(" jid='");
builder.append(getJid());
builder.append("'/>");
if (getNode() != null)
{
builder.append(" node='");
builder.append(getNode());
builder.append('\'');
}
builder.append(" jid='");
builder.append(getJid());
builder.append("'/>");
return builder.toString();
}
return builder.toString();
}
}

View file

@ -40,202 +40,202 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
*/
public class SubscribeForm extends Form
{
public SubscribeForm(DataForm configDataForm)
{
super(configDataForm);
}
public SubscribeForm(DataForm configDataForm)
{
super(configDataForm);
}
public SubscribeForm(Form subscribeOptionsForm)
{
super(subscribeOptionsForm.getDataFormToSend());
}
public SubscribeForm(Form subscribeOptionsForm)
{
super(subscribeOptionsForm.getDataFormToSend());
}
public SubscribeForm(DataForm.Type formType)
{
super(formType);
}
public SubscribeForm(DataForm.Type formType)
{
super(formType);
}
/**
* Determines if an entity wants to receive notifications.
*
* @return true if want to receive, false otherwise
*/
public boolean isDeliverOn()
{
return parseBoolean(getFieldValue(SubscribeOptionFields.deliver));
}
/**
* Determines if an entity wants to receive notifications.
*
* @return true if want to receive, false otherwise
*/
public boolean isDeliverOn()
{
return parseBoolean(getFieldValue(SubscribeOptionFields.deliver));
}
/**
* Sets whether an entity wants to receive notifications.
*
* @param deliverNotifications
*/
public void setDeliverOn(boolean deliverNotifications)
{
addField(SubscribeOptionFields.deliver, FormField.Type.bool);
setAnswer(SubscribeOptionFields.deliver.getFieldName(), deliverNotifications);
}
/**
* Sets whether an entity wants to receive notifications.
*
* @param deliverNotifications
*/
public void setDeliverOn(boolean deliverNotifications)
{
addField(SubscribeOptionFields.deliver, FormField.Type.bool);
setAnswer(SubscribeOptionFields.deliver.getFieldName(), deliverNotifications);
}
/**
* Determines if notifications should be delivered as aggregations or not.
*
* @return true to aggregate, false otherwise
*/
public boolean isDigestOn()
{
return parseBoolean(getFieldValue(SubscribeOptionFields.digest));
}
/**
* Determines if notifications should be delivered as aggregations or not.
*
* @return true to aggregate, false otherwise
*/
public boolean isDigestOn()
{
return parseBoolean(getFieldValue(SubscribeOptionFields.digest));
}
/**
* Sets whether notifications should be delivered as aggregations or not.
*
* @param digestOn true to aggregate, false otherwise
*/
public void setDigestOn(boolean digestOn)
{
addField(SubscribeOptionFields.deliver, FormField.Type.bool);
setAnswer(SubscribeOptionFields.deliver.getFieldName(), digestOn);
}
/**
* Sets whether notifications should be delivered as aggregations or not.
*
* @param digestOn true to aggregate, false otherwise
*/
public void setDigestOn(boolean digestOn)
{
addField(SubscribeOptionFields.deliver, FormField.Type.bool);
setAnswer(SubscribeOptionFields.deliver.getFieldName(), digestOn);
}
/**
* Gets the minimum number of milliseconds between sending notification digests.
*
* @return The frequency in milliseconds
*/
public int getDigestFrequency()
{
return Integer.parseInt(getFieldValue(SubscribeOptionFields.digest_frequency));
}
/**
* Gets the minimum number of milliseconds between sending notification digests.
*
* @return The frequency in milliseconds
*/
public int getDigestFrequency()
{
return Integer.parseInt(getFieldValue(SubscribeOptionFields.digest_frequency));
}
/**
* Sets the minimum number of milliseconds between sending notification digests.
*
* @param frequency The frequency in milliseconds
*/
public void setDigestFrequency(int frequency)
{
addField(SubscribeOptionFields.digest_frequency, FormField.Type.text_single);
setAnswer(SubscribeOptionFields.digest_frequency.getFieldName(), frequency);
}
/**
* Sets the minimum number of milliseconds between sending notification digests.
*
* @param frequency The frequency in milliseconds
*/
public void setDigestFrequency(int frequency)
{
addField(SubscribeOptionFields.digest_frequency, FormField.Type.text_single);
setAnswer(SubscribeOptionFields.digest_frequency.getFieldName(), frequency);
}
/**
* Get the time at which the leased subscription will expire, or has expired.
*
* @return The expiry date
*/
public Date getExpiry()
{
String dateTime = getFieldValue(SubscribeOptionFields.expire);
try
{
return XmppDateTime.parseDate(dateTime);
}
catch (ParseException e)
{
UnknownFormatConversionException exc = new UnknownFormatConversionException(dateTime);
exc.initCause(e);
throw exc;
}
}
/**
* Get the time at which the leased subscription will expire, or has expired.
*
* @return The expiry date
*/
public Date getExpiry()
{
String dateTime = getFieldValue(SubscribeOptionFields.expire);
try
{
return XmppDateTime.parseDate(dateTime);
}
catch (ParseException e)
{
UnknownFormatConversionException exc = new UnknownFormatConversionException(dateTime);
exc.initCause(e);
throw exc;
}
}
/**
* Sets the time at which the leased subscription will expire, or has expired.
*
* @param expire The expiry date
*/
public void setExpiry(Date expire)
{
addField(SubscribeOptionFields.expire, FormField.Type.text_single);
setAnswer(SubscribeOptionFields.expire.getFieldName(), XmppDateTime.formatXEP0082Date(expire));
}
/**
* Sets the time at which the leased subscription will expire, or has expired.
*
* @param expire The expiry date
*/
public void setExpiry(Date expire)
{
addField(SubscribeOptionFields.expire, FormField.Type.text_single);
setAnswer(SubscribeOptionFields.expire.getFieldName(), XmppDateTime.formatXEP0082Date(expire));
}
/**
* Determines whether the entity wants to receive an XMPP message body in
* addition to the payload format.
*
* @return true to receive the message body, false otherwise
*/
public boolean isIncludeBody()
{
return parseBoolean(getFieldValue(SubscribeOptionFields.include_body));
}
/**
* Determines whether the entity wants to receive an XMPP message body in
* addition to the payload format.
*
* @return true to receive the message body, false otherwise
*/
public boolean isIncludeBody()
{
return parseBoolean(getFieldValue(SubscribeOptionFields.include_body));
}
/**
* Sets whether the entity wants to receive an XMPP message body in
* addition to the payload format.
*
* @param include true to receive the message body, false otherwise
*/
public void setIncludeBody(boolean include)
{
addField(SubscribeOptionFields.include_body, FormField.Type.bool);
setAnswer(SubscribeOptionFields.include_body.getFieldName(), include);
}
/**
* Sets whether the entity wants to receive an XMPP message body in
* addition to the payload format.
*
* @param include true to receive the message body, false otherwise
*/
public void setIncludeBody(boolean include)
{
addField(SubscribeOptionFields.include_body, FormField.Type.bool);
setAnswer(SubscribeOptionFields.include_body.getFieldName(), include);
}
/**
* Gets the {@link PresenceState} for which an entity wants to receive
* notifications.
*
* @return the list of states
*/
public List<PresenceState> getShowValues()
{
ArrayList<PresenceState> result = new ArrayList<PresenceState>(5);
/**
* Gets the {@link PresenceState} for which an entity wants to receive
* notifications.
*
* @return the list of states
*/
public List<PresenceState> getShowValues()
{
ArrayList<PresenceState> result = new ArrayList<PresenceState>(5);
for (String state : getFieldValues(SubscribeOptionFields.show_values))
{
result.add(PresenceState.valueOf(state));
}
return result;
}
for (String state : getFieldValues(SubscribeOptionFields.show_values))
{
result.add(PresenceState.valueOf(state));
}
return result;
}
/**
* Sets the list of {@link PresenceState} for which an entity wants
* to receive notifications.
*
* @param stateValues The list of states
*/
public void setShowValues(Collection<PresenceState> stateValues)
{
ArrayList<String> values = new ArrayList<String>(stateValues.size());
/**
* Sets the list of {@link PresenceState} for which an entity wants
* to receive notifications.
*
* @param stateValues The list of states
*/
public void setShowValues(Collection<PresenceState> stateValues)
{
ArrayList<String> values = new ArrayList<String>(stateValues.size());
for (PresenceState state : stateValues)
{
values.add(state.toString());
}
addField(SubscribeOptionFields.show_values, FormField.Type.list_multi);
setAnswer(SubscribeOptionFields.show_values.getFieldName(), values);
}
for (PresenceState state : stateValues)
{
values.add(state.toString());
}
addField(SubscribeOptionFields.show_values, FormField.Type.list_multi);
setAnswer(SubscribeOptionFields.show_values.getFieldName(), values);
}
static private boolean parseBoolean(String fieldValue)
{
return ("1".equals(fieldValue) || "true".equals(fieldValue));
}
static private boolean parseBoolean(String fieldValue)
{
return ("1".equals(fieldValue) || "true".equals(fieldValue));
}
private String getFieldValue(SubscribeOptionFields field)
{
FormField formField = getField(field.getFieldName());
private String getFieldValue(SubscribeOptionFields field)
{
FormField formField = getField(field.getFieldName());
return formField.getValues().get(0);
}
return formField.getValues().get(0);
}
private List<String> getFieldValues(SubscribeOptionFields field)
{
FormField formField = getField(field.getFieldName());
private List<String> getFieldValues(SubscribeOptionFields field)
{
FormField formField = getField(field.getFieldName());
return formField.getValues();
}
return formField.getValues();
}
private void addField(SubscribeOptionFields nodeField, FormField.Type type)
{
String fieldName = nodeField.getFieldName();
private void addField(SubscribeOptionFields nodeField, FormField.Type type)
{
String fieldName = nodeField.getFieldName();
if (getField(fieldName) == null)
{
FormField field = new FormField(fieldName);
field.setType(type);
addField(field);
}
}
if (getField(fieldName) == null)
{
FormField field = new FormField(fieldName);
field.setType(type);
addField(field);
}
}
}

View file

@ -26,77 +26,77 @@ import java.util.Calendar;
*/
public enum SubscribeOptionFields
{
/**
* Whether an entity wants to receive or disable notifications.
*
* <p><b>Value: boolean</b></p>
*/
deliver,
/**
* Whether an entity wants to receive or disable notifications.
*
* <p><b>Value: boolean</b></p>
*/
deliver,
/**
* Whether an entity wants to receive digests (aggregations) of
* notifications or all notifications individually.
*
* <p><b>Value: boolean</b></p>
*/
digest,
/**
* Whether an entity wants to receive digests (aggregations) of
* notifications or all notifications individually.
*
* <p><b>Value: boolean</b></p>
*/
digest,
/**
* The minimum number of seconds between sending any two notifications digests.
*
* <p><b>Value: int</b></p>
*/
digest_frequency,
/**
* The minimum number of seconds between sending any two notifications digests.
*
* <p><b>Value: int</b></p>
*/
digest_frequency,
/**
* Expire.
* <p><b>Value: {@link Calendar}</b></p>
*/
expire,
/**
* Expire.
* <p><b>Value: {@link Calendar}</b></p>
*/
expire,
/**
* Whether an entity wants to receive an XMPP message body in addition to
* the payload format.
*
* <p><b>Value: boolean</b></p>
*/
include_body,
/**
* Whether an entity wants to receive an XMPP message body in addition to
* the payload format.
*
* <p><b>Value: boolean</b></p>
*/
include_body,
/**
* The presence states for which an entity wants to receive notifications.
*
* <p><b>Value: {@link PresenceState}</b></p>
*/
show_values,
/**
* The presence states for which an entity wants to receive notifications.
*
* <p><b>Value: {@link PresenceState}</b></p>
*/
show_values,
/**
* Subscription type.
*
* <p><b>Value: </b></p>
*/
subscription_type,
/**
* Subscription type.
*
* <p><b>Value: </b></p>
*/
subscription_type,
/**
* Subscription depth.
*
* <p><b>Value: </b></p>
*/
subscription_depth;
/**
* Subscription depth.
*
* <p><b>Value: </b></p>
*/
subscription_depth;
public String getFieldName()
{
if (this == show_values)
return "pubsub#" + toString().replace('_', '-');
return "pubsub#" + toString();
}
public String getFieldName()
{
if (this == show_values)
return "pubsub#" + toString().replace('_', '-');
return "pubsub#" + toString();
}
static public SubscribeOptionFields valueOfFromElement(String elementName)
{
String portion = elementName.substring(elementName.lastIndexOf('#' + 1));
static public SubscribeOptionFields valueOfFromElement(String elementName)
{
String portion = elementName.substring(elementName.lastIndexOf('#' + 1));
if ("show-values".equals(portion))
return show_values;
else
return valueOf(portion);
}
if ("show-values".equals(portion))
return show_values;
else
return valueOf(portion);
}
}

View file

@ -23,141 +23,141 @@ package org.jivesoftware.smackx.pubsub;
*/
public class Subscription extends NodeExtension
{
protected String jid;
protected String id;
protected State state;
protected boolean configRequired = false;
protected String jid;
protected String id;
protected State state;
protected boolean configRequired = false;
public enum State
{
subscribed, unconfigured, pending, none
}
public enum State
{
subscribed, unconfigured, pending, none
}
/**
* Used to constructs a subscription request to the root node with the specified
* JID.
*
* @param subscriptionJid The subscriber JID
*/
public Subscription(String subscriptionJid)
{
this(subscriptionJid, null, null, null);
}
/**
* Used to constructs a subscription request to the root node with the specified
* JID.
*
* @param subscriptionJid The subscriber JID
*/
public Subscription(String subscriptionJid)
{
this(subscriptionJid, null, null, null);
}
/**
* Used to constructs a subscription request to the specified node with the specified
* JID.
*
* @param subscriptionJid The subscriber JID
* @param nodeId The node id
*/
public Subscription(String subscriptionJid, String nodeId)
{
this(subscriptionJid, nodeId, null, null);
}
/**
* Used to constructs a subscription request to the specified node with the specified
* JID.
*
* @param subscriptionJid The subscriber JID
* @param nodeId The node id
*/
public Subscription(String subscriptionJid, String nodeId)
{
this(subscriptionJid, nodeId, null, null);
}
/**
* Constructs a representation of a subscription reply to the specified node
* and JID. The server will have supplied the subscription id and current state.
*
* @param jid The JID the request was made under
* @param nodeId The node subscribed to
* @param subscriptionId The id of this subscription
* @param state The current state of the subscription
*/
public Subscription(String jid, String nodeId, String subscriptionId, State state)
{
super(PubSubElementType.SUBSCRIPTION, nodeId);
this.jid = jid;
id = subscriptionId;
this.state = state;
}
/**
* Constructs a representation of a subscription reply to the specified node
* and JID. The server will have supplied the subscription id and current state.
*
* @param jid The JID the request was made under
* @param nodeId The node subscribed to
* @param subscriptionId The id of this subscription
* @param state The current state of the subscription
*/
public Subscription(String jid, String nodeId, String subscriptionId, State state)
{
super(PubSubElementType.SUBSCRIPTION, nodeId);
this.jid = jid;
id = subscriptionId;
this.state = state;
}
/**
* Constructs a representation of a subscription reply to the specified node
* and JID. The server will have supplied the subscription id and current state
* and whether the subscription need to be configured.
*
* @param jid The JID the request was made under
* @param nodeId The node subscribed to
* @param subscriptionId The id of this subscription
* @param state The current state of the subscription
* @param configRequired Is configuration required to complete the subscription
*/
public Subscription(String jid, String nodeId, String subscriptionId, State state, boolean configRequired)
{
super(PubSubElementType.SUBSCRIPTION, nodeId);
this.jid = jid;
id = subscriptionId;
this.state = state;
this.configRequired = configRequired;
}
/**
* Constructs a representation of a subscription reply to the specified node
* and JID. The server will have supplied the subscription id and current state
* and whether the subscription need to be configured.
*
* @param jid The JID the request was made under
* @param nodeId The node subscribed to
* @param subscriptionId The id of this subscription
* @param state The current state of the subscription
* @param configRequired Is configuration required to complete the subscription
*/
public Subscription(String jid, String nodeId, String subscriptionId, State state, boolean configRequired)
{
super(PubSubElementType.SUBSCRIPTION, nodeId);
this.jid = jid;
id = subscriptionId;
this.state = state;
this.configRequired = configRequired;
}
/**
* Gets the JID the subscription is created for.
*
* @return The JID
*/
public String getJid()
{
return jid;
}
/**
* Gets the JID the subscription is created for.
*
* @return The JID
*/
public String getJid()
{
return jid;
}
/**
* Gets the subscription id.
*
* @return The subscription id
*/
public String getId()
{
return id;
}
/**
* Gets the subscription id.
*
* @return The subscription id
*/
public String getId()
{
return id;
}
/**
* Gets the current subscription state.
*
* @return Current subscription state
*/
public State getState()
{
return state;
}
/**
* Gets the current subscription state.
*
* @return Current subscription state
*/
public State getState()
{
return state;
}
/**
* This value is only relevant when the {@link #getState()} is {@link State#unconfigured}.
*
* @return true if configuration is required, false otherwise
*/
public boolean isConfigRequired()
{
return configRequired;
}
/**
* This value is only relevant when the {@link #getState()} is {@link State#unconfigured}.
*
* @return true if configuration is required, false otherwise
*/
public boolean isConfigRequired()
{
return configRequired;
}
public String toXML()
{
StringBuilder builder = new StringBuilder("<subscription");
appendAttribute(builder, "jid", jid);
public String toXML()
{
StringBuilder builder = new StringBuilder("<subscription");
appendAttribute(builder, "jid", jid);
if (getNode() != null)
appendAttribute(builder, "node", getNode());
if (getNode() != null)
appendAttribute(builder, "node", getNode());
if (id != null)
appendAttribute(builder, "subid", id);
if (id != null)
appendAttribute(builder, "subid", id);
if (state != null)
appendAttribute(builder, "subscription", state.toString());
if (state != null)
appendAttribute(builder, "subscription", state.toString());
builder.append("/>");
return builder.toString();
}
builder.append("/>");
return builder.toString();
}
private static void appendAttribute(StringBuilder builder, String att, String value)
{
builder.append(' ');
builder.append(att);
builder.append("='");
builder.append(value);
builder.append('\'');
}
private static void appendAttribute(StringBuilder builder, String att, String value)
{
builder.append(' ');
builder.append(att);
builder.append("='");
builder.append(value);
builder.append('\'');
}
}

View file

@ -26,53 +26,53 @@ import java.util.List;
*/
abstract public class SubscriptionEvent extends NodeEvent
{
private List<String> subIds = Collections.emptyList();
private List<String> subIds = Collections.emptyList();
/**
* Construct an event with no subscription id's. This can
* occur when there is only one subscription to a node. The
* event may or may not report the subscription id along
* with the event.
*
* @param nodeId The id of the node the event came from
*/
protected SubscriptionEvent(String nodeId)
{
super(nodeId);
}
/**
* Construct an event with no subscription id's. This can
* occur when there is only one subscription to a node. The
* event may or may not report the subscription id along
* with the event.
*
* @param nodeId The id of the node the event came from
*/
protected SubscriptionEvent(String nodeId)
{
super(nodeId);
}
/**
* Construct an event with multiple subscriptions.
*
* @param nodeId The id of the node the event came from
* @param subscriptionIds The list of subscription id's
*/
protected SubscriptionEvent(String nodeId, List<String> subscriptionIds)
{
super(nodeId);
/**
* Construct an event with multiple subscriptions.
*
* @param nodeId The id of the node the event came from
* @param subscriptionIds The list of subscription id's
*/
protected SubscriptionEvent(String nodeId, List<String> subscriptionIds)
{
super(nodeId);
if (subscriptionIds != null)
subIds = subscriptionIds;
}
if (subscriptionIds != null)
subIds = subscriptionIds;
}
/**
* Get the subscriptions this event is associated with.
*
* @return List of subscription id's
*/
public List<String> getSubscriptions()
{
return Collections.unmodifiableList(subIds);
}
/**
* Get the subscriptions this event is associated with.
*
* @return List of subscription id's
*/
public List<String> getSubscriptions()
{
return Collections.unmodifiableList(subIds);
}
/**
* Set the list of subscription id's for this event.
*
* @param subscriptionIds The list of subscription id's
*/
protected void setSubscriptions(List<String> subscriptionIds)
{
if (subscriptionIds != null)
subIds = subscriptionIds;
}
/**
* Set the list of subscription id's for this event.
*
* @param subscriptionIds The list of subscription id's
*/
protected void setSubscriptions(List<String> subscriptionIds)
{
if (subscriptionIds != null)
subIds = subscriptionIds;
}
}

View file

@ -26,74 +26,74 @@ import java.util.List;
*/
public class SubscriptionsExtension extends NodeExtension
{
protected List<Subscription> items = Collections.emptyList();
protected List<Subscription> items = Collections.emptyList();
/**
* Subscriptions to the root node.
*
* @param subList The list of subscriptions
*/
public SubscriptionsExtension(List<Subscription> subList)
{
super(PubSubElementType.SUBSCRIPTIONS);
/**
* Subscriptions to the root node.
*
* @param subList The list of subscriptions
*/
public SubscriptionsExtension(List<Subscription> subList)
{
super(PubSubElementType.SUBSCRIPTIONS);
if (subList != null)
items = subList;
}
if (subList != null)
items = subList;
}
/**
* Subscriptions to the specified node.
*
* @param nodeId The node subscribed to
* @param subList The list of subscriptions
*/
public SubscriptionsExtension(String nodeId, List<Subscription> subList)
{
super(PubSubElementType.SUBSCRIPTIONS, nodeId);
/**
* Subscriptions to the specified node.
*
* @param nodeId The node subscribed to
* @param subList The list of subscriptions
*/
public SubscriptionsExtension(String nodeId, List<Subscription> subList)
{
super(PubSubElementType.SUBSCRIPTIONS, nodeId);
if (subList != null)
items = subList;
}
if (subList != null)
items = subList;
}
/**
* Gets the list of subscriptions.
*
* @return List of subscriptions
*/
public List<Subscription> getSubscriptions()
{
return items;
}
/**
* Gets the list of subscriptions.
*
* @return List of subscriptions
*/
public List<Subscription> getSubscriptions()
{
return items;
}
@Override
public CharSequence toXML()
{
if ((items == null) || (items.size() == 0))
{
return super.toXML();
}
else
{
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
@Override
public CharSequence toXML()
{
if ((items == null) || (items.size() == 0))
{
return super.toXML();
}
else
{
StringBuilder builder = new StringBuilder("<");
builder.append(getElementName());
if (getNode() != null)
{
builder.append(" node='");
builder.append(getNode());
builder.append('\'');
}
builder.append('>');
if (getNode() != null)
{
builder.append(" node='");
builder.append(getNode());
builder.append('\'');
}
builder.append('>');
for (Subscription item : items)
{
builder.append(item.toXML());
}
for (Subscription item : items)
{
builder.append(item.toXML());
}
builder.append("</");
builder.append(getElementName());
builder.append('>');
return builder.toString();
}
}
builder.append("</");
builder.append(getElementName());
builder.append('>');
return builder.toString();
}
}
}

View file

@ -26,35 +26,35 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
*/
public class UnsubscribeExtension extends NodeExtension
{
protected String jid;
protected String id;
protected String jid;
protected String id;
public UnsubscribeExtension(String subscriptionJid)
{
this(subscriptionJid, null, null);
}
public UnsubscribeExtension(String subscriptionJid)
{
this(subscriptionJid, null, null);
}
public UnsubscribeExtension(String subscriptionJid, String nodeId)
{
this(subscriptionJid, nodeId, null);
}
public UnsubscribeExtension(String subscriptionJid, String nodeId)
{
this(subscriptionJid, nodeId, null);
}
public UnsubscribeExtension(String jid, String nodeId, String subscriptionId)
{
super(PubSubElementType.UNSUBSCRIBE, nodeId);
this.jid = jid;
id = subscriptionId;
}
public UnsubscribeExtension(String jid, String nodeId, String subscriptionId)
{
super(PubSubElementType.UNSUBSCRIBE, nodeId);
this.jid = jid;
id = subscriptionId;
}
public String getJid()
{
return jid;
}
public String getJid()
{
return jid;
}
public String getId()
{
return id;
}
public String getId()
{
return id;
}
@Override
public XmlStringBuilder toXML() {

View file

@ -28,17 +28,17 @@ import org.jivesoftware.smackx.pubsub.LeafNode;
*/
public interface ItemDeleteListener
{
/**
* Called when items are deleted from a node the listener is
* registered with.
*
* @param items The event with item deletion details
*/
void handleDeletedItems(ItemDeleteEvent items);
/**
* Called when items are deleted from a node the listener is
* registered with.
*
* @param items The event with item deletion details
*/
void handleDeletedItems(ItemDeleteEvent items);
/**
* Called when <b>all</b> items are deleted from a node the listener is
* registered with.
*/
void handlePurge();
/**
* Called when <b>all</b> items are deleted from a node the listener is
* registered with.
*/
void handlePurge();
}

View file

@ -29,11 +29,11 @@ import org.jivesoftware.smackx.pubsub.LeafNode;
*/
public interface ItemEventListener<T extends Item>
{
/**
* Called whenever an item is published to the node the listener
* is registered with.
*
* @param items The publishing details.
*/
void handlePublishedItems(ItemPublishEvent<T> items);
/**
* Called whenever an item is published to the node the listener
* is registered with.
*
* @param items The publishing details.
*/
void handlePublishedItems(ItemPublishEvent<T> items);
}

View file

@ -28,11 +28,11 @@ import org.jivesoftware.smackx.pubsub.LeafNode;
*/
public interface NodeConfigListener
{
/**
* Called whenever the node the listener
* is registered with is configured.
*
* @param config The configuration details.
*/
void handleNodeConfiguration(ConfigurationEvent config);
/**
* Called whenever the node the listener
* is registered with is configured.
*
* @param config The configuration details.
*/
void handleNodeConfiguration(ConfigurationEvent config);
}

View file

@ -33,11 +33,11 @@ public class PubSub extends IQ
public static final String ELEMENT = "pubsub";
public static final String NAMESPACE = "http://jabber.org/protocol/pubsub";
public PubSub() {
public PubSub() {
super(ELEMENT, NAMESPACE);
}
}
public PubSub(PubSubNamespace ns) {
public PubSub(PubSubNamespace ns) {
super(ELEMENT, ns.getXmlns());
}
@ -49,9 +49,9 @@ public class PubSub extends IQ
@SuppressWarnings("unchecked")
public <PE extends ExtensionElement> PE getExtension(PubSubElementType elem)
{
return (PE) getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
}
{
return (PE) getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
}
/**
* Returns the XML representation of a pubsub element according the specification.

View file

@ -26,45 +26,45 @@ import java.util.Locale;
*/
public enum PubSubNamespace
{
BASIC(null),
ERROR("errors"),
EVENT("event"),
OWNER("owner");
BASIC(null),
ERROR("errors"),
EVENT("event"),
OWNER("owner");
private final String fragment;
private final String fullNamespace;
private PubSubNamespace(String fragment)
{
this.fragment = fragment;
private PubSubNamespace(String fragment)
{
this.fragment = fragment;
if (fragment != null) {
fullNamespace = PubSub.NAMESPACE + '#' + fragment;
}
else {
fullNamespace = PubSub.NAMESPACE;
}
}
}
public String getXmlns()
{
public String getXmlns()
{
return fullNamespace;
}
}
public String getFragment()
{
return fragment;
}
public String getFragment()
{
return fragment;
}
public static PubSubNamespace valueOfFromXmlns(String ns)
{
int index = ns.lastIndexOf('#');
public static PubSubNamespace valueOfFromXmlns(String ns)
{
int index = ns.lastIndexOf('#');
if (index != -1)
{
String suffix = ns.substring(ns.lastIndexOf('#')+1);
return valueOf(suffix.toUpperCase(Locale.US));
}
else
return BASIC;
}
if (index != -1)
{
String suffix = ns.substring(ns.lastIndexOf('#')+1);
return valueOf(suffix.toUpperCase(Locale.US));
}
else
return BASIC;
}
}

View file

@ -31,11 +31,11 @@ import org.jivesoftware.smackx.pubsub.AffiliationsExtension;
* @author Robin Collier
*/public class AffiliationsProvider extends EmbeddedExtensionProvider<AffiliationsExtension>
{
@SuppressWarnings("unchecked")
@Override
protected AffiliationsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
@SuppressWarnings("unchecked")
@Override
protected AffiliationsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
return new AffiliationsExtension((List<Affiliation>)content);
}
}
}

View file

@ -33,12 +33,12 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
*/
public class ConfigEventProvider extends EmbeddedExtensionProvider<ConfigurationEvent>
{
@Override
protected ConfigurationEvent createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends ExtensionElement> content)
{
if (content.size() == 0)
return new ConfigurationEvent(attMap.get("node"));
else
return new ConfigurationEvent(attMap.get("node"), new ConfigureForm((DataForm)content.iterator().next()));
}
@Override
protected ConfigurationEvent createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends ExtensionElement> content)
{
if (content.size() == 0)
return new ConfigurationEvent(attMap.get("node"));
else
return new ConfigurationEvent(attMap.get("node"), new ConfigureForm((DataForm)content.iterator().next()));
}
}

View file

@ -33,11 +33,9 @@ import org.jivesoftware.smackx.pubsub.NodeExtension;
*/
public class EventProvider extends EmbeddedExtensionProvider<EventElement>
{
@Override
protected EventElement createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends ExtensionElement> content)
{
// CHECKSTYLE:OFF
return new EventElement(EventElementType.valueOf(content.get(0).getElementName()), (NodeExtension)content.get(0));
// CHECKSTYLE:ON
}
@Override
protected EventElement createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attMap, List<? extends ExtensionElement> content)
{
return new EventElement(EventElementType.valueOf(content.get(0).getElementName()), (NodeExtension)content.get(0));
}
}

View file

@ -34,9 +34,9 @@ import org.jivesoftware.smackx.xdata.packet.DataForm;
*/
public class FormNodeProvider extends EmbeddedExtensionProvider<FormNode>
{
@Override
protected FormNode createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
@Override
protected FormNode createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
return new FormNode(FormNodeType.valueOfFromElementName(currentElement, currentNamespace), attributeMap.get("node"), new Form((DataForm)content.iterator().next()));
}
}
}

View file

@ -32,10 +32,10 @@ import org.jivesoftware.smackx.pubsub.ItemsExtension;
public class ItemsProvider extends EmbeddedExtensionProvider<ItemsExtension>
{
@Override
protected ItemsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
@Override
protected ItemsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
return new ItemsExtension(ItemsExtension.ItemsElementType.items, attributeMap.get("node"), content);
}
}
}

View file

@ -53,5 +53,5 @@ public class PubSubProvider extends IQProvider<PubSub>
}
}
return pubsub;
}
}
}

View file

@ -32,10 +32,10 @@ import org.jivesoftware.smackx.pubsub.RetractItem;
*/
public class RetractEventProvider extends EmbeddedExtensionProvider<RetractItem>
{
@Override
protected RetractItem createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
return new RetractItem(attributeMap.get("id"));
}
@Override
protected RetractItem createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
return new RetractItem(attributeMap.get("id"));
}
}

View file

@ -32,9 +32,9 @@ import org.jivesoftware.smackx.pubsub.PubSubElementType;
*/
public class SimpleNodeProvider extends EmbeddedExtensionProvider<NodeExtension>
{
@Override
protected NodeExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
@Override
protected NodeExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
return new NodeExtension(PubSubElementType.valueOfFromElemName(currentElement, currentNamespace), attributeMap.get("node"));
}
}
}

View file

@ -34,25 +34,25 @@ public class SubscriptionProvider extends ExtensionElementProvider<Subscription>
@Override
public Subscription parse(XmlPullParser parser, int initialDepth)
throws XmlPullParserException, IOException {
String jid = parser.getAttributeValue(null, "jid");
String nodeId = parser.getAttributeValue(null, "node");
String subId = parser.getAttributeValue(null, "subid");
String state = parser.getAttributeValue(null, "subscription");
boolean isRequired = false;
String jid = parser.getAttributeValue(null, "jid");
String nodeId = parser.getAttributeValue(null, "node");
String subId = parser.getAttributeValue(null, "subid");
String state = parser.getAttributeValue(null, "subscription");
boolean isRequired = false;
int tag = parser.next();
int tag = parser.next();
if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("subscribe-options"))
{
tag = parser.next();
if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("subscribe-options"))
{
tag = parser.next();
if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("required"))
isRequired = true;
if ((tag == XmlPullParser.START_TAG) && parser.getName().equals("required"))
isRequired = true;
while (tag != XmlPullParser.END_TAG && !parser.getName().equals("subscribe-options")) tag = parser.next();
}
while (parser.getEventType() != XmlPullParser.END_TAG) parser.next();
return new Subscription(jid, nodeId, subId, (state == null ? null : Subscription.State.valueOf(state)), isRequired);
}
while (tag != XmlPullParser.END_TAG && !parser.getName().equals("subscribe-options")) tag = parser.next();
}
while (parser.getEventType() != XmlPullParser.END_TAG) parser.next();
return new Subscription(jid, nodeId, subId, (state == null ? null : Subscription.State.valueOf(state)), isRequired);
}
}

View file

@ -32,11 +32,11 @@ import org.jivesoftware.smackx.pubsub.SubscriptionsExtension;
*/
public class SubscriptionsProvider extends EmbeddedExtensionProvider<SubscriptionsExtension>
{
@SuppressWarnings("unchecked")
@Override
protected SubscriptionsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
return new SubscriptionsExtension(attributeMap.get("node"), (List<Subscription>)content);
}
@SuppressWarnings("unchecked")
@Override
protected SubscriptionsExtension createReturnExtension(String currentElement, String currentNamespace, Map<String, String> attributeMap, List<? extends ExtensionElement> content)
{
return new SubscriptionsExtension(attributeMap.get("node"), (List<Subscription>)content);
}
}

View file

@ -29,17 +29,17 @@ import org.jivesoftware.smackx.xdata.Form;
*/
public class NodeUtils
{
/**
* Get a {@link ConfigureForm} from a packet.
*
* @param packet
* @param elem
* @return The configuration form
*/
public static ConfigureForm getFormFromPacket(Stanza packet, PubSubElementType elem)
{
FormNode config = packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
Form formReply = config.getForm();
return new ConfigureForm(formReply);
}
/**
* Get a {@link ConfigureForm} from a packet.
*
* @param packet
* @param elem
* @return The configuration form
*/
public static ConfigureForm getFormFromPacket(Stanza packet, PubSubElementType elem)
{
FormNode config = packet.getExtension(elem.getElementName(), elem.getNamespace().getXmlns());
Form formReply = config.getForm();
return new ConfigureForm(formReply);
}
}