Search in sources :

Example 1 with XHTMLExtension

use of org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension in project Smack by igniterealtime.

the class XHTMLExtensionProviderTest method parsesWell.

@Test
public void parsesWell() throws IOException, XmlPullParserException {
    XmlPullParser parser = PacketParserUtils.newXmppParser();
    parser.setInput(getClass().getResourceAsStream(XHTML_EXTENSION_SAMPLE_RESOURCE_NAME), "UTF-8");
    parser.next();
    XHTMLExtensionProvider provider = new XHTMLExtensionProvider();
    ExtensionElement extension = provider.parse(parser, parser.getDepth());
    assertThat(extension, instanceOf(XHTMLExtension.class));
    XHTMLExtension attachmentsInfo = (XHTMLExtension) extension;
    assertThat(sampleXhtml(), equalsCharSequence(attachmentsInfo.getBodies().get(0)));
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) XHTMLExtension(org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension) Test(org.junit.Test)

Example 2 with XHTMLExtension

use of org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension in project Smack by igniterealtime.

the class XHTMLManager method addBody.

/**
     * Adds an XHTML body to the message.
     *
     * @param message the message that will receive the XHTML body
     * @param xhtmlText the string to add as an XHTML body to the message
     */
public static void addBody(Message message, XHTMLText xhtmlText) {
    XHTMLExtension xhtmlExtension = XHTMLExtension.from(message);
    if (xhtmlExtension == null) {
        // Create an XHTMLExtension and add it to the message
        xhtmlExtension = new XHTMLExtension();
        message.addExtension(xhtmlExtension);
    }
    // Add the required bodies to the message
    xhtmlExtension.addBody(xhtmlText.toXML());
}
Also used : XHTMLExtension(org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension)

Example 3 with XHTMLExtension

use of org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension in project Smack by igniterealtime.

the class XHTMLExtensionProvider method parse.

@Override
public XHTMLExtension parse(XmlPullParser parser, int initialDepth) throws IOException, XmlPullParserException {
    XHTMLExtension xhtmlExtension = new XHTMLExtension();
    while (true) {
        int eventType = parser.getEventType();
        String name = parser.getName();
        if (eventType == XmlPullParser.START_TAG) {
            if (name.equals(Message.BODY)) {
                xhtmlExtension.addBody(PacketParserUtils.parseElement(parser));
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getDepth() == initialDepth) {
                return xhtmlExtension;
            }
        }
        parser.next();
    }
}
Also used : XHTMLExtension(org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension)

Aggregations

XHTMLExtension (org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension)3 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)1 Test (org.junit.Test)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1