Package org.apache.vysper.xml.fragment

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


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

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

        XMLElement sub = stanza.getFirstInnerElement().getFirstInnerElement(); // pubsub/subscribe
        String strSubJID = sub.getAttributeValue("jid"); // MUST

        try {
            subJID = EntityImpl.parse(strSubJID);
        } catch (EntityFormatException e) {
            return errorStanzaGenerator.generateJIDMalformedErrorStanza(sender, serverJID, stanza);
View Full Code Here


/**
*/
public class XMLElementTestCase extends TestCase {

    public void testBasicGetters() {
        XMLElement xmlElement = new XMLElementBuilder("message", "urn:test").
                addAttribute("lang", "de").
                addAttribute(NamespaceURIs.XML, "lang", "cn").
                addAttribute("xmllang", "en").
        build();
       
        assertEquals("message", xmlElement.getName());
        assertEquals("urn:test", xmlElement.getNamespaceURI());
        assertEquals("cn", xmlElement.getXMLLang());
       
        assertSame(Collections.emptyList(), xmlElement.getInnerElements());
        List<Attribute> list = xmlElement.getAttributes();
        assertNotNull(list);
       
        assertEquals(3, list.size());
    }
View Full Code Here

        assertEquals(3, list.size());
    }

    public void testInnerTextGetters() {
       
        XMLElement xmlElement = new XMLElementBuilder("message", "jabber:test").
                addText("t1").
                startInnerElement("i1").
                endInnerElement().
                addText("t2").
                addText("t3").
                startInnerElement("i2").
                endInnerElement().
                addText("t4").
        build();

        List<XMLText> list = xmlElement.getInnerTexts();
        assertEquals(4, list.size());
        assertEquals("t1", list.get(0).getText());
        assertEquals("t2", list.get(1).getText());
        assertEquals("t3", list.get(2).getText());
        assertEquals("t4", list.get(3).getText());

        assertEquals("t1", xmlElement.getFirstInnerText().getText());
        try {
            xmlElement.getSingleInnerText();
            fail("must raise exception");
        } catch (XMLSemanticError xmlSemanticError) {
            // test succeeded
        }

        xmlElement = new XMLElementBuilder("message", "jabber:test").
                startInnerElement("i1").
                endInnerElement().
        build();
        try {
            assertNull(xmlElement.getSingleInnerText());
        } catch (XMLSemanticError xmlSemanticError) {
            fail("must not raise error");
        }
    }
View Full Code Here

    protected boolean verifyInnerNamespace(Stanza stanza, String namespace) {
        XMLElementVerifier xmlElementVerifier = stanza.getVerifier();
        if (!xmlElementVerifier.subElementsPresentAtLeast(1)) return false;

        List<XMLElement> innerElements = stanza.getInnerElements();
        XMLElement firstInnerElement = innerElements.get(0);
        return firstInnerElement.getVerifier().namespacePresent(namespace);
    }
View Full Code Here

        }
    }

    public void testInnerElementGetters() {
       
        XMLElement xmlElement = new XMLElementBuilder("message", "jabber:test").
                addText("t1").
                startInnerElement("i1").
                endInnerElement().
                startInnerElement("i2").
                    addAttribute("order", "1").
                endInnerElement().
                startInnerElement("i2").
                    addAttribute("order", "2").
                endInnerElement().
                addText("t2").
                addText("t3").
                startInnerElement("i3").
                endInnerElement().
                addText("t4").
        build();

        List<XMLElement> list = xmlElement.getInnerElements();
        assertEquals(4, list.size());

        assertEquals("i1", xmlElement.getFirstInnerElement().getName());
        try {
            xmlElement.getSingleInnerElementsNamed("i2");
            fail("must raise exception");
        } catch (XMLSemanticError xmlSemanticError) {
            // test succeeded
        }

        try {
            XMLElement xmlElement1 = xmlElement.getSingleInnerElementsNamed("i3");
            assertEquals("i3", xmlElement1.getName());
        } catch (XMLSemanticError xmlSemanticError) {
            fail("must not raise exception");
        }

        xmlElement = new XMLElementBuilder("message", "jabber:test").
                addText("t1").
        build();
        try {
            assertNull(xmlElement.getSingleInnerElementsNamed("none"));
        } catch (XMLSemanticError xmlSemanticError) {
            fail("must not raise error");
        }

        xmlElement = new XMLElementBuilder("message", "jabber:test").
                startInnerElement("i").
                    addAttribute("order", "1").
                endInnerElement().
                startInnerElement("another").
                endInnerElement().
        build();
        try {
            XMLElement singleXmlElement = xmlElement.getSingleInnerElementsNamed("i");
            assertEquals("i", singleXmlElement.getName());
        } catch (XMLSemanticError xmlSemanticError) {
            fail("must not raise error");
        }

        xmlElement = new XMLElementBuilder("message", "jabber:test").
View Full Code Here

        }
    }
   
    public void testInnerElementsNamed() {
       
        XMLElement xmlElement = new XMLElementBuilder("message", "jabber:test").
                addText("t1").
                startInnerElement("body").
                endInnerElement().
                startInnerElement("body").
                    addAttribute("order", "1").
                endInnerElement().
                startInnerElement("body").
                    addAttribute("order", "2").
                endInnerElement().
                addText("body").
                addText("t3").
                startInnerElement("single").
                endInnerElement().
                addText("t4").
        build();

        List<XMLElement> list = xmlElement.getInnerElementsNamed("no-exist");
        assertEquals(0, list.size());

        list = xmlElement.getInnerElementsNamed("single");
        assertEquals(1, list.size());

        try {
            XMLElement xmlElementInner = xmlElement.getSingleInnerElementsNamed("single");
            assertNotNull(xmlElementInner);
        } catch (XMLSemanticError xmlSemanticError) {
            fail("single element not found");
        }
View Full Code Here

        }
    }
   
    public void testLanguageMapping() {
       
        XMLElement xmlElement = new XMLElementBuilder("message", "jabber:test").
                addText("t1").
                startInnerElement("body").
                endInnerElement().
                startInnerElement("body").
                    addAttribute(NamespaceURIs.XML, "lang", "en").
                endInnerElement().
                startInnerElement("body").
                    addAttribute(NamespaceURIs.XML, "lang", "de").
                endInnerElement().
                addText("body").
                addText("t3").
                startInnerElement("single").
                    addAttribute(NamespaceURIs.XML, "lang", "ru").
                endInnerElement().
                startInnerElement("body_inconsistent").
                    addAttribute(NamespaceURIs.XML, "lang", "ru").
                endInnerElement().
                startInnerElement("body_inconsistent").
                    addAttribute(NamespaceURIs.XML, "lang", "ru").
                endInnerElement().
                startInnerElement("body_lang_null").
                    addAttribute("order", "1").
                endInnerElement().
                startInnerElement("body_lang_null").
                    addAttribute("order", "2").
                endInnerElement().
                addText("t4").
        build();

        try {
            Map<String,XMLElement> map = xmlElement.getInnerElementsByXMLLangNamed("body");
            assertEquals(3, map.size());
            XMLElement element = map.get("en");
            assertEquals("en", element.getXMLLang());
            element = map.get("de");
            assertEquals("de", element.getXMLLang());
            element = map.get(null);
            assertEquals(null, element.getXMLLang());
           
        } catch (XMLSemanticError xmlSemanticError) {
            fail("no error expected");
        }
       
View Full Code Here

    protected boolean verifyInnerNamespace(Stanza stanza, String namespace) {
        XMLElementVerifier xmlElementVerifier = stanza.getVerifier();
        if (!xmlElementVerifier.subElementsPresentAtLeast(1)) return false;

        List<XMLElement> innerElements = stanza.getInnerElements();
        XMLElement firstInnerElement = innerElements.get(0);
        return firstInnerElement.getVerifier().namespacePresent(namespace);
    }
View Full Code Here

            // success
        }
    }

    public void testGetAttribute() {
        XMLElement xmlElement = new XMLElementBuilder("test").
                addAttribute("foo", "bar").
                addAttribute(NamespaceURIs.XML, "lang", "cn").
        build();
       
        assertEquals("bar", xmlElement.getAttribute("foo").getValue());
        assertNull(xmlElement.getAttribute("http://example.com", "foo"));
        assertNull(xmlElement.getAttribute("lang"));
        assertEquals("cn", xmlElement.getAttribute(NamespaceURIs.XML, "lang").getValue());

        assertEquals("bar", xmlElement.getAttributeValue("foo"));
        assertNull(xmlElement.getAttributeValue("http://example.com", "foo"));
        assertNull(xmlElement.getAttributeValue("lang"));
        assertEquals("cn", xmlElement.getAttributeValue(NamespaceURIs.XML, "lang"));

    }
View Full Code Here

            decoder.decode(session, byteBuffer, protocolDecoderOutput);
        } catch(Throwable th) {
            int lkjl = 0;
        }
        assertEquals(1, protocolDecoderOutput.size());
        XMLElement stanzaParsed = (XMLElement) protocolDecoderOutput.get(0);
        String stanzaName = stanzaParsed.getName();
        assertEquals("stream", stanzaName);
        String stanzaNSPrefix = stanzaParsed.getNamespacePrefix();
        assertEquals("stream", stanzaNSPrefix);
    }
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.