com.realtime.xmpp.dom
Class DomPacketTools

java.lang.Object
  |
  +--com.realtime.xmpp.dom.DomPacketTools

public class DomPacketTools
extends java.lang.Object

Helper class for modifying DOM elements to set XMPP fields and create child elements.

Version:
1.0 Copyright © 2002 Real Time Entertainment Group, LLC - All rights reserved.
Author:
Mike Prince

Field Summary
protected static org.dom4j.DocumentFactory m_documentFactory
          Our document factory.
protected static long m_nextPacketId
          packet id generator.
 
Constructor Summary
DomPacketTools()
           
 
Method Summary
static org.dom4j.Element createQuery(java.lang.String sNamespace)
          Create a simple query element.
static org.dom4j.Element createRequestPacket(java.lang.String sName, java.lang.String sFrom, java.lang.String sTo)
          Create a request packet element.
static org.dom4j.Element createResponsePacket(org.dom4j.Element request)
          Create a response packet from a request packet.
static org.dom4j.Element createStanza(java.lang.String sName, JID from, JID to)
          Create a request packet element.
static org.dom4j.Element createXdbPassword(java.lang.String sPassword)
          Create a password entry for the XDB.
protected static java.lang.String nextPacketId()
          Provide the next packet id.
static void setError(org.dom4j.Element packet, int nError, java.lang.String sMessage)
          Set the error on a packet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_nextPacketId

protected static long m_nextPacketId
packet id generator.


m_documentFactory

protected static final org.dom4j.DocumentFactory m_documentFactory
Our document factory.

Constructor Detail

DomPacketTools

public DomPacketTools()
Method Detail

createRequestPacket

public static org.dom4j.Element createRequestPacket(java.lang.String sName,
                                                    java.lang.String sFrom,
                                                    java.lang.String sTo)

Create a request packet element. Also generates a packet id.

Parameters:
sName - The packet name, such as iq, message, or presence.
sFrom - The source of the packet.
sTo - Who the packet is destined for.
Returns:
The new request as an Element.

createStanza

public static org.dom4j.Element createStanza(java.lang.String sName,
                                             JID from,
                                             JID to)

Create a request packet element. Also generates a packet id.

Parameters:
sName - The packet name, such as iq, message, or presence.
Returns:
The new request as an Element.

createResponsePacket

public static org.dom4j.Element createResponsePacket(org.dom4j.Element request)

Create a response packet from a request packet. Uses the request packet to get the 'from', 'to', and packet 'id' fields. Creates the response packet using the same top level element name as the request.

* @param request The packet we are generating a response to. * @return The new response packet.


setError

public static void setError(org.dom4j.Element packet,
                            int nError,
                            java.lang.String sMessage)

Set the error on a packet. Sets a packet attribute named 'type' to error. Adds an <error> element, and sets the code attribute to the given error.

If the message parameter is non-null, then it is used as the PCDATA for the error element.

Parameters:
packet - The packet to signal as an error.
nError - The error code to place in the code attribute of the error element.
sMessage - An optional error message.

createXdbPassword

public static org.dom4j.Element createXdbPassword(java.lang.String sPassword)

Create a password entry for the XDB. This is the single database record required for a new user.

Parameters:
sPassword - The users password.
Returns:
Element An xml fragment suitable for placing in an xdb set packet.

createQuery

public static org.dom4j.Element createQuery(java.lang.String sNamespace)

Create a simple query element.

* @param sNamespace The namespace to use. * @return An element named 'query' with the given namespace.


nextPacketId

protected static java.lang.String nextPacketId()

Provide the next packet id.

Returns:
The next packet id as a string.


Copyright © 2002,2003 Real Time Entertainment Group, LLC. All Rights Reserved.