📄 nodesubscription.java
字号:
* children of the collection or 0 when notififying only from all descendents. */ public int getDepth() { return depth; } /** * Returns the keyword that the event needs to match. When <tt>null</tt> all event * are going to be notified to the subscriber. * * @return the keyword that the event needs to match. When <tt>null</tt> all event * are going to be notified to the subscriber. */ public String getKeyword() { return keyword; } void setShouldDeliverNotifications(boolean deliverNotifications) { this.deliverNotifications = deliverNotifications; } void setUsingDigest(boolean usingDigest) { this.usingDigest = usingDigest; } void setDigestFrequency(int digestFrequency) { this.digestFrequency = digestFrequency; } void setExpire(Date expire) { this.expire = expire; } void setIncludingBody(boolean includingBody) { this.includingBody = includingBody; } void setPresenceStates(Collection<String> presenceStates) { this.presenceStates = presenceStates; } void setType(Type type) { this.type = type; } void setDepth(int depth) { this.depth = depth; } void setKeyword(String keyword) { this.keyword = keyword; } void setSavedToDB(boolean savedToDB) { this.savedToDB = savedToDB; } /** * Configures the subscription based on the sent {@link DataForm} included in the IQ * packet sent by the subscriber. If the subscription was pending of configuration * then the last published item is going to be sent to the subscriber.<p> * * The originalIQ parameter may be <tt>null</tt> when using this API internally. When no * IQ packet was sent then no IQ result will be sent to the sender. The rest of the * functionality is the same. * * @param originalIQ the IQ packet sent by the subscriber to configure his subscription or * null when using this API internally. * @param options the data form containing the new subscription configuration. */ public void configure(IQ originalIQ, DataForm options) { boolean wasUnconfigured = isConfigurationPending(); // Change the subscription configuration based on the completed form configure(options); if (originalIQ != null) { // Return success response service.send(IQ.createResultIQ(originalIQ)); } if (wasUnconfigured) { // If subscription is pending then send notification to node owners // asking to approve the now configured subscription if (isAuthorizationPending()) { sendAuthorizationRequest(); } // Send last published item (if node is leaf node and subscription status is ok) if (node.isSendItemSubscribe() && isActive()) { PublishedItem lastItem = node.getLastPublishedItem(); if (lastItem != null) { sendLastPublishedItem(lastItem); } } } } void configure(DataForm options) { List<String> values; String booleanValue; boolean wasUsingPresence = !presenceStates.isEmpty(); // Remove this field from the form options.removeField("FORM_TYPE"); // Process and remove specific collection node fields FormField collectionField = options.getField("pubsub#subscription_type"); if (collectionField != null) { values = collectionField.getValues(); if (values.size() > 0) { type = Type.valueOf(values.get(0)); } options.removeField("pubsub#subscription_type"); } collectionField = options.getField("pubsub#subscription_depth"); if (collectionField != null) { values = collectionField.getValues(); depth = "all".equals(values.get(0)) ? 0 : 1; options.removeField("pubsub#subscription_depth"); } // If there are more fields in the form then process them and set that // the subscription has been configured for (FormField field : options.getFields()) { boolean fieldExists = true; if ("pubsub#deliver".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); deliverNotifications = "1".equals(booleanValue); } else if ("pubsub#digest".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); usingDigest = "1".equals(booleanValue); } else if ("pubsub#digest_frequency".equals(field.getVariable())) { values = field.getValues(); digestFrequency = values.size() > 0 ? Integer.parseInt(values.get(0)) : 86400000; } else if ("pubsub#expire".equals(field.getVariable())) { values = field.getValues(); synchronized (dateFormat) { try { expire = dateFormat.parse(values.get(0)); } catch (ParseException e) { Log.error("Error parsing date", e); } } } else if ("pubsub#include_body".equals(field.getVariable())) { values = field.getValues(); booleanValue = (values.size() > 0 ? values.get(0) : "1"); includingBody = "1".equals(booleanValue); } else if ("pubsub#show-values".equals(field.getVariable())) { // Get the new list of presence states for which an entity wants to // receive notifications presenceStates = new ArrayList<String>(); for (String value : field.getValues()) { try { presenceStates.add(value); } catch (Exception e) { // Do nothing } } } else if ("x-pubsub#keywords".equals(field.getVariable())) { values = field.getValues(); keyword = values.isEmpty() ? null : values.get(0); } else { fieldExists = false; } if (fieldExists) { // Subscription has been configured so set the next state if (node.getAccessModel().isAuthorizationRequired() && !node.isAdmin(owner)) { state = State.pending; } else { state = State.subscribed; } } } if (savedToDB) { // Update the subscription in the backend store PubSubPersistenceManager.saveSubscription(service, node, this, false); } // Check if the service needs to subscribe or unsubscribe from the owner presence if (!node.isPresenceBasedDelivery() && wasUsingPresence != !presenceStates.isEmpty()) { if (presenceStates.isEmpty()) { service.presenceSubscriptionNotRequired(node, owner); } else { service.presenceSubscriptionRequired(node, owner); } } } /** * Returns a data form with the subscription configuration. The data form can be used to * edit the subscription configuration. * * @return data form used by the subscriber to edit the subscription configuration. */ public DataForm getConfigurationForm() { DataForm form = new DataForm(DataForm.Type.form); form.setTitle(LocaleUtils.getLocalizedString("pubsub.form.subscription.title")); List<String> params = new ArrayList<String>(); params.add(node.getNodeID()); form.addInstruction(LocaleUtils.getLocalizedString("pubsub.form.subscription.instruction", params)); // Add the form fields and configure them for edition FormField formField = form.addField(); formField.setVariable("FORM_TYPE"); formField.setType(FormField.Type.hidden); formField.addValue("http://jabber.org/protocol/pubsub#subscribe_options"); formField = form.addField(); formField.setVariable("pubsub#deliver"); formField.setType(FormField.Type.boolean_type); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.deliver")); formField.addValue(deliverNotifications); formField = form.addField(); formField.setVariable("pubsub#digest"); formField.setType(FormField.Type.boolean_type); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.digest")); formField.addValue(usingDigest); formField = form.addField(); formField.setVariable("pubsub#digest_frequency"); formField.setType(FormField.Type.text_single); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.digest_frequency")); formField.addValue(digestFrequency); formField = form.addField(); formField.setVariable("pubsub#expire"); formField.setType(FormField.Type.text_single); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.expire")); if (expire != null) { formField.addValue(fastDateFormat.format(expire)); } formField = form.addField(); formField.setVariable("pubsub#include_body"); formField.setType(FormField.Type.boolean_type); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.include_body")); formField.addValue(includingBody); formField = form.addField(); formField.setVariable("pubsub#show-values"); formField.setType(FormField.Type.list_multi); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.show-values")); formField.addOption(null, Presence.Show.away.name()); formField.addOption(null, Presence.Show.chat.name()); formField.addOption(null, Presence.Show.dnd.name()); formField.addOption(null, "online"); formField.addOption(null, Presence.Show.xa.name()); for (String value : presenceStates) { formField.addValue(value); } if (node.isCollectionNode()) { formField = form.addField(); formField.setVariable("pubsub#subscription_type"); formField.setType(FormField.Type.list_single); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.subscription_type")); formField.addOption(null, Type.items.name()); formField.addOption(null, Type.nodes.name()); formField.addValue(type); formField = form.addField(); formField.setVariable("pubsub#subscription_depth"); formField.setType(FormField.Type.list_single); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.subscription_depth")); formField.addOption(null, "1"); formField.addOption(null, "all"); formField.addValue(depth == 1 ? "1" : "all"); } if (!node.isCollectionNode() || type == Type.items) { formField = form.addField(); formField.setVariable("x-pubsub#keywords"); formField.setType(FormField.Type.text_single); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.subscription.keywords")); if (keyword != null) { formField.addValue(keyword); } } return form; } /** * Returns true if an event notification can be sent to the subscriber for the specified * published item based on the subsription configuration and subscriber status. * * @param leafNode the node that received the publication. * @param publishedItem the published item to send or null if the publication didn't * contain an item. * @return true if an event notification can be sent to the subscriber for the specified * published item. */ public boolean canSendPublicationEvent(LeafNode leafNode, PublishedItem publishedItem) { if (!canSendEvents()) { return false; } // Check that any defined keyword was matched (applies only if an item was published) if (publishedItem != null && !isKeywordMatched(publishedItem)) { return false; } // Check special conditions when subscribed to collection node if (node.isCollectionNode()) { // Check if not subscribe to items if (Type.items != type) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -