Example usage for org.dom4j Element addAttribute

List of usage examples for org.dom4j Element addAttribute

Introduction

In this page you can find the example usage for org.dom4j Element addAttribute.

Prototype

Element addAttribute(QName qName, String value);

Source Link

Document

Adds the attribute value of the given fully qualified name.

Usage

From source file:com.adspore.splat.xep0030.DiscoInfoHandler.java

License:Open Source License

protected void addAnonymousUser() {
    Element userIdentity = DocumentHelper.createElement("identity");
    userIdentity.addAttribute("category", "account");
    userIdentity.addAttribute("type", "anonymous");
    anonymousUserIdentities.add(userIdentity);
}

From source file:com.adspore.splat.xep0030.DiscoInfoHandler.java

License:Open Source License

protected void addRegisteredUser() {
    Element userIdentity = DocumentHelper.createElement("identity");
    userIdentity.addAttribute("category", "account");
    userIdentity.addAttribute("type", "registered");
    registeredUserIdentities.add(userIdentity);
}

From source file:com.adspore.splat.xep0060.CollectionNode.java

License:Open Source License

/**
 * Notification that a new node was created and added to this node. Trigger notifications
 * to node subscribers whose subscription type is {@link NodeSubscription.Type#nodes} and
 * have the proper depth./*from  w  w  w.j av  a2 s  .  co  m*/
 *
 * @param child the newly created node that was added to this node.
 */
void childNodeAdded(Node child) {
    // Build packet to broadcast to subscribers
    Message message = new Message();
    Element event = message.addChildElement("event", "http://jabber.org/protocol/pubsub#event");
    Element item = event.addElement("items").addElement("item");
    item.addAttribute("id", child.getNodeID());
    if (mDeliverPayloads) {
        item.add(child.getMetadataForm().getElement());
    }
    // Broadcast event notification to subscribers
    broadcastCollectionNodeEvent(child, message);
}

From source file:com.adspore.splat.xep0060.LeafNode.java

License:Open Source License

/**
 * Sends an IQ result with the list of items published to the node. Item ID and payload
 * may be included in the result based on the node configuration.
 *
 * @param originalRequest the IQ packet sent by a subscriber (or anyone) to get the node items.
 * @param publishedItems the list of published items to send to the subscriber.
 * @param forceToIncludePayload true if the item payload should be include if one exists. When
 *        false the decision is up to the node.
 *//*from ww w .j  a v  a2  s .co m*/
void sendPublishedItems(IQ originalRequest, List<PublishedItem> publishedItems, boolean forceToIncludePayload) {
    IQ result = IQ.createResultIQ(originalRequest);
    Element pubsubElem = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
    Element items = pubsubElem.addElement("items");
    items.addAttribute("node", getNodeID());

    for (PublishedItem publishedItem : publishedItems) {
        Element item = items.addElement("item");
        if (isItemRequired()) {
            item.addAttribute("id", publishedItem.getID());
        }
        if ((forceToIncludePayload || isPayloadDelivered()) && publishedItem.getPayload() != null) {
            item.add(publishedItem.getPayload().createCopy());
        }
    }
    // Send the result
    mService.send(result);
}

From source file:com.adspore.splat.xep0060.LeafNode.java

License:Open Source License

/**
 * Purges items that were published to the node. Only owners can request this operation.
 * This operation is only available for nodes configured to store items in the database. All
 * published items will be deleted with the exception of the last published item.
 *//*from  w ww.  j a  v  a  2  s .co m*/
public void purge() {
    //PubSubPersistenceManager.purgeNode(this);
    // Broadcast purge notification to subscribers
    // Build packet to broadcast to subscribers
    Message message = new Message();
    Element event = message.addChildElement("event", "http://jabber.org/protocol/pubsub#event");
    Element items = event.addElement("purge");
    items.addAttribute("node", mNodeID);
    // Send notification that the node configuration has changed
    broadcastNodeEvent(message, false);
}

From source file:com.adspore.splat.xep0060.Node.java

License:Open Source License

/**
 * The node configuration has changed. If this is the first time the node is configured
 * after it was created (i.e. is not yet persistent) then do nothing. Otherwise, send
 * a notification to the node subscribers informing that the configuration has changed.
 *//*  w w w  .  j  a v a2s  .co  m*/
private void nodeConfigurationChanged() {
    if (!isNotifiedOfConfigChanges() || !savedToDB) {
        // Do nothing if node was just created and configure or if notification
        // of config changes is disabled
        return;
    }

    // Build packet to broadcast to subscribers
    Message message = new Message();
    Element event = message.addChildElement("event", "http://jabber.org/protocol/pubsub#event");
    Element config = event.addElement("configuration");
    config.addAttribute("node", mNodeID);

    if (mDeliverPayloads) {
        config.add(getConfigurationChangeForm().getElement());
    }
    // Send notification that the node configuration has changed
    broadcastNodeEvent(message, false);
}

From source file:com.adspore.splat.xep0060.Node.java

License:Open Source License

/**
 * Deletes this node from memory and the database. Subscribers are going to be notified
 * that the node has been deleted after the node was successfully deleted.
 *
 * @return true if the node was successfully deleted.
 *//*from   w ww  .ja v a2  s  .  com*/
public boolean delete() {
    // Delete node from the database
    if (true) {
        // Remove this node from the parent node (if any)
        if (mParent != null) {
            mParent.removeChildNode(this);
        }
        deletingNode();
        // Broadcast delete notification to subscribers (if enabled)
        if (isNotifiedOfDelete()) {
            // Build packet to broadcast to subscribers
            Message message = new Message();
            Element event = message.addChildElement("event", "http://jabber.org/protocol/pubsub#event");
            Element items = event.addElement("delete");
            items.addAttribute("node", mNodeID);
            // Send notification that the node was deleted
            //   TODO:  This doesn't appear to be the same notification scheme as the publishing of events
            broadcastNodeEvent(message, true);
        }
        // Notify the parent (if any) that the node has been removed from the parent node
        if (mParent != null) {
            mParent.childNodeDeleted(this);
        }
        // Remove presence subscription when node was deleted.
        cancelPresenceSubscriptions();
        // Remove the node from memory
        mService.removeNode(getNodeID());

        // Clear collections in memory (clear them after broadcast was sent)
        affiliates.clear();
        subscriptionsByID.clear();
        subscriptionsByJID.clear();
        return true;
    }
    return false;
}

From source file:com.adspore.splat.xep0060.Node.java

License:Open Source License

/**
 * Sends the list of affiliations with the node to the owner that sent the IQ
 * request.//from  www  .j a  v a2s. c  o  m
 *
 * @param iqRequest IQ request sent by an owner of the node.
 */
void sendAffiliations(IQ iqRequest) {
    IQ reply = IQ.createResultIQ(iqRequest);
    Element childElement = iqRequest.getChildElement().createCopy();
    reply.setChildElement(childElement);
    Element affiliations = childElement.element("affiliations");

    for (NodeAffiliate affiliate : affiliates) {
        if (affiliate.getAffiliation() == NodeAffiliate.Affiliation.none) {
            continue;
        }
        Element entity = affiliations.addElement("affiliation");
        entity.addAttribute("jid", affiliate.getJID().toString());
        entity.addAttribute("affiliation", affiliate.getAffiliation().name());
    }
    // Send reply
    mService.send(reply);
}

From source file:com.adspore.splat.xep0060.Node.java

License:Open Source License

/**
 * Sends the list of subscriptions with the node to the owner that sent the IQ
 * request./*from   w ww .  j  a  v  a 2  s.c  om*/
 *
 * @param iqRequest IQ request sent by an owner of the node.
 */
void sendSubscriptions(IQ iqRequest) {
    IQ reply = IQ.createResultIQ(iqRequest);
    Element childElement = iqRequest.getChildElement().createCopy();
    reply.setChildElement(childElement);
    Element subscriptions = childElement.element("subscriptions");

    for (NodeAffiliate affiliate : affiliates) {
        for (NodeSubscription subscription : affiliate.getSubscriptions()) {
            if (subscription.isAuthorizationPending()) {
                continue;
            }
            Element entity = subscriptions.addElement("subscription");
            entity.addAttribute("jid", subscription.getJID().toString());
            //entity.addAttribute("affiliation", affiliate.getAffiliation().name());
            entity.addAttribute("subscription", subscription.getState().name());
            if (isMultipleSubscriptionsEnabled()) {
                entity.addAttribute("subid", subscription.getID());
            }
        }
    }
    // Send reply
    mService.send(reply);
}

From source file:com.adspore.splat.xep0060.Node.java

License:Open Source License

/**
 * Sends an event notification to the specified subscriber. The event notification may
 * include information about the affected subscriptions.
 *
 * @param subscriberJID the subscriber JID that will get the notification.
 * @param notification the message to send to the subscriber.
 * @param subIDs the list of affected subscription IDs or null when node does not
 *        allow multiple subscriptions.//w  w  w  .  j  a  v a 2  s  .co  m
 */
protected void sendEventNotification(JID subscriberJID, Message notification, Collection<String> subIDs) {
    Element headers = null;
    if (subIDs != null) {
        // Notate the event notification with the ID of the affected subscriptions
        headers = notification.addChildElement("headers", "http://jabber.org/protocol/shim");
        for (String subID : subIDs) {
            Element header = headers.addElement("header");
            header.addAttribute("name", "pubsub#subid");
            header.setText(subID);
        }
    }

    // Verify that the subscriber JID is currently available to receive notification 
    // messages. This is required because the message router will deliver packets via 
    // the bare JID if a session for the full JID is not available. The "isActiveRoute"
    // condition below will prevent inadvertent delivery of multiple copies of each
    // event notification to the user, possibly multiple times (e.g. route.all-resources). 
    // (Refer to http://issues.igniterealtime.org/browse/OF-14 for more info.)
    //
    // This approach is informed by the following XEP-0060 implementation guidelines:
    //   12.2 "Intended Recipients for Notifications" - only deliver to subscriber JID
    //   12.4 "Not Routing Events to Offline Storage" - no offline storage for notifications
    //
    // Note however that this may be somewhat in conflict with the following:
    //   12.3 "Presence-Based Delivery of Events" - automatically detect user's presence
    //

    //   FIXME:  Verify this is correct solution...  Commented out.
    Map<String, String> allSubPresences = mService.mComponent.getBarePresences().get(subscriberJID.toBareJID());
    if (null != allSubPresences && allSubPresences.containsKey(subscriberJID.toString())) {
        String status = allSubPresences.get(subscriberJID.toString());
        if (status.equals("online")) {
            mService.sendNotification(this, notification, subscriberJID);
        }
    }

    if (headers != null) {
        // Remove the added child element that includes subscription IDs information
        notification.getElement().remove(headers);
    }
}