Search in sources :

Example 1 with PEPServiceManager

use of org.jivesoftware.openfire.pep.PEPServiceManager 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)

Example 2 with PEPServiceManager

use of org.jivesoftware.openfire.pep.PEPServiceManager in project Openfire by igniterealtime.

the class NodeTask method getServiceIfLoaded.

/**
 * Finds the pubsub service for the pubsub node that is the subject of this task.
 *
 * Note that null, instead of a pubsub service instance, might be returned when the pubsub service is not currently
 * loaded in-memory on the cluster node that the task is executing on (although there is no guarantee that when this
 * method returns a non-null pubsub service, it was previously not loaded in-memory)! The rationale for this is that
 * this cluster tasks does not need to operate on data that is not in memory, as such operations are the
 * responsibility of the cluster node that initiates the cluster task.
 *
 * @return A pubsub service
 */
@Nonnull
public Optional<PubSubService> getServiceIfLoaded() {
    if (XMPPServer.getInstance().getPubSubModule().getServiceID().equals(serviceId)) {
        return Optional.of(XMPPServer.getInstance().getPubSubModule());
    } else {
        PEPServiceManager serviceMgr = XMPPServer.getInstance().getIQPEPHandler().getServiceManager();
        JID service = new JID(serviceId);
        return serviceMgr.hasCachedService(service) ? Optional.of(serviceMgr.getPEPService(service)) : Optional.empty();
    }
}
Also used : JID(org.xmpp.packet.JID) PEPServiceManager(org.jivesoftware.openfire.pep.PEPServiceManager) Nonnull(javax.annotation.Nonnull)

Example 3 with PEPServiceManager

use of org.jivesoftware.openfire.pep.PEPServiceManager in project Openfire by igniterealtime.

the class PrivateStorage method get.

/**
 * Returns the data stored under a key corresponding to the name and namespace
 * of the given element. The Element must be in the form:<p>
 *
 * <code>&lt;name xmlns='namespace'/&gt;</code><p>
 *
 * If no data is currently stored under the given key, an empty element will be
 * returned.
 *
 * @param data an XML document who's element name and namespace is used to
 *      match previously stored private data.
 * @param username the username of the account where private data is being stored.
 * @return the data stored under the given key or the data element.
 */
public Element get(String username, Element data) {
    if (enabled) {
        final PEPServiceManager serviceMgr = XMPPServer.getInstance().getIQPEPHandler().getServiceManager();
        final PEPService pepService = serviceMgr.getPEPService(XMPPServer.getInstance().createJID(username, null));
        if (pepService != null) {
            final Node node = pepService.getNode(data.getNamespaceURI());
            if (node != null) {
                final PublishedItem item = node.getPublishedItem("current");
                if (item != null) {
                    data.clearContent();
                    data = item.getPayload();
                }
            }
        }
    }
    return data;
}
Also used : PEPServiceManager(org.jivesoftware.openfire.pep.PEPServiceManager) PEPService(org.jivesoftware.openfire.pep.PEPService) Node(org.jivesoftware.openfire.pubsub.Node) LeafNode(org.jivesoftware.openfire.pubsub.LeafNode) PublishedItem(org.jivesoftware.openfire.pubsub.PublishedItem)

Example 4 with PEPServiceManager

use of org.jivesoftware.openfire.pep.PEPServiceManager in project Openfire by igniterealtime.

the class Node method getService.

/**
 * Returns the {@link PubSubService} to which this node belongs.
 *
 * @return the pubsub service.
 */
public PubSubService getService() {
    if (service == null) {
        if (getUniqueIdentifier().getServiceIdentifier().equals(XMPPServer.getInstance().getPubSubModule().getUniqueIdentifier())) {
            service = XMPPServer.getInstance().getPubSubModule();
        } else {
            final PEPServiceManager serviceMgr = XMPPServer.getInstance().getIQPEPHandler().getServiceManager();
            service = serviceMgr.getPEPService(getUniqueIdentifier().getServiceIdentifier(), false);
        }
    }
    return service;
}
Also used : PEPServiceManager(org.jivesoftware.openfire.pep.PEPServiceManager)

Example 5 with PEPServiceManager

use of org.jivesoftware.openfire.pep.PEPServiceManager in project Openfire by igniterealtime.

the class PublishedItem method getNode.

/**
 * Returns the {@link LeafNode} where this item was published.
 *
 * @return the leaf node where this item was published.
 */
public LeafNode getNode() {
    if (node == null) {
        synchronized (this) {
            if (node == null) {
                if (XMPPServer.getInstance().getPubSubModule().getServiceID().equals(serviceId)) {
                    node = (LeafNode) XMPPServer.getInstance().getPubSubModule().getNode(nodeId);
                } else {
                    PEPServiceManager serviceMgr = XMPPServer.getInstance().getIQPEPHandler().getServiceManager();
                    JID service = new JID(serviceId);
                    node = serviceMgr.hasCachedService(service) ? (LeafNode) serviceMgr.getPEPService(service).getNode(nodeId) : null;
                }
            }
        }
    }
    return node;
}
Also used : JID(org.xmpp.packet.JID) PEPServiceManager(org.jivesoftware.openfire.pep.PEPServiceManager)

Aggregations

PEPServiceManager (org.jivesoftware.openfire.pep.PEPServiceManager)5 JID (org.xmpp.packet.JID)3 PEPService (org.jivesoftware.openfire.pep.PEPService)2 LeafNode (org.jivesoftware.openfire.pubsub.LeafNode)2 Node (org.jivesoftware.openfire.pubsub.Node)2 Nonnull (javax.annotation.Nonnull)1 Element (org.dom4j.Element)1 PubSubEngine (org.jivesoftware.openfire.pubsub.PubSubEngine)1 PublishedItem (org.jivesoftware.openfire.pubsub.PublishedItem)1