Package org.apache.vysper.xml.fragment

Examples of org.apache.vysper.xml.fragment.XMLElement


    public static boolean verifyNamespace(Stanza stanza) {
        // either, the stanza should have a x element with the MUC namespace. Or, no extension
        // element at all. Else, return false
       
        XMLElement xElement = stanza.getFirstInnerElement();
        if(xElement != null && xElement.getName().equals("x")
                && xElement.getNamespaceURI().equals(NamespaceURIs.XEP0045_MUC)) {
            // got x element and in the correct namespace
            return true;
        } else if(xElement != null && xElement.getNamespaceURI().length() == 0) {
            // no extension namespace, ok
            return true;
        } else if(xElement == null) {
            return true;
        } else {
View Full Code Here


        // should be to the existing user
        assertEquals(to, stanza.getTo());
       
        assertEquals("unavailable", stanza.getAttributeValue("type"));
       
        XMLElement xElement = stanza.getSingleInnerElementsNamed("x");
        assertEquals(NamespaceURIs.XEP0045_MUC_USER, xElement.getNamespaceURI());
       
        // since this room is non-anonymous, x must contain an item element with the users full JID
        XMLElement itemElement = xElement.getSingleInnerElementsNamed("item");
        assertEquals("none", itemElement.getAttributeValue("affiliation"));
        assertEquals("none", itemElement.getAttributeValue("role"));
       
        if(own) {
            List<XMLElement> statuses = xElement.getInnerElementsNamed("status");
            assertEquals(1, statuses.size());
            assertEquals("110", statuses.get(0).getAttributeValue("code"));
View Full Code Here

                index++;
            }
        }
       
        // error element must always be present
        XMLElement errorElement = innerElements.get(index);
        assertEquals("error", errorElement.getName());
        assertEquals(type, errorElement.getAttributeValue("type"));
       
        XMLElement jidMalformedElement = errorElement.getFirstInnerElement();
        assertEquals(errorName, jidMalformedElement.getName());
        assertEquals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS, jidMalformedElement.getNamespaceURI());
    }
View Full Code Here

    private StanzaHandler getHandler(Stanza stanza, StanzaHandler defaultHandler) {
        StanzaHandler handlerForElement = null;

        if (stanza.getVerifier().subElementsPresentExact(1)) {
            XMLElement firstInnerElement = stanza.getFirstInnerElement();
            handlerForElement = getHandlerForElement(stanza, firstInnerElement);
            return handlerForElement;
        } else {
            // if no specialized handler can be identified, return general handler
            return defaultHandler;
View Full Code Here

        assertEquals(expectedFrom, stanza.getFrom());
        assertEquals(expectedTo, stanza.getTo());
        assertEquals(expectedShow, presenceStanza.getShow());
        assertEquals(expectedStatus, presenceStanza.getStatus(null));
       
        XMLElement xElm = stanza.getSingleInnerElementsNamed("x");
        assertEquals(NamespaceURIs.XEP0045_MUC_USER, xElm.getNamespaceURI());
       
        List<XMLElement> innerElements = xElm.getInnerElements();
           
        assertEquals(1, innerElements.size());
        XMLElement itemElm = innerElements.get(0);
        assertEquals("item", itemElm.getName());
        assertEquals(expectedItem.getJid().getFullQualifiedName(), itemElm.getAttributeValue("jid"));
        assertEquals(expectedItem.getNick(), itemElm.getAttributeValue("nick"));
        assertEquals(expectedItem.getAffiliation().toString(), itemElm.getAttributeValue("affiliation"));
        assertEquals(expectedItem.getRole().toString(), itemElm.getAttributeValue("role"));
       
    }
View Full Code Here

        assertEquals(IQStanzaType.RESULT.value(),response.getType());

        assertEquals("id123", response.getAttributeValue("id")); // IDs must match

        // get the query Element
        XMLElement query = response.getFirstInnerElement();
        List<XMLElement> inner = query.getInnerElements();

        assertEquals("query", query.getName());
       
        // at least we have an identity and a feature element
        assertTrue(inner.size() >= 2);
       
        // ordering etc. is unknown; step through all subelements and pick the ones we need
        XMLElement identity = null;
        XMLElement feature = null;
        for(XMLElement el : inner) {
            if(el.getName().equals("identity")
                    //&& el.getNamespace().equals(NamespaceURIs.XEP0030_SERVICE_DISCOVERY_INFO) // TODO enable when the parser is fixed
                    && el.getAttributeValue("category").equals("pubsub")
                    && el.getAttributeValue("type").equals("service")) {
View Full Code Here

        assertEquals(IQStanzaType.RESULT.value(),response.getType());

        assertEquals("id123", response.getAttributeValue("id")); // IDs must match
       
        // get the query Element
        XMLElement query = response.getFirstInnerElement();
        List<XMLElement> inner = query.getInnerElements();

        assertEquals("query", query.getName());
       
        // at least we have an identity element
        assertTrue(inner.size() >= 1);
       
        // ordering etc. is unknown; step through all subelements and pick the ones we need
        XMLElement identity = null;
        for(XMLElement el : inner) {
            if(el.getName().equals("identity")
                    //&& el.getNamespace().equals(NamespaceURIs.XEP0030_SERVICE_DISCOVERY_INFO) // TODO enable when the parser is fixed
                    && el.getAttributeValue("category").equals("pubsub")
                    && el.getAttributeValue("type").equals("leaf")) {
View Full Code Here

        @SpecCompliant(spec="rfc3921bis-08", section = "2.1.1", status = FINISHED, coverage = COMPLETE),
        @SpecCompliant(spec="rfc3921bis-08", section = "2.1.3", status = FINISHED,
                       coverage = PARTIAL, comment = "handles the conformance rules 1-3 when parseSubscriptionTypes is set to false")
    })
    private static RosterItem parseRosterItem(IQStanza stanza, boolean parseSubscriptionTypes) throws RosterBadRequestException, RosterNotAcceptableException {
        XMLElement queryElement;
        try {
            queryElement = stanza.getSingleInnerElementsNamed("query");
            if (queryElement == null) throw new XMLSemanticError("missing query node");
        } catch (XMLSemanticError xmlSemanticError) {
            throw new RosterBadRequestException("roster set needs a single query node.");
        }

        XMLElement itemElement;
        try {
            itemElement = queryElement.getSingleInnerElementsNamed("item");
            if (itemElement == null) throw new XMLSemanticError("missing item node");
        } catch (XMLSemanticError xmlSemanticError) {
            throw new RosterBadRequestException("roster set needs a single item node.");
        }

        Attribute attributeJID = itemElement.getAttribute("jid");
        if (attributeJID == null || attributeJID.getValue() == null) throw new RosterBadRequestException("missing 'jid' attribute on item node");

        XMLElementVerifier verifier = itemElement.getVerifier();
        String name = verifier.attributePresent("name") ? itemElement.getAttribute("name").getValue() : null;
        if (name != null && name.length() > RosterConfiguration.ROSTER_ITEM_NAME_MAX_LENGTH) {
            throw new RosterNotAcceptableException("roster name too long: " + name.length());
        }

        SubscriptionType subscription = verifier.attributePresent("subscription") ? SubscriptionType.valueOf(itemElement.getAttribute("subscription").getValue().toUpperCase()) : SubscriptionType.NONE;
        if (!parseSubscriptionTypes && subscription != SubscriptionType.REMOVE) subscription = SubscriptionType.NONE; // roster remove is always tolerated

        AskSubscriptionType askSubscriptionType = AskSubscriptionType.NOT_SET;
        if (parseSubscriptionTypes) {
            askSubscriptionType = verifier.attributePresent("ask") ? AskSubscriptionType.valueOf("ASK_" + itemElement.getAttribute("ask").getValue().toUpperCase()) : AskSubscriptionType.NOT_SET;
        }

        String contactJid = attributeJID.getValue();
        Entity contact;
        try {
            contact = EntityImpl.parse(contactJid);
        } catch (EntityFormatException e) {
            throw new RosterNotAcceptableException("jid cannot be parsed: " + contactJid);
        }

        List<RosterGroup> groups = new ArrayList<RosterGroup>();
        List<XMLElement> groupElements = itemElement.getInnerElementsNamed("group");
        if (groupElements != null) {
            for (XMLElement groupElement : groupElements) {
                String groupName = null;
                try {
                    groupName = groupElement.getSingleInnerText().getText();
View Full Code Here

       
        assertTrue(result.hasResponse());
       
        IQStanza response = new IQStanza(result.getResponseStanza());
        assertEquals(IQStanzaType.RESULT.value(),response.getType());
        XMLElement sub = response.getFirstInnerElement().getFirstInnerElement();
        assertEquals("subscriptions", sub.getName());
        assertEquals(2, sub.getInnerElements().size());
    }
View Full Code Here

        IQStanza response = new IQStanza(result.getResponseStanza());
        assertEquals(IQStanzaType.ERROR.value(),response.getType());

        assertEquals("id123", response.getAttributeValue("id")); // IDs must match

        XMLElement error = response.getInnerElementsNamed("error").get(0); //jump directly to the error part
        assertEquals("error", error.getName());
        assertEquals("auth", error.getAttributeValue("type"));

        List<XMLElement> errorContent = error.getInnerElements();
        assertEquals(1, errorContent.size());
        assertEquals("forbidden", errorContent.get(0).getName());
        assertEquals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS, errorContent.get(0).getNamespaceURI());
    }
View Full Code Here

TOP

Related Classes of org.apache.vysper.xml.fragment.XMLElement

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.