Example usage for org.dom4j QName get

List of usage examples for org.dom4j QName get

Introduction

In this page you can find the example usage for org.dom4j QName get.

Prototype

public static QName get(String qualifiedName, String uri) 

Source Link

Usage

From source file:android.apn.androidpn.server.xmpp.handler.IQAuthHandler.java

License:Open Source License

/**
 * Constructor.//from www  .j  a  va2 s.  c  o  m
 */
public IQAuthHandler() {
    probeResponse = DocumentHelper.createElement(QName.get("query", NAMESPACE));
    probeResponse.addElement("username");
    if (AuthManager.isPlainSupported()) {
        probeResponse.addElement("password");
    }
    if (AuthManager.isDigestSupported()) {
        probeResponse.addElement("digest");
    }
    probeResponse.addElement("resource");
}

From source file:android.apn.androidpn.server.xmpp.handler.IQRegisterHandler.java

License:Open Source License

/**
 * Constructor.//from   www.  j a v a  2  s  .  co m
 */
public IQRegisterHandler() {
    userService = ServiceLocator.getUserService();
    probeResponse = DocumentHelper.createElement(QName.get("query", NAMESPACE));
    probeResponse.addElement("username");
    probeResponse.addElement("password");
    probeResponse.addElement("email");
    probeResponse.addElement("name");
}

From source file:android.apn.androidpn.server.xmpp.push.NotificationManager.java

License:Open Source License

/**
 * Creates a new notification IQ and returns it.
 *//* ww  w  .ja va 2 s  .c  o  m*/
private IQ createNotificationIQ(String apiKey, String title, String message, String uri) {
    Random random = new Random();
    String id = Integer.toHexString(random.nextInt());
    // String id = String.valueOf(System.currentTimeMillis());

    Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE));
    notification.addElement("id").setText(id);
    notification.addElement("apiKey").setText(apiKey);
    notification.addElement("title").setText(title);
    notification.addElement("message").setText(message);
    notification.addElement("uri").setText(uri);

    IQ iq = new IQ();
    iq.setType(IQ.Type.set);
    iq.setChildElement(notification);

    return iq;
}

From source file:com.adspore.splat.xep0060.models.AuthorizeAccess.java

License:Open Source License

@Override
public Element getSubsriptionErrorDetail() {
    return DocumentHelper
            .createElement(QName.get("not-subscribed", "http://jabber.org/protocol/pubsub#errors"));
}

From source file:com.adspore.splat.xep0060.models.PresenceAccess.java

License:Open Source License

@Override
public Element getSubsriptionErrorDetail() {
    return DocumentHelper.createElement(
            QName.get("presence-subscription-required", "http://jabber.org/protocol/pubsub#errors"));
}

From source file:com.adspore.splat.xep0060.models.RosterAccess.java

License:Open Source License

@Override
public Element getSubsriptionErrorDetail() {
    return DocumentHelper
            .createElement(QName.get("not-in-roster-group", "http://jabber.org/protocol/pubsub#errors"));
}

From source file:com.adspore.splat.xep0060.models.WhitelistAccess.java

License:Open Source License

@Override
public Element getSubsriptionErrorDetail() {
    return DocumentHelper.createElement(QName.get("closed-node", "http://jabber.org/protocol/pubsub#errors"));
}

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

License:Open Source License

/**
 * Handles IQ packets sent to the pubsub service. Requests of disco#info and disco#items
 * are not being handled by the engine. Instead the service itself should handle disco packets.
 *
 * @param service the PubSub service this action is to be performed for.
 * @param iq the IQ packet sent to the pubsub service.
 * @return true if the IQ packet was handled by the engine.
 */// w w w .  j  a  v a2s  . com
public static IQ process(PubSubService service, IQ iq) {
    // Ignore IQs of type ERROR or RESULT
    if (IQ.Type.error == iq.getType() || IQ.Type.result == iq.getType()) {
        return createErrorPacket(iq, Condition.bad_request, null);
    }

    Element childElement = iq.getChildElement();
    String namespace = null;

    if (childElement != null) {
        namespace = childElement.getNamespaceURI();
    }

    //   PUBSUB
    if ("http://jabber.org/protocol/pubsub".equals(namespace)) {

        //   PUBLISH
        Element action = childElement.element("publish");
        if (action != null) {
            // Entity publishes an item
            return publishItemsToNode(service, iq, action);
        }

        //   SUBSCRIBE
        action = childElement.element("subscribe");
        if (action != null) {
            // Entity subscribes to a node
            return subscribeNode(service, iq, childElement, action);
        }

        //   OPTIONS
        action = childElement.element("options");
        if (action != null) {
            if (IQ.Type.get == iq.getType()) {
                // Subscriber requests subscription options form
                return getSubscriptionConfiguration(service, iq, childElement, action);
            } else {
                // Subscriber submits completed options form
                return configureSubscription(service, iq, action);
            }
        }

        //   CREATE
        action = childElement.element("create");
        if (action != null) {
            // Entity is requesting to create a new node
            return createNode(service, iq, childElement, action);
        }

        //   UNSUBSCRIBE
        action = childElement.element("unsubscribe");
        if (action != null) {
            // Entity unsubscribes from a node
            return unsubscribeNode(service, iq, action);
        }

        //   GET SUBSCRIPTIONS
        action = childElement.element("subscriptions");
        if (action != null) {
            // Entity requests all current subscriptions
            return getSubscriptions(service, iq, childElement);
        }

        //   GET AFFILIATIONS
        action = childElement.element("affiliations");
        if (action != null) {
            // Entity requests all current affiliations
            return getAffiliations(service, iq, childElement);
        }

        //   GET ITEMS
        action = childElement.element("items");
        if (action != null) {
            // Subscriber requests all active items
            return getPublishedItems(service, iq, action);
        }

        //   RETRACT
        action = childElement.element("retract");
        if (action != null) {
            // Entity deletes an item
            return deleteItems(service, iq, action);
        }

        // Unknown action requested
        //   TODO:  Add error packet
        return createErrorPacket(iq, PacketError.Condition.bad_request, null);
    }

    else if ("http://jabber.org/protocol/pubsub#owner".equals(namespace)) {
        //   CONFIGURE
        Element action = childElement.element("configure");
        if (action != null) {
            String nodeID = action.attributeValue("node");
            if (nodeID == null) {
                // if user is not sysadmin then return nodeid-required error
                if (!service.isServiceAdmin(iq.getFrom()) || !service.isCollectionNodesSupported()) {
                    // Configure elements must have a node attribute so answer an error
                    Element pubsubError = DocumentHelper.createElement(
                            QName.get("nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
                    return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
                } else {
                    // Sysadmin is trying to configure root collection node
                    nodeID = service.getRootCollectionNode().getNodeID();
                }
            }
            if (IQ.Type.get == iq.getType()) {
                // Owner requests configuration form of a node
                return getNodeConfiguration(service, iq, childElement, nodeID);
            } else {
                // Owner submits or cancels node configuration form
                configureNode(service, iq, action, nodeID);
            }
        }

        //   DEFAULT
        action = childElement.element("default");
        if (action != null) {
            // Owner requests default configuration options for
            // leaf or collection nodes
            return getDefaultNodeConfiguration(service, iq, childElement, action);
        }

        //   DELETE
        action = childElement.element("delete");
        if (action != null) {
            // Owner deletes a node
            return deleteNode(service, iq, action);
        }

        //   SUBSCRIPTIONS
        action = childElement.element("subscriptions");
        if (action != null) {
            if (IQ.Type.get == iq.getType()) {
                // Owner requests all affiliated entities
                return getNodeSubscriptions(service, iq, action);
            } else {
                return modifyNodeSubscriptions(service, iq, action);
            }
        }

        //   AFFILIATIONS
        action = childElement.element("affiliations");
        if (action != null) {
            if (IQ.Type.get == iq.getType()) {
                // Owner requests all affiliated entities
                return getNodeAffiliations(service, iq, action);
            } else {
                return modifyNodeAffiliations(service, iq, action);
            }
        }

        //   PURGE
        action = childElement.element("purge");
        if (action != null) {
            // Owner purges items from a node
            return purgeNode(service, iq, action);

        }
    }

    //   TODO:  Temporarily blocking commands; this should be handled by the command service, not pubsub
    //        //   GET COMMANDS
    //        else if (SplatNamespaces.NAMESPACE_COMMANDS.equals(namespace)) {
    //            // Process ad-hoc command
    //            IQ reply = service.getManager().process(iq);
    //            router.route(reply);
    //            return true;
    //        }
    return createErrorPacket(iq, PacketError.Condition.bad_request, null);
}

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

License:Open Source License

private static IQ publishItemsToNode(PubSubService service, IQ iq, Element publishElement) {
    String nodeID = publishElement.attributeValue("node");

    if (nodeID == null) {
        // No node was specified. Return bad_request error
        Element pubsubError = DocumentHelper
                .createElement(QName.get("nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
        return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
    }//from w w  w  . j  av  a2  s  .  c  o m

    // Look for the specified node
    Node node = service.getNode(nodeID);
    if (node == null) {
        // Node does not exist. Return item-not-found error
        return createErrorPacket(iq, PacketError.Condition.item_not_found, null);
    }

    JID from = iq.getFrom();
    // TODO Assuming that owner is the bare JID (as defined in the JEP). This can be replaced with an explicit owner specified in the packet
    JID owner = new JID(from.getNode(), from.getDomain(), null, true);
    if (!node.getPublisherModel().canPublish(node, owner) && !service.isServiceAdmin(owner)) {
        // Entity does not have sufficient privileges to publish to node
        return createErrorPacket(iq, PacketError.Condition.forbidden, null);
    }

    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", "publish");
        return createErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);
    }

    LeafNode leafNode = (LeafNode) node;
    Iterator itemElements = publishElement.elementIterator("item");

    // Check that an item was included if node persist items or includes payload
    if (!itemElements.hasNext() && leafNode.isItemRequired()) {
        Element pubsubError = DocumentHelper
                .createElement(QName.get("item-required", "http://jabber.org/protocol/pubsub#errors"));
        return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
    }

    // Check that no item was included if node doesn't persist items and doesn't
    // includes payload
    if (itemElements.hasNext() && !leafNode.isItemRequired()) {
        Element pubsubError = DocumentHelper
                .createElement(QName.get("item-forbidden", "http://jabber.org/protocol/pubsub#errors"));
        return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
    }

    List<Element> items = new ArrayList<Element>();
    List entries;
    Element payload;
    while (itemElements.hasNext()) {
        Element item = (Element) itemElements.next();
        entries = item.elements();
        payload = entries.isEmpty() ? null : (Element) entries.get(0);
        // Check that a payload was included if node is configured to include payload
        // in notifications
        if (payload == null && leafNode.isPayloadDelivered()) {
            Element pubsubError = DocumentHelper
                    .createElement(QName.get("payload-required", "http://jabber.org/protocol/pubsub#errors"));
            return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
        }

        // Check that the payload (if any) contains only one child element
        if (entries.size() > 1) {
            Element pubsubError = DocumentHelper
                    .createElement(QName.get("invalid-payload", "http://jabber.org/protocol/pubsub#errors"));
            return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);

        }
        items.add(item);
    }

    // Publish item and send event notifications to subscribers
    leafNode.publishItems(from, items);
    // Return success operation
    return createSuccessPacket(iq);
}

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

License:Open Source License

private static IQ deleteItems(PubSubService service, IQ iq, Element retractElement) {
    String nodeID = retractElement.attributeValue("node");

    if (nodeID == null) {
        // No node was specified. Return bad_request error
        Element pubsubError = DocumentHelper
                .createElement(QName.get("nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
        return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
    }/*from  w  w w. jav a  2  s  .  c  om*/

    Node node;
    // Look for the specified node
    node = service.getNode(nodeID);
    if (node == null) {
        // Node does not exist. Return item-not-found error
        return createErrorPacket(iq, PacketError.Condition.item_not_found, null);
    }

    // Get the items to delete
    Iterator itemElements = retractElement.elementIterator("item");
    if (!itemElements.hasNext()) {
        Element pubsubError = DocumentHelper
                .createElement(QName.get("item-required", "http://jabber.org/protocol/pubsub#errors"));
        return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
    }

    if (node.isCollectionNode()) {
        // Cannot delete items from a collection node. Return an error.
        Element pubsubError = DocumentHelper
                .createElement(QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors"));
        pubsubError.addAttribute("feature", "persistent-items");
        return createErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);
    }
    LeafNode leafNode = (LeafNode) node;

    if (!leafNode.isItemRequired()) {
        // Cannot delete items from a leaf node that doesn't handle itemIDs. Return an error.
        Element pubsubError = DocumentHelper
                .createElement(QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors"));
        pubsubError.addAttribute("feature", "persistent-items");
        return createErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);
    }

    List<PublishedItem> items = new ArrayList<PublishedItem>();
    while (itemElements.hasNext()) {
        Element itemElement = (Element) itemElements.next();
        String itemID = itemElement.attributeValue("id");
        if (itemID != null) {
            PublishedItem item = node.getPublishedItem(itemID);
            if (item == null) {
                // ItemID does not exist. Return item-not-found error
                return createErrorPacket(iq, PacketError.Condition.item_not_found, null);
            } else {
                if (item.canDelete(iq.getFrom())) {
                    items.add(item);
                } else {
                    // Publisher does not have sufficient privileges to delete this item
                    createErrorPacket(iq, PacketError.Condition.forbidden, null);
                }
            }
        } else {
            // No item ID was specified so return a bad_request error
            Element pubsubError = DocumentHelper
                    .createElement(QName.get("item-required", "http://jabber.org/protocol/pubsub#errors"));
            return createErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
        }
    }
    // Send reply with success
    //router.route(IQ.createResultIQ(iq));
    // Delete items and send subscribers a notification
    leafNode.deleteItems(items);
    return createSuccessPacket(iq);
}