📄 nodesubscription.java
字号:
/** * $RCSfile: $ * $Revision: $ * $Date: $ * * Copyright (C) 2008 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution, or a commercial license * agreement with Jive. */package org.jivesoftware.openfire.pubsub;import org.dom4j.Element;import org.jivesoftware.util.FastDateFormat;import org.jivesoftware.util.LocaleUtils;import org.jivesoftware.util.Log;import org.xmpp.forms.DataForm;import org.xmpp.forms.FormField;import org.xmpp.packet.IQ;import org.xmpp.packet.JID;import org.xmpp.packet.Message;import org.xmpp.packet.Presence;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.*;/** * A subscription to a node. Entities may subscribe to a node to be notified when new events * are published to the node. Published events may contain a {@link PublishedItem}. Only * nodes that are configured to not deliver payloads with event notifications and to not * persist items will let publishers to publish events without items thus not including * items in the notifications sent to subscribers.<p> * * Node subscriptions may need to be configured by the subscriber or approved by a node owner * to become active. The node configuration establishes whether configuration or approval are * required. In any case, the subscriber will not get event notifications until the subscription * is active.<p> * * Depending on the node configuration it may be possible for the same subscriber to subscribe * multiple times to the node. Each subscription may have a different configuration like for * instance different keywords. Keywords can be used as a way to filter the type of * {@link PublishedItem} to be notified of. When the same subscriber has subscribed multiple * times to the node a single notification is going to be sent to the subscriber instead of * sending a notification for each subscription. * * @author Matt Tucker */public class NodeSubscription { private static final SimpleDateFormat dateFormat; private static final FastDateFormat fastDateFormat; /** * Reference to the publish and subscribe service. */ private PubSubService service; /** * The node to which this subscription is interested in. */ private Node node; /** * JID of the entity that will receive the event notifications. */ private JID jid; /** * JID of the entity that owns this subscription. This JID is the JID of the * NodeAffiliate that is subscribed to the node. */ private JID owner; /** * ID that uniquely identifies the subscription of the user in the node. */ private String id; /** * Current subscription state. */ private State state; /** * Flag indicating whether an entity wants to receive or has disabled notifications. */ private boolean deliverNotifications = true; /** * Flag indicating whether an entity wants to receive digests (aggregations) of * notifications or all notifications individually. */ private boolean usingDigest = false; /** * The minimum number of milliseconds between sending any two notification digests. * Default is 24 hours. */ private int digestFrequency = 86400000; /** * The Date at which a leased subscription will end or has ended. A value of * <tt>null</tt> means that the subscription will never expire. */ private Date expire = null; /** * Flag indicating whether an entity wants to receive an XMPP message body in * addition to the payload format. */ private boolean includingBody = false; /** * The presence states for which an entity wants to receive notifications. */ private Collection<String> presenceStates = new ArrayList<String>(); /** * When subscribing to collection nodes it is possible to be interested in new nodes * added to the collection node or new items published in the children nodes. The default * value is "nodes". */ private Type type = Type.nodes; /** * Receive notification from children up to certain depth. Possible values are 1 or 0. * Zero means that there is no depth limit. */ private int depth = 1; /** * Keyword that the event needs to match. When <tt>null</tt> all event are going to * be notified to the subscriber. */ private String keyword = null; /** * Indicates if the subscription is present in the database. */ private boolean savedToDB = false; static { dateFormat = new SimpleDateFormat("yyyy-MM-DD'T'HH:mm:ss.SSS'Z'"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); fastDateFormat = FastDateFormat .getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("UTC")); } /** * Creates a new subscription of the specified user with the node. * * @param service the pubsub service hosting the node where this subscription lives. * @param node Node to which this subscription is interested in. * @param owner the JID of the entity that owns this subscription. * @param jid the JID of the user that owns the subscription. * @param state the state of the subscription with the node. * @param id the id the uniquely identifies this subscriptin within the node. */ NodeSubscription(PubSubService service, Node node, JID owner, JID jid, State state, String id) { this.service = service; this.node = node; this.jid = jid; this.owner = owner; this.state = state; this.id = id; } /** * Returns the node that holds this subscription. * * @return the node that holds this subscription. */ public Node getNode() { return node; } /** * Returns the ID that uniquely identifies the subscription of the user in the node. * * @return the ID that uniquely identifies the subscription of the user in the node. */ public String getID() { return id; } /** * Returns the JID that is going to receive the event notifications. This JID can be the * owner JID or a full JID if the owner wants to receive the notification at a particular * resource.<p> * * Moreover, since subscriber and owner are separated it should be theorically possible to * have a different owner JID (e.g. gato@server1.com) and a subscriber JID * (e.g. gato@server2.com). Note that letting this case to happen may open the pubsub service * to get spam or security problems. However, the pubsub service should avoid this case to * happen. * * @return the JID that is going to receive the event notifications. */ public JID getJID() { return jid; } /** * Retuns the JID of the entity that owns this subscription. The owner entity will have * a {@link NodeAffiliate} for the owner JID. The owner may have more than one subscription * with the node based on what this message * {@link org.jivesoftware.openfire.pubsub.Node#isMultipleSubscriptionsEnabled()}. * * @return he JID of the entity that owns this subscription. */ public JID getOwner() { return owner; } /** * Returns the current subscription state. Subscriptions with status of pending should be * authorized by a node owner. * * @return the current subscription state. */ public State getState() { return state; } /** * Returns true if configuration is required by the node and is still pending to * be configured by the subscriber. Otherwise return false. Once a subscription is * configured it might need to be approved by a node owner to become active. * * @return true if configuration is required by the node and is still pending to * be configured by the subscriber. */ public boolean isConfigurationPending() { return state == State.unconfigured; } /** * Returns true if the subscription needs to be approved by a node owner to become * active. Until the subscription is not activated the subscriber will not receive * event notifications. * * @return true if the subscription needs to be approved by a node owner to become active. */ public boolean isAuthorizationPending() { return state == State.pending; } /** * Returns whether an entity wants to receive or has disabled notifications. * * @return true when notifications should be sent to the subscriber. */ public boolean shouldDeliverNotifications() { return deliverNotifications; } /** * Returns whether an entity wants to receive digests (aggregations) of * notifications or all notifications individually. * * @return true when an entity wants to receive digests (aggregations) of notifications. */ public boolean isUsingDigest() { return usingDigest; } /** * Returns the minimum number of milliseconds between sending any two notification digests. * Default is 24 hours. * * @return the minimum number of milliseconds between sending any two notification digests. */ public int getDigestFrequency() { return digestFrequency; } /** * Returns the Date at which a leased subscription will end or has ended. A value of * <tt>null</tt> means that the subscription will never expire. * * @return the Date at which a leased subscription will end or has ended. A value of * <tt>null</tt> means that the subscription will never expire. */ public Date getExpire() { return expire; } /** * Returns whether an entity wants to receive an XMPP message body in * addition to the payload format. * * @return true when an entity wants to receive an XMPP message body in * addition to the payload format */ public boolean isIncludingBody() { return includingBody; } /** * The presence states for which an entity wants to receive notifications. When the owner * is in any of the returned presence states then he is allowed to receive notifications. * * @return the presence states for which an entity wants to receive notifications. * (e.g. available, away, etc.) */ public Collection<String> getPresenceStates() { return presenceStates; } /** * Returns if the owner has subscribed to receive notification of new items only * or of new nodes only. When subscribed to a Leaf Node then only <tt>items</tt> * is available. * * @return whether the owner has subscribed to receive notification of new items only * or of new nodes only. */ public Type getType() { return type; } /** * Returns 1 when the subscriber wants to receive notifications only from first-level * children of the collection. A value of 0 means that the subscriber wants to receive * notifications from all descendents. * * @return 1 when the subscriber wants to receive notifications only from first-level
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -