📄 pepservice.java
字号:
} return false; } public boolean isCollectionNodesSupported() { return true; } public boolean isInstantNodeSupported() { return true; } public boolean isMultipleSubscriptionsEnabled() { return false; } public boolean isServiceAdmin(JID user) { // Here we consider a 'service admin' to be the user that this PEPService // is associated with. if (serviceOwnerJID.equals(user.toBareJID())) { return true; } else { return false; } } public boolean isNodeCreationRestricted() { return nodeCreationRestricted; } public void presenceSubscriptionNotRequired(Node node, JID user) { PubSubEngine.presenceSubscriptionNotRequired(this, node, user); } public void presenceSubscriptionRequired(Node node, JID user) { PubSubEngine.presenceSubscriptionRequired(this, node, user); } public void send(Packet packet) { router.route(packet); } public void broadcast(Node node, Message message, Collection<JID> jids) { message.setFrom(getAddress()); for (JID jid : jids) { message.setTo(jid); message.setID(node.getNodeID() + "__" + jid.toBareJID() + "__" + StringUtils.randomString(5)); router.route(message); } } public void sendNotification(Node node, Message message, JID recipientJID) { message.setTo(recipientJID); message.setFrom(getAddress()); message.setID(node.getNodeID() + "__" + recipientJID.toBareJID() + "__" + StringUtils.randomString(5)); // If the recipient subscribed with a bare JID and this PEPService can retrieve // presence information for the recipient, collect all of their full JIDs and // send the notification to each below. Set<JID> recipientFullJIDs = new HashSet<JID>(); if (XMPPServer.getInstance().isLocal(recipientJID)) { if (recipientJID.getResource() == null) { for (ClientSession clientSession : SessionManager.getInstance().getSessions(recipientJID.getNode())) { recipientFullJIDs.add(clientSession.getAddress()); } } } else { // Since recipientJID is not local, try to get presence info from cached known remote // presences. Map<String, Set<JID>> knownRemotePresences = XMPPServer.getInstance().getIQPEPHandler().getKnownRemotePresenes(); Set<JID> remotePresenceSet = knownRemotePresences.get(getAddress().toBareJID()); if (remotePresenceSet != null) { for (JID remotePresence : remotePresenceSet) { if (recipientJID.toBareJID().equals(remotePresence.toBareJID())) { recipientFullJIDs.add(remotePresence); } } } } if (recipientFullJIDs.isEmpty()) { router.route(message); return; } for (JID recipientFullJID : recipientFullJIDs) { // Include an Extended Stanza Addressing "replyto" extension specifying the publishing // resource. However, only include the extension if the receiver has a presence subscription // to the service owner. try { JID publisher = null; // Get the ID of the node that had an item published to or retracted from. Element itemsElement = message.getElement().element("event").element("items"); String nodeID = itemsElement.attributeValue("node"); // Get the ID of the item that was published or retracted. String itemID = null; Element itemElement = itemsElement.element("item"); if (itemElement == null) { Element retractElement = itemsElement.element("retract"); if (retractElement != null) { itemID = retractElement.attributeValue("id"); } } else { itemID = itemElement.attributeValue("id"); } // Check if the recipientFullJID is interested in notifications for this node. // If the recipient has not yet requested any notification filtering, continue and send // the notification. EntityCapabilities entityCaps = entityCapsManager.getEntityCapabilities(recipientFullJID); if (entityCaps != null) { if (!entityCaps.containsFeature(nodeID + "+notify")) { return; } } // Get the full JID of the item publisher from the node that was published to. // This full JID will be used as the "replyto" address in the addressing extension. if (node.isCollectionNode()) { for (Node leafNode : node.getNodes()) { if (leafNode.getNodeID().equals(nodeID)) { publisher = leafNode.getPublishedItem(itemID).getPublisher(); // Ensure the recipientJID has access to receive notifications for items published to the leaf node. AccessModel accessModel = leafNode.getAccessModel(); if (!accessModel.canAccessItems(leafNode, recipientFullJID, publisher)) { return; } break; } } } else { publisher = node.getPublishedItem(itemID).getPublisher(); } // Ensure the recipient is subscribed to the service owner's (publisher's) presence. if (canProbePresence(publisher, recipientFullJID)) { Element addresses = DocumentHelper.createElement(QName.get("addresses", "http://jabber.org/protocol/address")); Element address = addresses.addElement("address"); address.addAttribute("type", "replyto"); address.addAttribute("jid", publisher.toString()); Message extendedMessage = message.createCopy(); extendedMessage.addExtension(new PacketExtension(addresses)); extendedMessage.setTo(recipientFullJID); router.route(extendedMessage); } } catch (IndexOutOfBoundsException e) { // Do not add addressing extension to message. } catch (UserNotFoundException e) { // Do not add addressing extension to message. router.route(message); } catch (NullPointerException e) { try { if (canProbePresence(getAddress(), recipientFullJID)) { message.setTo(recipientFullJID); } } catch (UserNotFoundException e1) { // Do nothing } router.route(message); } } } /** * Sends an event notification for the last published item of each leaf node under the * root collection node to the recipient JID. If the recipient has no subscription to * the root collection node, has not yet been authorized, or is pending to be * configured -- then no notifications are going to be sent.<p> * * Depending on the subscription configuration the event notifications may or may not have * a payload, may not be sent if a keyword (i.e. filter) was defined and it was not matched. * * @param recipientJID the recipient that is to receive the last published item notifications. */ public void sendLastPublishedItems(JID recipientJID) { // Ensure the recipient has a subscription to this service's root collection node. NodeSubscription subscription = rootCollectionNode.getSubscription(recipientJID); if (subscription == null) { subscription = rootCollectionNode.getSubscription(new JID(recipientJID.toBareJID())); } if (subscription == null) { return; } // Send the last published item of each leaf node to the recipient. for (Node leafNode : rootCollectionNode.getNodes()) { // Retrieve last published item for the leaf node. PublishedItem leafLastPublishedItem = null; leafLastPublishedItem = leafNode.getLastPublishedItem(); if (leafLastPublishedItem == null) { continue; } // Check if the published item can be sent to the subscriber if (!subscription.canSendPublicationEvent(leafLastPublishedItem.getNode(), leafLastPublishedItem)) { return; } // Send event notification to the subscriber Message notification = new Message(); Element event = notification.getElement().addElement("event", "http://jabber.org/protocol/pubsub#event"); Element items = event.addElement("items"); items.addAttribute("node", leafLastPublishedItem.getNode().getNodeID()); Element item = items.addElement("item"); if (((LeafNode) leafLastPublishedItem.getNode()).isItemRequired()) { item.addAttribute("id", leafLastPublishedItem.getID()); } if (leafLastPublishedItem.getNode().isPayloadDelivered() && leafLastPublishedItem.getPayload() != null) { item.add(leafLastPublishedItem.getPayload().createCopy()); } // Add a message body (if required) if (subscription.isIncludingBody()) { notification.setBody(LocaleUtils.getLocalizedString("pubsub.notification.message.body")); } // Include date when published item was created notification.getElement().addElement("x", "jabber:x:delay").addAttribute("stamp", fastDateFormat.format(leafLastPublishedItem.getCreationDate())); // Send the event notification to the subscriber this.sendNotification(subscription.getNode(), notification, subscription.getJID()); } } public void queueItemToAdd(PublishedItem newItem) { PubSubEngine.queueItemToAdd(this, newItem); } public void queueItemToRemove(PublishedItem removedItem) { PubSubEngine.queueItemToRemove(this, removedItem); } public Map<String, Map<String, String>> getBarePresences() { return barePresences; } public Queue<PublishedItem> getItemsToAdd() { return itemsToAdd; } public Queue<PublishedItem> getItemsToDelete() { return itemsToDelete; } public AdHocCommandManager getManager() { return adHocCommandManager; } public PublishedItemTask getPublishedItemTask() { return publishedItemTask; } public void setPublishedItemTask(PublishedItemTask task) { publishedItemTask = task; } public Timer getTimer() { return timer; } public int getItemsTaskTimeout() { return items_task_timeout; } public void setItemsTaskTimeout(int timeout) { items_task_timeout = timeout; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -