Search in sources :

Example 1 with LeafNode

use of org.jivesoftware.openfire.pubsub.LeafNode in project Openfire by igniterealtime.

the class PrivateStorage method add.

/**
 * Stores private data. If the name and namespace of the element matches another
 * stored private data XML document, then replace it with the new one.
 *
 * @param data the data to store (XML element)
 * @param username the username of the account where private data is being stored
 */
public void add(String username, Element data) {
    if (!enabled) {
        return;
    }
    final JID owner = XMPPServer.getInstance().createJID(username, null);
    final PEPServiceManager serviceMgr = XMPPServer.getInstance().getIQPEPHandler().getServiceManager();
    PEPService pepService = serviceMgr.getPEPService(owner);
    if (pepService == null) {
        pepService = serviceMgr.create(owner);
    }
    Node node = pepService.getNode(data.getNamespaceURI());
    if (node == null) {
        PubSubEngine.CreateNodeResponse response = PubSubEngine.createNodeHelper(pepService, owner, pepService.getDefaultNodeConfiguration(true).getConfigurationForm().getElement(), data.getNamespaceURI(), PRIVATE_DATA_PUBLISHING_OPTIONS);
        node = response.newNode;
        if (node == null) {
            Log.error("Unable to create new PEP node, to be used to store private data. Error condition: {}", response.creationStatus.toXMPP());
            return;
        }
    }
    if (!(node instanceof LeafNode)) {
        Log.error("Unable to store private data into a PEP node. The node that is available is not a leaf node.");
        return;
    }
    data.detach();
    final Element item = DocumentHelper.createElement("item");
    item.addAttribute("id", "current");
    item.add(data);
    ((LeafNode) node).publishItems(owner, Collections.singletonList(item));
}
Also used : JID(org.xmpp.packet.JID) PEPServiceManager(org.jivesoftware.openfire.pep.PEPServiceManager) PEPService(org.jivesoftware.openfire.pep.PEPService) Node(org.jivesoftware.openfire.pubsub.Node) LeafNode(org.jivesoftware.openfire.pubsub.LeafNode) LeafNode(org.jivesoftware.openfire.pubsub.LeafNode) Element(org.dom4j.Element) PubSubEngine(org.jivesoftware.openfire.pubsub.PubSubEngine)

Aggregations

Element (org.dom4j.Element)1 PEPService (org.jivesoftware.openfire.pep.PEPService)1 PEPServiceManager (org.jivesoftware.openfire.pep.PEPServiceManager)1 LeafNode (org.jivesoftware.openfire.pubsub.LeafNode)1 Node (org.jivesoftware.openfire.pubsub.Node)1 PubSubEngine (org.jivesoftware.openfire.pubsub.PubSubEngine)1 JID (org.xmpp.packet.JID)1