diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2008-08-28 22:53:08 +0000 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2008-08-28 22:53:08 +0000 |
commit | 7562dd005201968c21a21612fd42680e0962acbc (patch) | |
tree | 134a49eabbb6e59be435603fd3e1e166a74c022b | |
parent | d36c3f5d96a4e669eed32132be923f1b3dfff67e (diff) | |
download | jitsi-7562dd005201968c21a21612fd42680e0962acbc.zip jitsi-7562dd005201968c21a21612fd42680e0962acbc.tar.gz jitsi-7562dd005201968c21a21612fd42680e0962acbc.tar.bz2 |
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 ???.
37 files changed, 756 insertions, 2739 deletions
diff --git a/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java b/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java index b7c462c..1e994df 100644 --- a/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java +++ b/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java @@ -466,15 +466,15 @@ public class MetaContactImpl 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) diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/MetaContactChatPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/MetaContactChatPanel.java index 02cb3ae..9cf3df5 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/MetaContactChatPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/MetaContactChatPanel.java @@ -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 @@ public class MetaContactChatPanel || 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 { diff --git a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java index 2dac934..9eafcd4 100644 --- a/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/msghistory/MessageHistoryServiceImpl.java @@ -11,7 +11,6 @@ import java.util.*; 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 @@ import net.java.sip.communicator.util.*; * * @author Alexander Pelov * @author Damian Minkov + * @author Lubomir Marinov */ public class MessageHistoryServiceImpl implements MessageHistoryService, @@ -519,7 +519,7 @@ public class MessageHistoryServiceImpl */ 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 @@ public class MessageHistoryServiceImpl 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 @@ public class MessageHistoryServiceImpl .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 @@ public class MessageHistoryServiceImpl * 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() diff --git a/src/net/java/sip/communicator/impl/protocol/dict/MessageDictImpl.java b/src/net/java/sip/communicator/impl/protocol/dict/MessageDictImpl.java index 0d7057e..b7465f6 100644 --- a/src/net/java/sip/communicator/impl/protocol/dict/MessageDictImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/dict/MessageDictImpl.java @@ -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 @@ import net.java.sip.communicator.service.protocol.*; /** * 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); } } diff --git a/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java b/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java index 626dda0..fd958a9 100644 --- a/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java @@ -19,16 +19,11 @@ import net.java.sip.communicator.util.*; * @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 class 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); } /** @@ -144,60 +88,6 @@ public class OperationSetBasicInstantMessagingDictImpl } /** - * 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 * return true for protocols that support offline messages and false for @@ -298,10 +188,9 @@ public class OperationSetBasicInstantMessagingDictImpl 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) { diff --git a/src/net/java/sip/communicator/impl/protocol/gibberish/MessageGibberishImpl.java b/src/net/java/sip/communicator/impl/protocol/gibberish/MessageGibberishImpl.java index bda2a06..fcec016 100644 --- a/src/net/java/sip/communicator/impl/protocol/gibberish/MessageGibberishImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/gibberish/MessageGibberishImpl.java @@ -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 @@ import net.java.sip.communicator.service.protocol.*; /** * 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); } } diff --git a/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetBasicInstantMessagingGibberishImpl.java b/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetBasicInstantMessagingGibberishImpl.java index 8a0f088..dec82b8 100644 --- a/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetBasicInstantMessagingGibberishImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetBasicInstantMessagingGibberishImpl.java @@ -17,12 +17,8 @@ import net.java.sip.communicator.service.protocol.event.*; * @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 class 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); } /** @@ -196,60 +143,6 @@ public class OperationSetBasicInstantMessagingGibberishImpl } /** - * 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 * return true for protocols that support offline messages and false for diff --git a/src/net/java/sip/communicator/impl/protocol/icq/MessageIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/MessageIcqImpl.java index 993b26f..be3b69d 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/MessageIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/MessageIcqImpl.java @@ -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 @@ import net.java.sip.communicator.service.protocol.*; /** * 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); } } diff --git a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java index bbd7a79..6f8e003 100644 --- a/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/icq/OperationSetBasicInstantMessagingIcqImpl.java @@ -29,15 +29,10 @@ import net.java.sip.communicator.service.protocol.icqconstants.*; * @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 class OperationSetBasicInstantMessagingIcqImpl } } - - - /** - * 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 class OperationSetBasicInstantMessagingIcqImpl 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() diff --git a/src/net/java/sip/communicator/impl/protocol/irc/MessageIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/MessageIrcImpl.java index ae9e90a..9bbdc26 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/MessageIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/MessageIrcImpl.java @@ -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 @@ import net.java.sip.communicator.service.protocol.*; /** * Very simple message implementation for the IRC protocol. - * + * * @author Stephane Remy * @author Loic Kempf + * @author Lubomir Marinov */ public class MessageIrcImpl - implements Message + extends AbstractMessage { /** @@ -29,124 +29,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 class MessageIrcImpl */ public boolean isCommand() { - return textContent.startsWith("/"); + return getContent().startsWith("/"); } /** @@ -165,7 +61,7 @@ public class MessageIrcImpl */ public boolean isAction() { - return textContent.startsWith("/me"); + return getContent().startsWith("/me"); } /** @@ -176,6 +72,6 @@ public class MessageIrcImpl */ protected void setContent(String messageContent) { - this.textContent = messageContent; + super.setContent(messageContent); } -}
\ No newline at end of file +} diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/MessageJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/MessageJabberImpl.java index f958687..01651c0 100755 --- a/src/net/java/sip/communicator/impl/protocol/jabber/MessageJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/MessageJabberImpl.java @@ -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 @@ import net.java.sip.communicator.service.protocol.*; /** * 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); } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java index 2fbbd9b..9cca898 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java @@ -13,7 +13,6 @@ import net.java.sip.communicator.impl.protocol.jabber.extensions.version.*; 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 @@ import org.jivesoftware.smackx.packet.XHTMLExtension; * @author Damian Minkov */ public class OperationSetBasicInstantMessagingJabberImpl - implements OperationSetBasicInstantMessaging + extends AbstractOperationSetBasicInstantMessaging { private static final Logger logger = Logger.getLogger(OperationSetBasicInstantMessagingJabberImpl.class); @@ -65,11 +64,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. */ private ProtocolProviderServiceJabberImpl jabberProvider = null; @@ -115,77 +109,21 @@ public class OperationSetBasicInstantMessagingJabberImpl } /** - * 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 class OperationSetBasicInstantMessagingJabberImpl } } } - - /** - * 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 class OperationSetBasicInstantMessagingJabberImpl 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 = diff --git a/src/net/java/sip/communicator/impl/protocol/mock/MockBasicInstantMessaging.java b/src/net/java/sip/communicator/impl/protocol/mock/MockBasicInstantMessaging.java index 405d045..a4294ff 100644 --- a/src/net/java/sip/communicator/impl/protocol/mock/MockBasicInstantMessaging.java +++ b/src/net/java/sip/communicator/impl/protocol/mock/MockBasicInstantMessaging.java @@ -12,18 +12,14 @@ import net.java.sip.communicator.service.protocol.*; 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 class 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 class MockBasicInstantMessaging } /** - * 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 class MockBasicInstantMessaging */ 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 class MockBasicInstantMessaging { 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())); } -}
\ No newline at end of file +} diff --git a/src/net/java/sip/communicator/impl/protocol/mock/MockMessage.java b/src/net/java/sip/communicator/impl/protocol/mock/MockMessage.java index cf62c73..253c9a0 100644 --- a/src/net/java/sip/communicator/impl/protocol/mock/MockMessage.java +++ b/src/net/java/sip/communicator/impl/protocol/mock/MockMessage.java @@ -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 @@ package net.java.sip.communicator.impl.protocol.mock; 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); } } diff --git a/src/net/java/sip/communicator/impl/protocol/msn/MessageMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/MessageMsnImpl.java index e689010..893040d 100755 --- a/src/net/java/sip/communicator/impl/protocol/msn/MessageMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/MessageMsnImpl.java @@ -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 @@ import net.java.sip.communicator.service.protocol.*; /** * 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); } } diff --git a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java index 8d1fa66..262d1a3 100644 --- a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java @@ -11,7 +11,6 @@ import java.text.*; 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,17 +24,12 @@ import net.java.sip.communicator.impl.protocol.msn.mail.utils.*; * @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. */ private ProtocolProviderServiceMsnImpl msnProvider = null; @@ -60,39 +54,6 @@ public class OperationSetBasicInstantMessagingMsnImpl } /** - * 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 * return true for protocols that support offline messages and false for @@ -126,33 +87,10 @@ public class OperationSetBasicInstantMessagingMsnImpl 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 class OperationSetBasicInstantMessagingMsnImpl } } - /** - * 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 class OperationSetBasicInstantMessagingMsnImpl 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()); diff --git a/src/net/java/sip/communicator/impl/protocol/rss/MessageRssImpl.java b/src/net/java/sip/communicator/impl/protocol/rss/MessageRssImpl.java index 1071bdf..470eda8 100644 --- a/src/net/java/sip/communicator/impl/protocol/rss/MessageRssImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/rss/MessageRssImpl.java @@ -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 @@ import net.java.sip.communicator.service.protocol.*; /** * 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); } } diff --git a/src/net/java/sip/communicator/impl/protocol/rss/OperationSetBasicInstantMessagingRssImpl.java b/src/net/java/sip/communicator/impl/protocol/rss/OperationSetBasicInstantMessagingRssImpl.java index 92d6618..98ebc3a 100644 --- a/src/net/java/sip/communicator/impl/protocol/rss/OperationSetBasicInstantMessagingRssImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/rss/OperationSetBasicInstantMessagingRssImpl.java @@ -21,15 +21,11 @@ import net.java.sip.communicator.util.*; * @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 class 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); } /** @@ -378,40 +334,6 @@ public class OperationSetBasicInstantMessagingRssImpl } /** - * 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 * return true for protocols that support offline messages and false for diff --git a/src/net/java/sip/communicator/impl/protocol/sip/MessageSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/MessageSipImpl.java index 678b9be..e9bf236 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/MessageSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/MessageSipImpl.java @@ -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); } } diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java index e07f2a4..25b46b8 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetBasicInstantMessagingSipImpl.java @@ -27,17 +27,12 @@ import net.java.sip.communicator.util.*; * @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. */ private Vector messageProcessors = new Vector(); @@ -101,39 +96,6 @@ public class OperationSetBasicInstantMessagingSipImpl } /** - * 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 * incoming messages.. @@ -166,33 +128,10 @@ public class OperationSetBasicInstantMessagingSipImpl } } - /** - * 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); } /** @@ -646,44 +585,6 @@ public class OperationSetBasicInstantMessagingSipImpl } /** - * 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. */ private class BasicInstantMessagingMethodProcessor @@ -875,8 +776,7 @@ public class OperationSetBasicInstantMessagingSipImpl 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: " diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTypingNotificationsSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTypingNotificationsSipImpl.java index 3fc5e80..9ea9428 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTypingNotificationsSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetTypingNotificationsSipImpl.java @@ -481,12 +481,11 @@ public class OperationSetTypingNotificationsSipImpl } 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; diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/MessageSSHImpl.java b/src/net/java/sip/communicator/impl/protocol/ssh/MessageSSHImpl.java index db67ab8..84edf68 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/MessageSSHImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/ssh/MessageSSHImpl.java @@ -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; - } } diff --git a/src/net/java/sip/communicator/impl/protocol/ssh/OperationSetBasicInstantMessagingSSHImpl.java b/src/net/java/sip/communicator/impl/protocol/ssh/OperationSetBasicInstantMessagingSSHImpl.java index f01ae73..4040506 100644 --- a/src/net/java/sip/communicator/impl/protocol/ssh/OperationSetBasicInstantMessagingSSHImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/ssh/OperationSetBasicInstantMessagingSSHImpl.java @@ -14,7 +14,6 @@ package net.java.sip.communicator.impl.protocol.ssh; 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 @@ import net.java.sip.communicator.service.protocol.event.*; * @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 class 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 @@ -307,64 +247,15 @@ public class OperationSetBasicInstantMessagingSSHImpl /** * 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())); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/MessageYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/MessageYahooImpl.java index a84c5c8..8773f5b 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/MessageYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/MessageYahooImpl.java @@ -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 @@ import net.java.sip.communicator.service.protocol.*; /** * 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); } } diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java index 4b838f3..b26993f 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java @@ -25,8 +25,8 @@ import ymsg.support.*; * @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. @@ -83,39 +77,6 @@ public class OperationSetBasicInstantMessagingYahooImpl } /** - * 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 * return true for protocols that support offline messages and false for @@ -150,35 +111,10 @@ public class OperationSetBasicInstantMessagingYahooImpl 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 class OperationSetBasicInstantMessagingYahooImpl * @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 @@ public class OperationSetBasicInstantMessagingYahooImpl 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 @@ public class OperationSetBasicInstantMessagingYahooImpl "$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()); diff --git a/src/net/java/sip/communicator/impl/protocol/zeroconf/MessageZeroconfImpl.java b/src/net/java/sip/communicator/impl/protocol/zeroconf/MessageZeroconfImpl.java index cdcce25..f17d141 100644 --- a/src/net/java/sip/communicator/impl/protocol/zeroconf/MessageZeroconfImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/zeroconf/MessageZeroconfImpl.java @@ -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 @@ import net.java.sip.communicator.service.protocol.*; /** * 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 class MessageZeroconfImpl /** * 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; } diff --git a/src/net/java/sip/communicator/impl/protocol/zeroconf/OperationSetBasicInstantMessagingZeroconfImpl.java b/src/net/java/sip/communicator/impl/protocol/zeroconf/OperationSetBasicInstantMessagingZeroconfImpl.java index 9840c99..ae66024 100644 --- a/src/net/java/sip/communicator/impl/protocol/zeroconf/OperationSetBasicInstantMessagingZeroconfImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/zeroconf/OperationSetBasicInstantMessagingZeroconfImpl.java @@ -21,15 +21,10 @@ import net.java.sip.communicator.util.*; * */ 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 class 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); } /** @@ -203,57 +147,14 @@ public class OperationSetBasicInstantMessagingZeroconfImpl /** * 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); } /** diff --git a/src/net/java/sip/communicator/service/protocol/AbstractMessage.java b/src/net/java/sip/communicator/service/protocol/AbstractMessage.java new file mode 100644 index 0000000..ee28d3d --- /dev/null +++ b/src/net/java/sip/communicator/service/protocol/AbstractMessage.java @@ -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; + } + } +} diff --git a/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java b/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java new file mode 100644 index 0000000..6351dcc --- /dev/null +++ b/src/net/java/sip/communicator/service/protocol/AbstractOperationSetBasicInstantMessaging.java @@ -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); + } + } +} diff --git a/src/net/java/sip/communicator/service/protocol/Message.java b/src/net/java/sip/communicator/service/protocol/Message.java index ab0b4bc..9890cd9 100644 --- a/src/net/java/sip/communicator/service/protocol/Message.java +++ b/src/net/java/sip/communicator/service/protocol/Message.java @@ -17,7 +17,7 @@ package net.java.sip.communicator.service.protocol; * 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 */ diff --git a/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java b/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java index ff7cb1f..4329bc2 100644 --- a/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java +++ b/src/net/java/sip/communicator/service/protocol/OperationSetBasicInstantMessaging.java @@ -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 diff --git a/test/net/java/sip/communicator/slick/protocol/gibberish/TestOperationSetBasicInstantMessaging.java b/test/net/java/sip/communicator/slick/protocol/gibberish/TestOperationSetBasicInstantMessaging.java index 5323000..3adc3dc 100644 --- a/test/net/java/sip/communicator/slick/protocol/gibberish/TestOperationSetBasicInstantMessaging.java +++ b/test/net/java/sip/communicator/slick/protocol/gibberish/TestOperationSetBasicInstantMessaging.java @@ -373,9 +373,8 @@ public class TestOperationSetBasicInstantMessaging 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" diff --git a/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetBasicInstantMessaging.java b/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetBasicInstantMessaging.java index 6360757..1f171c7 100644 --- a/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetBasicInstantMessaging.java +++ b/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetBasicInstantMessaging.java @@ -266,9 +266,8 @@ public class TestOperationSetBasicInstantMessaging 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" diff --git a/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetBasicInstantMessaging.java b/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetBasicInstantMessaging.java index e24ae17..f481c9f 100644 --- a/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetBasicInstantMessaging.java +++ b/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetBasicInstantMessaging.java @@ -11,7 +11,6 @@ import java.util.*; 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 class TestOperationSetBasicInstantMessaging 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" diff --git a/test/net/java/sip/communicator/slick/protocol/msn/TestOperationSetBasicInstantMessaging.java b/test/net/java/sip/communicator/slick/protocol/msn/TestOperationSetBasicInstantMessaging.java index 023181e..4153ff6 100644 --- a/test/net/java/sip/communicator/slick/protocol/msn/TestOperationSetBasicInstantMessaging.java +++ b/test/net/java/sip/communicator/slick/protocol/msn/TestOperationSetBasicInstantMessaging.java @@ -11,7 +11,6 @@ import java.util.*; 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 class TestOperationSetBasicInstantMessaging 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" diff --git a/test/net/java/sip/communicator/slick/protocol/sip/TestOperationSetBasicInstantMessaging.java b/test/net/java/sip/communicator/slick/protocol/sip/TestOperationSetBasicInstantMessaging.java index eeab992..eccdef5 100644 --- a/test/net/java/sip/communicator/slick/protocol/sip/TestOperationSetBasicInstantMessaging.java +++ b/test/net/java/sip/communicator/slick/protocol/sip/TestOperationSetBasicInstantMessaging.java @@ -412,9 +412,8 @@ public class TestOperationSetBasicInstantMessaging 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()); diff --git a/test/net/java/sip/communicator/slick/protocol/yahoo/TestOperationSetBasicInstantMessaging.java b/test/net/java/sip/communicator/slick/protocol/yahoo/TestOperationSetBasicInstantMessaging.java index 5b7aba0..014de9e 100644 --- a/test/net/java/sip/communicator/slick/protocol/yahoo/TestOperationSetBasicInstantMessaging.java +++ b/test/net/java/sip/communicator/slick/protocol/yahoo/TestOperationSetBasicInstantMessaging.java @@ -11,7 +11,6 @@ import java.util.*; 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 class TestOperationSetBasicInstantMessaging 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" |