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)));
}
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());
}
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();
}
}
Aggregations