powered by Jive Software

How to extend xiff with support for new namespaces?

Hi,

I have to extend xiff with two new namespaces:

First ext. will xiff enable to show composing events from other clients, second will allow xiff to show the real date a message was composed when receiving history messages from a chatroom. Now it shows the time it arrives at the client, which is wrong.

What’'s the easiest way to get support for the extenstinons above. Is there a hook in the xiff code where I have to add this?

Thanks for any hints!

Guido

Hi guido,

I’‘ve have been trying to add the composing event to some of my code by writing a new MessageEventExtension according to JEP-0022. It works but it’‘s not finished yet and I’‘m still trying to work out if I’'m taking the wright approach.

here’'s an OLD UNFINISHED /b version of my class code…

/*

  • 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;

/**

  • This class provides an extension for Message Events.
  • @author Patrick Gutlich

  • @since 2.0.0

  • @availability Flash Player 7

  • @param parent The parent node for this extension

*/

class org.jivesoftware.xiff.data.messageEvent.messageEventExtension extends Extension implements IExtension,ISerializable

{

// Static class variables to be overridden in subclasses;

public static var NS:String = “jabber:x:event”;

public static var ELEMENT:String = “x”;

private static var staticDepends = ExtensionClassRegistry;

private var messageEvents:Array;

public function messageEventExtension(parent:XMLNode)

{

super(parent);

messageEvents = new Array();

}

/**

  • Gets the namespace associated with this extension.

  • The namespace for the messageEventExtension is “jabber:x:event”.

  • @return The namespace

  • @availability Flash Player 7

*/

public function getNS():String

{

return messageEventExtension.NS;

}

/**

  • Gets the element name associated with this extension.

  • The element for this extension is “x”.

  • @return The element name

  • @availability Flash Player 7

*/

public function getElementName():String

{

return messageEventExtension.ELEMENT;

}

/**

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

  • @availability Flash Player 7

*/

public static function enable():Void

{

ExtensionClassRegistry.register(messageEventExtension);

}

/**

  • Serializes the data to XML for sending.
  • @availability Flash Player 7

  • @param parent The parent node that this extension should be serialized into

  • @return An indicator as to whether serialization was successful

*/

public function serialize( parent:XMLNode ):Boolean

{

getNode().removeNode();

var ext_node:XMLNode = XMLFactory.createElement(getElementName());

ext_node.attributes.xmlns = getNS();

var eventNode:XML = new XML();

var eventCount:Number = messageEvents.length;

for(var i=0;i< eventCount;i++){

eventNode.appendChild(eventNode.createElement(messageEvents[ i ]));

}

ext_node.appendChild(eventNode);

parent.appendChild(ext_node);

return true;

}

/**

  • Deserializes the Message Event data.
  • @availability Flash Player 7

  • @param node The XML node associated this data

  • @return An indicator as to whether deserialization was successful

*/

public function deserialize( node:XMLNode ):Boolean

{

setNode( node );

messageEvents = new Array();

var children = node.childNodes;

for (var i in children) {

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

}

return true;

}

public function addEvent(pEventType:String){

switch(pEventType){

case “composing”:

if (!in_array(messageEvents,pEventType)){

messageEvents.push(pEventType);

}

break;

default:

break;

}

}

private function in_array (pArray,obj):Boolean {

for (var i in this) {

if (this[ i ]==obj) return true;

}

return false;

}

}

/code

you can then send the composing event somewhat like this

this piece of code is part of another applicationclass[/i]

// all your other (class) code for making the connection etc… goes here

// don’'t forget to import the extension…

// import org.jivesoftware.xiff.data.messageEvent.messageEventExtension;

public function sendComposing( jid:String):Void{

var tempMessage:Message = new Message( jid, null, “”, “”, Message.CHAT_TYPE );

var mEvent:messageEventExtension = new messageEventExtension(tempMessage.getNode());

mEvent.addEvent(“composing”);

tempMessage.addExtension(mEvent);

// conn is an instance of the connection class

conn.send( tempMessage );

}

/code

Hope this helps

Gepatto

Thanks for your reply. At least somone with the same problems out there . I think together we will come along the problems. I will try this out and let you know my experiences!

Guido