package org.jivesoftware.xiff.data.xhtml{ /* * Copyright (C) 2003-2007 * Nick Velloff * Derrick Grigg * Sean Voisen * Sean Treadway * * 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); } /** * Gets the namespace associated with this extension. * The namespace for the XHTMLExtension is "http://jabber.org/protocol/xhtml-im". * * @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 Xhtml 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(bodyNode); if (!exists(node.parentNode)) { parentNode.appendChild(node.cloneNode(true)); } return true; } /** * Deserializes the Xhtml 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; } } }