powered by Jive Software

Formatted Messages

Greetings

What would be the best option to send formatted messages using Smack. Formatting may include multiple fonts and colors for a start.

TIA

Rajesh,

The way to go is to use XHTML. Smack supports XHTML messages. Follow this link http://www.jivesoftware.com/xmpp/smack/documentation/extensions/index.html to learn how to use XHTML in Smack.

Let us know if you need anything else.

Regards,

– Gato

Dear Gato

That was quick and thank you.

I did go through the link and yes it does address my rek.

I will post if I run into any issues.

Thanks

Dear Gato

I was working on using formatted messages and have the following to share.

1.Formatted messages would need similar or XHTML enabled clients at either end or is there any discovery mechanism for client capability ?

2.I currently have used a HTML editor kit to type in the chat message, using this I can retrieve the typed text as valid HTML. This can be put into a normal Smack Message and sent. On the receving end this can be inserted into a HTML editor kit view document. Probably this would need some massaging of the HTML for display but it seems to work.

Am I confused here or the Smack extension is the way to go, maybe XMPP compliance ???

-Rajesh

Rajesh,

1.Formatted messages would need similar or XHTML

enabled clients at either end or is there any

discovery mechanism for client capability ?

Only XHTML enabled clients should receive XHTML messages. In the documentation folder you can find the document about XHTML Messages which explains how to discover support for XHTML. Below is a code snippet that provides a discovery example.

Message msg = chat.createMessage();
// Include a normal body in the message
msg.setBody(getTextToSend());
// Check if the other user supports XHTML messages
if (XHTMLManager.isServiceEnabled(connection, chat.getParticipant())) {
  // Obtain the XHTML text to send from somewhere
  String xhtmlBody = getXHTMLTextToSend();   // Include an XHTML body in the message
  XHTMLManager.addBody(msg, xhtmlBody);
} // Send the message
chat.sendMessage(msg);

2.I currently have used a HTML editor kit to type in

the chat message, using this I can retrieve the typed

text as valid HTML. This can be put into a normal

Smack Message and sent. On the receving end this can

be inserted into a HTML editor kit view document.

Probably this would need some massaging of the HTML

for display but it seems to work.

XMPP includes a JEP that specifies that if you want to send formatted messages you should send them in the XHTML-IM format. The XHTML used is a subset of HTML. You can read about the supported elements in this link: http://www.jabber.org/jeps/jep-0071.html#sect-id2598980

Regards,

– Gato