refactoring - moving version and keepalive jabber extensions to their own packages in impl.provider.jabber.extension

cusax-fix
Emil Ivov 19 years ago
parent 601eec696d
commit 0bb574b7bf

@ -0,0 +1,124 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.keepalive;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.util.*;
import net.java.sip.communicator.impl.protocol.jabber.extensions.*;
/**
* KeepAlive Event. Events are send on specified interval
* and must be received from the sendin provider.
* Carries the information for the source ProtocolProvider and
* source OperationSet - so we can be sure that we are sending and receiving the
* same package.
*
* @author Damian Minkov
*/
public class KeepAliveEvent
extends IQ
{
public static final String SOURCE_PROVIDER_HASH = "src-provider-hash";
public static final String SOURCE_OPSET_HASH = "src-opset-hash";
private int srcProviderHash = -1;
private int srcOpSetHash = -1;
/**
* Constructs empty packet
*/
public KeepAliveEvent()
{}
/**
* Construct packet for sending.
*
* @param to the address of the contact that the packet is to be sent to.
*/
public KeepAliveEvent(String to)
{
if (to == null)
{
throw new IllegalArgumentException("Parameter cannot be null");
}
setTo(to);
}
/**
* Returns the sub-element XML section of this packet
*
* @return the packet as XML.
*/
public String getChildElementXML()
{
StringBuffer buf = new StringBuffer();
buf.append("<").append(KeepAliveEventProvider.ELEMENT_NAME).
append(" xmlns=\"").append(KeepAliveEventProvider.NAMESPACE).
append("\">");
buf.append("<").
append(SOURCE_PROVIDER_HASH).append(">").
append(getSrcProviderHash()).append("</").
append(SOURCE_PROVIDER_HASH).append(">");
buf.append("<").
append(SOURCE_OPSET_HASH).append(">").
append(getSrcOpSetHash()).append("</").
append(SOURCE_OPSET_HASH).append(">");
buf.append("</").append(KeepAliveEventProvider.ELEMENT_NAME).append(">");
return buf.toString();
}
/**
* The user id sending this packet
* @return String user id
*/
public String getFromUserID()
{
if(getFrom() != null)
return StringUtils.parseBareAddress(getFrom());
else
return null;
}
/**
* Returns the hash of the source opeartion set sending this message
* @return int hash of the operation set
*/
public int getSrcOpSetHash()
{
return srcOpSetHash;
}
/**
* Returns the hash of the source provider sending this message
* @return int hash of the provider
*/
public int getSrcProviderHash()
{
return srcProviderHash;
}
/**
* Sets the hash of the source provider that will send the message
* @param srcProviderHash int hash of the provider
*/
public void setSrcProviderHash(int srcProviderHash)
{
this.srcProviderHash = srcProviderHash;
}
/**
* Sets the hash of the source opeartion set that will send the message
* @param srcOpSetHash int hash of the operation set
*/
public void setSrcOpSetHash(int srcOpSetHash)
{
this.srcOpSetHash = srcOpSetHash;
}
}

@ -0,0 +1,80 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber.extensions.keepalive;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.provider.*;
import org.xmlpull.v1.*;
/**
* The KeepAliveEventProvider parses KeepAlive Event packets.
*
* @author Damian Minkov
*/
public class KeepAliveEventProvider
implements IQProvider
{
public static final String ELEMENT_NAME = "keepalive";
public static final String NAMESPACE = "sip-communicator:iq:keepalive";
/**
* Creates a new KeepAliveEventProvider.
* ProviderManager requires that every PacketExtensionProvider has a public,
* no-argument constructor
*/
public KeepAliveEventProvider()
{}
/**
* Parses a KeepAliveEvent packet .
*
* @param parser an XML parser.
* @return a new IQ instance.
* @throws Exception if an error occurs parsing the XML.
*/
public IQ parseIQ(XmlPullParser parser)
throws Exception
{
KeepAliveEvent result = new KeepAliveEvent();
boolean done = false;
while (!done)
{
try
{
int eventType = parser.next();
if(eventType == XmlPullParser.START_TAG)
{
if(parser.getName().equals(KeepAliveEvent.
SOURCE_PROVIDER_HASH))
{
result.setSrcProviderHash(Integer.parseInt(parser.
nextText()));
}
if(parser.getName().equals(KeepAliveEvent.SOURCE_OPSET_HASH))
{
result.setSrcOpSetHash(Integer.parseInt(parser.nextText()));
}
}
else if(eventType == XmlPullParser.END_TAG)
{
if(parser.getName().equals(ELEMENT_NAME))
{
done = true;
}
}
}
catch(NumberFormatException ex)
{
ex.printStackTrace();
}
}
return result;
}
}
Loading…
Cancel
Save