⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pepservice.java

📁 openfire 服务器源码下载
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * $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.pep;import org.dom4j.DocumentHelper;import org.dom4j.Element;import org.dom4j.QName;import org.jivesoftware.openfire.PacketRouter;import org.jivesoftware.openfire.SessionManager;import org.jivesoftware.openfire.XMPPServer;import org.jivesoftware.openfire.commands.AdHocCommandManager;import org.jivesoftware.openfire.entitycaps.EntityCapabilities;import org.jivesoftware.openfire.entitycaps.EntityCapabilitiesManager;import org.jivesoftware.openfire.pubsub.*;import org.jivesoftware.openfire.pubsub.models.AccessModel;import org.jivesoftware.openfire.pubsub.models.PublisherModel;import org.jivesoftware.openfire.roster.Roster;import org.jivesoftware.openfire.roster.RosterItem;import org.jivesoftware.openfire.session.ClientSession;import org.jivesoftware.openfire.user.UserNotFoundException;import org.jivesoftware.util.FastDateFormat;import org.jivesoftware.util.LocaleUtils;import org.jivesoftware.util.StringUtils;import org.xmpp.packet.JID;import org.xmpp.packet.Message;import org.xmpp.packet.Packet;import org.xmpp.packet.PacketExtension;import java.util.*;import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.LinkedBlockingQueue;/** * A PEPService is a {@link PubSubService} for use with XEP-0163: "Personal Eventing via * Pubsub" Version 1.0 *  * @author Armando Jagucki *  */public class PEPService implements PubSubService {    /**     * The bare JID that this service is identified by.     */    private String serviceOwnerJID;    /**     * Collection node that acts as the root node of the entire node hierarchy.     */    private CollectionNode rootCollectionNode = null;    /**     * Nodes managed by this service, table: key nodeID (String); value Node     */    private Map<String, Node> nodes = new ConcurrentHashMap<String, Node>();    /**     * The packet router for the server.     */    private PacketRouter router = null;    /**     * Default configuration to use for newly created leaf nodes.     */    private DefaultNodeConfiguration leafDefaultConfiguration;    /**     * Default configuration to use for newly created collection nodes.     */    private DefaultNodeConfiguration collectionDefaultConfiguration;    /**     * Returns the permission policy for creating nodes. A true value means that     * not anyone can create a node, only the service admin.     */    private boolean nodeCreationRestricted = true;    /**     * Keep a registry of the presence's show value of users that subscribed to     * a node of the pep service and for which the node only delivers     * notifications for online users or node subscriptions deliver events based     * on the user presence show value. Offline users will not have an entry in     * the map. Note: Key-> bare JID and Value-> Map whose key is full JID of     * connected resource and value is show value of the last received presence.     */    private Map<String, Map<String, String>> barePresences = new ConcurrentHashMap<String, Map<String, String>>();    /**     * Queue that holds the items that need to be added to the database.     */    private Queue<PublishedItem> itemsToAdd = new LinkedBlockingQueue<PublishedItem>();    /**     * Queue that holds the items that need to be deleted from the database.     */    private Queue<PublishedItem> itemsToDelete = new LinkedBlockingQueue<PublishedItem>();    /**     * Manager that keeps the list of ad-hoc commands and processing command     * requests.     */    private AdHocCommandManager adHocCommandManager;    /**     * Used to handle filtered-notifications.     */    private EntityCapabilitiesManager entityCapsManager = EntityCapabilitiesManager.getInstance();    /**     * The time to elapse between each execution of the maintenance process.     * Default is 2 minutes.     */    private int items_task_timeout = 2 * 60 * 1000;    /**     * Task that saves or deletes published items from the database.     */    private PublishedItemTask publishedItemTask;    /**     * Timer to save published items to the database or remove deleted or old     * items.     */    private Timer timer = new Timer("PEP service maintenance");    /**     * Date format to use for time stamps in delayed event notifications.     */    private static final FastDateFormat fastDateFormat;    static {        fastDateFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("UTC"));    }    /**     * Constructs a PEPService.     *      * @param server  the XMPP server.     * @param bareJID the bare JID (service ID) of the user owning the service.     */    public PEPService(XMPPServer server, String bareJID) {        this.serviceOwnerJID = bareJID;        router = server.getPacketRouter();        // Initialize the ad-hoc commands manager to use for this pep service        adHocCommandManager = new AdHocCommandManager();        adHocCommandManager.addCommand(new PendingSubscriptionsCommand(this));        // Save or delete published items from the database every 2 minutes        // starting in 2 minutes (default values)        publishedItemTask = new PublishedItemTask(this);        timer.schedule(publishedItemTask, items_task_timeout, items_task_timeout);        // Load default configuration for leaf nodes        leafDefaultConfiguration = PubSubPersistenceManager.loadDefaultConfiguration(this, true);        if (leafDefaultConfiguration == null) {            // Create and save default configuration for leaf nodes;            leafDefaultConfiguration = new DefaultNodeConfiguration(true);            leafDefaultConfiguration.setAccessModel(AccessModel.presence);            leafDefaultConfiguration.setPublisherModel(PublisherModel.publishers);            leafDefaultConfiguration.setDeliverPayloads(true);            leafDefaultConfiguration.setLanguage("English");            leafDefaultConfiguration.setMaxPayloadSize(5120);            leafDefaultConfiguration.setNotifyConfigChanges(true);            leafDefaultConfiguration.setNotifyDelete(true);            leafDefaultConfiguration.setNotifyRetract(true);            leafDefaultConfiguration.setPersistPublishedItems(false);            leafDefaultConfiguration.setMaxPublishedItems(-1);            leafDefaultConfiguration.setPresenceBasedDelivery(false);            leafDefaultConfiguration.setSendItemSubscribe(true);            leafDefaultConfiguration.setSubscriptionEnabled(true);            leafDefaultConfiguration.setReplyPolicy(null);            PubSubPersistenceManager.createDefaultConfiguration(this, leafDefaultConfiguration);        }        // Load default configuration for collection nodes        collectionDefaultConfiguration = PubSubPersistenceManager.loadDefaultConfiguration(this, false);        if (collectionDefaultConfiguration == null) {            // Create and save default configuration for collection nodes;            collectionDefaultConfiguration = new DefaultNodeConfiguration(false);            collectionDefaultConfiguration.setAccessModel(AccessModel.presence);            collectionDefaultConfiguration.setPublisherModel(PublisherModel.publishers);            collectionDefaultConfiguration.setDeliverPayloads(false);            collectionDefaultConfiguration.setLanguage("English");            collectionDefaultConfiguration.setNotifyConfigChanges(true);            collectionDefaultConfiguration.setNotifyDelete(true);            collectionDefaultConfiguration.setNotifyRetract(true);            collectionDefaultConfiguration.setPresenceBasedDelivery(false);            collectionDefaultConfiguration.setSubscriptionEnabled(true);            collectionDefaultConfiguration.setReplyPolicy(null);            collectionDefaultConfiguration.setAssociationPolicy(CollectionNode.LeafNodeAssociationPolicy.all);            collectionDefaultConfiguration.setMaxLeafNodes(-1);            PubSubPersistenceManager.createDefaultConfiguration(this, collectionDefaultConfiguration);        }        // Load nodes to memory        PubSubPersistenceManager.loadNodes(this);        // Ensure that we have a root collection node        if (nodes.isEmpty()) {            // Create root collection node            JID creatorJID = new JID(bareJID);            rootCollectionNode = new CollectionNode(this, null, bareJID, creatorJID);            // Add the creator as the node owner            rootCollectionNode.addOwner(creatorJID);            // Save new root node            rootCollectionNode.saveToDB();        }        else {            rootCollectionNode = (CollectionNode) getNode(bareJID);        }    }    public void addNode(Node node) {        nodes.put(node.getNodeID(), node);    }    public void removeNode(String nodeID) {        nodes.remove(nodeID);    }    public Node getNode(String nodeID) {        return nodes.get(nodeID);    }    public Collection<Node> getNodes() {        return nodes.values();    }    public CollectionNode getRootCollectionNode() {        return rootCollectionNode;    }    public JID getAddress() {        return new JID(serviceOwnerJID);    }    public String getServiceID() {        // The bare JID of the user is the service ID for PEP        return serviceOwnerJID;    }    public DefaultNodeConfiguration getDefaultNodeConfiguration(boolean leafType) {        if (leafType) {            return leafDefaultConfiguration;        }        return collectionDefaultConfiguration;    }    public Collection<String> getShowPresences(JID subscriber) {        return PubSubEngine.getShowPresences(this, subscriber);    }    public boolean canCreateNode(JID creator) {        // Node creation is always allowed for sysadmin        if (isNodeCreationRestricted() && !isServiceAdmin(creator)) {            // The user is not allowed to create nodes            return false;        }        return true;    }    /**     * Returns true if the the prober is allowed to see the presence of the probee.     *     * @param prober the user that is trying to probe the presence of another user.     * @param probee the username of the uset that is being probed.     * @return true if the the prober is allowed to see the presence of the probee.     * @throws UserNotFoundException If the probee does not exist in the local server or the prober     *         is not present in the roster of the probee.     */    private boolean canProbePresence(JID prober, JID probee) throws UserNotFoundException {        Roster roster;        roster = XMPPServer.getInstance().getRosterManager().getRoster(prober.getNode());        RosterItem item = roster.getRosterItem(probee);        if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) {            return true;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -