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

📄 pubsubengine.java

📁 openfire 服务器源码下载
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                        parentNode = (CollectionNode) tempNode;                    }                }                field = completedForm.getField("pubsub#node_type");                if (field != null) {                    // Check if user requested to create a new collection node                    List<String> values = field.getValues();                    if (!values.isEmpty()) {                        collectionType = "collection".equals(values.get(0));                    }                }            }        }        // If no parent was defined then use the root collection node        if (parentNode == null && service.isCollectionNodesSupported()) {            parentNode = service.getRootCollectionNode();        }        // Check that the requested nodeID does not exist        Node existingNode = service.getNode(newNodeID);        if (existingNode != null) {            // There is a conflict since a node with the same ID already exists            sendErrorPacket(iq, PacketError.Condition.conflict, null);            return;        }        if (collectionType && !service.isCollectionNodesSupported()) {            // Cannot create a collection node since the service doesn't support it            Element pubsubError = DocumentHelper.createElement(                    QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors"));            pubsubError.addAttribute("feature", "collections");            sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);            return;        }        if (parentNode != null && !collectionType) {            // Check if requester is allowed to add a new leaf child node to the parent node            if (!parentNode.isAssociationAllowed(from)) {                // User is not allowed to add child leaf node to parent node. Return an error.                sendErrorPacket(iq, PacketError.Condition.forbidden, null);                return;            }            // Check if number of child leaf nodes has not been exceeded            if (parentNode.isMaxLeafNodeReached()) {                // Max number of child leaf nodes has been reached. Return an error.                Element pubsubError = DocumentHelper.createElement(QName.get("max-nodes-exceeded",                        "http://jabber.org/protocol/pubsub#errors"));                sendErrorPacket(iq, PacketError.Condition.conflict, pubsubError);                return;            }        }        // Create and configure the node        boolean conflict = false;        Node newNode = null;        try {            // TODO Assumed that the owner of the subscription is the bare JID of the subscription JID. Waiting StPeter answer for explicit field.            JID owner = new JID(from.toBareJID());            synchronized (newNodeID.intern()) {                if (service.getNode(newNodeID) == null) {                    // Create the node                    if (collectionType) {                        newNode = new CollectionNode(service, parentNode, newNodeID, from);                    }                    else {                        newNode = new LeafNode(service, parentNode, newNodeID, from);                    }                    // Add the creator as the node owner                    newNode.addOwner(owner);                    // Configure and save the node to the backend store                    if (completedForm != null) {                        newNode.configure(completedForm);                    }                    else {                        newNode.saveToDB();                    }                }                else {                    conflict = true;                }            }            if (conflict) {                // There is a conflict since a node with the same ID already exists                sendErrorPacket(iq, PacketError.Condition.conflict, null);            }            else {                // Return success to the node owner                IQ reply = IQ.createResultIQ(iq);                // Include new nodeID if it has changed from the original nodeID                if (!newNode.getNodeID().equals(nodeID)) {                    Element elem =                            reply.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");                    elem.addElement("create").addAttribute("node", newNode.getNodeID());                }                router.route(reply);            }        }        catch (NotAcceptableException e) {            // Node should have at least one owner. Return not-acceptable error.            sendErrorPacket(iq, PacketError.Condition.not_acceptable, null);        }    }    private void getNodeConfiguration(PubSubService service, IQ iq, Element childElement, String nodeID) {        Node node = service.getNode(nodeID);        if (node == null) {            // Node does not exist. Return item-not-found error            sendErrorPacket(iq, PacketError.Condition.item_not_found, null);            return;        }        if (!node.isAdmin(iq.getFrom())) {            // Requesting entity is prohibited from configuring this node. Return forbidden error            sendErrorPacket(iq, PacketError.Condition.forbidden, null);            return;        }        // Return data form containing node configuration to the owner        IQ reply = IQ.createResultIQ(iq);        Element replyChildElement = childElement.createCopy();        reply.setChildElement(replyChildElement);        replyChildElement.element("configure").add(node.getConfigurationForm().getElement());        router.route(reply);    }    private void getDefaultNodeConfiguration(PubSubService service, IQ iq,                                             Element childElement, Element defaultElement) {        String type = defaultElement.attributeValue("type");        type = type == null ? "leaf" : type;        boolean isLeafType = "leaf".equals(type);        DefaultNodeConfiguration config = service.getDefaultNodeConfiguration(isLeafType);        if (config == null) {            // Service does not support the requested node type so return an error            Element pubsubError = DocumentHelper.createElement(                    QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors"));            pubsubError.addAttribute("feature", isLeafType ? "leaf" : "collections");            sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);            return;        }        // Return data form containing default node configuration        IQ reply = IQ.createResultIQ(iq);        Element replyChildElement = childElement.createCopy();        reply.setChildElement(replyChildElement);        replyChildElement.element("default").add(config.getConfigurationForm().getElement());        router.route(reply);    }    private void configureNode(PubSubService service, IQ iq, Element configureElement, String nodeID) {        Node node = service.getNode(nodeID);        if (node == null) {            // Node does not exist. Return item-not-found error            sendErrorPacket(iq, PacketError.Condition.item_not_found, null);            return;        }        if (!node.isAdmin(iq.getFrom())) {            // Requesting entity is not allowed to get node configuration. Return forbidden error            sendErrorPacket(iq, PacketError.Condition.forbidden, null);            return;        }        // Get the data form that contains the parent nodeID        DataForm completedForm = getSentConfigurationForm(configureElement);        if (completedForm != null) {            try {                // Update node configuration with the provided data form                // (and update the backend store)                node.configure(completedForm);                // Return that node configuration was successful                router.route(IQ.createResultIQ(iq));            }            catch (NotAcceptableException e) {                // Node should have at least one owner. Return not-acceptable error.                sendErrorPacket(iq, PacketError.Condition.not_acceptable, null);            }        }        else {            // No data form was included so return bad-request error            sendErrorPacket(iq, PacketError.Condition.bad_request, null);        }    }    private void deleteNode(PubSubService service, IQ iq, Element deleteElement) {        String nodeID = deleteElement.attributeValue("node");        if (nodeID == null) {            // NodeID was not provided. Return bad-request error            sendErrorPacket(iq, PacketError.Condition.bad_request, null);            return;        }        Node node = service.getNode(nodeID);        if (node == null) {            // Node does not exist. Return item-not-found error            sendErrorPacket(iq, PacketError.Condition.item_not_found, null);            return;        }        if (!node.isAdmin(iq.getFrom())) {            // Requesting entity is prohibited from deleting this node. Return forbidden error            sendErrorPacket(iq, PacketError.Condition.forbidden, null);            return;        }        if (node.isRootCollectionNode()) {            // Root collection node cannot be deleted. Return not-allowed error            sendErrorPacket(iq, PacketError.Condition.not_allowed, null);            return;        }        // Delete the node        if (node.delete()) {            // Return that node was deleted successfully            router.route(IQ.createResultIQ(iq));        }        else {            // Some error occured while trying to delete the node            sendErrorPacket(iq, PacketError.Condition.internal_server_error, null);        }    }    private void purgeNode(PubSubService service, IQ iq, Element purgeElement) {        String nodeID = purgeElement.attributeValue("node");        if (nodeID == null) {            // NodeID was not provided. Return bad-request error            sendErrorPacket(iq, PacketError.Condition.bad_request, null);            return;        }        Node node = service.getNode(nodeID);        if (node == null) {            // Node does not exist. Return item-not-found error            sendErrorPacket(iq, PacketError.Condition.item_not_found, null);            return;        }        if (!node.isAdmin(iq.getFrom())) {            // Requesting entity is prohibited from configuring this node. Return forbidden error            sendErrorPacket(iq, PacketError.Condition.forbidden, null);            return;        }        if (!((LeafNode) node).isPersistPublishedItems()) {            // Node does not persist items. Return feature-not-implemented error            Element pubsubError = DocumentHelper.createElement(                    QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors"));            pubsubError.addAttribute("feature", "persistent-items");            sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);            return;        }        if (node.isCollectionNode()) {            // Node is a collection node. Return feature-not-implemented error            Element pubsubError = DocumentHelper.createElement(                    QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors"));            pubsubError.addAttribute("feature", "purge-nodes");            sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);            return;        }        // Purge the node        ((LeafNode) node).purge();        // Return that node purged successfully        router.route(IQ.createResultIQ(iq));    }    private void getNodeSubscriptions(PubSubService service, IQ iq, Element affiliationsElement) {        String nodeID = affiliationsElement.attributeValue("node");        if (nodeID == null) {            // NodeID was not provided. Return bad-request error.            sendErrorPacket(iq, PacketError.Condition.bad_request, null);            return;        }        Node node = service.getNode(nodeID);        if (node == null) {            // Node does not exist. Return item-not-found error.            sendErrorPacket(iq, PacketError.Condition.item_not_found, null);            return;        }        if (!node.isAdmin(iq.getFrom())) {            // Requesting entity i

⌨️ 快捷键说明

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