XHTMLExtension

Lo,

It seems the XHTMLExtension is broken or I’ve not understood how to get it working.

So I propose my XHTMLExtension file using ISerializable. I’m not an AS3 expert so I’m not sure it is the best way to do it but it’s working at least

I’ve done it in a way to keep Message.as untouched. So just change XHTMLExtension.as and rebuild the swc…


package org.jivesoftware.xiff.data.xhtml{

/*

  • This library is free software; you can redistribute it and/or

  • modify it under the terms of the GNU Lesser General Public

  • License as published by the Free Software Foundation; either

  • version 2.1 of the License, or (at your option) any later version.

  • This library is distributed in the hope that it will be useful,

  • but WITHOUT ANY WARRANTY; without even the implied warranty of

  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU

  • Lesser General Public License for more details.

  • You should have received a copy of the GNU Lesser General Public

  • License along with this library; if not, write to the Free Software

  • Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

*/

import org.jivesoftware.xiff.data.Extension;

import org.jivesoftware.xiff.data.ExtensionClassRegistry;

import org.jivesoftware.xiff.data.IExtension;

import org.jivesoftware.xiff.data.ISerializable;

import flash.xml.XMLNode;

import flash.xml.XMLNodeType;

import flash.xml.XMLDocument;

/**

  • This class provides an extension for XHTML body text in messages.
  • @author Sean Treadway

  • @since 2.0.0

  • @availability Flash Player 7

  • @param parent The parent node for this extension

  • @toc-path Extensions/HTML

  • @toc-sort 1/2

*/

public class XHTMLExtension extends Extension implements IExtension, ISerializable

{

// Static class variables to be overridden in subclasses;

    public static var NS:String = "http://jabber.org/protocol/xhtml-im";

public static var ELEMENT:String = “html”;

private static var staticDepends:Class = ExtensionClassRegistry;

public var body:String;

public function XHTMLExtension(parent:XMLNode = null)

{

super(parent);

}

/**

  • @return The namespace

  • @availability Flash Player 7

*/

public function getNS():String

{

return XHTMLExtension.NS;

}

/**

  • Gets the element name associated with this extension.

  • The element for this extension is “html”.

  • @return The element name

  • @availability Flash Player 7

*/

public function getElementName():String

{

return XHTMLExtension.ELEMENT;

}

/**

  • Performs the registration of this extension into the extension registry.

  • @availability Flash Player 7

*/

public static function enable():void

{

ExtensionClassRegistry.register(XHTMLExtension);

}

/**

  • Serializes the Html data
  • @param (XMLNode) Parent The parent node that this extension should be serialized into

  • @return (Boolean) An indicator as to whether serialization was successful

*/

public function serialize(parentNode:XMLNode):Boolean {

var node:XMLNode = getNode();

var bodyNode:XMLNode = new XMLNode(XMLNodeType.ELEMENT_NODE, ‘body’);

bodyNode.appendChild(new XMLDocument(body));

node.appendChild(body);

if (!exists(node.parentNode)) {

parentNode.appendChild(node.cloneNode(true));

}

return true;

}

/**

  • Deserializes the Html data
  • @param (XMLNode) The XML node associated this data

  • @return (Boolean) An indicator as to whether deserialization was successful

*/

public function deserialize(node:XMLNode):Boolean {

setNode(node);

var html:Array = new Array();

var children:Array = node.childNodes[0].childNodes;

for (var i:String in children) {

html.push(children[i].toString());

}

html.reverse();

body = html.join();

return true;

}

}

}

XHTMLExtension IS broken You came up with this fix right on time, I was going to fix it today, but you did the job for me. Thanks a lot.

Did you mean

node.appendChild(bodyNode); instead of node.appendChild(body); ? in serialize

Yes of course, sorry I’ve renamed some variables before posting (to keep Message.as untouched) and maybe not copy past the right version

Hummmm why I can’t edit my first message… ???

Download the patch or the full XHTMLExtension.as file…
xhtmlextension.patch (3785 Bytes)
XHTMLExtension.as (4063 Bytes)