Monday, November 08, 2010 at 12:06 AM.
system.verbs.builtins.tcp.im.builtinDrivers.jabber.code.messages.message
on message ( dest, text = nil, htmlText = nil, subject = nil, type = "chat", thread = nil, connection = @system.temp.jabber.connection) {
<<Changes
<<10/25/02; 2:27:50 PM by JES
<<Entity-encode the text here instead of through a call to xml.entityEncode, per recommendation from Andre Radke.
<<Radio and Frontier's implementation of xml.entityEncode are slightly different, but changing Frontier's xml.entityEncode verb would introduce too much possibility for breakage for the problem to be addressed at that level.
<<5/14/02; 1:51:34 PM by JB
<<Changelog created.
on addAtt ( XMLadr, name, value ) {
if not defined ( XMLadr^.["/atts"] ) {
new ( tableType, @XMLadr^.["/atts"] )};
XMLadr^.["/atts"].[name] = value};
if not defined ( connection^ ) { // should I lock a semaphore after this?
scriptError ( "Can't send the message because there is no active Jabber connection." )};
local ( flHaveHtml = (htmlText != nil), result, mesTag, htmlTable);
new ( tableType, @result );
text = string ( text ); htmlText = string ( htmlText );
bundle { // text = xml.entityEncode(text,true)
text = xml.entityEncode (text, false);
text = string.replaceall (text, "&", "&");
text = string.replaceall (text, "<", "<");
text = string.replaceall (text, ">", ">");
text = string.replaceall (text, "\"", """);
text = string.replaceall (text, "'", "'")};
bundle { // handle the text/htmlText conditions as described in the docs
if flHaveHtml and typeOf ( htmlText ) == stringType { // convert into an XML table
new (tableType, @htmlTable);
try {
xml.compile ( htmlText, @htmlTable )}
else {
scriptError ( "Can't send message via Jabber because the given htmlText did not compile correctly. xml.compile said: " + tryError )}};
if text == nil and not flHaveHtml { // prepare empty message
text = ""};
if text == nil and flHaveHtml { // convert HTML to Text with string.htmlToEmail
text = string.htmlToEmail(htmlText)};
if flHaveHtml { // make sure the HTML starts with <html>, or kick it out.
if xml.convertToDisplayName ( nameOf ( htmlTable[1] ) ) != "html" {
scriptError ( "Can't send HTML message over Jabber because the given htmlText is not a valid HTML document." )}}};
bundle { // <message from="username@server/resource" to="dest" type="chat">
mesTag = xml.addTable ( @result, "message" );
addAtt ( mesTag, "from", connection^.username + "@" + connection^.host + "/" + connection^.resource );
addAtt ( mesTag, "to", dest );
addAtt ( mesTag, "type", type )};
if subject != nil and subject != "" {
xml.addValue(mesTag, "subject", subject )};
xml.addValue(mesTag, "body", text );
if flHaveHtml {
table.copy(@htmlTable[1], mesTag)};
if thread != nil and thread != "" {
xml.addValue(mesTag, "thread", thread)};
tcp.im.builtinDrivers.jabber.code.writeXML ( @result, connection: connection )};
message("Jeremy@192.168.0.4/Human", "Hello!")
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.