1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +02:00

Don't append closing body in XHTMLText.toString()

Also add XHTMLExtension.from(Message) and change XHTMLManager.addBody()
signature so that it expects a XHTMLText (Modifications to the original
patch by Florian Schmaus).
This commit is contained in:
vito-c 2015-01-04 20:11:06 -08:00 committed by Florian Schmaus
parent b77d61527c
commit e31b284afa
4 changed files with 23 additions and 23 deletions

View file

@ -37,11 +37,10 @@ import java.util.List;
* @author Gaston Dombiak
*/
public class XHTMLManager {
// Enable the XHTML support on every established connection
// The ServiceDiscoveryManager class should have been already initialized
static {
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
public void connectionCreated(XMPPConnection connection) {
// Enable the XHTML support on every established connection
XHTMLManager.setServiceEnabled(connection, true);
}
});
@ -55,7 +54,7 @@ public class XHTMLManager {
* @return an Iterator for the bodies in the message or null if none.
*/
public static List<CharSequence> getBodies(Message message) {
XHTMLExtension xhtmlExtension = (XHTMLExtension) message.getExtension(XHTMLExtension.ELEMENT, XHTMLExtension.NAMESPACE);
XHTMLExtension xhtmlExtension = XHTMLExtension.from(message);
if (xhtmlExtension != null)
return xhtmlExtension.getBodies();
else
@ -66,17 +65,17 @@ public class XHTMLManager {
* Adds an XHTML body to the message.
*
* @param message the message that will receive the XHTML body
* @param body the string to add as an XHTML body to the message
* @param xhtmlText the string to add as an XHTML body to the message
*/
public static void addBody(Message message, String body) {
XHTMLExtension xhtmlExtension = (XHTMLExtension) message.getExtension(XHTMLExtension.ELEMENT, XHTMLExtension.NAMESPACE);
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(body);
xhtmlExtension.addBody(xhtmlText.toXML());
}
/**

View file

@ -398,12 +398,9 @@ public class XHTMLText {
/**
* Returns the text of the XHTMLText.
*
* Note: Automatically adds the closing body tag.
*
* @return the text of the XHTMLText
*/
public String toString() {
appendCloseBodyTag();
return text.toString();
}

View file

@ -17,6 +17,7 @@
package org.jivesoftware.smackx.xhtmlim.packet;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.XmlStringBuilder;
@ -122,4 +123,7 @@ public class XHTMLExtension implements PacketExtension {
}
}
public static XHTMLExtension from(Message message) {
return message.getExtension(ELEMENT, NAMESPACE);
}
}