Attempts to fix the problem of writingcyrillic text (it's just an example but it should happen with other encodings as well) and sending ??? instead and receiving cyrillic text which should be displayed correctly but is instead displayed as ???.

cusax-fix
Lyubomir Marinov 18 years ago
parent d36c3f5d96
commit 7562dd0052

@ -466,15 +466,15 @@ void addProtoContact(Contact contact)
this.protoContacts.add(contact);
//if this is our firt contact and we don't already have a display
//name, use theirs.
if(this.protoContacts.size() == 1
&&( this.displayName == null
|| this.displayName.trim().length() == 0)){
//be careful not to use setDisplayName() here cause this will
//bring us into a deadlock.
this.displayName
= new String(contact.getDisplayName().getBytes());
// if this is our firt contact and we don't already have a display
// name, use theirs.
if (this.protoContacts.size() == 1
&& (this.displayName == null || this.displayName.trim()
.length() == 0))
{
// be careful not to use setDisplayName() here cause this will
// bring us into a deadlock.
this.displayName = contact.getDisplayName();
}
if (parentGroup != null)

@ -4,7 +4,6 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.gui.main.chat;
import java.awt.*;
@ -964,10 +963,7 @@ private void sendInstantMessage()
|| htmlText.indexOf("<u") > -1
|| htmlText.indexOf("<font") > -1))
{
msg = im.createMessage( htmlText.getBytes(),
"text/html",
"utf-8",
"");
msg = im.createMessage(htmlText, "text/html", "utf-8", "");
}
else
{

@ -11,7 +11,6 @@
import org.osgi.framework.*;
import net.java.sip.communicator.impl.msghistory.MessageHistoryActivator.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.configuration.event.*;
import net.java.sip.communicator.service.resources.*;
@ -34,6 +33,7 @@
*
* @author Alexander Pelov
* @author Damian Minkov
* @author Lubomir Marinov
*/
public class MessageHistoryServiceImpl
implements MessageHistoryService,
@ -519,7 +519,7 @@ private History getHistoryForMultiChat(
*/
private Object convertHistoryRecordToMessageEvent(HistoryRecord hr, Contact contact)
{
MessageImpl msg = new MessageImpl(hr);
MessageImpl msg = createMessageFromHistoryRecord(hr);
Date timestamp = null;
// if there is value for date of receiving the message
@ -563,7 +563,7 @@ private Object convertHistoryRecordToMessageEvent(HistoryRecord hr, Contact cont
private Object convertHistoryRecordToMessageEvent(
HistoryRecord hr, ChatRoom room)
{
MessageImpl msg = new MessageImpl(hr);
MessageImpl msg = createMessageFromHistoryRecord(hr);
Date timestamp = null;
// if there is value for date of receiving the message
@ -605,6 +605,54 @@ private Object convertHistoryRecordToMessageEvent(
.CONVERSATION_MESSAGE_RECEIVED);
}
private MessageImpl createMessageFromHistoryRecord(HistoryRecord hr)
{
// History structure
// 0 - dir
// 1 - msg_CDATA
// 2 - msgTyp
// 3 - enc
// 4- uid
// 5 - sub
// 6 - receivedTimestamp
String textContent = null;
String contentType = null;
String contentEncoding = null;
String messageUID = null;
String subject = null;
boolean isOutgoing = false;
Date messageReceivedDate = null;
for (int i = 0; i < hr.getPropertyNames().length; i++)
{
String propName = hr.getPropertyNames()[i];
if (propName.equals("msg") || propName.equals(STRUCTURE_NAMES[1]))
textContent = hr.getPropertyValues()[i];
else if (propName.equals(STRUCTURE_NAMES[2]))
contentType = hr.getPropertyValues()[i];
else if (propName.equals(STRUCTURE_NAMES[3]))
contentEncoding = hr.getPropertyValues()[i];
else if (propName.equals(STRUCTURE_NAMES[4]))
messageUID = hr.getPropertyValues()[i];
else if (propName.equals(STRUCTURE_NAMES[5]))
subject = hr.getPropertyValues()[i];
else if (propName.equals(STRUCTURE_NAMES[0]))
{
if (hr.getPropertyValues()[i].equals("in"))
isOutgoing = false;
else if (hr.getPropertyValues()[i].equals("out"))
isOutgoing = true;
}
else if (propName.equals(STRUCTURE_NAMES[6]))
{
messageReceivedDate =
new Date(Long.parseLong(hr.getPropertyValues()[i]));
}
}
return new MessageImpl(textContent, contentType, contentEncoding,
subject, messageUID, isOutgoing, messageReceivedDate);
}
/**
* starts the service. Check the current registerd protocol providers
* which supports BasicIM and adds message listener to them
@ -1767,91 +1815,20 @@ void clear()
* Simple message implementation.
*/
private class MessageImpl
implements Message
extends AbstractMessage
{
private String textContent = null;
private String contentType = null;
private String contentEncoding = null;
private String messageUID = null;
private String subject = null;
private boolean isOutgoing = false;
private Date messageReceivedDate = null;
MessageImpl(HistoryRecord hr)
{
// History structure
// 0 - dir
// 1 - msg_CDATA
// 2 - msgTyp
// 3 - enc
// 4- uid
// 5 - sub
// 6 - receivedTimestamp
for (int i = 0; i < hr.getPropertyNames().length; i++)
{
String propName = hr.getPropertyNames()[i];
if(propName.equals("msg") || propName.equals(STRUCTURE_NAMES[1]))
textContent = hr.getPropertyValues()[i];
else if(propName.equals(STRUCTURE_NAMES[2]))
contentType = hr.getPropertyValues()[i];
else if(propName.equals(STRUCTURE_NAMES[3]))
contentEncoding = hr.getPropertyValues()[i];
else if(propName.equals(STRUCTURE_NAMES[4]))
messageUID = hr.getPropertyValues()[i];
else if(propName.equals(STRUCTURE_NAMES[5]))
subject = hr.getPropertyValues()[i];
else if(propName.equals(STRUCTURE_NAMES[0]))
{
if (hr.getPropertyValues()[i].equals("in"))
isOutgoing = false;
else if (hr.getPropertyValues()[i].equals("out"))
isOutgoing = true;
}
else if(propName.equals(STRUCTURE_NAMES[6]))
{
messageReceivedDate = new Date(
Long.parseLong(hr.getPropertyValues()[i]));
}
}
}
public String getContent()
{
return textContent;
}
public String getContentType()
{
return contentType;
}
public String getEncoding()
{
return contentEncoding;
}
private final boolean isOutgoing;
public String getMessageUID()
{
return messageUID;
}
private final Date messageReceivedDate;
public byte[] getRawData()
MessageImpl(String content, String contentType, String encoding,
String subject, String messageUID, boolean isOutgoing,
Date messageReceivedDate)
{
return getContent().getBytes();
}
super(content, contentType, encoding, subject, messageUID);
public int getSize()
{
return getContent().length();
}
public String getSubject()
{
return subject;
this.isOutgoing = isOutgoing;
this.messageReceivedDate = messageReceivedDate;
}
public Date getMessageReceivedDate()

@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.dict;
@ -10,129 +9,26 @@
/**
* Very simple message implementation for the Dict protocol.
*
*
* @author ROTH Damien
* @author LITZELMANN Cedric
* @author Lubomir Marinov
*/
public class MessageDictImpl
implements Message
extends AbstractMessage
{
/**
* The actual message content.
*/
private String textContent = null;
/**
* The content type of the message. (text/plain if null)
*/
private String contentType = null;
/**
* The message encoding. (UTF8 if null).
*/
private String contentEncoding = null;
/**
* A String uniquely identifying the message
*/
private String messageUID = null;
/**
* The subject of the message. (most often is null)
*/
private String subject = null;
/**
* Creates a message instance according to the specified parameters.
*
*
* @param content the message body
* @param contentType message content type or null for text/plain
* @param contentEncoding message encoding or null for UTF8
* @param subject the subject of the message or null for no subject.
*/
public MessageDictImpl(String content,
String contentType,
String contentEncoding,
String subject)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
//generate the uid
this.messageUID = String.valueOf(System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the message body.
*
* @return the message content.
*/
public String getContent()
{
return textContent;
}
/**
* Returns the type of the content of this message.
*
* @return the type of the content of this message.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the encoding used for the message content.
*
* @return the encoding of the message body.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* A string uniquely identifying the message.
*
* @return a <tt>String</tt> uniquely identifying the message.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Returns the message body in a binary form.
*
* @return a <tt>byte[]</tt> representation of the message body.
*/
public byte[] getRawData()
{
return getContent().getBytes();
}
/**
* Return the length of this message.
*
* @return the length of this message.
*/
public int getSize()
{
return getContent().length();
}
/**
* Returns the message subject.
*
* @return the message subject.
*/
public String getSubject()
public MessageDictImpl(String content, String contentType,
String contentEncoding, String subject)
{
return subject;
super(content, contentType, contentEncoding, subject);
}
}

@ -19,16 +19,11 @@
* @author LITZELMANN Cedric
*/
public class OperationSetBasicInstantMessagingDictImpl
implements OperationSetBasicInstantMessaging,
RegistrationStateChangeListener
extends AbstractOperationSetBasicInstantMessaging
implements RegistrationStateChangeListener
{
private static final Logger logger
= Logger.getLogger(OperationSetBasicInstantMessagingDictImpl.class);
/**
* Currently registered message listeners.
*/
private Vector messageListeners = new Vector();
/**
* The currently valid persistent presence operation set.
@ -58,61 +53,10 @@ public OperationSetBasicInstantMessagingDictImpl(
parentProvider.addRegistrationStateChangeListener(this);
}
/**
* Registers a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages.
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
if(!messageListeners.contains(listener))
{
messageListeners.add(listener);
}
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now
* subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject)
{
return new MessageDictImpl(new String(content), contentType,
contentEncoding, subject);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
{
return new MessageDictImpl(messageText, DEFAULT_MIME_TYPE,
DEFAULT_MIME_ENCODING, null);
}
/**
* Unregisters <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception
* of incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
messageListeners.remove(listener);
return new MessageDictImpl(content, contentType, encoding, subject);
}
/**
@ -143,60 +87,6 @@ public void sendInstantMessage(Contact to, Message message)
this.submitDictQuery((ContactDictImpl) to, message);
}
/**
* Notifies all registered message listeners that a message has been
* delivered successfully to its addressee..
*
* @param message the <tt>Message</tt> that has been delivered.
* @param to the <tt>Contact</tt> that <tt>message</tt> was delivered to.
*/
private void fireMessageDelivered(Message message, Contact to)
{
MessageDeliveredEvent evt
= new MessageDeliveredEvent(message, to, new Date());
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
listener.messageDelivered(evt);
}
}
/**
* Notifies all registered message listeners that a message has been
* received.
*
* @param message the <tt>Message</tt> that has been received.
* @param from the <tt>Contact</tt> that <tt>message</tt> was received from.
*/
private void fireMessageReceived(Message message, Contact from)
{
MessageReceivedEvent evt
= new MessageReceivedEvent(message, from, new Date());
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
listener.messageReceived(evt);
}
}
/**
* Determines whether the protocol provider (or the protocol itself) supports
* sending and receiving offline messages. Most often this method would
@ -298,10 +188,9 @@ private void submitDictQuery(ContactDictImpl dictContact, Message message)
try
{
fctResult = dictAdapter.define(database, word);
msg = this.createMessage(this.retrieveDefine(fctResult, word).getBytes()
, HTML_MIME_TYPE
, DEFAULT_MIME_ENCODING,
null);
msg =
this.createMessage(this.retrieveDefine(fctResult, word),
HTML_MIME_TYPE, DEFAULT_MIME_ENCODING, null);
}
catch(DictException dex)
{

@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.gibberish;
@ -10,128 +9,25 @@
/**
* Very simple message implementation for the Gibberish protocol.
*
*
* @author Emil Ivov
* @authro Lubomir Marinov
*/
public class MessageGibberishImpl
implements Message
extends AbstractMessage
{
/**
* The actual message content.
*/
private String textContent = null;
/**
* The content type of the message. (text/plain if null)
*/
private String contentType = null;
/**
* The message encoding. (UTF8 if null).
*/
private String contentEncoding = null;
/**
* A String uniquely identifying the message
*/
private String messageUID = null;
/**
* The subject of the message. (most often is null)
*/
private String subject = null;
/**
* Creates a message instance according to the specified parameters.
*
*
* @param content the message body
* @param contentType message content type or null for text/plain
* @param contentEncoding message encoding or null for UTF8
* @param subject the subject of the message or null for no subject.
*/
public MessageGibberishImpl(String content,
String contentType,
String contentEncoding,
String subject)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
//generate the uid
this.messageUID = String.valueOf(System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the message body.
*
* @return the message content.
*/
public String getContent()
{
return textContent;
}
/**
* Returns the type of the content of this message.
*
* @return the type of the content of this message.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the encoding used for the message content.
*
* @return the encoding of the message body.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* A string uniquely identifying the message.
*
* @return a <tt>String</tt> uniquely identifying the message.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Returns the message body in a binary form.
*
* @return a <tt>byte[]</tt> representation of the message body.
*/
public byte[] getRawData()
{
return getContent().getBytes();
}
/**
* Return the length of this message.
*
* @return the length of this message.
*/
public int getSize()
{
return getContent().length();
}
/**
* Returns the message subject.
*
* @return the message subject.
*/
public String getSubject()
public MessageGibberishImpl(String content, String contentType,
String contentEncoding, String subject)
{
return subject;
super(content, contentType, contentEncoding, subject);
}
}

@ -17,12 +17,8 @@
* @author Emil Ivov
*/
public class OperationSetBasicInstantMessagingGibberishImpl
implements OperationSetBasicInstantMessaging
extends AbstractOperationSetBasicInstantMessaging
{
/**
* Currently registered message listeners.
*/
private Vector messageListeners = new Vector();
/**
* The currently valid persistent presence operation set..
@ -50,59 +46,10 @@ public OperationSetBasicInstantMessagingGibberishImpl(
this.parentProvider = provider;
}
/**
* Registers a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
if(!messageListeners.contains(listener))
messageListeners.add(listener);
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now
* subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject)
{
return new MessageGibberishImpl(new String(content), contentType
, contentEncoding, subject);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
{
return new MessageGibberishImpl(messageText, DEFAULT_MIME_TYPE
, DEFAULT_MIME_ENCODING, null);
}
/**
* Unregisteres <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception
* of incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
{
messageListeners.remove(listener);
return new MessageGibberishImpl(content, contentType, encoding, subject);
}
/**
@ -195,60 +142,6 @@ private void deliverMessage(Message message, ContactGibberishImpl to)
}
}
/**
* Notifies all registered message listeners that a message has been
* delivered successfully to its addressee..
*
* @param message the <tt>Message</tt> that has been delivered.
* @param to the <tt>Contact</tt> that <tt>message</tt> was delivered to.
*/
private void fireMessageDelivered(Message message, Contact to)
{
MessageDeliveredEvent evt
= new MessageDeliveredEvent(message, to, new Date());
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
listener.messageDelivered(evt);
}
}
/**
* Notifies all registered message listeners that a message has been
* received.
*
* @param message the <tt>Message</tt> that has been received.
* @param from the <tt>Contact</tt> that <tt>message</tt> was received from.
*/
private void fireMessageReceived(Message message, Contact from)
{
MessageReceivedEvent evt
= new MessageReceivedEvent(message, from, new Date());
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
listener.messageReceived(evt);
}
}
/**
* Determines wheter the protocol provider (or the protocol itself) support
* sending and receiving offline messages. Most often this method would

@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.icq;
@ -11,146 +10,27 @@
/**
* A simple implementation of the <tt>Message</tt> interface. Right now the
* message only supports test contents and no binary data.
*
*
* @author Emil Ivov
* @author Lubomir Marinov
*/
public class MessageIcqImpl
implements Message
extends AbstractMessage
{
/**
* The content of this message.
*/
private String textContent = null;
/**
* The content type of text. Right now only text content types (such as
* text/plain or text/html) are supported.
*/
private String contentType = null;
/**
* The encoding under which the contennt of this message is encoded.
*/
private String contentEncoding = null;
/**
* An String uniquely identifying this Message.
*/
private String messageUID = null;
/**
* The subject of the message if any (may remain null).
*/
private String subject = null;
/**
* Creates an instance of this Message with the specified parameters.
*
*
* @param content the text content of the message.
* @param contentType a MIME string indicating the content type of the
* <tt>content</tt> String.
* <tt>content</tt> String.
* @param contentEncoding a MIME String indicating the content encoding of
* the <tt>content</tt> String.
* the <tt>content</tt> String.
* @param subject the subject of the message or null for empty.
* @param messageUID an UID in case we'd like to set our own or null for an
* automatically generated one.
*/
public MessageIcqImpl(String content,
String contentType,
String contentEncoding,
String subject,
String messageUID)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
if(messageUID == null)
{
//generate the uid
this.messageUID = String.valueOf(System.currentTimeMillis())
+ String.valueOf(hashCode());
}
else
{
this.messageUID = messageUID;
}
}
/**
* Returns the content of this message if representable in text form or
* null if this message does not contain text data.
*
* @return a String containing the content of this message or null if
* the message does not contain data representable in text form.
*/
public String getContent()
{
return textContent;
}
/**
* Returns the MIME type for the message content.
*
* @return a String containing the mime type of the message contant.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the MIME content encoding of this message.
*
* @return a String indicating the MIME encoding of this message.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* Returns a unique identifier of this message.
*
* @return a String that uniquely represents this message in the scope
* of this protocol.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Get the raw/binary content of an instant message.
*
* @return a byte[] array containing message bytes.
*/
public byte[] getRawData()
{
return getContent().getBytes();
}
/**
* Returns the size of the content stored in this message.
*
* @return an int indicating the number of bytes that this message
* contains.
*/
public int getSize()
{
return getContent().length();
}
/**
* Returns the subject of this message or null if the message contains no
* subject.
*
* @return the subject of this message or null if the message contains
* no subject.
*/
public String getSubject()
public MessageIcqImpl(String content, String contentType,
String contentEncoding, String subject)
{
return subject;
super(content, contentType, contentEncoding, subject);
}
}

@ -29,15 +29,10 @@
* @author Damian Minkov
*/
public class OperationSetBasicInstantMessagingIcqImpl
implements OperationSetBasicInstantMessaging
extends AbstractOperationSetBasicInstantMessaging
{
private static final Logger logger =
Logger.getLogger(OperationSetBasicInstantMessagingIcqImpl.class);
/**
* A list of listeneres registered for message events.
*/
private Vector messageListeners = new Vector();
/**
* The icq provider that created us.
@ -131,67 +126,10 @@ public class OperationSetBasicInstantMessagingIcqImpl
icqProvider.addRegistrationStateChangeListener(providerRegListener);
}
/**
* Registeres a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
synchronized(messageListeners)
{
if(!messageListeners.contains(listener))
this.messageListeners.add(listener);
}
}
/**
* Unregisteres <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
{
synchronized(messageListeners)
{
this.messageListeners.remove(listener);
}
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject)
{
return new MessageIcqImpl( new String(content),
contentType,
contentEncoding,
subject,
null);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
return new MessageIcqImpl(messageText, DEFAULT_MIME_TYPE
, DEFAULT_MIME_ENCODING, null, null);
return new MessageIcqImpl(content, contentType, encoding, subject);
}
/**
@ -467,41 +405,6 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
}
}
/**
* Delivers the specified event to all registered message listeners.
* @param evt the <tt>EventObject</tt> that we'd like delivered to all
* registered message listerners.
*/
private void fireMessageEvent(EventObject evt)
{
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
if (evt instanceof MessageDeliveredEvent)
{
listener.messageDelivered( (MessageDeliveredEvent) evt);
}
else if (evt instanceof MessageReceivedEvent)
{
listener.messageReceived( (MessageReceivedEvent) evt);
}
else if (evt instanceof MessageDeliveryFailedEvent)
{
listener.messageDeliveryFailed(
(MessageDeliveryFailedEvent) evt);
}
}
}
/**
* The listener that would retrieve instant messaging events from oscar.jar.
*/
@ -588,8 +491,9 @@ public void gotMessage(Conversation conversation, MessageInfo minfo)
else
msgContent = msgBody;
Message newMessage = createMessage(msgContent.getBytes(),
HTML_MIME_TYPE, DEFAULT_MIME_ENCODING, null);
Message newMessage =
createMessage(msgContent, HTML_MIME_TYPE,
DEFAULT_MIME_ENCODING, null);
Contact sourceContact =
opSetPersPresence.findContactByID( conversation.getBuddy()

@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.irc;
@ -10,12 +9,13 @@
/**
* Very simple message implementation for the IRC protocol.
*
*
* @author Stephane Remy
* @author Loic Kempf
* @author Lubomir Marinov
*/
public class MessageIrcImpl
implements Message
extends AbstractMessage
{
/**
@ -28,124 +28,20 @@ public class MessageIrcImpl
*/
public static final String DEFAULT_MIME_TYPE = "text/plain";
/**
* The actual message content.
*/
private String textContent = null;
/**
* The content type of the message. (text/html if null)
*/
private String contentType = DEFAULT_MIME_TYPE;
/**
* The message encoding. (UTF8 if null).
*/
private String contentEncoding = null;
/**
* A String uniquely identifying the message
*/
private String messageUID = null;
/**
* The subject of the message. (most often is null)
*/
private String subject = null;
/**
* Creates a message instance according to the specified parameters.
*
*
* @param content the message body
* @param contentType message content type or null for text/plain
* @param contentEncoding message encoding or null for UTF8
* @param subject the subject of the message or null for no subject.
*/
public MessageIrcImpl(String content,
String contentType,
String contentEncoding,
String subject)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
//generate the uid
this.messageUID = String.valueOf(System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the message body.
*
* @return the message content.
*/
public String getContent()
{
return textContent;
}
/**
* Returns the type of the content of this message.
*
* @return the type of the content of this message.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the encoding used for the message content.
*
* @return the encoding of the message body.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* A string uniquely identifying the message.
*
* @return a <tt>String</tt> uniquely identifying the message.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Returns the message body in a binary form.
*
* @return a <tt>byte[]</tt> representation of the message body.
*/
public byte[] getRawData()
public MessageIrcImpl(String content, String contentType,
String contentEncoding, String subject)
{
return textContent.getBytes();
super(content, contentType, contentEncoding, subject);
}
/**
* Return the length of this message.
*
* @return the length of this message.
*/
public int getSize()
{
return textContent.length();
}
/**
* Returns the message subject.
*
* @return the message subject.
*/
public String getSubject()
{
return subject;
}
/**
* Checks if this message is a command. In IRC all messages that start with
* the '/' character are commands.
@ -154,7 +50,7 @@ public String getSubject()
*/
public boolean isCommand()
{
return textContent.startsWith("/");
return getContent().startsWith("/");
}
/**
@ -165,7 +61,7 @@ public boolean isCommand()
*/
public boolean isAction()
{
return textContent.startsWith("/me");
return getContent().startsWith("/me");
}
/**
@ -176,6 +72,6 @@ public boolean isAction()
*/
protected void setContent(String messageContent)
{
this.textContent = messageContent;
super.setContent(messageContent);
}
}
}

@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber;
@ -11,137 +10,27 @@
/**
* A simple implementation of the <tt>Message</tt> interface. Right now the
* message only supports test contents and no binary data.
*
*
* @author Damian Minkov
* @author Lubomir Marinov
*/
public class MessageJabberImpl
implements Message
extends AbstractMessage
{
/**
* The content of this message.
*/
private String textContent = null;
/**
* The content type of text. Right now only text content types (such as
* text/plain or text/html) are supported.
*/
private String contentType = null;
/**
* The encoding under which the contennt of this message is encoded.
*/
private String contentEncoding = null;
/**
* An String uniquely identifying this Message.
*/
private String messageUID = null;
/**
* The subject of the message if any (may remain null).
*/
private String subject = null;
/**
* Creates an instance of this Message with the specified parameters.
*
*
* @param content the text content of the message.
* @param contentType a MIME string indicating the content type of the
* <tt>content</tt> String.
* <tt>content</tt> String.
* @param contentEncoding a MIME String indicating the content encoding of
* the <tt>content</tt> String.
* the <tt>content</tt> String.
* @param subject the subject of the message or null for empty.
*/
public MessageJabberImpl(String content,
String contentType,
String contentEncoding,
String subject)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
//generate the uid
this.messageUID = String.valueOf( System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the content of this message if representable in text form or
* null if this message does not contain text data.
*
* @return a String containing the content of this message or null if
* the message does not contain data representable in text form.
*/
public String getContent()
{
return textContent;
}
/**
* Returns the MIME type for the message content.
*
* @return a String containing the mime type of the message contant.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the MIME content encoding of this message.
*
* @return a String indicating the MIME encoding of this message.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* Returns a unique identifier of this message.
*
* @return a String that uniquely represents this message in the scope
* of this protocol.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Get the raw/binary content of an instant message.
*
* @return a byte[] array containing message bytes.
*/
public byte[] getRawData()
{
return getContent().getBytes();
}
/**
* Returns the size of the content stored in this message.
*
* @return an int indicating the number of bytes that this message
* contains.
*/
public int getSize()
{
return getContent().length();
}
/**
* Returns the subject of this message or null if the message contains no
* subject.
*
* @return the subject of this message or null if the message contains
* no subject.
*/
public String getSubject()
public MessageJabberImpl(String content, String contentType,
String contentEncoding, String subject)
{
return subject;
super(content, contentType, contentEncoding, subject);
}
}

@ -13,7 +13,6 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.Message;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.protocol.event.MessageListener;
import net.java.sip.communicator.service.protocol.jabberconstants.*;
import net.java.sip.communicator.util.*;
@ -32,7 +31,7 @@
* @author Damian Minkov
*/
public class OperationSetBasicInstantMessagingJabberImpl
implements OperationSetBasicInstantMessaging
extends AbstractOperationSetBasicInstantMessaging
{
private static final Logger logger =
Logger.getLogger(OperationSetBasicInstantMessagingJabberImpl.class);
@ -64,11 +63,6 @@ public class OperationSetBasicInstantMessagingJabberImpl
private int failedKeepalivePackets = 0;
/**
* A list of listeneres registered for message events.
*/
private Vector messageListeners = new Vector();
/**
* The provider that created us.
*/
@ -114,78 +108,22 @@ public class OperationSetBasicInstantMessagingJabberImpl
new KeepAliveEventProvider());
}
/**
* Registeres a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
synchronized(messageListeners)
{
if(!messageListeners.contains(listener))
{
this.messageListeners.add(listener);
}
}
}
/**
* Unregisteres <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
{
synchronized(messageListeners)
{
this.messageListeners.remove(listener);
}
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject)
{
return new MessageJabberImpl(new String(content), contentType
, contentEncoding, subject);
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType)
public Message createMessage(String content, String contentType)
{
return createMessage(content, contentType, DEFAULT_MIME_ENCODING, null);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
return createMessage(messageText.getBytes(), DEFAULT_MIME_TYPE
, DEFAULT_MIME_ENCODING, null);
return new MessageJabberImpl(content, contentType, encoding, subject);
}
/**
@ -360,40 +298,6 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
}
}
}
/**
* Delivers the specified event to all registered message listeners.
* @param evt the <tt>EventObject</tt> that we'd like delivered to all
* registered message listerners.
*/
private void fireMessageEvent(EventObject evt)
{
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
if (evt instanceof MessageDeliveredEvent)
{
listener.messageDelivered( (MessageDeliveredEvent) evt);
}
else if (evt instanceof MessageReceivedEvent)
{
listener.messageReceived( (MessageReceivedEvent) evt);
}
else if (evt instanceof MessageDeliveryFailedEvent)
{
listener.messageDeliveryFailed(
(MessageDeliveryFailedEvent) evt);
}
}
}
/**
* The listener that we use in order to handle incoming messages.
@ -440,10 +344,10 @@ public void processPacket(Packet packet)
String body = (String)bodies.next();
messageBuff.append(body);
}
if(messageBuff.length() > 0)
newMessage = createMessage(messageBuff.toString().getBytes(),
HTML_MIME_TYPE);
if (messageBuff.length() > 0)
newMessage =
createMessage(messageBuff.toString(), HTML_MIME_TYPE);
}
Contact sourceContact =

@ -12,18 +12,14 @@
import net.java.sip.communicator.service.protocol.event.*;
/**
* Instant messaging functionalites for the mock protocol.
* Instant messaging functionality for the mock protocol.
*
* @author Damian Minkov
* @author Emil Ivov
*/
public class MockBasicInstantMessaging
implements OperationSetBasicInstantMessaging
extends AbstractOperationSetBasicInstantMessaging
{
/**
* Currently registered message listeners.
*/
private Vector messageListeners = new Vector();
/**
* The currently valid persistent presence operation set..
@ -51,89 +47,32 @@ public MockBasicInstantMessaging(
this.parentProvider = provider;
}
/**
* Registeres a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
if(!messageListeners.contains(listener))
messageListeners.add(listener);
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now
* subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject)
{
return new MockMessage(new String(content), contentType
, contentEncoding, subject);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
return new MockMessage(messageText, DEFAULT_MIME_TYPE,
DEFAULT_MIME_ENCODING, null);
}
/**
* Unregisteres <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception
* of incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
{
messageListeners.remove(listener);
return new MockMessage(content, contentType, encoding, subject);
}
/**
* Sends the <tt>message</tt> to the destination indicated by the
* <tt>to</tt> contact.
*
*
* @param to the <tt>Contact</tt> to send <tt>message</tt> to
* @param message the <tt>Message</tt> to send.
* @throws IllegalStateException if the underlying ICQ stack is not
* registered and initialized.
* registered and initialized.
* @throws IllegalArgumentException if <tt>to</tt> is not an instance
* belonging to the underlying implementation.
* belonging to the underlying implementation.
*/
public void sendInstantMessage(Contact to, Message message) throws
IllegalStateException, IllegalArgumentException
public void sendInstantMessage(Contact to, Message message)
throws IllegalStateException,
IllegalArgumentException
{
MessageDeliveredEvent msgDeliveredEvt
= new MessageDeliveredEvent(
message, to, new Date());
Iterator iter = messageListeners.iterator();
while (iter.hasNext())
{
MessageListener listener = (MessageListener)iter.next();
listener.messageDelivered(msgDeliveredEvt);
}
fireMessageEvent(new MessageDeliveredEvent(message, to, new Date()));
}
/**
* Determines wheter the protocol provider (or the protocol itself) support
* Determines whether the protocol provider (or the protocol itself) support
* sending and receiving offline messages. Most often this method would
* return true for protocols that support offline messages and false for
* those that don't. It is however possible for a protocol to support these
@ -152,7 +91,7 @@ public boolean isOfflineMessagingSupported()
}
/**
* Determines wheter the protocol supports the supplied content type
* Determines whether the protocol supports the supplied content type
*
* @param contentType the type we want to check
* @return <tt>true</tt> if the protocol supports it and
@ -160,16 +99,12 @@ public boolean isOfflineMessagingSupported()
*/
public boolean isContentTypeSupported(String contentType)
{
if(contentType.equals(DEFAULT_MIME_TYPE))
return true;
else
return false;
return contentType.equals(DEFAULT_MIME_TYPE);
}
/**
* Methods for manipulating mock operation set as
* deliver(receive) messageop
*
* Methods for manipulating mock operation set as deliver(receive) messageop
*
* @param to the address of the contact whom we are to deliver the message.
* @param msg the message that we are to deliver.
*/
@ -177,14 +112,7 @@ public void deliverMessage(String to, Message msg)
{
Contact sourceContact = opSetPersPresence.findContactByID(to);
MessageReceivedEvent msgReceivedEvt
= new MessageReceivedEvent(
msg, sourceContact , new Date());
Iterator iter = messageListeners.iterator();
while (iter.hasNext())
{
MessageListener listener = (MessageListener)iter.next();
listener.messageReceived(msgReceivedEvt);
}
fireMessageEvent(new MessageReceivedEvent(msg, sourceContact,
new Date()));
}
}
}

@ -1,10 +1,10 @@
/*
* MockMessage.java
*
*
* Created on Jun 21, 2007, 3:10:21 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*
* To change this template, choose Tools | Template Manager and open the
* template in the editor.
*/
package net.java.sip.communicator.impl.protocol.mock;
@ -12,116 +12,23 @@
import net.java.sip.communicator.service.protocol.*;
/**
* Message Impl.
* Message Impl.
*
* @author Damian Minkov
* @author Lubomir Marinov
*/
public class MockMessage
implements Message
{
private String textContent = null;
private String contentType = null;
private String contentEncoding = null;
private String messageUID = null;
private String subject = null;
MockMessage(String content,
String contentType,
String contentEncoding,
String subject)
extends AbstractMessage
{
MockMessage(String content, String contentType, String contentEncoding,
String subject)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
//generate the uid
this.messageUID = String.valueOf( System.currentTimeMillis())
+ String.valueOf(hashCode());
super(content, contentType, contentEncoding, subject);
}
MockMessage(String content)
{
this.textContent = content;
this.contentType =
OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE;
this.contentEncoding =
OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING;
this.subject = null;
//generate the uid
this.messageUID = String.valueOf( System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the content of this message if representable in text form or null
* if this message does not contain text data.
* @return a String containing the content of this message or null if the
* message does not contain data representable in text form.
*/
public String getContent()
{
return textContent;
}
/**
* Returns the MIME type for the message content.
* @return a String containing the mime type of the message contant.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the MIME content encoding of this message.
* @return a String indicating the MIME encoding of this message.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* Returns a unique identifier of this message.
* @return a String that uniquely represents this message in the scope of
* this protocol.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Get the raw/binary content of an instant message.
* @return a byte[] array containing message bytes.
*/
public byte[] getRawData()
{
return getContent().getBytes();
}
/**
* Returns the size of the content stored in this message.
* @return an int indicating the number of bytes that this message contains.
*/
public int getSize()
{
return getContent().length();
}
/**
* Returns the subject of this message or null if the message contains no
* subject.
* @return the subject of this message or null if the message contains no
* subject.
*/
public String getSubject()
MockMessage(String content)
{
return subject;
this(content, OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE,
OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING, null);
}
}

@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.msn;
@ -11,137 +10,27 @@
/**
* A simple implementation of the <tt>Message</tt> interface. Right now the
* message only supports test contents and no binary data.
*
*
* @author Damian Minkov
* @author Lubomir Marinov
*/
public class MessageMsnImpl
implements Message
extends AbstractMessage
{
/**
* The content of this message.
*/
private String textContent = null;
/**
* The content type of text. Right now only text content types (such as
* text/plain or text/html) are supported.
*/
private String contentType = null;
/**
* The encoding under which the contennt of this message is encoded.
*/
private String contentEncoding = null;
/**
* An String uniquely identifying this Message.
*/
private String messageUID = null;
/**
* The subject of the message if any (may remain null).
*/
private String subject = null;
/**
* Creates an instance of this Message with the specified parameters.
*
*
* @param content the text content of the message.
* @param contentType a MIME string indicating the content type of the
* <tt>content</tt> String.
* <tt>content</tt> String.
* @param contentEncoding a MIME String indicating the content encoding of
* the <tt>content</tt> String.
* the <tt>content</tt> String.
* @param subject the subject of the message or null for empty.
*/
public MessageMsnImpl(String content,
String contentType,
String contentEncoding,
String subject)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
//generate the uid
this.messageUID = String.valueOf( System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the content of this message if representable in text form or
* null if this message does not contain text data.
*
* @return a String containing the content of this message or null if
* the message does not contain data representable in text form.
*/
public String getContent()
{
return textContent;
}
/**
* Returns the MIME type for the message content.
*
* @return a String containing the mime type of the message contant.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the MIME content encoding of this message.
*
* @return a String indicating the MIME encoding of this message.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* Returns a unique identifier of this message.
*
* @return a String that uniquely represents this message in the scope
* of this protocol.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Get the raw/binary content of an instant message.
*
* @return a byte[] array containing message bytes.
*/
public byte[] getRawData()
{
return getContent().getBytes();
}
/**
* Returns the size of the content stored in this message.
*
* @return an int indicating the number of bytes that this message
* contains.
*/
public int getSize()
{
return getContent().length();
}
/**
* Returns the subject of this message or null if the message contains no
* subject.
*
* @return the subject of this message or null if the message contains
* no subject.
*/
public String getSubject()
public MessageMsnImpl(String content, String contentType,
String contentEncoding, String subject)
{
return subject;
super(content, contentType, contentEncoding, subject);
}
}

@ -11,7 +11,6 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.protocol.msnconstants.*;
import net.java.sip.communicator.util.*;
import net.sf.jml.*;
import net.sf.jml.event.*;
@ -25,16 +24,11 @@
* @author Damian Minkov
*/
public class OperationSetBasicInstantMessagingMsnImpl
implements OperationSetBasicInstantMessaging
extends AbstractOperationSetBasicInstantMessaging
{
private static final Logger logger =
Logger.getLogger(OperationSetBasicInstantMessagingMsnImpl.class);
/**
* A list of listeners registered for message events.
*/
private Vector messageListeners = new Vector();
/**
* The provider that created us.
*/
@ -59,39 +53,6 @@ public class OperationSetBasicInstantMessagingMsnImpl
provider.addRegistrationStateChangeListener(new RegistrationStateListener());
}
/**
* Registers a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
synchronized(messageListeners)
{
if(!messageListeners.contains(listener))
{
this.messageListeners.add(listener);
}
}
}
/**
* Unregisters <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
{
synchronized(messageListeners)
{
this.messageListeners.remove(listener);
}
}
/**
* Determines whether the protocol provider (or the protocol itself) support
* sending and receiving offline messages. Most often this method would
@ -126,33 +87,10 @@ public boolean isContentTypeSupported(String contentType)
return false;
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
return new MessageMsnImpl(new String(content), contentType
, contentEncoding, subject);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
{
return new MessageMsnImpl(messageText, DEFAULT_MIME_TYPE
, DEFAULT_MIME_ENCODING, null);
return new MessageMsnImpl(content, contentType, encoding, subject);
}
/**
@ -239,40 +177,6 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
}
}
/**
* Delivers the specified event to all registered message listeners.
* @param evt the <tt>EventObject</tt> that we'd like delivered to all
* registered message listeners.
*/
private void fireMessageEvent(EventObject evt)
{
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
if (evt instanceof MessageDeliveredEvent)
{
listener.messageDelivered( (MessageDeliveredEvent) evt);
}
else if (evt instanceof MessageReceivedEvent)
{
listener.messageReceived( (MessageReceivedEvent) evt);
}
else if (evt instanceof MessageDeliveryFailedEvent)
{
listener.messageDeliveryFailed(
(MessageDeliveryFailedEvent) evt);
}
}
}
private class MsnMessageListener
extends MsnMessageAdapter
implements MsnEmailListener
@ -315,8 +219,8 @@ public void offlineMessageReceived(String body,
String encoding,
MsnContact contact)
{
Message newMessage =
createMessage(body.getBytes(), contentType, encoding, null);
Message newMessage =
createMessage(body, contentType, encoding, null);
Contact sourceContact = opSetPersPresence.
findContactByID(contact.getEmail().getEmailAddress());

@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.rss;
@ -10,128 +9,25 @@
/**
* Very simple message implementation for the Rss protocol.
*
*
* @author Emil Ivov
* @authro Lubomir Marinov
*/
public class MessageRssImpl
implements Message
extends AbstractMessage
{
/**
* The actual message content.
*/
private String textContent = null;
/**
* The content type of the message. (text/plain if null)
*/
private String contentType = null;
/**
* The message encoding. (UTF8 if null).
*/
private String contentEncoding = null;
/**
* A String uniquely identifying the message
*/
private String messageUID = null;
/**
* The subject of the message. (most often is null)
*/
private String subject = null;
/**
* Creates a message instance according to the specified parameters.
*
*
* @param content the message body
* @param contentType message content type or null for text/plain
* @param contentEncoding message encoding or null for UTF8
* @param subject the subject of the message or null for no subject.
*/
public MessageRssImpl(String content,
String contentType,
String contentEncoding,
String subject)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
//generate the uid
this.messageUID = String.valueOf(System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the message body.
*
* @return the message content.
*/
public String getContent()
{
return textContent;
}
/**
* Returns the type of the content of this message.
*
* @return the type of the content of this message.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the encoding used for the message content.
*
* @return the encoding of the message body.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* A string uniquely identifying the message.
*
* @return a <tt>String</tt> uniquely identifying the message.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Returns the message body in a binary form.
*
* @return a <tt>byte[]</tt> representation of the message body.
*/
public byte[] getRawData()
{
return getContent().getBytes();
}
/**
* Return the length of this message.
*
* @return the length of this message.
*/
public int getSize()
{
return getContent().length();
}
/**
* Returns the message subject.
*
* @return the message subject.
*/
public String getSubject()
public MessageRssImpl(String content, String contentType,
String contentEncoding, String subject)
{
return subject;
super(content, contentType, contentEncoding, subject);
}
}

@ -21,15 +21,11 @@
* @author Mihai Balan
*/
public class OperationSetBasicInstantMessagingRssImpl
implements OperationSetBasicInstantMessaging,
RegistrationStateChangeListener
extends AbstractOperationSetBasicInstantMessaging
implements RegistrationStateChangeListener
{
private static final Logger logger
= Logger.getLogger(OperationSetBasicInstantMessagingRssImpl.class);
/**
* Currently registered message listeners.
*/
private Vector messageListeners = new Vector();
/**
* The currently valid persistent presence operation set.
@ -97,62 +93,22 @@ public OperationSetBasicInstantMessagingRssImpl(
}
/**
* Registers a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages.
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
if(!messageListeners.contains(listener))
messageListeners.add(listener);
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now
* subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject)
{
return new MessageRssImpl(new String(content),
contentType,
contentEncoding,
subject);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* Create a Message instance for sending a simple text messages with default
* (text/html) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
{
return new MessageRssImpl(messageText,
HTML_MIME_TYPE,
DEFAULT_MIME_ENCODING,
null);
return createMessage(messageText, HTML_MIME_TYPE,
DEFAULT_MIME_ENCODING, null);
}
/**
* Unregisters <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception
* of incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
messageListeners.remove(listener);
return new MessageRssImpl(content, contentType, encoding, subject);
}
/**
@ -377,40 +333,6 @@ public void sendInstantMessage(Contact to, Message message)
threadedContactFeedUpdate((ContactRssImpl)to);
}
/**
* Delivers the specified event to all registered message listeners.
* @param evt the <tt>EventObject</tt> that we'd like delivered to all
* registered message listeners.
*/
private void fireMessageEvent(EventObject evt)
{
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
if (evt instanceof MessageDeliveredEvent)
{
listener.messageDelivered( (MessageDeliveredEvent) evt);
}
else if (evt instanceof MessageReceivedEvent)
{
listener.messageReceived( (MessageReceivedEvent) evt);
}
else if (evt instanceof MessageDeliveryFailedEvent)
{
listener.messageDeliveryFailed(
(MessageDeliveryFailedEvent) evt);
}
}
}
/**
* Determines whether the protocol provider (or the protocol itself) supports
* sending and receiving offline messages. Most often this method would

@ -1,168 +1,35 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.sip;
import java.io.*;
import java.nio.charset.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
/**
* A simple implementation of the <tt>Message</tt> interface for SIP/SIMPLE.
*
*
* @author Benoit Pradelle
* @author Lubomir Marinov
*/
public class MessageSipImpl
implements Message
extends AbstractMessage
{
private static final Logger logger = Logger.getLogger(MessageSipImpl.class);
/**
* The content of this message.
*/
private String textContent = null;
/**
* The content of this message, in raw bytes according to the encoding.
*/
private byte[] rawContent = null;
/**
* The content type of text. Right now only text/plain is supported.
*/
private String contentType = null;
/**
* The encoding under which the contennt of this message is encoded.
*/
private String contentEncoding = null;
/**
* An String uniquely identifying this Message.
*/
private String messageUID = null;
/**
* The subject of the message if any (may remain null).
*/
private String subject = null;
/**
* Creates an instance of this Message with the specified parameters.
*
*
* @param content the text content of the message.
* @param contentType a MIME string indicating the content type of the
* <tt>content</tt> String.
* <tt>content</tt> String.
* @param contentEncoding a MIME String indicating the content encoding of
* the <tt>content</tt> String.
* the <tt>content</tt> String.
* @param subject the subject of the message or null for empty.
*/
public MessageSipImpl(String content,
String contentType,
String contentEncoding,
String subject)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
try
{
this.rawContent = content.getBytes(contentEncoding);
}
catch (UnsupportedEncodingException ex)
{
logger.warn("can't handle the requested encoding", ex);
this.contentEncoding = Charset.defaultCharset().name();
this.rawContent = content.getBytes();
}
//generate the uid
this.messageUID = String.valueOf(System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the content of this message if representable in text form or
* null if this message does not contain text data.
*
* @return a String containing the content of this message or null if
* the message does not contain data representable in text form.
*/
public String getContent()
{
return this.textContent;
}
/**
* Returns the MIME type for the message content.
*
* @return a String containing the mime type of the message contant.
*/
public String getContentType()
{
return this.contentType;
}
/**
* Returns the MIME content encoding of this message.
*
* @return a String indicating the MIME encoding of this message.
*/
public String getEncoding()
{
return this.contentEncoding;
}
/**
* Returns a unique identifier of this message.
*
* @return a String that uniquely represents this message in the scope
* of this protocol.
*/
public String getMessageUID()
{
return this.messageUID;
}
/**
* Get the raw/binary content of an instant message.
*
* @return a byte[] array containing message bytes.
*/
public byte[] getRawData()
{
return rawContent;
}
/**
* Returns the size of the content stored in this message.
*
* @return an int indicating the number of bytes that this message
* contains.
*/
public int getSize()
{
return rawContent.length;
}
/**
* Returns the subject of this message or null if the message contains no
* subject.
*
* @return the subject of this message or null if the message contains
* no subject.
*/
public String getSubject()
public MessageSipImpl(String content, String contentType,
String contentEncoding, String subject)
{
return this.subject;
super(content, contentType, contentEncoding, subject);
}
}

@ -27,16 +27,11 @@
* @author Benoit Pradelle
*/
public class OperationSetBasicInstantMessagingSipImpl
implements OperationSetBasicInstantMessaging
extends AbstractOperationSetBasicInstantMessaging
{
private static final Logger logger =
Logger.getLogger(OperationSetBasicInstantMessagingSipImpl.class);
/**
* A list of listeners registered for message events.
*/
private Vector messageListeners = new Vector();
/**
* A list of processors registered for incoming sip messages.
*/
@ -100,39 +95,6 @@ public class OperationSetBasicInstantMessagingSipImpl
this.sipStatusEnum = sipProvider.getSipStatusEnum();
}
/**
* Registers a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
synchronized (this.messageListeners)
{
if (!this.messageListeners.contains(listener))
{
this.messageListeners.add(listener);
}
}
}
/**
* Unregisters <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
{
synchronized (this.messageListeners)
{
this.messageListeners.remove(listener);
}
}
/**
* Registers a SipMessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
@ -166,33 +128,10 @@ void removeMessageProcessor(SipMessageProcessor processor)
}
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
return new MessageSipImpl(new String(content), contentType
, contentEncoding, subject);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
{
return new MessageSipImpl(messageText, DEFAULT_MIME_TYPE
, DEFAULT_MIME_ENCODING, null);
return new MessageSipImpl(content, contentType, encoding, subject);
}
/**
@ -645,44 +584,6 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
}
}
/**
* Delivers the specified event to all registered message listeners.
* @param evt the <tt>EventObject</tt> that we'd like delivered to all
* registered message listeners.
*/
private void fireMessageEvent(EventObject evt)
{
Iterator listeners = null;
synchronized (this.messageListeners)
{
listeners = new ArrayList(this.messageListeners).iterator();
}
logger.debug("Dispatching Message Listeners="
+ messageListeners.size()
+ " evt=" + evt);
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
if (evt instanceof MessageDeliveredEvent)
{
listener.messageDelivered( (MessageDeliveredEvent) evt);
}
else if (evt instanceof MessageReceivedEvent)
{
listener.messageReceived( (MessageReceivedEvent) evt);
}
else if (evt instanceof MessageDeliveryFailedEvent)
{
listener.messageDeliveryFailed(
(MessageDeliveryFailedEvent) evt);
}
}
}
/**
* Class for listening incoming packets.
*/
@ -875,8 +776,7 @@ public boolean processRequest(RequestEvent requestEvent)
if(cencoding == null)
cencoding = DEFAULT_MIME_ENCODING;
Message newMessage =
createMessage(content.getBytes(), ctype, cencoding, null);
Message newMessage = createMessage(content, ctype, cencoding, null);
if (from == null) {
logger.debug("received a message from an unknown contact: "

@ -481,12 +481,11 @@ else if(typingState == STATE_STOPPED)
}
else // ignore other events
return;
Message message = opSetBasicIm.createMessage(
new String(opSetPersPresence.convertDocument(doc)).getBytes(),
CONTENT_TYPE,
OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING,
null);
Message message =
opSetBasicIm.createMessage(opSetPersPresence.convertDocument(doc),
CONTENT_TYPE,
OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING, null);
//create the message
Request mes;

@ -1,143 +1,54 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
*
* Distributable under LGPL license. See terms of license at gnu.org.
*
* MessageSSHImpl.java
*
*
* SSH Suport in SIP Communicator - GSoC' 07 Project
*
*/
package net.java.sip.communicator.impl.protocol.ssh;
import net.java.sip.communicator.service.protocol.*;
/**
* Very simple message implementation for the SSH protocol.
*
*
* @author Shobhit Jindal
* @author Lubomir Marinov
*/
public class MessageSSHImpl
implements Message
extends AbstractMessage
{
/**
* The actual message content.
*/
private String textContent = null;
/**
* The content type of the message.
* The content type of the message.
*/
public static String contentType = "text/plain";
/**
* The message encoding. (UTF8 if null).
*/
private String contentEncoding = null;
/**
* A String uniquely identifying the message
*/
private String messageUID = null;
/**
* The subject of the message. (most often is null)
*/
private String subject = null;
/**
* Creates a message instance according to the specified parameters.
*
*
* @param content the message body
* @param contentType message content type or null for text/plain
* @param contentEncoding message encoding or null for UTF8
* @param subject the subject of the message or null for no subject.
*/
public MessageSSHImpl(String content,
String contentType,
String contentEncoding,
String subject)
public MessageSSHImpl(String content, String contentType,
String contentEncoding, String subject)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
//generate the uid
this.messageUID = String.valueOf(System.currentTimeMillis())
+ String.valueOf(hashCode());
super(content, null, contentEncoding, subject);
}
/**
* Returns the message body.
*
* @return the message content.
*/
public String getContent()
{
return textContent;
MessageSSHImpl.contentType = contentType;
}
/**
* Returns the type of the content of this message.
*
*
* @return the type of the content of this message.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the encoding used for the message content.
*
* @return the encoding of the message body.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* A string uniquely identifying the message.
*
* @return a <tt>String</tt> uniquely identifying the message.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Returns the message body in a binary form.
*
* @return a <tt>byte[]</tt> representation of the message body.
*/
public byte[] getRawData()
{
return getContent().getBytes();
}
/**
* Return the length of this message.
*
* @return the length of this message.
*/
public int getSize()
{
return getContent().length();
}
/**
* Returns the message subject.
*
* @return the message subject.
*/
public String getSubject()
{
return subject;
}
}

@ -14,7 +14,6 @@
import java.io.*;
import java.util.*;
import net.java.sip.communicator.util.Logger;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
@ -25,15 +24,8 @@
* @author Shobhit Jindal
*/
public class OperationSetBasicInstantMessagingSSHImpl
implements OperationSetBasicInstantMessaging
extends AbstractOperationSetBasicInstantMessaging
{
private static final Logger logger
= Logger.getLogger(OperationSetBasicInstantMessagingSSHImpl.class);
/**
* Currently registered message listeners.
*/
private Vector messageListeners = new Vector();
/**
* The currently valid persistent presence operation set..
@ -64,65 +56,13 @@ public OperationSetBasicInstantMessagingSSHImpl(
this.opSetPersPresence = (OperationSetPersistentPresenceSSHImpl)
provider.getOperationSet(OperationSetPersistentPresence.class);
}
/**
* Registers a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
if(!messageListeners.contains(listener))
messageListeners.add(listener);
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now
* subject.
* @return the newly created message.
*/
public Message createMessage(
byte[] content,
String contentType,
String contentEncoding,
String subject)
{
return new MessageSSHImpl(new String(content), contentType
, contentEncoding, subject);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
{
return new MessageSSHImpl(messageText, DEFAULT_MIME_TYPE
, DEFAULT_MIME_ENCODING, null);
}
/**
* Unregisteres <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception
* of incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
messageListeners.remove(listener);
return new MessageSSHImpl(content, contentType, encoding, subject);
}
/**
* Sends the <tt>message</tt> to the destination indicated by the
* <tt>to</tt> contact. An attempt is made to re-establish the shell
@ -305,66 +245,17 @@ void deliverMessage(
}
}
/**
* Notifies all registered message listeners that a message has been
* delivered successfully to its addressee..
*
* @param message the <tt>Message</tt> that has been delivered.
* @param to the <tt>Contact</tt> that <tt>message</tt> was delivered to.
*/
private void fireMessageDelivered(
Message message,
Contact to)
{
MessageDeliveredEvent evt
= new MessageDeliveredEvent(message, to, new Date());
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
listener.messageDelivered(evt);
}
}
/**
* Notifies all registered message listeners that a message has been
* received.
*
*
* @param message the <tt>Message</tt> that has been received.
* @param from the <tt>Contact</tt> that <tt>message</tt> was received from.
*/
private void fireMessageReceived(
Message message,
Contact from)
protected void fireMessageReceived(Message message, Contact from)
{
MessageReceivedEvent evt
= new MessageReceivedEvent(
message,
from,
new Date(),
((ContactSSH)from).getMessageType());
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
listener.messageReceived(evt);
}
fireMessageEvent(new MessageReceivedEvent(message, from, new Date(),
((ContactSSH) from).getMessageType()));
}
/**

@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.yahoo;
@ -11,137 +10,27 @@
/**
* A simple implementation of the <tt>Message</tt> interface. Right now the
* message only supports test contents and no binary data.
*
*
* @author Damian Minkov
* @authro Lubomir Marinov
*/
public class MessageYahooImpl
implements Message
extends AbstractMessage
{
/**
* The content of this message.
*/
private String textContent = null;
/**
* The content type of text. Right now only text content types (such as
* text/plain or text/html) are supported.
*/
private String contentType = null;
/**
* The encoding under which the contennt of this message is encoded.
*/
private String contentEncoding = null;
/**
* An String uniquely identifying this Message.
*/
private String messageUID = null;
/**
* The subject of the message if any (may remain null).
*/
private String subject = null;
/**
* Creates an instance of this Message with the specified parameters.
*
*
* @param content the text content of the message.
* @param contentType a MIME string indicating the content type of the
* <tt>content</tt> String.
* <tt>content</tt> String.
* @param contentEncoding a MIME String indicating the content encoding of
* the <tt>content</tt> String.
* the <tt>content</tt> String.
* @param subject the subject of the message or null for empty.
*/
public MessageYahooImpl(String content,
String contentType,
String contentEncoding,
String subject)
{
this.textContent = content;
this.contentType = contentType;
this.contentEncoding = contentEncoding;
this.subject = subject;
//generate the uid
this.messageUID = String.valueOf( System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the content of this message if representable in text form or
* null if this message does not contain text data.
*
* @return a String containing the content of this message or null if
* the message does not contain data representable in text form.
*/
public String getContent()
{
return textContent;
}
/**
* Returns the MIME type for the message content.
*
* @return a String containing the mime type of the message contant.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the MIME content encoding of this message.
*
* @return a String indicating the MIME encoding of this message.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* Returns a unique identifier of this message.
*
* @return a String that uniquely represents this message in the scope
* of this protocol.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Get the raw/binary content of an instant message.
*
* @return a byte[] array containing message bytes.
*/
public byte[] getRawData()
{
return getContent().getBytes();
}
/**
* Returns the size of the content stored in this message.
*
* @return an int indicating the number of bytes that this message
* contains.
*/
public int getSize()
{
return getContent().length();
}
/**
* Returns the subject of this message or null if the message contains no
* subject.
*
* @return the subject of this message or null if the message contains
* no subject.
*/
public String getSubject()
public MessageYahooImpl(String content, String contentType,
String contentEncoding, String subject)
{
return subject;
super(content, contentType, contentEncoding, subject);
}
}

@ -25,8 +25,8 @@
* @author Keio Kraaner
*/
public class OperationSetBasicInstantMessagingYahooImpl
implements OperationSetBasicInstantMessaging,
OperationSetInstantMessageFiltering
extends AbstractOperationSetBasicInstantMessaging
implements OperationSetInstantMessageFiltering
{
/**
* Logger for this class
@ -39,12 +39,6 @@ public class OperationSetBasicInstantMessagingYahooImpl
* message is not delivered and no notification is received for that.
*/
private static int MAX_MESSAGE_LENGTH = 800; // 949
/**
* A list of listeneres registered for message events.
*/
private Vector<MessageListener> messageListeners
= new Vector<MessageListener>();
/**
* A list of filters registered for message events.
@ -82,39 +76,6 @@ public class OperationSetBasicInstantMessagingYahooImpl
new RegistrationStateListener());
}
/**
* Registeres a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
synchronized(messageListeners)
{
if(!messageListeners.contains(listener))
{
this.messageListeners.add(listener);
}
}
}
/**
* Unregisteres <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
{
synchronized(messageListeners)
{
this.messageListeners.remove(listener);
}
}
/**
* Determines wheter the protocol provider (or the protocol itself) support
* sending and receiving offline messages. Most often this method would
@ -150,35 +111,10 @@ public boolean isContentTypeSupported(String contentType)
return false;
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
return new MessageYahooImpl(new String(content), contentType
, contentEncoding, subject);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
{
return new MessageYahooImpl(
messageText,
DEFAULT_MIME_TYPE,
DEFAULT_MIME_ENCODING, null);
return new MessageYahooImpl(content, contentType, encoding, subject);
}
/**
@ -312,7 +248,7 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
* @param evt the <tt>EventObject</tt> that we'd like delivered to all
* registered message listerners.
*/
private void fireMessageEvent(EventObject evt)
protected void fireMessageEvent(EventObject evt)
{
// check if this event should be filtered out
Iterator<EventFilter> filters = null;
@ -344,35 +280,7 @@ private void fireMessageEvent(EventObject evt)
return;
}
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
logger.debug("Dispatching msg evt. Listeners="
+ messageListeners.size()
+ " evt=" + evt);
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
if (evt instanceof MessageDeliveredEvent)
{
listener.messageDelivered( (MessageDeliveredEvent) evt);
}
else if (evt instanceof MessageReceivedEvent)
{
listener.messageReceived( (MessageReceivedEvent) evt);
}
else if (evt instanceof MessageDeliveryFailedEvent)
{
listener.messageDeliveryFailed(
(MessageDeliveryFailedEvent) evt);
}
}
super.fireMessageEvent(evt);
}
/**
@ -513,13 +421,12 @@ private void handleNewMessage(SessionEvent ev)
"$1 $2 style=\"font-size: $3px;\">");
logger.debug("formatted Message : " + formattedMessage);
//As no indications in the protocol is it html or not. No harm
//to set all messages html - doesn't affect the appearance of the gui
Message newMessage = createMessage(
formattedMessage.getBytes(),
HTML_MIME_TYPE,
DEFAULT_MIME_ENCODING,
null);
// As no indications in the protocol is it html or not. No harm
// to set all messages html - doesn't affect the appearance of the
// gui
Message newMessage =
createMessage(formattedMessage, HTML_MIME_TYPE,
DEFAULT_MIME_ENCODING, null);
Contact sourceContact = opSetPersPresence.
findContactByID(ev.getFrom());

@ -1,8 +1,7 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.zeroconf;
@ -10,218 +9,120 @@
/**
* Very simple message implementation for the Zeroconf protocol.
*
*
* @author Christian Vincenot
* @author Maxime Catelin
* @author Jonathan Martin
* @author Lubomir Marinov
*/
public class MessageZeroconfImpl
implements Message
extends AbstractMessage
{
/**
* The actual message content.
*/
private String textContent = null;
/**
* The content type of the message.
*/
private String contentType = null;
/**
* The message encoding. (UTF8 if null).
*/
private String contentEncoding = null;
/**
* A String uniquely identifying the message
*/
private String messageUID = null;
/**
* The subject of the message. (most often is null)
*/
private String subject = null;
/**
* Message Type.
*/
private int type;
/**
* Message type indicating that a stream is being created
*/
public static final int STREAM_OPEN = 0x1;
/**
* Normal chat message
*/
public static final int MESSAGE = 0x2;
/**
* Typing notification
*/
public static final int TYPING = 0x3;
/**
* Message indicating that the stream is being closed
*/
public static final int STREAM_CLOSE = 0x4;
/**
* Message indicating that the previsous message was delivered successfully
*/
public static final int DELIVERED = 0x5;
/**
* Undefined message
*/
public static final int UNDEF = 0x6;
/*
* The Baloon Icon color.
* (we probably won't ever use it)
/*
* The Baloon Icon color. (we probably won't ever use it)
*/
private int baloonColor = 0x7BB5EE;
/*
/*
* The Text Color.
*/
private int textColor = 0x000000;
/*
* The font of the message.
*/
private String textFont = "Helvetica";
/*
* The size of the caracters composing the message.
*/
private int textSize = 12;
/*
* The source contact id announced in the message.
* TODO: Could be set & checked to identify more precisely the contact in
* case several users would be sharing the same IP.
* The source contact id announced in the message. TODO: Could be set &
* checked to identify more precisely the contact in case several users
* would be sharing the same IP.
*/
private String contactID;
/**
* Creates a message instance according to the specified parameters.
* @param type Type of message
*
* @param content the message body
* @param contentType of the message
* @param contentEncoding message encoding or null for UTF8
* @param contentType of the message
* @param type Type of message
*/
public MessageZeroconfImpl(String content,
String contentEncoding,
String contentType,
int type)
public MessageZeroconfImpl(String content, String contentEncoding,
String contentType, int type)
{
this.textContent = content;
this.contentEncoding = contentEncoding;
this.contentType = contentType;
this.type = type;
super(content, contentType, contentEncoding, null);
//generate the uid
this.messageUID = String.valueOf(System.currentTimeMillis())
+ String.valueOf(hashCode());
this.type = type;
}
/**
* Creates a message instance according to the specified parameters.
*
* @param type Type of message
* @param content the message body
* @param contentEncoding message encoding or null for UTF8
*/
public MessageZeroconfImpl(String content,
String contentEncoding,
int type)
public MessageZeroconfImpl(String content, String contentEncoding, int type)
{
this(content,
contentEncoding,
OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE,
type);
this(content, contentEncoding,
OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE, type);
}
/**
* Returns the message body.
*
* @return the message content.
*/
public String getContent()
{
return textContent;
}
/**
* Returns the type of the content of this message.
*
* @return the type of the content of this message.
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the encoding used for the message content.
*
* @return the encoding of the message body.
*/
public String getEncoding()
{
return contentEncoding;
}
/**
* A string uniquely identifying the message.
*
* @return a <tt>String</tt> uniquely identifying the message.
*/
public String getMessageUID()
{
return messageUID;
}
/**
* Returns the message body in a binary form.
*
* @return a <tt>byte[]</tt> representation of the message body.
*/
public byte[] getRawData()
{
return getContent().getBytes();
}
/**
* Return the length of this message.
*
* @return the length of this message.
*/
public int getSize()
{
return getContent().length();
}
/**
* Returns the subject of the message. ALWAYS null in Zeroconf
* @return null
*/
public String getSubject()
{
return subject;
}
/**
* Returns the type of message. Always text/plain for Zeroconf, so null.
*
* @return null
*/
public int getType()
public int getType()
{
return type;
}
/**
* Gets the baloon color declared in messages sent by iChat-like clients
*
* @return baloon color
*/
public int getBaloonColor()
@ -231,81 +132,90 @@ public int getBaloonColor()
/**
* Sets the baloon color declared in messages sent by iChat-like clients
*
* @param baloonColor baloon color
*/
public void setBaloonColor(int baloonColor)
public void setBaloonColor(int baloonColor)
{
this.baloonColor = baloonColor;
}
/**
* Returns the text color
*
* @return Text color
*/
public int getTextColor()
public int getTextColor()
{
return textColor;
}
/**
* Sets the text color
*
* @param textColor Text color
*/
public void setTextColor(int textColor)
public void setTextColor(int textColor)
{
this.textColor = textColor;
}
/**
* Returns the text font
*
* @return Text font
*/
public String getTextFont()
public String getTextFont()
{
return textFont;
}
/**
* Sets the text color
*
* @param textFont Text font
*/
public void setTextFont(String textFont)
public void setTextFont(String textFont)
{
this.textFont = textFont;
}
/**
* Returns the text size
*
* @return Text size
*/
public int getTextSize()
public int getTextSize()
{
return textSize;
}
/**
* Sets the text size
*
* @param textSize Text size
*/
public void setTextSize(int textSize)
public void setTextSize(int textSize)
{
this.textSize = textSize;
}
/**
* Returns the contact's ID
*
* @return String representing the contact's ID
*/
public String getContactID()
public String getContactID()
{
return contactID;
}
/**
* Sets the contact's ID
*
* @param contactID String representing the contact's ID
*/
public void setContactID(String contactID)
public void setContactID(String contactID)
{
this.contactID = contactID;
}

@ -21,15 +21,10 @@
*
*/
public class OperationSetBasicInstantMessagingZeroconfImpl
implements OperationSetBasicInstantMessaging
extends AbstractOperationSetBasicInstantMessaging
{
private static final Logger logger
= Logger.getLogger(OperationSetBasicInstantMessagingZeroconfImpl.class);
/**
* Currently registered message listeners.
*/
private Vector messageListeners = new Vector();
/**
* The currently valid persistent presence operation set..
@ -57,62 +52,11 @@ public OperationSetBasicInstantMessagingZeroconfImpl(
this.parentProvider = provider;
}
/**
* Registers a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
if(!messageListeners.contains(listener))
messageListeners.add(listener);
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now
* subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject)
{
return new MessageZeroconfImpl(new String(content),
contentEncoding, contentType,
MessageZeroconfImpl.MESSAGE);
}
/**
* Create a Message instance for sending a simple text messages with
* default (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
{
return new MessageZeroconfImpl(messageText,
DEFAULT_MIME_ENCODING,
DEFAULT_MIME_TYPE,
MessageZeroconfImpl.MESSAGE);
}
/**
* Unregisteres <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception
* of incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
public Message createMessage(String content, String contentType,
String encoding, String subject)
{
messageListeners.remove(listener);
return new MessageZeroconfImpl(content, encoding, contentType,
MessageZeroconfImpl.MESSAGE);
}
/**
@ -201,59 +145,16 @@ private void deliverMessage(Message message, ContactZeroconfImpl to)
}
/**
* Notifies all registered message listeners that a message has been
* delivered successfully to its addressee..
*
* @param message the <tt>Message</tt> that has been delivered.
* @param to the <tt>Contact</tt> that <tt>message</tt> was delivered to.
*/
private void fireMessageDelivered(Message message, Contact to)
{
MessageDeliveredEvent evt
= new MessageDeliveredEvent(message, to, new Date());
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
listener.messageDelivered(evt);
}
}
/**
* Notifies all registered message listeners that a message has been
* received.
*
*
* @param message the <tt>Message</tt> that has been received.
* @param from the <tt>Contact</tt> that <tt>message</tt> was received from.
*/
public void fireMessageReceived(Message message, Contact from)
{
MessageReceivedEvent evt
= new MessageReceivedEvent(message, from, new Date());
Iterator listeners = null;
synchronized (messageListeners)
{
listeners = new ArrayList(messageListeners).iterator();
}
while (listeners.hasNext())
{
MessageListener listener
= (MessageListener) listeners.next();
listener.messageReceived(evt);
}
super.fireMessageReceived(message, from);
}
/**

@ -0,0 +1,200 @@
/*
* 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.service.protocol;
import java.io.*;
import java.nio.charset.*;
import net.java.sip.communicator.util.*;
/**
* Represents a default implementation of {@link Message} in order to make it
* easier for implementers to provide complete solutions while focusing on
* implementation-specific details.
*
* @author Lubomir Marinov
*/
public abstract class AbstractMessage
implements Message
{
private static final Logger logger =
Logger.getLogger(AbstractMessage.class);
private static boolean equals(String a, String b)
{
return (a == null) ? (b == null) : a.equals(b);
}
private String content;
private final String contentType;
private String encoding;
private final String messageUID;
/**
* The content of this message, in raw bytes according to the encoding.
*/
private byte[] rawData;
private final String subject;
protected AbstractMessage(String content, String contentType,
String encoding, String subject)
{
this.contentType = contentType;
this.subject = subject;
setEncoding(encoding);
setContent(content);
this.messageUID = createMessageUID();
}
protected AbstractMessage(String content, String contentType,
String encoding, String subject, String messageUID)
{
this.contentType = contentType;
this.subject = subject;
setEncoding(encoding);
setContent(content);
this.messageUID = messageUID;
}
protected String createMessageUID()
{
return String.valueOf(System.currentTimeMillis())
+ String.valueOf(hashCode());
}
/**
* Returns the content of this message if representable in text form or null
* if this message does not contain text data.
* <p>
* The implementation is final because it caches the raw data of the
* content.
* </p>
*
* @return a String containing the content of this message or null if the
* message does not contain data representable in text form.
*/
public final String getContent()
{
return content;
}
/*
* (non-Javadoc)
*
* @see net.java.sip.communicator.service.protocol.Message#getContentType()
*/
public String getContentType()
{
return contentType;
}
/**
* Returns the MIME content encoding of this message.
* <p>
* The implementation is final because of the presumption it can set the
* encoding.
* </p>
*
* @return a String indicating the MIME encoding of this message.
*/
public final String getEncoding()
{
return encoding;
}
/*
* (non-Javadoc)
*
* @see net.java.sip.communicator.service.protocol.Message#getMessageUID()
*/
public String getMessageUID()
{
return messageUID;
}
/*
* (non-Javadoc)
*
* @see net.java.sip.communicator.service.protocol.Message#getRawData()
*/
public byte[] getRawData()
{
if (rawData == null)
{
String content = getContent();
String encoding = getEncoding();
boolean useDefaultEncoding = true;
if (encoding != null)
{
try
{
rawData = content.getBytes(encoding);
useDefaultEncoding = false;
}
catch (UnsupportedEncodingException ex)
{
logger.warn(
"Failed to get raw data from content using encoding "
+ encoding, ex);
// We'll use the default encoding
}
}
if (useDefaultEncoding)
{
setEncoding(Charset.defaultCharset().name());
rawData = content.getBytes();
}
}
return rawData;
}
/*
* (non-Javadoc)
*
* @see net.java.sip.communicator.service.protocol.Message#getSize()
*/
public int getSize()
{
return getRawData().length;
}
/*
* (non-Javadoc)
*
* @see net.java.sip.communicator.service.protocol.Message#getSubject()
*/
public String getSubject()
{
return subject;
}
protected void setContent(String content)
{
if (equals(this.content, content) == false)
{
this.content = content;
this.rawData = null;
}
}
private void setEncoding(String encoding)
{
if (equals(this.encoding, encoding) == false)
{
this.encoding = encoding;
this.rawData = null;
}
}
}

@ -0,0 +1,184 @@
/*
* 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.service.protocol;
import java.io.*;
import java.nio.charset.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
/**
* Represents a default implementation of
* {@link OperationSetBasicInstantMessaging} in order to make it easier for
* implementers to provide complete solutions while focusing on
* implementation-specific details.
*
* @author Lubomir Marinov
*/
public abstract class AbstractOperationSetBasicInstantMessaging
implements OperationSetBasicInstantMessaging
{
private static final Logger logger =
Logger.getLogger(AbstractOperationSetBasicInstantMessaging.class);
/**
* A list of listeners registered for message events.
*/
private final List<MessageListener> messageListeners =
new LinkedList<MessageListener>();
/**
* Registers a MessageListener with this operation set so that it gets
* notifications of successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to register.
*/
public void addMessageListener(MessageListener listener)
{
synchronized (messageListeners)
{
if (!messageListeners.contains(listener))
{
messageListeners.add(listener);
}
}
}
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param encoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now
* subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String encoding, String subject)
{
String contentAsString = null;
boolean useDefaultEncoding = true;
if (encoding != null)
{
try
{
contentAsString = new String(content, encoding);
useDefaultEncoding = false;
}
catch (UnsupportedEncodingException ex)
{
logger.warn("Failed to decode content using encoding "
+ encoding, ex);
// We'll use the default encoding.
}
}
if (useDefaultEncoding)
{
encoding = Charset.defaultCharset().name();
contentAsString = new String(content);
}
return createMessage(contentAsString, contentType, encoding, subject);
}
/**
* Create a Message instance for sending a simple text messages with default
* (text/plain) content type and encoding.
*
* @param messageText the string content of the message.
* @return Message the newly created message
*/
public Message createMessage(String messageText)
{
return createMessage(messageText, DEFAULT_MIME_TYPE,
DEFAULT_MIME_ENCODING, null);
}
public abstract Message createMessage(String content, String contentType,
String encoding, String subject);
/**
* Notifies all registered message listeners that a message has been
* delivered successfully to its addressee..
*
* @param message the <tt>Message</tt> that has been delivered.
* @param to the <tt>Contact</tt> that <tt>message</tt> was delivered to.
*/
protected void fireMessageDelivered(Message message, Contact to)
{
fireMessageEvent(new MessageDeliveredEvent(message, to, new Date()));
}
/**
* Delivers the specified event to all registered message listeners.
*
* @param evt the <tt>EventObject</tt> that we'd like delivered to all
* registered message listeners.
*/
protected void fireMessageEvent(EventObject evt)
{
Collection<MessageListener> listeners = null;
synchronized (this.messageListeners)
{
listeners = new ArrayList<MessageListener>(this.messageListeners);
}
logger.debug("Dispatching Message Listeners=" + listeners.size()
+ " evt=" + evt);
for (Iterator<MessageListener> listenerIter = listeners.iterator(); listenerIter
.hasNext();)
{
MessageListener listener = listenerIter.next();
if (evt instanceof MessageDeliveredEvent)
{
listener.messageDelivered((MessageDeliveredEvent) evt);
}
else if (evt instanceof MessageReceivedEvent)
{
listener.messageReceived((MessageReceivedEvent) evt);
}
else if (evt instanceof MessageDeliveryFailedEvent)
{
listener
.messageDeliveryFailed((MessageDeliveryFailedEvent) evt);
}
}
}
/**
* Notifies all registered message listeners that a message has been
* received.
*
* @param message the <tt>Message</tt> that has been received.
* @param from the <tt>Contact</tt> that <tt>message</tt> was received from.
*/
protected void fireMessageReceived(Message message, Contact from)
{
fireMessageEvent(new MessageReceivedEvent(message, from, new Date()));
}
/**
* Unregisters <tt>listener</tt> so that it won't receive any further
* notifications upon successful message delivery, failure or reception of
* incoming messages..
*
* @param listener the <tt>MessageListener</tt> to unregister.
*/
public void removeMessageListener(MessageListener listener)
{
synchronized (messageListeners)
{
messageListeners.remove(listener);
}
}
}

@ -17,7 +17,7 @@
* operation set.
* <p>
* All messages have message ids that allow the underlying implementation to
* notify the user of their succesful delivery.
* notify the user of their successful delivery.
*
* @author Emil Ivov
*/

@ -33,15 +33,16 @@ public interface OperationSetBasicInstantMessaging
/**
* Create a Message instance for sending arbitrary MIME-encoding content.
*
*
* @param content content value
* @param contentType the MIME-type for <tt>content</tt>
* @param contentEncoding encoding used for <tt>content</tt>
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now subject.
* @param subject a <tt>String</tt> subject or <tt>null</tt> for now
* subject.
* @return the newly created message.
*/
public Message createMessage(byte[] content, String contentType,
String contentEncoding, String subject);
public Message createMessage(String content, String contentType,
String contentEncoding, String subject);
/**
* Create a Message instance for sending a simple text messages with default

@ -373,9 +373,8 @@ public void testCreateMessage2()
String contentType = "text/html";
String encoding = "UTF-16";
String subject = "test message";
net.java.sip.communicator.service.protocol.Message msg
= opSetBasicIM1.createMessage(
body.getBytes(), contentType, encoding, subject);
net.java.sip.communicator.service.protocol.Message msg =
opSetBasicIM1.createMessage(body, contentType, encoding, subject);
assertEquals("message body", body, msg.getContent());
assertTrue("message body bytes"

@ -266,9 +266,8 @@ public void testCreateMessage2()
String contentType = "text/html";
String encoding = "UTF-16";
String subject = "test message";
net.java.sip.communicator.service.protocol.Message msg
= opSetBasicIM.createMessage(
body.getBytes(), contentType, encoding, subject);
net.java.sip.communicator.service.protocol.Message msg =
opSetBasicIM.createMessage(body, contentType, encoding, subject);
assertEquals("message body", body, msg.getContent());
assertTrue("message body bytes"

@ -11,7 +11,6 @@
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.Message;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@ -377,9 +376,8 @@ public void testCreateMessage2()
String contentType = "text/html";
String encoding = "UTF-16";
String subject = "test message";
net.java.sip.communicator.service.protocol.Message msg
= opSetBasicIM1.createMessage(
body.getBytes(), contentType, encoding, subject);
net.java.sip.communicator.service.protocol.Message msg =
opSetBasicIM1.createMessage(body, contentType, encoding, subject);
assertEquals("message body", body, msg.getContent());
assertTrue("message body bytes"

@ -11,7 +11,6 @@
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.Message;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@ -344,9 +343,8 @@ public void testCreateMessage2()
String contentType = "text/html";
String encoding = "UTF-16";
String subject = "test message";
net.java.sip.communicator.service.protocol.Message msg
= opSetBasicIM1.createMessage(
body.getBytes(), contentType, encoding, subject);
net.java.sip.communicator.service.protocol.Message msg =
opSetBasicIM1.createMessage(body, contentType, encoding, subject);
assertEquals("message body", body, msg.getContent());
assertTrue("message body bytes"

@ -412,9 +412,8 @@ public void testCreateMessage2()
String contentType = "text/html";
String encoding = "UTF-16";
String subject = "test message";
net.java.sip.communicator.service.protocol.Message msg
= opSetBasicIM1.createMessage(
body.getBytes(), contentType, encoding, subject);
net.java.sip.communicator.service.protocol.Message msg =
opSetBasicIM1.createMessage(body, contentType, encoding, subject);
assertEquals("message body", body, msg.getContent());
assertEquals("message encoding", encoding, msg.getEncoding());

@ -11,7 +11,6 @@
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.Message;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@ -354,9 +353,8 @@ public void testCreateMessage2()
String contentType = "text/html";
String encoding = "UTF-16";
String subject = "test message";
net.java.sip.communicator.service.protocol.Message msg
= opSetBasicIM1.createMessage(
body.getBytes(), contentType, encoding, subject);
net.java.sip.communicator.service.protocol.Message msg =
opSetBasicIM1.createMessage(body, contentType, encoding, subject);
assertEquals("message body", body, msg.getContent());
assertTrue("message body bytes"

Loading…
Cancel
Save