Package org.apache.vysper.xmpp.stanza

Examples of org.apache.vysper.xmpp.stanza.StanzaBuilder$ElementStruct


        } catch (RosterException e) {
            return handleCannotRetrieveRoster(stanza, sessionContext);
        }

        // from becomes to
        StanzaBuilder stanzaBuilder = RosterStanzaUtils.createRosterItemsIQ(from, stanza.getID(), IQStanzaType.RESULT, roster);
        return stanzaBuilder.build();
    }
View Full Code Here


        CollectionNode root = serviceConfiguration.getRootNode();
       
        Entity sender = extractSenderJID(stanza, sessionContext);
        String iqStanzaID = stanza.getAttributeValue("id");

        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);
        sb.startInnerElement("pubsub", NamespaceURIs.XEP0060_PUBSUB);
        String nodeName = extractNodeName(stanza);
       
        List<SubscriptionItem> subscriptions = collectSubscriptions(root, sender, nodeName);

        buildSuccessStanza(sb, nodeName, subscriptions);

        sb.endInnerElement(); // pubsub
        return new IQStanza(sb.build());
    }
View Full Code Here

       
        Entity sender = extractSenderJID(stanza, sessionContext);

        String iqStanzaID = stanza.getAttributeValue("id");

        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);

        String nodeName = extractNodeName(stanza);

        if(root.find(nodeName) != null) {
            return errorStanzaGenerator.generateDuplicateNodeErrorStanza(sender, serverJID, stanza);
        }

        LeafNode node = new LeafNode(serviceConfiguration, nodeName, sender);
        root.add(node);

        return new IQStanza(sb.build());
    }
View Full Code Here

       
        Entity sender = extractSenderJID(stanza, sessionContext);

        String iqStanzaID = stanza.getAttributeValue("id");

        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);
        sb.startInnerElement("pubsub", NamespaceURIs.XEP0060_PUBSUB);

        XMLElement publish = stanza.getFirstInnerElement().getFirstInnerElement(); // pubsub/publish
        String nodeName = publish.getAttributeValue("node"); // MUST

        XMLElement item = publish.getFirstInnerElement();
        String strID = item.getAttributeValue("id"); // MAY

        LeafNode node = root.find(nodeName);

        if(node == null) {
            // node does not exist - error condition 3 (7.1.3)
            return errorStanzaGenerator.generateNoNodeErrorStanza(sender, serverJID, stanza);
        }

        if(!node.isAuthorized(sender, PubSubPrivilege.PUBLISH)) {
            // not enough privileges to publish - error condition 1 (7.1.3)
            return errorStanzaGenerator.generateInsufficientPrivilegesErrorStanza(sender, serverJID, stanza);
        }

        if(strID == null) {
            strID = idGenerator.create();
            // wrap a new item element with the id attribute
            StanzaBuilder itemBuilder = new StanzaBuilder("item");
            itemBuilder.addAttribute("id", strID);
            itemBuilder.addPreparedElement(item.getFirstInnerElement());
            item = itemBuilder.build();
        }

        StanzaRelay relay = serverRuntimeContext.getStanzaRelay();
        node.publish(sender, relay, strID, item);
View Full Code Here

        CollectionNode root = serviceConfiguration.getRootNode();
       
        Entity sender = extractSenderJID(stanza, sessionContext);
       
        String iqStanzaID = stanza.getAttributeValue("id");
        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);
        String nodeName = extractNodeName(stanza);
        LeafNode node = root.find(nodeName);
       
        if(node == null) {
            return errorStanzaGenerator.generateNoNodeErrorStanza(sender, serverJID, stanza);
        }
       
        if(!node.isAuthorized(sender, PubSubPrivilege.DELETE)) {
            return errorStanzaGenerator.generateInsufficientPrivilegesErrorStanza(sender, serverJID, stanza);
        }
       
        sendDeleteNotifications(serverRuntimeContext, sender, nodeName, node);
        root.deleteNode(nodeName);

        return new IQStanza(sb.build());
    }
View Full Code Here

        CollectionNode root = serviceConfiguration.getRootNode();
       
        Entity sender = extractSenderJID(stanza, sessionContext);
        String iqStanzaID = stanza.getAttributeValue("id");

        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);
        sb.startInnerElement("pubsub", NamespaceURIs.XEP0060_PUBSUB);
       
        List<AffiliationItem> subscriptions = collectAffiliations(root, sender);

        buildSuccessStanza(sb, subscriptions);

        sb.endInnerElement(); // pubsub
        return new IQStanza(sb.build());
    }
View Full Code Here

        Entity sender = extractSenderJID(stanza, sessionContext);
        Entity subJID = null;

        String iqStanzaID = stanza.getAttributeValue("id");

        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);
        sb.startInnerElement("pubsub", NamespaceURIs.XEP0060_PUBSUB);

        XMLElement unsub = stanza.getFirstInnerElement().getFirstInnerElement(); // pubsub/unsubscribe
        String strSubJID = unsub.getAttributeValue("jid"); // MUST
        String strSubID = unsub.getAttributeValue("subid"); // SHOULD (req. for more than one subscription)

        try {
            subJID = EntityImpl.parse(strSubJID);
        } catch (EntityFormatException e) {
            // return error stanza... (general error)
            return errorStanzaGenerator.generateJIDMalformedErrorStanza(sender, serverJID, stanza);
        }

        if(!sender.getBareJID().equals(subJID.getBareJID())) {
            // insufficient privileges (error condition 3 (6.2.3))
            return errorStanzaGenerator.generateInsufficientPrivilegesErrorStanza(sender, serverJID, stanza);
        }

        String nodeName = extractNodeName(stanza);
        LeafNode node = root.find(nodeName);

        if(node == null) {
            // no such node (error condition 4 (6.2.3))
            return errorStanzaGenerator.generateNoNodeErrorStanza(sender, serverJID, stanza);
        }

        if(strSubID == null) {
            try {
                if(node.unsubscribe(subJID) == false) {
                    // has no subscription (6.2.3.2)
                    return errorStanzaGenerator.generateNoSuchSubscriberErrorStanza(sender, serverJID, stanza);
                }
            } catch(MultipleSubscriptionException e) {
                // error case 6.2.3.1
                return errorStanzaGenerator.generateSubIDRequiredErrorStanza(sender, serverJID, stanza);
            }
        } else {
            if(node.unsubscribe(strSubID, subJID) == false) {
                // subID not valid (6.2.3.5)
                return errorStanzaGenerator.generateSubIDNotValidErrorStanza(sender, serverJID, stanza);
            }
        }

        sb.endInnerElement(); // pubsub
        return new IQStanza(sb.build());
    }
View Full Code Here

        CollectionNode root = serviceConfiguration.getRootNode();

        Entity sender = extractSenderJID(stanza, sessionContext);

        String iqStanzaID = stanza.getAttributeValue("id");
        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);
        sb.startInnerElement("pubsub", NamespaceURIs.XEP0060_PUBSUB_OWNER);
       
        String nodeName = extractNodeName(stanza);
        LeafNode node = root.find(nodeName);

        if(node == null) {
            return errorStanzaGenerator.generateNoNodeErrorStanza(sender, serverJID, stanza);
        }

        if(!node.isAuthorized(sender, PubSubPrivilege.MANAGE_AFFILIATIONS)) {
            return errorStanzaGenerator.generateInsufficientPrivilegesErrorStanza(sender, serverJID, stanza);
        }

        List<AffiliationItem> affiliations = collectAllAffiliations(node);
        buildSuccessStanza(sb, node, affiliations);

        sb.endInnerElement();
        return new IQStanza(sb.build());
    }
View Full Code Here

        Entity serverJID = serviceConfiguration.getServerJID();
        CollectionNode root = serviceConfiguration.getRootNode();
        Entity sender = extractSenderJID(stanza, sessionContext);

        String iqStanzaID = stanza.getAttributeValue("id");
        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);
        sb.startInnerElement("pubsub", NamespaceURIs.XEP0060_PUBSUB_OWNER);

        String nodeName = extractNodeName(stanza);
        LeafNode node = root.find(nodeName);

        if(node == null) {
            return errorStanzaGenerator.generateNoNodeErrorStanza(sender, serverJID, stanza);
        }

        if(!node.isAuthorized(sender, PubSubPrivilege.MANAGE_AFFILIATIONS)) {
            return errorStanzaGenerator.generateInsufficientPrivilegesErrorStanza(sender, serverJID, stanza);
        }


        XMLElement affiliationElement = null;
        try {
            if(stanza.getFirstInnerElement().getFirstInnerElement().getInnerElements().size() != 1) {
                return errorStanzaGenerator.generateNotAcceptableErrorStanza(serverJID, sender, stanza);
            }

            affiliationElement = stanza.getFirstInnerElement().getFirstInnerElement().getFirstInnerElement();

            Entity userJID = null;
            try {
                userJID = EntityImpl.parse(affiliationElement.getAttributeValue("jid"));
            } catch (EntityFormatException e) {
                return errorStanzaGenerator.generateJIDMalformedErrorStanza(serverJID, sender, stanza); // TODO not defined in the standard(?)
            }

            PubSubAffiliation newAffiliation = PubSubAffiliation.get(affiliationElement.getAttributeValue("affiliation"));
            node.setAffiliation(userJID, newAffiliation);
        } catch(LastOwnerResignedException e) {
            // if the last owner tries to resign.
            return errorStanzaGenerator.generateNotAcceptableErrorStanza(serverJID, sender, stanza);
        } catch(Throwable t) { // possible null-pointer
            return errorStanzaGenerator.generateBadRequestErrorStanza(serverJID, sender, stanza); // TODO not defined in the standard(?)
        }

        sb.endInnerElement();
        return new IQStanza(sb.build());
    }
View Full Code Here

            return bindError(stanza, sessionContext);
        }

        Entity entity = new EntityImpl(sessionContext.getInitiatingEntity(), resourceId);

        StanzaBuilder stanzaBuilder =
            StanzaBuilder.createIQStanza(null, null, IQStanzaType.RESULT, stanza.getID()).
            startInnerElement("bind", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND).
                    startInnerElement("jid", NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_BIND).
                    addText(entity.getFullQualifiedName()).endInnerElement().
            endInnerElement();

        return stanzaBuilder.build();
    }
View Full Code Here

TOP

Related Classes of org.apache.vysper.xmpp.stanza.StanzaBuilder$ElementStruct

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.