diff options
author | damencho <damencho@jitsi.org> | 2015-07-16 15:31:43 -0500 |
---|---|---|
committer | damencho <damencho@jitsi.org> | 2015-07-16 15:31:43 -0500 |
commit | d75bd2cc4718ac0f42b5c31b02b131f411f7178d (patch) | |
tree | 032b60cd6009a7475f8b2719db0b8e4f838f6747 /src/net/java/sip/communicator/impl | |
parent | 1fdab4331d907debb3aa45b48299cb00560ce91c (diff) | |
download | jitsi-d75bd2cc4718ac0f42b5c31b02b131f411f7178d.zip jitsi-d75bd2cc4718ac0f42b5c31b02b131f411f7178d.tar.gz jitsi-d75bd2cc4718ac0f42b5c31b02b131f411f7178d.tar.bz2 |
Removes msn protocol.
Diffstat (limited to 'src/net/java/sip/communicator/impl')
34 files changed, 0 insertions, 9260 deletions
diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsQuery.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsQuery.java index f37121e..8148777 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsQuery.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsQuery.java @@ -346,12 +346,6 @@ public class GoogleContactsQuery OperationSetBasicTelephony.class, ProtocolNames.JABBER); break; - case MSN: - supportedOpSets.add(OperationSetBasicInstantMessaging.class); - preferredProtocols.put( - OperationSetBasicInstantMessaging.class, - ProtocolNames.MSN); - break; case YAHOO: supportedOpSets.add(OperationSetBasicInstantMessaging.class); preferredProtocols.put( diff --git a/src/net/java/sip/communicator/impl/protocol/msn/AbstractContactGroupMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/AbstractContactGroupMsnImpl.java deleted file mode 100644 index 0a7b9cf..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/AbstractContactGroupMsnImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import net.java.sip.communicator.service.protocol.*; - -/** - * The Msn implementation of the service.protocol.ContactGroup interface. There - * are two types of groups possible here. <tt>RootContactGroupMsnImpl</tt> - * which is the root node of the ContactList itself and - * <tt>ContactGroupMsnImpl</tt> which represents standard groups. The - * reason for having those 2 is that generally, Msn groups may not contain - * subgroups. A contact list on the other hand may not directly contain buddies. - * - * - * The reason for having an abstract class is only - being able to esily - * recognize our own (Msn) contacts. - * @author Damian Minkov - */ -public abstract class AbstractContactGroupMsnImpl - implements ContactGroup -{ - - -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/AdHocChatRoomInvitationMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/AdHocChatRoomInvitationMsnImpl.java deleted file mode 100644 index aeef55e..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/AdHocChatRoomInvitationMsnImpl.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import net.java.sip.communicator.service.protocol.*; - -/** - * The MSN implementation of the <tt>AdHocChatRoomInvitation</tt> interface. - * - * @author Rupert Burchardi - * @author Yana Stamcheva - */ -public class AdHocChatRoomInvitationMsnImpl - implements AdHocChatRoomInvitation -{ - /** - * Corresponding chat room instance. - */ - private AdHocChatRoom chatRoom; - /** - * The name of the inviter. - */ - private String inviter; - - /** - * Creates an instance of the <tt>AdHocChatRoomInvitationMsnImpl</tt> by - * specifying the targetChatRoom, the inviter, the reason and the password. - * - * @param targetChatRoom the <tt>AdHocChatRoom</tt> for which the invitation - * is - * @param inviter the contact, which sent the invitation - */ - public AdHocChatRoomInvitationMsnImpl(AdHocChatRoom targetChatRoom, - String inviter) - { - this.chatRoom = targetChatRoom; - this.inviter = inviter; - } - - /** - * Returns the corresponding chat room. - * @return The chat room - */ - public AdHocChatRoom getTargetAdHocChatRoom() - { - return chatRoom; - } - - /** - * Returns the corresponding inviter. - * @return The name of the inviter - */ - public String getInviter() - { - return inviter; - } - - /** - * Returns the invitation reason. - * @return the invitation reason - */ - public String getReason() - { - //Not supported in the Msn protocol. - return null; - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/AdHocChatRoomMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/AdHocChatRoomMsnImpl.java deleted file mode 100644 index cadcfd8..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/AdHocChatRoomMsnImpl.java +++ /dev/null @@ -1,595 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.util.*; -import net.sf.jml.*; - -/** - * Implements ad-hoc chat rooms for MSN. - * - * @author Rupert Burchardi - * @author Valentin Martinet - */ -public class AdHocChatRoomMsnImpl - implements AdHocChatRoom -{ - private static final Logger logger - = Logger.getLogger(AdHocChatRoomMsnImpl.class); - - /** - * The protocol provider that created us - */ - private final ProtocolProviderServiceMsnImpl provider; - - /** - * The OperationSet for MSN multi user chats. - */ - private OperationSetAdHocMultiUserChatMsnImpl opSetAdHocMuc = null; - - /** - * The corresponding switchboard for the chat room. Each chat room has its - * own switchboard and if it is closed the user cannot reconnect to it, see - * MSN documentation for further infos. - */ - private MsnSwitchboard switchboard = null; - - /** - * Listeners that will be notified of changes in participants status in the - * ad-hoc room, such as participant joined, left, etc. - */ - private Vector<AdHocChatRoomParticipantPresenceListener> - participantsPresenceListeners = - new Vector<AdHocChatRoomParticipantPresenceListener>(); - - /** - * Listeners that will be notified every time a new message is received on - * this ad-hoc chat room. - */ - private Vector<AdHocChatRoomMessageListener> messageListeners - = new Vector<AdHocChatRoomMessageListener>(); - - /** - * A Message buffer, will keep all messages until the MSN ad-hoc chat room - * is ready. - */ - public Vector<EventObject> messageBuffer = new Vector<EventObject>(); - - /** - * The name of this ad-hoc chat room - */ - private String name; - - /** - * The list of participants of this ad-hoc chat room. - */ - private final Hashtable<String, Contact> participants = - new Hashtable<String, Contact>(); - - /** - * List of unresolved member names. - */ - private ArrayList<String> pendingInvitations = new ArrayList<String>(); - - /** - * The presence operation set for the Msn protocol. - */ - private final OperationSetPersistentPresenceMsnImpl presenceOpSet; - - /** - * Creates a new ad-hoc chat room for MSN named <tt>name</tt>, using the - * protocol provider <tt>provider</tt>. - * - * @param name - * @param provider - */ - public AdHocChatRoomMsnImpl(String name, - ProtocolProviderServiceMsnImpl provider) - { - this.name = name; - this.provider = provider; - this.opSetAdHocMuc = - (OperationSetAdHocMultiUserChatMsnImpl) - this.provider.getOperationSet(OperationSetAdHocMultiUserChat.class); - - this.presenceOpSet - = (OperationSetPersistentPresenceMsnImpl) - this.provider.getOperationSet( - OperationSetPersistentPresence.class); - } - - /** - * Creates a new ad-hoc chat room for MSN named <tt>name</tt>, using the - * protocol provider <tt>provider</tt> and the msn switchboard - * <tt>switchboard</tt>. - * - * @param name - * @param provider - * @param switchboard - */ - public AdHocChatRoomMsnImpl(String name, - ProtocolProviderServiceMsnImpl provider, - MsnSwitchboard switchboard) - { - this.name = name; - this.provider = provider; - this.opSetAdHocMuc - = (OperationSetAdHocMultiUserChatMsnImpl) - this.provider.getOperationSet(OperationSetAdHocMultiUserChat.class); - - this.presenceOpSet - = (OperationSetPersistentPresenceMsnImpl) - this.provider.getOperationSet( - OperationSetPersistentPresence.class); - - this.switchboard = switchboard; - - this.updateParticipantsList(switchboard); - } - - /** - * Adds a listener that will be notified of changes in our status in the - * room. - * - * @param listener a participant status listener. - */ - public void addParticipantPresenceListener( - AdHocChatRoomParticipantPresenceListener listener) - { - synchronized(this.participantsPresenceListeners) - { - if (!this.participantsPresenceListeners.contains(listener)) - this.participantsPresenceListeners.add(listener); - } - } - - /** - * Registers <tt>listener</tt> so that it would receive events every time a - * new message is received on this chat room. - * - * @param listener a <tt>MessageListener</tt> that would be notified every - * time a new message is received on this chat room. - */ - public void addMessageListener(AdHocChatRoomMessageListener listener) - { - synchronized(this.messageListeners) - { - if (!this.messageListeners.contains(listener)) - this.messageListeners.add(listener); - } - } - - /** - * Removes <tt>listener</tt> so that it won't receive any further message - * events from this room. - * - * @param listener the <tt>MessageListener</tt> to remove from this room - */ - public void removeMessageListener(ChatRoomMessageListener listener) - { - synchronized (messageListeners) - { - if (messageListeners.contains(listener)) - messageListeners.remove(messageListeners.indexOf(listener)); - } - } - - /** - * Finds the participant of this ad-hoc chat room corresponding to the - * given address. - * - * @param address the address to search for. - * @return the participant of this chat room corresponding to the given - * nick name. - */ - public Contact findParticipantForAddress(String address) - { - Iterator<Contact> participantsIter - = this.participants.values().iterator(); - - while (participantsIter.hasNext()) - { - Contact contact = participantsIter.next(); - - if (contact.getAddress().equals(address)) - { - return contact; - } - } - - return null; - } - - /** - * Creates a <tt>Message</tt> for this ad-hoc chat room containing - * <tt>text</tt>. - * - * @param text - * @return Message the newly created <tt>Message</tt> - */ - public Message createMessage(String text) - { - Message msg = - new MessageMsnImpl(text, - OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE, - OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING, null); - - return msg; - } - - /** - * Returns the name of this ad-hoc chatroom - * - * @return String - */ - public String getName() - { - return this.name; - } - - /** - * Returns the parent provider - * - * @return ProtocolProviderService - */ - public ProtocolProviderService getParentProvider() - { - return this.provider; - } - - /** - * Returns a list containing all the <tt>Contact</tt>s who participate in - * this ad-hoc chat room. - * - * @return List<Contact> - */ - public List<Contact> getParticipants() - { - return new LinkedList<Contact>(this.participants.values()); - } - - /** - * Returns the participant of this ad-hoc chat room which corresponds to - * the given id. - * - * @param id ID of the participant - * @return Contact the corresponding Contact - */ - public Contact getAdHocChatRoomParticipant(String id) - { - return this.participants.get(id); - } - - /** - * Adds a participant to the participants list. - * - * @param id the ID - * @param participant The participant (<tt>Contact</tt>) to add. - */ - public void addAdHocChatRoomParticipant(String id, Contact participant) - { - this.participants.put(id, participant); - - fireParticipantPresenceEvent(participant, - AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_JOINED, null); - } - - /** - * Removes the participant of this ad-hoc chat room which corresponds to - * the given id. - * - * @param id ID of the participant - */ - public void removeParticipant(String id) - { - Contact contact= this.participants.get(id); - this.participants.remove(id); - - fireParticipantPresenceEvent(contact, - AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_LEFT, null); - } - - /** - * Returns the number of <tt>Contact</tt>s who participate in this ad-hoc - * chat room. - */ - public int getParticipantsCount() - { - return this.participants.size(); - } - - /** - * Returns the subject. - * - * @return null - */ - public String getSubject() - { - return null; - } - - /** - * Invites another user to this room. If we're not joined nothing will - * happen. - * - * @param userAddress the address of the user (email address) to invite to - * the room.(one may also invite users not on their contact - * list). - * @param reason You cannot specify a Reason inside the msn protocol - */ - public void invite(String userAddress, String reason) - { - // msn requires lower case email addresses - userAddress = userAddress.toLowerCase(); - - if (switchboard == null) - { - pendingInvitations.add(userAddress); - } - else - { - switchboard.inviteContact(Email.parseStr(userAddress)); - } - } - - public void join() - { - // We don't specify a reason. - this.opSetAdHocMuc.fireLocalUserPresenceEvent(this, - LocalUserAdHocChatRoomPresenceChangeEvent.LOCAL_USER_JOINED, null); - - // We buffered the messages before the user has joined the chat, now the - // user has joined so we fire them again - for (EventObject evt : this.messageBuffer) - { - this.fireMessageEvent(evt); - } - } - - /** - * Leave this chat room. Once this method is called, the user won't be - * listed as a member of the chat room any more and no further chat events - * will be delivered. Depending on the underlying protocol and - * implementation leave() might cause the room to be destroyed if it has - * been created by the local user. - */ - public void leave() - { - if (switchboard != null) - { - switchboard.close(); - switchboard = null; - } - - Iterator<Contact> participantsIter - = participants.values().iterator(); - - while (participantsIter.hasNext()) - { - Contact participant = participantsIter.next(); - - fireParticipantPresenceEvent(participant, - AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_LEFT, - "Local user has left the chat room."); - } - - // Delete the list of members - participants.clear(); - } - - /** - * Returns if this chatroom is a system ones. - * - * @return false - */ - public boolean isSystem() - { - return false; - } - - /** - * Sends the given message through the participants of this ad-hoc chat - * room. - * - * @param message the message to delivered - * - * @throws OperationFailedException if send fails - */ - public void sendMessage(Message message) throws OperationFailedException - { - if (logger.isInfoEnabled()) - logger.info("switchboard="+this.switchboard); - this.switchboard.sendText(message.getContent()); - - AdHocChatRoomMessageDeliveredEvent msgDeliveredEvt - = new AdHocChatRoomMessageDeliveredEvent( - this, - new Date(), - message, - AdHocChatRoomMessageDeliveredEvent.CONVERSATION_MESSAGE_DELIVERED); - - this.fireMessageEvent(msgDeliveredEvt); - } - - /** - * Sets the corresponding switchboard. - * - * @param switchboard Corresponding switchboard. - */ - public void setSwitchboard(MsnSwitchboard switchboard) - { - this.switchboard = switchboard; - } - - /** - * Creates the corresponding AdHocChatRoomParticipantPresenceChangeEvent and - * notifies all <tt>AdHocChatRoomParticipantPresenceListener</tt>s that a - * participant has joined or left this <tt>AdHocChatRoom</tt>. - * - * @param participant the <tt>Contact</tt> - * @param eventID the identifier of the event - * @param eventReason the reason of the event - */ - private void fireParticipantPresenceEvent( Contact participant, - String eventID, - String eventReason) - { - AdHocChatRoomParticipantPresenceChangeEvent evt = - new AdHocChatRoomParticipantPresenceChangeEvent( - this, participant, eventID, eventReason); - - if (logger.isTraceEnabled()) - logger.trace("Will dispatch the following AdHocChatRoom event: " + evt); - - Iterator<AdHocChatRoomParticipantPresenceListener> listeners = null; - synchronized (this.participantsPresenceListeners) - { - listeners = new ArrayList<AdHocChatRoomParticipantPresenceListener>( - this.participantsPresenceListeners).iterator(); - } - - while (listeners.hasNext()) - { - listeners.next().participantPresenceChanged(evt); - } - } - - /** - * Notifies all interested listeners that a - * <tt>AdHocChatRoomMessageDeliveredEvent</tt>, - * <tt>AdHocChatRoomMessageReceivedEvent</tt> or a - * <tt>AdHocChatRoomMessageDeliveryFailedEvent</tt> has been fired. - * - * @param evt The specific event - */ - public void fireMessageEvent(EventObject evt) - { - Iterator<AdHocChatRoomMessageListener> listeners = null; - synchronized (messageListeners) - { - listeners = new ArrayList<AdHocChatRoomMessageListener>( - messageListeners).iterator(); - } - - if (!listeners.hasNext()) - { - messageBuffer.add(evt); - } - - while (listeners.hasNext()) - { - AdHocChatRoomMessageListener listener = listeners.next(); - - if (evt instanceof AdHocChatRoomMessageDeliveredEvent) - { - listener.messageDelivered( - (AdHocChatRoomMessageDeliveredEvent) evt); - } - else if (evt instanceof AdHocChatRoomMessageReceivedEvent) - { - listener.messageReceived( - (AdHocChatRoomMessageReceivedEvent) evt); - } - else if (evt instanceof AdHocChatRoomMessageDeliveryFailedEvent) - { - listener.messageDeliveryFailed( - (AdHocChatRoomMessageDeliveryFailedEvent) evt); - } - } - } - - /** - * Fills the participants list with all participants inside the switchboard - * (ad-hoc chat room). - * - * @param switchboard The corresponding switchboard - */ - public void updateParticipantsList(MsnSwitchboard switchboard) - { - MsnContact[] contacts = switchboard.getAllContacts(); - - for (MsnContact msnContact : contacts) - { - if (!this.participants.containsKey(msnContact.getId())) - { - // if the member is not inside the members list, create a - // contact instance, - // add it to the list and fire a member presence event - ContactMsnImpl contact - = presenceOpSet.getServerStoredContactList() - .findContactById( - msnContact.getEmail().getEmailAddress()); - - if (contact == null) - contact = new ContactMsnImpl( - msnContact, - presenceOpSet.getServerStoredContactList(), - false, - false); - - this.participants.put(msnContact.getId(), contact); - - fireParticipantPresenceEvent( - contact, - AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_JOINED, - null); - } - } - - for (String contactAddress: this.pendingInvitations) - { - this.invite(contactAddress, ""); - } - // We have sent all invites and we can now clear the content of - // pending invitations. - pendingInvitations.clear(); - } - - /** - * Returns the identifier of this ad-hoc chat room. - * - * @return a <tt>String</tt> containing the identifier of this ad-hoc room - */ - public String getIdentifier() - { - return this.getName(); - } - - /** - * Removes the given participant presence listener. - * - * @param listener the listener to remove - */ - public void removeParticipantPresenceListener( - AdHocChatRoomParticipantPresenceListener listener) - { - synchronized (this.participantsPresenceListeners) - { - if (this.participantsPresenceListeners.contains(listener)) - this.participantsPresenceListeners.remove(listener); - } - } - - /** - * Removes the given message listener. - * - * @param listener the listener to remove - */ - public void removeMessageListener(AdHocChatRoomMessageListener listener) - { - synchronized(this.messageListeners) - { - if(this.messageListeners.contains(listener)) - { - this.messageListeners.remove(listener); - } - } - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ContactGroupMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ContactGroupMsnImpl.java deleted file mode 100644 index 64085a6..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/ContactGroupMsnImpl.java +++ /dev/null @@ -1,437 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; -import net.sf.jml.*; - -/** - * The Msn implementation of the ContactGroup interface. Instances of this class - * (contrary to <tt>RootContactGroupMsnImpl</tt>) may only contain buddies - * and cannot have sub groups. Note that instances of this class only use the - * corresponding smack source group for reading their names and only - * initially fill their <tt>buddies</tt> <tt>java.util.List</tt> with - * the ContactMsnImpl objects corresponding to those contained in the source - * group at the moment it is being created. They would, however, never try to - * sync or update their contents ulteriorly. This would have to be done through - * the addContact()/removeContact() methods. - * The content of buddies is created on creating of the group and when the smack - * source group is changed. - * - * @author Damian Minkov - * @author Emil Ivov - */ -public class ContactGroupMsnImpl - extends AbstractContactGroupMsnImpl -{ - - /** - * Maps all MSN IDs in our contact list to the actual contacts so that we - * could easily search the set of existing contacts. Note that we only store - * lower case strings in the left column because MSN IDs in XMPP are not - * case sensitive. - */ - private final Map<String, Contact> buddies - = new Hashtable<String, Contact>(); - - private boolean isResolved = false; - - /** - * The Msn Group corresponding to this contact group. - */ - private MsnGroup msnGroup = null; - - /** - * a list that would always remain empty. We only use it so that we're able - * to extract empty iterators - */ - private final List<ContactGroup> dummyGroupsList - = new LinkedList<ContactGroup>(); - - private final ServerStoredContactListMsnImpl ssclCallback; - - /** - * Whether this group is persistent. - */ - private boolean isPersistent; - - /** - * Creates an Msn group using the specified <tt>RosterGroup</tt> as - * a source. The newly created group will always return the name of the - * underlying RosterGroup and would thus automatically adapt to changes. - * It would, however, not receive or try to poll for modifications of the - * buddies it contains and would therefore have to be updated manually by - * ServerStoredContactListImpl update will only be done if source group - * is changed. - - * @param msnGroup the Msn Group corresponding to the group - * @param groupMembers the group members that we should add to the group. - * @param ssclCallback a callback to the server stored contact list - * we're creating. - * @param isResolved a boolean indicating whether or not the group has been - * resolved against the server. - */ - ContactGroupMsnImpl(MsnGroup msnGroup, - MsnContact[] groupMembers, - ServerStoredContactListMsnImpl ssclCallback, - boolean isResolved, - boolean isPersistent) - { - this.msnGroup = msnGroup; - this.isResolved = isResolved; - this.isPersistent = isPersistent; - this.ssclCallback = ssclCallback; - - for (MsnContact groupMember : groupMembers) - { - /* - * Only add the contact if it doesn't already exist in some other - * group. This is necessary because MSN would allow having one and - * the same contact in more than one group. - */ - if(ssclCallback.findContactById( - groupMember.getEmail().getEmailAddress()) - == null) - addContact( - new ContactMsnImpl(groupMember, ssclCallback, true, true)); - } - } - - /** - * Returns the number of <tt>Contact</tt> members of this - * <tt>ContactGroup</tt> - * - * @return an int indicating the number of <tt>Contact</tt>s, - * members of this <tt>ContactGroup</tt>. - */ - public int countContacts() - { - return buddies.size(); - } - - /** - * Returns a reference to the root group which in Msn is the parent of - * any other group since the protocol does not support subgroups. - * @return a reference to the root group. - */ - public ContactGroup getParentContactGroup() - { - return ssclCallback.getRootGroup(); - } - - /** - * Adds the specified contact to the end of this group. - * @param contact the new contact to add to this group - */ - void addContact(ContactMsnImpl contact) - { - buddies.put(contact.getAddress().toLowerCase(), contact); - } - - - /** - * Removes the specified contact from this contact group - * @param contact the contact to remove. - * - * @return <tt>true</tt> if the argument was a component of this vector; - * false otherwise. - */ - boolean removeContact(ContactMsnImpl contact) - { - return buddies.remove(contact.getAddress().toLowerCase()) != null; - } - - /** - * Returns an Iterator over all contacts, member of this - * <tt>ContactGroup</tt>. - * - * @return a java.util.Iterator over all contacts inside this - * <tt>ContactGroup</tt>. In case the group doesn't contain any members it - * will return an empty iterator. - */ - public Iterator<Contact> contacts() - { - return buddies.values().iterator(); - } - - /** - * Returns the <tt>Contact</tt> with the specified address or - * identifier. - * @param id the address or identifier of the <tt>Contact</tt> we are - * looking for. - * @return the <tt>Contact</tt> with the specified id or address. - */ - public Contact getContact(String id) - { - return this.findContact(id); - } - - /** - * Returns the name of this group. - * @return a String containing the name of this group. - */ - public String getGroupName() - { - return msnGroup.getGroupName(); - } - - /** - * Determines whether the group may contain subgroups or not. - * - * @return always false since only the root group may contain subgroups. - */ - public boolean canContainSubgroups() - { - return false; - } - - /** - * Returns the subgroup with the specified index (i.e. always null since - * this group may not contain subgroups). - * - * @param index the index of the <tt>ContactGroup</tt> to retrieve. - * @return always null - */ - public ContactGroup getGroup(int index) - { - return null; - } - - /** - * Returns the subgroup with the specified name. - * @param groupName the name of the <tt>ContactGroup</tt> to retrieve. - * @return the <tt>ContactGroup</tt> with the specified index. - */ - public ContactGroup getGroup(String groupName) - { - return null; - } - - /** - * Returns an empty iterator. Subgroups may only be present in the root - * group. - * - * @return an empty iterator - */ - public Iterator<ContactGroup> subgroups() - { - return dummyGroupsList.iterator(); - } - - /** - * Returns the number of subgroups contained by this group, which is - * always 0 since sub groups in the protocol may only be contained - * by the root group - <tt>RootContactGroupImpl</tt>. - * @return a 0 int. - */ - public int countSubgroups() - { - return 0; - } - - /** - * Returns a hash code value for the object, which is actually the hashcode - * value of the groupname. - * - * @return a hash code value for this ContactGroup. - */ - @Override - public int hashCode() - { - return getGroupName().hashCode(); - } - - /** - * Indicates whether some other object is "equal to" this group. - * - * @param obj the reference object with which to compare. - * @return <tt>true</tt> if this object is the same as the obj - * argument; <tt>false</tt> otherwise. - */ - @Override - public boolean equals(Object obj) - { - if( obj == this ) - return true; - - if (obj == null - || !(obj instanceof ContactGroupMsnImpl) ) - return false; - - if(!((ContactGroup)obj).getGroupName().equals(getGroupName())) - return false; - - if(getProtocolProvider() != ((ContactGroup)obj).getProtocolProvider()) - return false; - - //since Msn does not support having two groups with the same name - // at this point we could bravely state that the groups are the same - // and not bother to compare buddies. (gotta check that though) - return true; - } - - /** - * Returns the protocol provider that this group belongs to. - * @return a regerence to the ProtocolProviderService instance that this - * ContactGroup belongs to. - */ - public ProtocolProviderService getProtocolProvider() - { - return this.ssclCallback.getParentProvider(); - } - - /** - * Returns a string representation of this group, in the form - * MsnGroup.GroupName[size]{ buddy1.toString(), buddy2.toString(), ...}. - * @return a String representation of the object. - */ - @Override - public String toString() - { - StringBuffer buff = new StringBuffer("MSnGroup."); - buff.append(getGroupName()); - buff.append(", childContacts="+countContacts()+":["); - - Iterator<Contact> contacts = contacts(); - while (contacts.hasNext()) - { - Contact contact = contacts.next(); - buff.append(contact.toString()); - if(contacts.hasNext()) - buff.append(", "); - } - return buff.append("]").toString(); - } - - /** - * Returns the contact encapsulating with the spcieified name or - * null if no such contact was found. - * - * @param id the id for the contact we're looking for. - * @return the <tt>ContactMsnImpl</tt> corresponding to the specified - * screnname or null if no such contact existed. - */ - ContactMsnImpl findContact(String id) - { - if (id == null) - return null; - - return (ContactMsnImpl)buddies.get(id.toLowerCase()); - } - - /** - * Determines whether or not this contact group is being stored by the - * server. Non persistent contact groups exist for the sole purpose of - * containing non persistent contacts. - * @return true if the contact group is persistent and false otherwise. - */ - public boolean isPersistent() - { - return isPersistent; - } - - /** - * Returns null as no persistent data is required and the contact address is - * sufficient for restoring the contact. - * <p> - * @return null as no such data is needed. - */ - public String getPersistentData() - { - return null; - } - - /** - * Determines whether or not this contact group has been resolved against - * the server. Unresolved group are used when initially loading a contact - * list that has been stored in a local file until the presence operation - * set has managed to retrieve all the contact list from the server and has - * properly mapped contacts and groups to their corresponding on-line - * buddies. - * @return true if the contact has been resolved (mapped against a buddy) - * and false otherwise. - */ - public boolean isResolved() - { - return isResolved; - } - - /** - * Resolve this contact group against the specified group - * @param msnGroup the server stored group - */ - void setResolved(MsnGroup msnGroup) - { - if(isResolved) - return; - - this.isResolved = true; - this.isPersistent = true; - - this.msnGroup = msnGroup; - - MsnContact[] contacts = msnGroup.getContacts(); - for (int i = 0; i < contacts.length; i++) - { - MsnContact item = contacts[i]; - - ContactMsnImpl contact = - ssclCallback.findContactById(item.getEmail().getEmailAddress()); - if(contact != null) - { - contact.setResolved(item); - - ssclCallback.fireContactResolved(this, contact); - } - else - { - ContactMsnImpl newContact = - new ContactMsnImpl(item, ssclCallback, true, true); - addContact(newContact); - - ssclCallback.fireContactAdded(this, newContact); - } - - } - } - - /** - * Returns a <tt>String</tt> that uniquely represnets the group. In this we - * use the name of the group as an identifier. This may cause problems - * though, in clase the name is changed by some other application between - * consecutive runs of the sip-communicator. - * - * @return a String representing this group in a unique and persistent - * way. - */ - public String getUID() - { - return getGroupName(); - } - - /** - * The source group we are encapsulating - * @return MsnGroup - */ - MsnGroup getSourceGroup() - { - return msnGroup; - } - - /** - * Change the source group - * change the buddies - * - * @param newGroup MsnGroup - */ - void setSourceGroup(MsnGroup newGroup) - { - this.msnGroup = newGroup; - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ContactMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ContactMsnImpl.java deleted file mode 100644 index 9db02a3..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/ContactMsnImpl.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.msnconstants.*; -import net.sf.jml.*; - -/** - * The Msn implementation of the service.protocol.Contact interface. - * @author Damian Minkov - */ -public class ContactMsnImpl - extends AbstractContact -{ - private MsnContact contact = null; - private byte[] image = null; - private PresenceStatus status = MsnStatusEnum.OFFLINE; - private ServerStoredContactListMsnImpl ssclCallback = null; - private boolean isPersistent = false; - private boolean isResolved = false; - - /** - * The contact's status message. - */ - private String statusMessage = null; - - /** - * Creates an MsnContactImpl - * @param contact the contact object that we will be encapsulating. - * @param ssclCallback a reference to the ServerStoredContactListImpl - * instance that created us. - * @param isPersistent determines whether this contact is persistent or not. - * @param isResolved specifies whether the contact has been resolved against - * the server contact list - */ - ContactMsnImpl(MsnContact contact, - ServerStoredContactListMsnImpl ssclCallback, - boolean isPersistent, - boolean isResolved) - { - this.contact = contact; - this.ssclCallback = ssclCallback; - this.isPersistent = isPersistent; - this.isResolved = isResolved; - } - - /** - * Returns the Msn Userid of this contact - * @return the Msn Userid of this contact - */ - public String getAddress() - { - if(isResolved) - return contact.getEmail().getEmailAddress(); - else - return contact.getId(); - } - - /** - * Returns an avatar if one is already present or <tt>null</tt> in case it - * is not in which case it the method also queues the contact for image - * updates. - * - * @return the avatar of this contact or <tt>null</tt> if no avatar is - * currently available. - */ - public byte[] getImage() - { - return getImage(true); - } - - /** - * Returns a reference to the image assigned to this contact. If no image - * is present and the retrieveIfNecessary flag is true, we schedule the - * image for retrieval from the server. - * - * @param retrieveIfNecessary specifies whether the method should queue - * this contact for avatar update from the server. - * - * @return a reference to the image currently stored by this contact. - */ - byte[] getImage(boolean retrieveIfNecessary) - { - if((image == null) && retrieveIfNecessary) - ssclCallback.addContactForImageUpdate(this); - return image; - } - - /** - * Set the image of the contact - * - * @param imgBytes the new image we'd like to assign this contact. - */ - void setImage(byte[] imgBytes) - { - this.image = imgBytes; - } - - /** - * Returns a string representation of this contact, containing most of its - * representative details. - * - * @return a string representation of this contact. - */ - @Override - public String toString() - { - StringBuffer buff = new StringBuffer("MsnContact[ id="); - buff.append(getAddress()).append("]"); - - return buff.toString(); - } - - /** - * Sets the status that this contact is currently in. The method is to - * only be called as a result of a status update received from the server. - * - * @param status the MsnStatusEnum that this contact is currently in. - */ - void updatePresenceStatus(PresenceStatus status) - { - this.status = status; - } - - /** - * Returns the status of the contact as per the last status update we've - * received for it. Note that this method is not to perform any network - * operations and will simply return the status received in the last - * status update message. If you want a reliable way of retrieving someone's - * status, you should use the <tt>queryContactStatus()</tt> method in - * <tt>OperationSetPresence</tt>. - * @return the PresenceStatus that we've received in the last status update - * pertaining to this contact. - */ - public PresenceStatus getPresenceStatus() - { - return status; - } - - /** - * Returns a String that could be used by any user interacting modules for - * referring to this contact. An alias is not necessarily unique but is - * often more human readable than an address (or id). - * @return a String that can be used for referring to this contact when - * interacting with the user. - */ - public String getDisplayName() - { - String name = contact.getFriendlyName(); - - if (name == null) - name = getAddress(); - - return name; - } - - /** - * Returns a reference to the contact group that this contact is currently - * a child of or null if the underlying protocol does not suppord persistent - * presence. - * @return a reference to the contact group that this contact is currently - * a child of or null if the underlying protocol does not suppord persistent - * presence. - */ - public ContactGroup getParentContactGroup() - { - return ssclCallback.findContactGroup(this); - } - - - /** - * Returns a reference to the protocol provider that created the contact. - * @return a refererence to an instance of the ProtocolProviderService - */ - public ProtocolProviderService getProtocolProvider() - { - return ssclCallback.getParentProvider(); - } - - /** - * Determines whether or not this contact is being stored by the server. - * Non persistent contacts are common in the case of simple, non-persistent - * presence operation sets. They could however also be seen in persistent - * presence operation sets when for example we have received an event - * from someone not on our contact list. Non persistent contacts are - * volatile even when coming from a persistent presence op. set. They would - * only exist until the application is closed and will not be there next - * time it is loaded. - * @return true if the contact is persistent and false otherwise. - */ - public boolean isPersistent() - { - return isPersistent; - } - - /** - * Specifies whether this contact is to be considered persistent or not. The - * method is to be used _only_ when a non-persistent contact has been added - * to the contact list and its encapsulated VolatileBuddy has been repalced - * with a standard buddy. - * @param persistent true if the buddy is to be considered persistent and - * false for volatile. - */ - void setPersistent(boolean persistent) - { - this.isPersistent = persistent; - } - - /** - * Resolve this contact against the given entry - * @param entry the server stored entry - */ - void setResolved(MsnContact entry) - { - if(isResolved) - return; - - this.isResolved = true; - this.isPersistent = true; - contact = entry; - } - - /** - * Returns the persistent data - * @return the persistent data - */ - public String getPersistentData() - { - return null; - } - - /** - * Determines whether or not this contact has been resolved against the - * server. Unresolved contacts are used when initially loading a contact - * list that has been stored in a local file until the presence operation - * set has managed to retrieve all the contact list from the server and has - * properly mapped contacts to their on-line buddies. - * @return true if the contact has been resolved (mapped against a buddy) - * and false otherwise. - */ - public boolean isResolved() - { - return isResolved; - } - - public void setPersistentData(String persistentData) - { - } - - /** - * Get source contact - * @return MsnContact - */ - MsnContact getSourceContact() - { - return contact; - } - - /** - * Return the current status message of this contact. - * - * @return the current status messages - */ - public String getStatusMessage() - { - return statusMessage; - } - - /** - * Changes the current status message of this contact. - * - * @param newStatusMessage the new message. - */ - public void setStatusMessage(String newStatusMessage) - { - this.statusMessage = newStatusMessage; - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/EventAdapter.java b/src/net/java/sip/communicator/impl/protocol/msn/EventAdapter.java deleted file mode 100644 index 9562f32..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/EventAdapter.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import net.sf.jml.*; - -/** - * Contactlist modification listener receives events - * for successful changing - * - * @author Damian Minkov - */ -public class EventAdapter - implements MsnContactListEventListener -{ - /** - * Message is successfully delivered - * @param transactionID int the transaction that send the message - */ - public void messageDelivered(int transactionID){} - /** - * Message is not delivered - * @param transactionID int the transaction that send the message - */ - public void messageDeliveredFailed(int transactionID){} - /** - * Indicates that a group is successfully renamed - * @param group MsnGroup the renamed group with the new name - */ - public void groupRenamed(MsnGroup group){} - - /** - * Indicates that we are logged out - * because account logged in from other location - */ - public void loggingFromOtherLocation(){} -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/EventManager.java b/src/net/java/sip/communicator/impl/protocol/msn/EventManager.java deleted file mode 100644 index 646be8a..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/EventManager.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.util.*; -import net.sf.jml.*; -import net.sf.jml.impl.*; -import net.sf.jml.net.*; -import net.sf.jml.net.Message; -import net.sf.jml.protocol.*; -import net.sf.jml.protocol.incoming.*; - -/** - * Manager which listens for changing of the contact list and fires some events. - * - * @author Damian Minkov - */ -public class EventManager - extends SessionAdapter -{ - /** - * The class logger. - */ - private static final Logger logger = Logger.getLogger(EventManager.class); - - /** - * Whether we are connected. - */ - private boolean connected = false; - - /** - * The timer for monitoring connection. - */ - private Timer connectionTimer; - - /** - * Event listeners. - */ - private final List<MsnContactListEventListener> listeners - = new Vector<MsnContactListEventListener>(); - - /** - * The messenger. - */ - private final BasicMessenger msnMessenger; - - /** - * The provider that is on top of us. - */ - private final ProtocolProviderServiceMsnImpl msnProvider; - - /** - * Initializes a new <tt>EventManager</tt> instance which is to manage the - * events of a specific <tt>BasicMessenger</tt> as part of its operation for - * the purposes of a specific <tt>ProtocolProviderServiceMsnImpl</tt>. - * - * @param msnProvider the <tt>ProtocolProviderServiceMsnImpl</tt> which is - * the creator of the new instance - * @param msnMessenger the <tt>BasicMessenger</tt> which is to have its - * events managed by the new instance - */ - public EventManager(ProtocolProviderServiceMsnImpl msnProvider, - BasicMessenger msnMessenger) - { - this.msnProvider = msnProvider; - this.msnMessenger = msnMessenger; - - msnMessenger.addSessionListener(this); - } - - /** - * Adds listener of the modification fired events - * @param listener the modification listener we're adding - */ - public void addModificationListener(MsnContactListEventListener listener) - { - synchronized(listeners) - { - if (!listeners.contains(listener)) - listeners.add(listener); - } - } - - /** - * Removes listener of the modification fired events - * @param listener EventListener - */ - public void removeModificationListener(MsnContactListEventListener listener) - { - synchronized(listeners) - { - listeners.remove(listener); - } - } - - /** - * Called from the underling lib when message is sent to the server - * @param session Session - * @param message Message - * @throws Exception - */ - @Override - public void messageSent(Session session, Message message) throws Exception - { - if (logger.isTraceEnabled()) - logger.trace(msnMessenger.getOwner().getEmail().getEmailAddress() + - " outgoing " + message); - } - - /** - * Called from the underling lib when message is received from the server - * @param session Session - * @param message Message - * @throws Exception - */ - @Override - public void messageReceived(Session session, Message message) - throws Exception - { - MsnIncomingMessage incoming = (MsnIncomingMessage)((WrapperMessage)message) - .getMessage(); - - if (logger.isTraceEnabled()) - logger.trace(msnMessenger.getOwner().getEmail().getEmailAddress() + - " incoming : " + incoming); - - if(incoming instanceof IncomingACK) - { - //indicate the message has successed send to remote user. - fireMessageDelivered(((IncomingACK)incoming).getTransactionId()); - } - else if(incoming instanceof IncomingNAK) - { - //indicate the message has not successed send to remote user. - fireMessageDeliveredFailed(((IncomingNAK)incoming).getTransactionId()); - } - else if(incoming instanceof IncomingREG) - { - //indicate the group name has changed successfully. - IncomingREG incomingREG = (IncomingREG)incoming; - - MsnGroupImpl group = (MsnGroupImpl)msnMessenger.getContactList(). - getGroup(incomingREG.getGroupId()); - fireGroupRenamed(group); - } - else if(incoming instanceof IncomingOUT) - { - IncomingOUT incomingOUT = (IncomingOUT)incoming; - if(incomingOUT.isLoggingFromOtherLocation()) - fireLoggingFromOtherLocation(); - } - else if(incoming instanceof IncomingQNG) - { - connected = true; - } - } - - /** - * Called when there was timeout on the connection. - * @param socketSession - * @throws Exception - */ - @Override - public void sessionTimeout(Session socketSession) throws Exception - { - Timer connectionTimer; - - /* - * Delays the creation of Timer because it immediately starts a new - * Thread while it may not be necessary at all. - */ - synchronized (this) - { - if (this.connectionTimer == null) - this.connectionTimer = new Timer("Msn connection timer", true); - connectionTimer = this.connectionTimer; - } - - connectionTimer.schedule(new TimerTask() - { - @Override - public void run() - { - if(!connected && msnProvider.isRegistered()) - { - msnProvider.unregisterInternal(false); - msnProvider.fireRegistrationStateChanged( - msnProvider.getRegistrationState(), - RegistrationState.CONNECTION_FAILED, - RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, - null); - } - } - }, 20000); - connected = false; - } - - /** - * Fired when a message is delivered successfully - * @param transactionID int - */ - private void fireMessageDelivered(int transactionID) - { - synchronized(listeners) - { - for (MsnContactListEventListener listener : listeners) - listener.messageDelivered(transactionID); - } - } - - /** - * Fired when a message is not delivered successfully - * @param transactionID int - */ - private void fireMessageDeliveredFailed(int transactionID) - { - synchronized(listeners) - { - for (MsnContactListEventListener listener : listeners) - listener.messageDeliveredFailed(transactionID); - } - } - - /** - * Fired when a group is renamed successfully - * @param group MsnGroup - */ - private void fireGroupRenamed(MsnGroup group) - { - synchronized(listeners) - { - for (MsnContactListEventListener listener : listeners) - listener.groupRenamed(group); - } - } - - /** - * Fired when we received event for logging in from other location - */ - private void fireLoggingFromOtherLocation() - { - synchronized (listeners) - { - for (MsnContactListEventListener listener : listeners) - listener.loggingFromOtherLocation(); - } - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/FileTransferImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/FileTransferImpl.java deleted file mode 100644 index 6774ef6..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/FileTransferImpl.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.io.*; - -import net.java.sip.communicator.service.protocol.*; -import net.sf.jml.*; - -/** - * The Filetransfer imeplementation for msn. - * @author Damian Minkov - */ -public class FileTransferImpl - extends AbstractFileTransfer -{ - private String id = null; - private Contact contact = null; - private File file = null; - private int direction = -1; - private long transferedBytes; - private MsnFileTransfer fileTransfer; - - public FileTransferImpl( - MsnFileTransfer fileTransfer, - Contact contact, File file, int direction) - { - this.fileTransfer = fileTransfer; - this.id = fileTransfer.getID(); - this.contact = contact; - this.file = file; - this.direction = direction; - } - - /** - * Cancels this file transfer. When this method is called transfer should - * be interrupted. - */ - @Override - public void cancel() - { - fileTransfer.cancel(); - } - - /** - * Returns the number of bytes already transfered through this file transfer. - * - * @return the number of bytes already transfered through this file transfer - */ - @Override - public long getTransferedBytes() - { - return transferedBytes; - } - - /** - * Uniquie ID that is identifying the FileTransfer - * if the request has been accepted. - * - * @return the id. - */ - public String getID() - { - return id; - } - - /** - * The file transfer direction. - * @return returns the direction of the file transfer : IN or OUT. - */ - public int getDirection() - { - return direction; - } - - /** - * Returns the file that is transfered. - * - * @return the file - */ - public File getLocalFile() - { - return file; - } - - /** - * Returns the contact that we are transfering files with. - * @return the contact. - */ - public Contact getContact() - { - return contact; - } - - /** - * @param transferedBytes the transferedBytes to set - */ - public void setTransferedBytes(long transferedBytes) - { - this.transferedBytes = transferedBytes; - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/IncomingFileTransferRequestMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/IncomingFileTransferRequestMsnImpl.java deleted file mode 100644 index b6744f1..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/IncomingFileTransferRequestMsnImpl.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.io.*; -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.util.*; -import net.sf.jml.*; - -/** - * Msn implementation of the incoming file transfer request - * - * @author Damian Minkov - */ -public class IncomingFileTransferRequestMsnImpl - implements IncomingFileTransferRequest -{ - /** - * Logger - */ - private static final Logger logger = - Logger.getLogger(IncomingFileTransferRequestMsnImpl.class); - - private OperationSetFileTransferMsnImpl fileTransferOpSet; - - /** - * The msn file transfer received - */ - private MsnFileTransfer incomingFileTransfer = null; - - private Contact sender = null; - - private Date date; - - private String id; - - private boolean rejected = false; - - /** - * Constructor - * - * @param incomingFileTransfer MSN file transfer request that was received - */ - public IncomingFileTransferRequestMsnImpl( - OperationSetFileTransferMsnImpl fileTransferOpSet, - MsnFileTransfer incomingFileTransfer, - Contact sender, - Date date) - { - this.fileTransferOpSet = fileTransferOpSet; - this.incomingFileTransfer = incomingFileTransfer; - this.sender = sender; - this.date = date; - - id = incomingFileTransfer.getID(); - } - - /** - * Uniquie ID that is identifying the request and then the FileTransfer - * if the request has been accepted. - * - * @return the id. - */ - public String getID() - { - return id; - } - - /** - * Returns a String that represents the name of the file that is being - * received. - * If there is no name, returns null. - * @return a String that represents the name of the file - */ - public String getFileName() - { - return incomingFileTransfer.getFile().getName(); - } - - /** - * Returns a String that represents the description of the file that is - * being received. - * If there is no description available, returns null. - * - * @return a String that represents the description of the file - */ - public String getFileDescription() - { - return ""; - } - - /** - * Returns a long that represents the size of the file that is being - * received. - * If there is no file size available, returns null. - * - * @return a long that represents the size of the file - */ - public long getFileSize() - { - return incomingFileTransfer.getFileTotalSize(); - } - - /** - * Returns a String that represents the name of the sender of the file - * being received. - * If there is no sender name available, returns null. - * - * @return a String that represents the name of the sender - */ - public Contact getSender() - { - return sender; - } - - /** - * Function called to accept and receive the file. - * - * @param file the file to accept - * @return the <tt>FileTransfer</tt> object managing the transfer - */ - public FileTransfer acceptFile(File file) - { - incomingFileTransfer.setFile(file); - - FileTransferImpl inFileTransfer = - new FileTransferImpl( - incomingFileTransfer, - sender, - file, - FileTransfer.IN); - - FileTransferCreatedEvent event - = new FileTransferCreatedEvent(inFileTransfer, date); - - fileTransferOpSet.fireFileTransferCreated(event); - - inFileTransfer.fireStatusChangeEvent( - FileTransferStatusChangeEvent.PREPARING); - - incomingFileTransfer.start(); - - return inFileTransfer; - } - - /** - * Function called to refuse the file. - */ - public void rejectFile() - { - try - { - rejected = true; - - incomingFileTransfer.cancel(); - - fileTransferOpSet.fireFileTransferRequestRejected( - new FileTransferRequestEvent(fileTransferOpSet, this, date)); - } - catch(IllegalStateException e) - { - if (logger.isDebugEnabled()) - logger.debug("Error rejecting file",e); - return; - } - } - - public byte[] getThumbnail() - { - return null; - } - - /** - * @return the date - */ - public Date getDate() - { - return date; - } - - /** - * @return the rejected - */ - public boolean isRejected() - { - return rejected; - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/MessageMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/MessageMsnImpl.java deleted file mode 100644 index c1ffeb4..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/MessageMsnImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -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 - extends AbstractMessage -{ - - /** - * 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. - * @param contentEncoding a MIME String indicating the content encoding of - * 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) - { - super(content, contentType, contentEncoding, subject); - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/MsnAccountID.java b/src/net/java/sip/communicator/impl/protocol/msn/MsnAccountID.java deleted file mode 100644 index 5580928..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/MsnAccountID.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.java.sip.communicator.impl.protocol.msn; - -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; - -/** - * The Msn implementation of a sip-communicator AccountID - * - * @author Damian Minkov - */ -public class MsnAccountID - extends AccountID -{ - /** - * Creates an account id from the specified id and account properties. - * @param id the id identifying this account - * @param accountProperties any other properties necessary for the account. - */ - MsnAccountID(String id, Map<String, String> accountProperties ) - { - super(id, accountProperties, ProtocolNames.MSN, "msn.com"); - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/MsnActivator.java b/src/net/java/sip/communicator/impl/protocol/msn/MsnActivator.java deleted file mode 100644 index 50b1fd2..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/MsnActivator.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.resources.*; -import net.java.sip.communicator.util.*; - -import org.jitsi.service.configuration.*; -import org.jitsi.service.fileaccess.*; -import org.jitsi.service.resources.*; -import org.osgi.framework.*; - -/** - * Loads the MSN provider factory and registers it with service in the OSGI - * bundle context. - * - * @author Damian Minkov - * @author Lubomir Marinov - */ -public class MsnActivator - implements BundleActivator -{ - private ServiceRegistration msnPpFactoryServReg = null; - private static BundleContext bundleContext = null; - private static ConfigurationService configurationService = null; - private static FileAccessService fileAccessService = null; - - private static ProtocolProviderFactoryMsnImpl msnProviderFactory = null; - - /** - * The <tt>ResourceManagementService</tt> instance which provides common - * resources such as internationalized and localized strings, images to the - * MSN bundle. - */ - private static ResourceManagementService resources; - - /** - * Called when this bundle is started so the Framework can perform the - * bundle-specific activities necessary to start this bundle. - * - * @param context The execution context of the bundle being started. - * @throws Exception If this method throws an exception, this bundle is - * marked as stopped and the Framework will remove this bundle's - * listeners, unregister all services registered by this bundle, and - * release all services used by this bundle. - */ - public void start(BundleContext context) throws Exception - { - MsnActivator.bundleContext = context; - - Hashtable<String, String> hashtable = new Hashtable<String, String>(); - hashtable.put(ProtocolProviderFactory.PROTOCOL, ProtocolNames.MSN); - - msnProviderFactory = new ProtocolProviderFactoryMsnImpl(); - - /* - * Fixes issue #647: MalformedURLException in java-jml. Has to execute - * before a login in attempted so before the factory is registered seems - * OK since the ProtocolProviderService instances are not created yet. - */ - ReferenceURLStreamHandlerService.registerService(bundleContext); - - //reg the msn account man. - msnPpFactoryServReg = context.registerService( - ProtocolProviderFactory.class.getName(), - msnProviderFactory, - hashtable); - } - - /** - * Returns a reference to a ConfigurationService implementation currently - * registered in the bundle context or null if no such implementation was - * found. - * - * @return ConfigurationService a currently valid implementation of the - * configuration service. - */ - public static ConfigurationService getConfigurationService() - { - if(configurationService == null) - { - ServiceReference confReference - = bundleContext.getServiceReference( - ConfigurationService.class.getName()); - configurationService - = (ConfigurationService) bundleContext.getService(confReference); - } - return configurationService; - } - - /** - * Returns a reference to the bundle context that we were started with. - * @return a reference to the BundleContext instance that we were started - * witn. - */ - public static BundleContext getBundleContext() - { - return bundleContext; - } - - /** - * Retrurns a reference to the protocol provider factory that we have - * registered. - * @return a reference to the <tt>ProtocolProviderFactoryMsnImpl</tt> - * instance that we have registered from this package. - */ - static ProtocolProviderFactoryMsnImpl getProtocolProviderFactory() - { - return msnProviderFactory; - } - - /** - * Called when this bundle is stopped so the Framework can perform the - * bundle-specific activities necessary to stop the bundle. - * - * @param context The execution context of the bundle being stopped. - * @throws Exception If this method throws an exception, the bundle is - * still marked as stopped, and the Framework will remove the bundle's - * listeners, unregister all services registered by the bundle, and - * release all services used by the bundle. - */ - public void stop(BundleContext context) throws Exception - { - msnProviderFactory.stop(); - msnPpFactoryServReg.unregister(); - } - - /** - * Gets the <tt>ResourceManagementService</tt> instance which provides - * common resources such as internationalized and localized strings, images - * to the MSN bundle. - * - * @return the <tt>ResourceManagementService</tt> instance which provides - * common resources such as internationalized and localized strings, images - * to the MSN bundle - */ - public static ResourceManagementService getResources() - { - if (resources == null) - resources - = ResourceManagementServiceUtils.getService(bundleContext); - return resources; - } - - /** - * Returns the <tt>FileAccessService</tt> obtained from the bundle context. - * - * @return the <tt>FileAccessService</tt> obtained from the bundle context - */ - public static FileAccessService getFileAccessService() - { - if (fileAccessService == null) - { - fileAccessService - = ServiceUtils.getService( - bundleContext, - FileAccessService.class); - } - return fileAccessService; - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/MsnContactListEventListener.java b/src/net/java/sip/communicator/impl/protocol/msn/MsnContactListEventListener.java deleted file mode 100644 index 38d1ddb..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/MsnContactListEventListener.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import net.sf.jml.*; - -/** - * Contactlist modification listener receives events - * for successful changing - * - * @author Damian Minkov - */ -public interface MsnContactListEventListener - extends java.util.EventListener -{ - /** - * Message is successfully delivered - * @param transactionID int the transaction that send the message - */ - public void messageDelivered(int transactionID); - - /** - * Message is not delivered - * @param transactionID int the transaction that send the message - */ - public void messageDeliveredFailed(int transactionID); - - /** - * Indicates that a group is successfully renamed - * @param group MsnGroup the renamed group with the new name - */ - public void groupRenamed(MsnGroup group); - - /** - * Indicates that we are logged out - * because account logged in from other location - */ - public void loggingFromOtherLocation(); -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetAdHocMultiUserChatMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetAdHocMultiUserChatMsnImpl.java deleted file mode 100644 index 46851a1..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetAdHocMultiUserChatMsnImpl.java +++ /dev/null @@ -1,687 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.util.*; -import net.sf.jml.*; -import net.sf.jml.event.*; -import net.sf.jml.message.*; - -/** - * A MSN implementation of the ad-hoc multi user chat operation set. - * - * @author Valentin Martinet - */ -public class OperationSetAdHocMultiUserChatMsnImpl -implements OperationSetAdHocMultiUserChat -{ - /** - * The logger used to log messages. - */ - private static final Logger logger - = Logger.getLogger(OperationSetAdHocMultiUserChatMsnImpl.class); - - /** - * Listeners that will be notified of changes in our status in the room. - */ - private Vector<LocalUserAdHocChatRoomPresenceListener> presenceListeners - = new Vector<LocalUserAdHocChatRoomPresenceListener>(); - - /** - * The currently valid MSN protocol provider service implementation. - */ - private ProtocolProviderServiceMsnImpl provider = null; - - /** - * The ad-hoc rooms we currently are in. - */ - private Hashtable<MsnSwitchboard, AdHocChatRoomMsnImpl> adHocChatRoomCache - = new Hashtable<MsnSwitchboard, AdHocChatRoomMsnImpl>(); - - /** - * A list of listeners subscribed for invitations multi user chat events. - */ - private Vector<AdHocChatRoomInvitationListener> invitationListeners - = new Vector<AdHocChatRoomInvitationListener>(); - - /** - * A list of listeners subscribed for events indicating rejection of a multi - * user chat invitation sent by us. - */ - private Vector<AdHocChatRoomInvitationRejectionListener> - invitationRejectionListeners - = new Vector<AdHocChatRoomInvitationRejectionListener>(); - - /** - * A list of the ad-hoc rooms that are currently open and created by this - * account. - */ - private Hashtable<Object, AdHocChatRoom> pendingAdHocChatRoomList - = new Hashtable<Object, AdHocChatRoom>(); - - /** - * Creates an <tt>OperationSetAdHocMultiUserChatMsnImpl</tt> by specifying - * the parent provider. - * @param provider the Msn provider - */ - public OperationSetAdHocMultiUserChatMsnImpl( - ProtocolProviderServiceMsnImpl provider) - { - this.provider = provider; - this.provider.addRegistrationStateChangeListener( - new RegistrationStateListener()); - } - - /** - * Adds the given presence listener to existing presence listeners list. - * - * @param listener the listener to add - */ - public void addPresenceListener( - LocalUserAdHocChatRoomPresenceListener listener) - { - synchronized(presenceListeners) - { - if(!presenceListeners.contains(listener)) - presenceListeners.add(listener); - } - } - - /** - * Adds a listener to invitation notifications. - * - * @param listener an invitation listener. - */ - public void addInvitationListener(AdHocChatRoomInvitationListener listener) - { - synchronized (invitationListeners) - { - if (!invitationListeners.contains(listener)) - invitationListeners.add(listener); - } - } - - /** - * Removes <tt>listener</tt> from the list of invitation listeners - * registered to receive invitation events. - * - * @param listener the invitation listener to remove. - */ - public void removeInvitationListener( - AdHocChatRoomInvitationListener listener) - { - synchronized (invitationListeners) - { - invitationListeners.remove(listener); - } - } - - /** - * Adds a listener to invitation notifications. - * - * @param listener an invitation listener. - */ - public void addInvitationRejectionListener( - AdHocChatRoomInvitationRejectionListener listener) - { - synchronized (invitationRejectionListeners) - { - if (!invitationRejectionListeners.contains(listener)) - invitationRejectionListeners.add(listener); - } - } - - /** - * Removes <tt>listener</tt> from the list of invitation listeners - * registered to receive invitation events. - * - * @param listener the invitation listener to remove. - */ - public void removeInvitationRejectionListener( - AdHocChatRoomInvitationRejectionListener listener) - { - synchronized (invitationRejectionListeners) - { - invitationRejectionListeners.remove(listener); - } - } - - /** - * Creates a message by a given message text. - * - * @param messageText The message text. - * @return the newly created message. - */ - public Message createMessage(String messageText) - { - return new MessageMsnImpl(messageText, - OperationSetBasicInstantMessaging.DEFAULT_MIME_TYPE, - OperationSetBasicInstantMessaging.DEFAULT_MIME_ENCODING, null); - } - - /** - * Creates an ad-hoc room with the named <tt>adHocRoomName</tt> and in - * including to the specified <tt>contacts</tt>. - * - * @param adHocRoomName the name of the ad-hoc room - * @param contacts the list of contacts ID - * @param reason the reason (will not be used since MSN does not support - * invitation with the possibility to reject it) - * - * @return the ad-hoc room that has been just created - * @throws OperationFailedException - * @throws OperationNotSupportedException - */ - public AdHocChatRoom createAdHocChatRoom(String adHocRoomName, - List<String> contacts, - String reason) - throws OperationFailedException, OperationNotSupportedException - { - AdHocChatRoom adHocChatRoom = createAdHocChatRoom( - adHocRoomName, new Hashtable<String, Object>()); - - if (adHocChatRoom != null && contacts != null) - { - for (String address : contacts) - { - adHocChatRoom.invite(address, reason); - } - } - - return adHocChatRoom; - } - - /** - * Creates an <tt>AdHocChatRoom</tt> whose name is adHocRoomName with the - * properties contained in adHocRoomProperties - * - * @param adHocRoomName the name of the ad-hoc room - * @param adHocRoomProperties the ad-hoc room's properties - * - * @return the created ad-hoc room - * @throws OperationFailedException - * @throws OperationNotSupportedException - */ - public AdHocChatRoom createAdHocChatRoom(String adHocRoomName, - Map<String, Object> adHocRoomProperties) - throws OperationFailedException, OperationNotSupportedException - { - AdHocChatRoom adHocRoom = adHocChatRoomCache.get(adHocRoomName); - - if (adHocRoom == null) - { - assertConnected(); - - // we create an identifier object and create a new switchboard - // we need to track this object to identify this chatRoom - Object id = new Object(); - this.provider.getMessenger().newSwitchboard(id); - - // when the room hasn't been created, we create it. - adHocRoom = createLocalAdHocChatRoomInstance(adHocRoomName, id); - } - - return adHocRoom; - } - - /** - * Creates a <tt>ChatRoom</tt> from the specified chatRoomName. - * - * @param adHocChatRoomName the specific ad-hoc chat room name. - * @param switchboardId the identifier of the switchboard - * @return the ad-hoc chat room that we've just created. - */ - private AdHocChatRoomMsnImpl createLocalAdHocChatRoomInstance( - String adHocChatRoomName, Object switchboardId) - { - synchronized (this.pendingAdHocChatRoomList) - { - AdHocChatRoomMsnImpl adHocChatRoom = - new AdHocChatRoomMsnImpl(adHocChatRoomName, this.provider); - - // We put it to the pending ad hoc chat rooms, waiting for the - // switchboard to be created. - this.pendingAdHocChatRoomList.put(switchboardId, adHocChatRoom); - - adHocChatRoom.join(); - - return adHocChatRoom; - } - } - - /** - * Returns the <tt>AdHocChatRoomMsnImpl</tt> corresponding to the given - * <tt>switchboard</tt>, if one exists, otherwise returns null. - * - * @param switchboard the Msn switchboard corresponding to a chat room - * - * @return the <tt>AdHocChatRoomMsnImpl</tt> corresponding to the given - * <tt>switchboard</tt>, otherwise null - */ - private AdHocChatRoomMsnImpl getLocalAdHocChatRoomInstance( - MsnSwitchboard switchboard) - { - return adHocChatRoomCache.get(switchboard); - } - - /** - * Creates an <tt>AdHocChatRoomMsnImpl</tt> corresponding to the given - * <tt>switchboard</tt>. - * @param switchboard the Msn switchboard that will correspond to the - * created chat room - * @return an <tt>AdHocChatRoomMsnImpl</tt> corresponding to the given - * <tt>switchboard</tt> - */ - private AdHocChatRoomMsnImpl createLocalAdHocChatRoomInstance( - MsnSwitchboard switchboard) - { - AdHocChatRoomMsnImpl adHocChatRoom - = adHocChatRoomCache.get(switchboard); - - if (adHocChatRoom == null) - { - String name = String.valueOf(switchboard.hashCode()); - adHocChatRoom - = new AdHocChatRoomMsnImpl(name, provider, switchboard); - - this.adHocChatRoomCache.put(switchboard, adHocChatRoom); - - Object attachment = switchboard.getAttachment(); - if (attachment != null && pendingAdHocChatRoomList - .containsKey(attachment)) - { - pendingAdHocChatRoomList.remove(attachment); - } - } - adHocChatRoom.join(); - - return adHocChatRoom; - } - - /** - * Delivers a <tt>LocalUserAdHocChatRoomPresenceChangeEvent</tt> to all - * registered <tt>LocalUserAdHocChatRoomPresenceListener</tt>s. - * - * @param adHocChatRoom the <tt>AdHocChatRoom</tt> which has been joined, - * left, etc. - * @param eventType the type of this event; one of LOCAL_USER_JOINED, - * LOCAL_USER_LEFT, etc. - * @param reason the reason - */ - public void fireLocalUserPresenceEvent( AdHocChatRoom adHocChatRoom, - String eventType, - String reason) - { - LocalUserAdHocChatRoomPresenceChangeEvent evt - = new LocalUserAdHocChatRoomPresenceChangeEvent(this, - adHocChatRoom, - eventType, - reason); - - Iterator<LocalUserAdHocChatRoomPresenceListener> listeners = null; - synchronized(this.presenceListeners) - { - listeners = new ArrayList<LocalUserAdHocChatRoomPresenceListener> - (this.presenceListeners).iterator(); - } - - while (listeners.hasNext()) - { - LocalUserAdHocChatRoomPresenceListener listener = listeners.next(); - - listener.localUserAdHocPresenceChanged(evt); - } - } - - /** - * Checks if an incoming message is a multi user chat message. This is done - * by the switchboard, if it is not created by the user, its an active file - * transfer switchboard or the user count is too low then this method return - * false. - * - * @param switchboard The corresponding MSNswitchboard. - * @return true if it is a group chat message or false in the other case. - */ - public boolean isGroupChatMessage(MsnSwitchboard switchboard) - { - if (getLocalAdHocChatRoomInstance(switchboard) != null) - return true; - else - { - Object attachment = switchboard.getAttachment(); - - if (attachment != null) - { - return pendingAdHocChatRoomList.containsKey(attachment); - } - else - { // the user did not created the chat room by him/her self, - // the only way to figure out if this is a group chat message - // is to check the user count - return (switchboard.getAllContacts().length > 1); - } - } - } - - /** - * Removes the given listener from presence listeners' list. - * - * @param listener the listener to remove - */ - public void removePresenceListener( - LocalUserAdHocChatRoomPresenceListener listener) - { - synchronized (this.presenceListeners) - { - if(this.presenceListeners.contains(listener)) - { - this.presenceListeners.remove(listener); - } - } - } - - /** - * Makes sure that we are properly connected. - * - * @throws OperationFailedException if the provider is not connected. - * @throws OperationNotSupportedException if the service is not supported by - * the server. - */ - private void assertConnected() - throws OperationFailedException, - OperationNotSupportedException - { - if (this.provider == null) - throw new IllegalStateException( - "The provider must be non-null and signed on the " - + "service before being able to communicate."); - if (!this.provider.isRegistered()) - throw new IllegalStateException( - "The provider must be signed on the service before " - + "being able to communicate."); - } - - /** - * Our listener that will tell us when we're registered to msn. - */ - private class RegistrationStateListener - implements RegistrationStateChangeListener - { - /** - * The method is called by a ProtocolProvider implementation whenever a - * change in the registration state of the corresponding provider had - * occurred. - * - * @param evt ProviderStatusChangeEvent the event describing the status - * change. - */ - public void registrationStateChanged(RegistrationStateChangeEvent evt) - { - if (evt.getNewState() == RegistrationState.REGISTERED) - { - if(provider.getMessenger() != null) - { - provider.getMessenger().addSwitchboardListener( - new MsnSwitchboardListener()); - provider.getMessenger().addMessageListener( - new MsnMessageListener()); - } - else if(logger.isInfoEnabled()) - logger.info("Registered but msnMessenger is missing!", - new Exception()); - } - } - - } - - /** - * Our group chat message listener, it extends the MsnMessageAdapter from - * the the jml library. - */ - private class MsnMessageListener - extends MsnMessageAdapter - implements MsnEmailListener - { - /** - * Indicates that an instant message has been received. - * @param switchboard the switchboard - * @param message the message - * @param contact the contact sending the message - */ - @Override - public void instantMessageReceived( MsnSwitchboard switchboard, - MsnInstantMessage message, - MsnContact contact) - { - if (!isGroupChatMessage(switchboard)) - return; - - Message newMessage = createMessage(message.getContent()); - - if (logger.isDebugEnabled()) - logger.debug("Group chat message received."); - - AdHocChatRoomMsnImpl chatRoom - = getLocalAdHocChatRoomInstance(switchboard); - - if (chatRoom == null) - { - chatRoom = createLocalAdHocChatRoomInstance(switchboard); - } - - Contact participant = - chatRoom.getAdHocChatRoomParticipant(contact.getId()); - - AdHocChatRoomMessageReceivedEvent msgReceivedEvent = - new AdHocChatRoomMessageReceivedEvent( - chatRoom, - participant, - new Date(), - newMessage, - AdHocChatRoomMessageReceivedEvent - .CONVERSATION_MESSAGE_RECEIVED); - - chatRoom.fireMessageEvent(msgReceivedEvent); - } - - /** - * Not interested in this event. - */ - public void initialEmailNotificationReceived( - MsnSwitchboard switchboard, MsnEmailInitMessage message, - MsnContact contact) - {} - - /** - * Not interested in this event. - */ - public void initialEmailDataReceived(MsnSwitchboard switchboard, - MsnEmailInitEmailData message, MsnContact contact) - {} - - /** - * Not interested in this event. - */ - public void newEmailNotificationReceived(MsnSwitchboard switchboard, - MsnEmailNotifyMessage message, MsnContact contact) - {} - - /** - * Not interested in this event. - */ - public void activityEmailNotificationReceived( - MsnSwitchboard switchboard, MsnEmailActivityMessage message, - MsnContact contact) - {} - } - - /** - * The Switchboard Listener, listens to all four switchboard events: - * Switchboard started/closed and User joins/left. - * - */ - private class MsnSwitchboardListener - extends MsnSwitchboardAdapter - { - /** - * Indicates that the given <tt>msnContact</tt> has joined the given - * <tt>switchboard</tt>. - * @param switchboard the switchboard - * @param msnContact the contact that has joined - */ - @Override - public void contactJoinSwitchboard( MsnSwitchboard switchboard, - MsnContact msnContact) - { - if (!isGroupChatMessage(switchboard)) - return; - - try - { - AdHocChatRoomMsnImpl chatRoom - = getLocalAdHocChatRoomInstance(switchboard); - - if (chatRoom == null) - { - chatRoom = createLocalAdHocChatRoomInstance(switchboard); - } - - OperationSetPersistentPresenceMsnImpl presenceOpSet - = (OperationSetPersistentPresenceMsnImpl) provider - .getOperationSet(OperationSetPersistentPresence.class); - - ContactMsnImpl contact - = presenceOpSet.getServerStoredContactList() - .findContactById( - msnContact.getEmail().getEmailAddress()); - - if (contact == null) - contact = new ContactMsnImpl( - msnContact, - presenceOpSet.getServerStoredContactList(), - false, - false); - - chatRoom.addAdHocChatRoomParticipant( msnContact.getId(), - contact); - } - catch (Exception e) - { - logger.error("Failed to join switchboard.", e); - } - } - - /** - * Indicates that the given <tt>contact</tt> has left the given - * <tt>switchboard</tt>. - * @param switchboard the switchboard - * @param contact the contact that has left - */ - @Override - public void contactLeaveSwitchboard(MsnSwitchboard switchboard, - MsnContact contact) - { - logger - .debug(contact.getDisplayName() + " has left the Switchboard"); - - AdHocChatRoomMsnImpl chatRoom - = getLocalAdHocChatRoomInstance(switchboard); - - if (chatRoom == null) - return; - - String participantId = contact.getId(); - - Contact participant - = chatRoom.getAdHocChatRoomParticipant(participantId); - - if (participant != null) - { - chatRoom.removeParticipant(participantId); - } - } - - /** - * Indicates that a switchboard has been closed. - * @param switchboard the switchboard that has been closed - */ - @Override - public void switchboardClosed(MsnSwitchboard switchboard) - { - AdHocChatRoomMsnImpl adHocChatRoom - = getLocalAdHocChatRoomInstance(switchboard); - - if (adHocChatRoom == null) - return; - else - { - adHocChatRoom.setSwitchboard(null); - - adHocChatRoom.leave(); - fireLocalUserPresenceEvent(adHocChatRoom, - LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_DROPPED , - "Switchboard closed."); - } - } - - /** - * Indicates that a switchboard has been started. - * @param switchboard the switchboard that has been started - */ - @Override - public void switchboardStarted(MsnSwitchboard switchboard) - { - Object switchboardID = switchboard.getAttachment(); - - AdHocChatRoomMsnImpl adHocChatRoom = null; - if (switchboardID != null - && pendingAdHocChatRoomList.containsKey(switchboardID)) - { - adHocChatRoom - = (AdHocChatRoomMsnImpl) pendingAdHocChatRoomList - .get(switchboardID); - - // Remove this room from the list of pending chat rooms. - pendingAdHocChatRoomList.remove(switchboardID); - - adHocChatRoom.setSwitchboard(switchboard); - adHocChatRoom.updateParticipantsList(switchboard); - - // Add this room to the list of created chat rooms. - adHocChatRoomCache.put(switchboard, adHocChatRoom); - } - } - } - - /** - * Supposed to reject an invitation for MUC. - * Note: Not supported inside the MSN. - */ - public void rejectInvitation(AdHocChatRoomInvitation invitation, - String rejectReason) - { - // there is no way to block invitations, because there arn't any - // invitations. - // the only way would be to block the Friend and that shouldn't be done - // here. - return; - } - - /** - * Returns a list of all currently joined <tt>AdHocChatRoom</tt>-s. - * - * @return a list of all currently joined <tt>AdHocChatRoom</tt>-s - */ - public List<AdHocChatRoom> getAdHocChatRooms() - { - return new ArrayList<AdHocChatRoom>(adHocChatRoomCache.values()); - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetAvatarMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetAvatarMsnImpl.java deleted file mode 100644 index e5b9fbf..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetAvatarMsnImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import net.java.sip.communicator.service.protocol.*; - -/** - * A simple implementation of the <tt>OperationSetAvatar</tt> interface for the - * msn protocol. - * - * @author Damian Minkov - */ -public class OperationSetAvatarMsnImpl - extends AbstractOperationSetAvatar<ProtocolProviderServiceMsnImpl> -{ - public OperationSetAvatarMsnImpl( - ProtocolProviderServiceMsnImpl parentProvider, - OperationSetServerStoredAccountInfo accountInfoOpSet) - { - super(parentProvider, accountInfoOpSet, 0, 0, 0); - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java deleted file mode 100644 index e09d9c1..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetBasicInstantMessagingMsnImpl.java +++ /dev/null @@ -1,506 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.text.*; -import java.util.*; - -import net.java.sip.communicator.impl.protocol.msn.mail.utils.*; -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.util.*; -import net.sf.jml.*; -import net.sf.jml.event.*; -import net.sf.jml.message.*; - -/** - * A straightforward implementation of the basic instant messaging operation - * set. - * - * @author Damian Minkov - */ -public class OperationSetBasicInstantMessagingMsnImpl - extends AbstractOperationSetBasicInstantMessaging -{ - private static final Logger logger - = Logger.getLogger(OperationSetBasicInstantMessagingMsnImpl.class); - - /** - * The provider that created us. - */ - private final ProtocolProviderServiceMsnImpl msnProvider; - - /** - * A reference to the persistent presence operation set that we use - * to match incoming messages to <tt>Contact</tt>s and vice versa. - */ - private OperationSetPersistentPresenceMsnImpl opSetPersPresence = null; - - private final OperationSetAdHocMultiUserChatMsnImpl opSetMuc; - - /** - * The thread that will send messages. - */ - private SenderThread senderThread = null; - - /** - * Creates an instance of this operation set. - * @param provider a ref to the <tt>ProtocolProviderServiceImpl</tt> - * that created us and that we'll use for retrieving the underlying aim - * connection. - */ - OperationSetBasicInstantMessagingMsnImpl( - ProtocolProviderServiceMsnImpl provider) - { - this.msnProvider = provider; - opSetMuc - = (OperationSetAdHocMultiUserChatMsnImpl) - msnProvider - .getOperationSet(OperationSetAdHocMultiUserChat.class); - provider.addRegistrationStateChangeListener(new RegistrationStateListener()); - } - - /** - * 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 - * messages and yet have a particular account that does not (i.e. feature - * not enabled on the protocol server). In cases like this it is possible - * for this method to return true even when offline messaging is not - * supported, and then have the sendMessage method throw an - * OperationFailedException with code - OFFLINE_MESSAGES_NOT_SUPPORTED. - * - * @return <tt>true</tt> if the protocol supports offline messages and - * <tt>false</tt> otherwise. - */ - public boolean isOfflineMessagingSupported() - { - return true; - } - - /** - * 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 - * <tt>false</tt> otherwise. - */ - public boolean isContentTypeSupported(String contentType) - { - return DEFAULT_MIME_TYPE.equals(contentType); - } - - @Override - public Message createMessage(String content, String contentType, - String encoding, String subject) - { - return new MessageMsnImpl(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 java.lang.IllegalStateException if the underlying stack is - * not registered and initialized. - * @throws java.lang.IllegalArgumentException if <tt>to</tt> is not an - * instance of ContactImpl. - */ - public void sendInstantMessage(final Contact to, final Message message) - throws IllegalStateException, IllegalArgumentException - { - assertConnected(); - - if( !(to instanceof ContactMsnImpl) ) - throw new IllegalArgumentException( - "The specified contact is not an MSN contact." - + to); - - MessageDeliveredEvent[] transformedEvents = messageDeliveryPendingTransform( - new MessageDeliveredEvent(message, to)); - - if (transformedEvents == null || transformedEvents.length == 0) - return; - - MessageDeliveredEvent msgDeliveredEvt = - new MessageDeliveredEvent(message, to); - - fireMessageEvent(msgDeliveredEvt); - - // send message in separate thread so we won't block ui if it takes - // time. - if (senderThread == null) - { - senderThread = new SenderThread(); - senderThread.start(); - } - - for (MessageDeliveredEvent event : transformedEvents) - { - senderThread.sendMessage((ContactMsnImpl) to, event - .getSourceMessage().getContent()); - } - } - - /** - * Utility method throwing an exception if the stack is not properly - * initialized. - * @throws java.lang.IllegalStateException if the underlying stack is - * not registered and initialized. - */ - private void assertConnected() throws IllegalStateException - { - if (msnProvider == null) - throw new IllegalStateException( - "The provider must be non-null and signed on the " - +"service before being able to communicate."); - if (!msnProvider.isRegistered()) - throw new IllegalStateException( - "The provider must be signed on the service before " - +"being able to communicate."); - } - - /** - * Our listener that will tell us when we're registered to - */ - private class RegistrationStateListener - implements RegistrationStateChangeListener - { - /** - * The method is called by a ProtocolProvider implementation whenever - * a change in the registration state of the corresponding provider had - * occurred. - * @param evt ProviderStatusChangeEvent the event describing the status - * change. - */ - public void registrationStateChanged(RegistrationStateChangeEvent evt) - { - if (logger.isDebugEnabled()) - logger.debug("The provider changed state from: " - + evt.getOldState() - + " to: " + evt.getNewState()); - - if (evt.getNewState() == RegistrationState.REGISTERED) - { - opSetPersPresence = - (OperationSetPersistentPresenceMsnImpl) msnProvider - .getOperationSet(OperationSetPersistentPresence.class); - - MsnMessenger msnMessenger = msnProvider.getMessenger(); - - if(msnMessenger != null) - { - MsnMessageListener listener = new MsnMessageListener(); - msnMessenger.addMessageListener(listener); - msnMessenger.addEmailListener(listener); - } - else if(logger.isInfoEnabled()) - logger.info("Registered but msnMessenger is missing!", - new Exception()); - } - else if(evt.getNewState() == RegistrationState.UNREGISTERED - || evt.getNewState() == RegistrationState.CONNECTION_FAILED - || evt.getNewState() == RegistrationState.AUTHENTICATION_FAILED) - { - if(senderThread != null) - { - senderThread.stopRunning(); - senderThread = null; - } - } - } - } - - private class MsnMessageListener - extends MsnMessageAdapter - implements MsnEmailListener - { - @Override - public void instantMessageReceived(MsnSwitchboard switchboard, - MsnInstantMessage message, - MsnContact contact) - { - // FILTER OUT THE GROUP MESSAGES - if (opSetMuc.isGroupChatMessage(switchboard)) - return; - - Message newMessage = createMessage(message.getContent()); - Contact sourceContact = opSetPersPresence. - findContactByID(contact.getEmail().getEmailAddress()); - - if(sourceContact == null) - { - if (logger.isDebugEnabled()) - logger.debug("received a message from an unknown contact: " - + contact); - //create the volatile contact - sourceContact = opSetPersPresence. - createVolatileContact(contact); - } - - MessageReceivedEvent msgReceivedEvt - = new MessageReceivedEvent( - newMessage, sourceContact , new Date()); - - // msgReceivedEvt = messageReceivedTransform(msgReceivedEvt); - - if (msgReceivedEvt != null) - fireMessageEvent(msgReceivedEvt); - } - - /** - * Received offline text message. - * - * @param body of message - * @param contentType of message - * @param encoding of message - * @param contact the user who sent this message - */ - public void offlineMessageReceived(String body, - String contentType, - String encoding, - MsnContact contact) - { - Message newMessage = - createMessage(body, contentType, encoding, null); - - Contact sourceContact = opSetPersPresence. - findContactByID(contact.getEmail().getEmailAddress()); - - if(sourceContact == null) - { - if (logger.isDebugEnabled()) - logger.debug("received a message from an unknown contact: " - + contact); - //create the volatile contact - sourceContact = opSetPersPresence. - createVolatileContact(contact); - } - - MessageReceivedEvent msgReceivedEvt - = new MessageReceivedEvent( - newMessage, sourceContact , new Date()); - - fireMessageEvent(msgReceivedEvt); - } - - public void initialEmailNotificationReceived(MsnSwitchboard switchboard, - MsnEmailInitMessage message, - MsnContact contact) - { - } - - public void initialEmailDataReceived(MsnSwitchboard switchboard, - MsnEmailInitEmailData message, - MsnContact contact) - { - } - - public void newEmailNotificationReceived(MsnSwitchboard switchboard, - MsnEmailNotifyMessage message, - MsnContact contact) - { - // we don't process incoming event without email. - String messageFromAddr = message.getFromAddr(); - if ((messageFromAddr == null) - || (messageFromAddr.indexOf('@') < 0)) - return; - - String subject = message.getSubject(); - - try - { - subject = MimeUtility.decodeText(subject); - } - catch (Exception ex) - { - logger.warn("Failed to decode the subject of a new e-mail", ex); - } - - // FIXME Escape HTML! - String messageFrom = message.getFrom(); - Message newMailMessage = new MessageMsnImpl( - MessageFormat.format( - MsnActivator.getResources() - .getI18NString("service.gui.NEW_MAIL"), - messageFrom, - messageFromAddr, - subject, - "" /* - * TODO What is {3} meant for? The Yahoo! protocol - * implementation seems to put a link to a mail login - * page. - */), - HTML_MIME_TYPE, - DEFAULT_MIME_ENCODING, - subject); - - Contact sourceContact - = opSetPersPresence.findContactByID(messageFromAddr); - - if (sourceContact == null) - { - if (logger.isDebugEnabled()) - logger.debug("received a new mail from an unknown contact: " - + messageFrom - + " <" + messageFromAddr + ">"); - //create the volatile contact - String id = contact.getId(); - Email email = contact.getEmail(); - String displayName = contact.getDisplayName(); - - if (id == null) - id = messageFromAddr; - if (email == null) - email = Email.parseStr(messageFromAddr); - if (displayName == null) - displayName = messageFrom; - sourceContact - = opSetPersPresence.createVolatileContact(id, email, displayName); - } - - MessageReceivedEvent msgReceivedEvt - = new MessageReceivedEvent( - newMailMessage, - sourceContact, - new Date(), - MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED); - - fireMessageEvent(msgReceivedEvt); - } - - public void activityEmailNotificationReceived(MsnSwitchboard switchboard, - MsnEmailActivityMessage message, - MsnContact contact) - { - } - } - - /** - * Sends instant messages in separate thread so we don't block - * our calling thread. - * When sending offline messages msn uses soap - * and http and xml exchange can be time consuming. - */ - private class SenderThread - extends Thread - { - /** - * start/stop indicator. - */ - private boolean stopped = true; - - /** - * List of messages queued to be sent. - */ - private List<MessageToSend> messagesToSend = - new ArrayList<MessageToSend>(); - - /** - * Sends instant messages in separate thread so we don't block - * our calling thread. - */ - @Override - public void run() - { - stopped = false; - - while(!stopped) - { - MessageToSend msgToSend = null; - - synchronized(this) - { - if(messagesToSend.isEmpty()) - { - try - { - wait(); - - } - catch (InterruptedException iex) - { - } - } - - if(!messagesToSend.isEmpty()) - msgToSend = messagesToSend.remove(0); - } - - if(msgToSend != null) - { - try - { - msnProvider.getMessenger().sendText( - msgToSend.to.getSourceContact().getEmail(), - msgToSend.content); - } - catch(Throwable t) - { - fireMessageDeliveryFailed( - createMessage(msgToSend.content, - DEFAULT_MIME_TYPE, - DEFAULT_MIME_ENCODING, - null), - msgToSend.to, - MessageDeliveryFailedEvent.UNKNOWN_ERROR); - } - } - } - } - - /** - * Interrupts this sender so that it would no longer send messages. - */ - public synchronized void stopRunning() - { - stopped = true; - notifyAll(); - } - - /** - * Schedule new message to be sent. - * @param to destination. - * @param content content. - */ - public synchronized void sendMessage(ContactMsnImpl to, String content) - { - messagesToSend.add(new MessageToSend(to , content)); - notifyAll(); - } - - /** - * Structure used to store data to be sent. - */ - private class MessageToSend - { - /** - * Message sent to. - */ - private ContactMsnImpl to; - - /** - * Content of message. - */ - private String content; - - /** - * Creates MessageToSend. - * @param to contact to. - * @param content content to be sent. - */ - MessageToSend(ContactMsnImpl to, String content) - { - this.to = to; - this.content = content; - } - } - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetFileTransferMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetFileTransferMsnImpl.java deleted file mode 100644 index 3992d20..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetFileTransferMsnImpl.java +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.io.*; -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.util.*; -import net.sf.jml.*; -import net.sf.jml.event.*; - -/** - * The Msn protocol filetransfer OperationSet. - * - * @author Damian Minkov - */ -public class OperationSetFileTransferMsnImpl - implements OperationSetFileTransfer -{ - private static final Logger logger = - Logger.getLogger(OperationSetFileTransferMsnImpl.class); - - /** - * A call back to the Msn provider that created us. - */ - private ProtocolProviderServiceMsnImpl msnProvider = null; - - /** - * A list of listeners registered for file transfer events. - */ - private ArrayList<FileTransferListener> fileTransferListeners - = new ArrayList<FileTransferListener>(); - - /** - * A list of active fileTransfers. - */ - private Hashtable<String, Object> activeFileTransfers - = new Hashtable<String, Object>(); - - /** - * Create a new FileTransfer OperationSet over the specified Msn provider - * @param msnProvider MSN protocol provider service - */ - public OperationSetFileTransferMsnImpl( - ProtocolProviderServiceMsnImpl msnProvider) - { - this.msnProvider = msnProvider; - - msnProvider.addRegistrationStateChangeListener( - new RegistrationStateListener()); - } - - - /** - * Sends a file transfer request to the given <tt>toContact</tt> by - * specifying the local and remote file path and the <tt>fromContact</tt>, - * sending the file. - * - * @param toContact the contact that should receive the file - * @param file the file to send - * - * @return the transfer object - * - * @throws IllegalStateException if the protocol provider is not registered - * or connected - * @throws IllegalArgumentException if some of the arguments doesn't fit the - * protocol requirements - */ - public FileTransfer sendFile( Contact toContact, - File file) - throws IllegalStateException, - IllegalArgumentException - { - assertConnected(); - - if(file.length() > getMaximumFileLength()) - throw new IllegalArgumentException( - "File length exceeds the allowed one for this protocol"); - - if( !(toContact instanceof ContactMsnImpl) ) - throw new IllegalArgumentException( - "The specified contact is not an msn contact." + toContact); - - MsnFileTransfer ft = msnProvider.getMessenger(). - getFileTransferManager(). - sendFile( - ((ContactMsnImpl)toContact).getSourceContact().getEmail(), - file); - - if(ft == null) - throw new IllegalStateException( - "A problem occured sending file, contact not found or offline"); - - FileTransferImpl outFileTransfer = new FileTransferImpl( - ft, toContact, file, FileTransfer.OUT); - - - // Notify all interested listeners that a file transfer has been - // created. - FileTransferCreatedEvent event - = new FileTransferCreatedEvent(outFileTransfer, new Date()); - - fireFileTransferCreated(event); - - outFileTransfer.fireStatusChangeEvent( - FileTransferStatusChangeEvent.PREPARING); - - return outFileTransfer; - } - - /** - * Sends a file transfer request to the given <tt>toContact</tt> by - * specifying the local and remote file path and the <tt>fromContact</tt>, - * sending the file. - * - * @param toContact the contact that should receive the file - * @param fromContact the contact sending the file - * @param remotePath the remote file path - * @param localPath the local file path - * - * @return the transfer object - * - * @throws IllegalStateException if the protocol provider is not registered - * or connected - * @throws IllegalArgumentException if some of the arguments doesn't fit the - * protocol requirements - */ - public FileTransfer sendFile( Contact toContact, - Contact fromContact, - String remotePath, - String localPath) - throws IllegalStateException, - IllegalArgumentException - { - return this.sendFile(toContact, new File(localPath)); - } - - /** - * Adds the given <tt>FileTransferListener</tt> that would listen for - * file transfer requests and created file transfers. - * - * @param listener the <tt>FileTransferListener</tt> to add - */ - public void addFileTransferListener( - FileTransferListener listener) - { - synchronized(fileTransferListeners) - { - if(!fileTransferListeners.contains(listener)) - { - this.fileTransferListeners.add(listener); - } - } - } - - /** - * Removes the given <tt>FileTransferListener</tt> that listens for - * file transfer requests and created file transfers. - * - * @param listener the <tt>FileTransferListener</tt> to remove - */ - public void removeFileTransferListener( - FileTransferListener listener) - { - synchronized(fileTransferListeners) - { - this.fileTransferListeners.remove(listener); - } - } - - /** - * Utility method throwing an exception if the stack is not properly - * initialized. - * @throws java.lang.IllegalStateException if the underlying stack is - * not registered and initialized. - */ - private void assertConnected() - throws IllegalStateException - { - if (msnProvider == null) - throw new IllegalStateException( - "The provider must be non-null and signed on the " - +"service before being able to send a file."); - else if (!msnProvider.isRegistered()) - throw new IllegalStateException( - "The provider must be signed on the service before " - +"being able to send a file."); - } - - /** - * Delivers the specified event to all registered file transfer listeners. - * - * @param event the <tt>EventObject</tt> that we'd like delivered to all - * registered file transfer listeners. - */ - private void fireFileTransferRequest(FileTransferRequestEvent event) - { - Iterator<FileTransferListener> listeners = null; - synchronized (fileTransferListeners) - { - listeners = new ArrayList<FileTransferListener> - (fileTransferListeners).iterator(); - } - - while (listeners.hasNext()) - { - FileTransferListener listener = listeners.next(); - - listener.fileTransferRequestReceived(event); - } - } - - /** - * Delivers the specified event to all registered file transfer listeners. - * - * @param event the <tt>EventObject</tt> that we'd like delivered to all - * registered file transfer listeners. - */ - void fireFileTransferRequestRejected(FileTransferRequestEvent event) - { - Iterator<FileTransferListener> listeners = null; - synchronized (fileTransferListeners) - { - listeners = new ArrayList<FileTransferListener> - (fileTransferListeners).iterator(); - } - - while (listeners.hasNext()) - { - FileTransferListener listener = listeners.next(); - - listener.fileTransferRequestRejected(event); - } - } - - /** - * Delivers the specified event to all registered file transfer listeners. - * - * @param event the <tt>EventObject</tt> that we'd like delivered to all - * registered file transfer listeners. - */ - void fireFileTransferRequestCanceled(FileTransferRequestEvent event) - { - Iterator<FileTransferListener> listeners = null; - synchronized (fileTransferListeners) - { - listeners = new ArrayList<FileTransferListener> - (fileTransferListeners).iterator(); - } - - while (listeners.hasNext()) - { - FileTransferListener listener = listeners.next(); - - listener.fileTransferRequestCanceled(event); - } - } - - /** - * Delivers the file transfer to all registered listeners. - * - * @param event the <tt>FileTransferEvent</tt> that we'd like delivered to - * all registered file transfer listeners. - */ - void fireFileTransferCreated(FileTransferCreatedEvent event) - { - activeFileTransfers.put( - event.getFileTransfer().getID(), event.getFileTransfer()); - - Iterator<FileTransferListener> listeners = null; - synchronized (fileTransferListeners) - { - listeners = new ArrayList<FileTransferListener> - (fileTransferListeners).iterator(); - } - - while (listeners.hasNext()) - { - FileTransferListener listener = listeners.next(); - listener.fileTransferCreated(event); - } - } - - /** - * Returns the maximum file length supported by the protocol in bytes. - * Supports up to 2GB. - * - * @return the file length that is supported. - */ - public long getMaximumFileLength() - { - return 2147483648l;// = 2048*1024*1024; - } - - /** - * Our listener that will tell us when we're registered to - */ - private class RegistrationStateListener - implements RegistrationStateChangeListener - { - /** - * The method is called by a ProtocolProvider implementation whenever - * a change in the registration state of the corresponding provider had - * occurred. - * @param evt ProviderStatusChangeEvent the event describing the status - * change. - */ - public void registrationStateChanged(RegistrationStateChangeEvent evt) - { - if (logger.isDebugEnabled()) - logger.debug("The provider changed state from: " - + evt.getOldState() - + " to: " + evt.getNewState()); - - if (evt.getNewState() == RegistrationState.REGISTERED) - { - if(msnProvider.getMessenger() != null) - { - msnProvider.getMessenger().addFileTransferListener( - new FileTransferProtocolListener()); - } - else if(logger.isInfoEnabled()) - logger.info("Registered but msnMessenger is missing!", - new Exception()); - } - } - } - - /** - * Receives notifications from the slick about new filetransfers - * and filetransfer changes. - */ - private class FileTransferProtocolListener - implements MsnFileTransferListener - { - public void fileTransferRequestReceived(MsnFileTransfer ft) - { - OperationSetPersistentPresenceMsnImpl opSetPersPresence - = (OperationSetPersistentPresenceMsnImpl) - msnProvider.getOperationSet( - OperationSetPersistentPresence.class); - - Contact sender = opSetPersPresence.findContactByID( - ft.getContact().getEmail().getEmailAddress()); - - if(sender == null) - return; - - Date recvDate = new Date(); - - IncomingFileTransferRequest req = - new IncomingFileTransferRequestMsnImpl( - OperationSetFileTransferMsnImpl.this, - ft, sender, recvDate); - - activeFileTransfers.put(ft.getID(), req); - - fireFileTransferRequest( - new FileTransferRequestEvent( - OperationSetFileTransferMsnImpl.this, req, recvDate)); - } - - public void fileTransferStarted(MsnFileTransfer ft) - { - Object ftObj = activeFileTransfers.get(ft.getID()); - - if(ftObj != null && ftObj instanceof FileTransferImpl) - { - FileTransferImpl fileTransfer = (FileTransferImpl)ftObj; - - fileTransfer.fireStatusChangeEvent( - FileTransferStatusChangeEvent.IN_PROGRESS); - } - } - - public void fileTransferProcess(MsnFileTransfer ft) - { - Object ftObj = activeFileTransfers.get(ft.getID()); - - if(ftObj != null && ftObj instanceof FileTransferImpl) - { - FileTransferImpl fileTransfer = (FileTransferImpl)ftObj; - - fileTransfer.setTransferedBytes(ft.getTransferredSize()); - fileTransfer.fireProgressChangeEvent( - System.currentTimeMillis(), ft.getTransferredSize()); - } - } - - public void fileTransferFinished(MsnFileTransfer ft) - { - Object ftObj = activeFileTransfers.get(ft.getID()); - - if(ftObj == null) - return; - - if(ftObj instanceof FileTransferImpl) - { - FileTransferImpl fileTransfer = (FileTransferImpl)ftObj; - - if(ft.getState() == MsnFileTransferState.COMPLETED) - fileTransfer.fireStatusChangeEvent( - FileTransferStatusChangeEvent.COMPLETED); - else if(ft.getState() == MsnFileTransferState.CANCELED) - fileTransfer.fireStatusChangeEvent( - FileTransferStatusChangeEvent.CANCELED); - else if(ft.getState() == MsnFileTransferState.REFUSED) - fileTransfer.fireStatusChangeEvent( - FileTransferStatusChangeEvent.REFUSED); - } - else if(ftObj instanceof IncomingFileTransferRequest) - { - IncomingFileTransferRequestMsnImpl inReq = - (IncomingFileTransferRequestMsnImpl)ftObj; - - if(!inReq.isRejected() - && ft.getState() == MsnFileTransferState.CANCELED) - fireFileTransferRequestCanceled( - new FileTransferRequestEvent( - OperationSetFileTransferMsnImpl.this, - inReq, - inReq.getDate())); - } - - activeFileTransfers.remove(ft.getID()); - } - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetPersistentPresenceMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetPersistentPresenceMsnImpl.java deleted file mode 100644 index e872eed..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetPersistentPresenceMsnImpl.java +++ /dev/null @@ -1,913 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.util.*; - -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.*; - -/** - * The Msn implementation of a Persistent Presence Operation set. This class - * manages our own presence status as well as subscriptions for the presence - * status of our buddies. It also offers methods for retrieving and modifying - * the buddy contact list and adding listeners for changes in its layout. - * - * @author Damian Minkov - */ -public class OperationSetPersistentPresenceMsnImpl - extends AbstractOperationSetPersistentPresence<ProtocolProviderServiceMsnImpl> -{ - private static final Logger logger = - Logger.getLogger(OperationSetPersistentPresenceMsnImpl.class); - - /** - * Contains our current status message. Note that this field would only - * be changed once the server has confirmed the new status message and - * not immediately upon setting a new one.. - */ - private String currentStatusMessage = ""; - - /** - * The presence status that we were last notified of entering. - * The initial one is OFFLINE - */ - private PresenceStatus currentStatus = MsnStatusEnum.OFFLINE; - - /** - * Sometimes status changes are received before the contact list is inited - * here we store such events so we can show them correctly - */ - private Hashtable<String, MsnUserStatus> earlyStatusChange - = new Hashtable<String, MsnUserStatus>(); - - private AuthorizationHandler authorizationHandler = null; - - /** - * The array list we use when returning from the getSupportedStatusSet() - * method. - */ - private static final List<PresenceStatus> supportedPresenceStatusSet - = new ArrayList<PresenceStatus>(); - static{ - supportedPresenceStatusSet.add(MsnStatusEnum.AWAY); - supportedPresenceStatusSet.add(MsnStatusEnum.BE_RIGHT_BACK); - supportedPresenceStatusSet.add(MsnStatusEnum.BUSY); - supportedPresenceStatusSet.add(MsnStatusEnum.HIDE); - supportedPresenceStatusSet.add(MsnStatusEnum.IDLE); - supportedPresenceStatusSet.add(MsnStatusEnum.OFFLINE); - supportedPresenceStatusSet.add(MsnStatusEnum.ONLINE); - supportedPresenceStatusSet.add(MsnStatusEnum.ON_THE_PHONE); - supportedPresenceStatusSet.add(MsnStatusEnum.IN_A_MEETING); - supportedPresenceStatusSet.add(MsnStatusEnum.OUT_TO_LUNCH); - } - - /** - * A map containing bindings between SIP Communicator's msn presence status - * instances and Msn status codes - */ - private static Map<MsnStatusEnum, MsnUserStatus> scToMsnModesMappings - = new Hashtable<MsnStatusEnum, MsnUserStatus>(); - static{ - scToMsnModesMappings.put(MsnStatusEnum.AWAY, - MsnUserStatus.AWAY); - scToMsnModesMappings.put(MsnStatusEnum.BE_RIGHT_BACK, - MsnUserStatus.BE_RIGHT_BACK); - scToMsnModesMappings.put(MsnStatusEnum.BUSY, - MsnUserStatus.BUSY); - scToMsnModesMappings.put(MsnStatusEnum.HIDE, - MsnUserStatus.HIDE); - scToMsnModesMappings.put(MsnStatusEnum.IDLE, - MsnUserStatus.IDLE); - scToMsnModesMappings.put(MsnStatusEnum.OFFLINE, - MsnUserStatus.OFFLINE); - scToMsnModesMappings.put(MsnStatusEnum.ONLINE, - MsnUserStatus.ONLINE); - scToMsnModesMappings.put(MsnStatusEnum.ON_THE_PHONE, - MsnUserStatus.ON_THE_PHONE); - scToMsnModesMappings.put(MsnStatusEnum.OUT_TO_LUNCH, - MsnUserStatus.OUT_TO_LUNCH); - } - - /** - * The server stored contact list that will be encapsulating msn's - * buddy list. - */ - private ServerStoredContactListMsnImpl ssContactList = null; - - public OperationSetPersistentPresenceMsnImpl( - ProtocolProviderServiceMsnImpl provider) - { - super(provider); - - ssContactList = new ServerStoredContactListMsnImpl( this , provider); - - parentProvider.addRegistrationStateChangeListener( - new RegistrationStateListener()); - } - - /** - * Registers a listener that would receive events upon changes in server - * stored groups. - * - * @param listener a ServerStoredGroupChangeListener impl that would - * receive events upon group changes. - */ - @Override - public void addServerStoredGroupChangeListener(ServerStoredGroupListener - listener) - { - ssContactList.addGroupListener(listener); - } - - /** - * Creates a group with the specified name and parent in the server - * stored contact list. - * - * @param parent the group where the new group should be created - * @param groupName the name of the new group to create. - * @throws OperationFailedException if such group already exists - */ - public void createServerStoredContactGroup(ContactGroup parent, - String groupName) - throws OperationFailedException - { - assertConnected(); - - if (!parent.canContainSubgroups()) - throw new IllegalArgumentException( - "The specified contact group cannot contain child groups. Group:" - + parent ); - - ssContactList.createGroup(groupName); - } - - /** - * Creates a non persistent contact for the specified address. This would - * also create (if necessary) a group for volatile contacts that would not - * be added to the server stored contact list. The volatile contact would - * remain in the list until it is really added to the contact list or - * until the application is terminated. - * @param contact the msn contact. - * @return the newly created volatile <tt>ContactImpl</tt> - */ - public ContactMsnImpl createVolatileContact(MsnContact contact) - { - return ssContactList.createVolatileContact(contact); - } - - /** - * Creates a non persistent contact for the specified address. This would - * also create (if necessary) a group for volatile contacts that would not - * be added to the server stored contact list. The volatile contact would - * remain in the list until it is really added to the contact list or until - * the application is terminated. - * - * @param id the id of the MSN contact - * @param email the e-mail address of the MSN contact - * @param displayName the display name of the MSN contact - * @return the newly created volatile <tt>ContactImpl</tt> - */ - public ContactMsnImpl createVolatileContact( - String id, - Email email, - String displayName) - { - return ssContactList.createVolatileContact(id, email, displayName); - } - - /** - * Creates and returns a unresolved contact from the specified - * <tt>address</tt> and <tt>persistentData</tt>. - * - * @param address an identifier of the contact that we'll be creating. - * @param persistentData a String returned Contact's getPersistentData() - * method during a previous run and that has been persistently stored - * locally. - * @param parentGroup the group where the unresolved contact is supposed - * to belong to. - * @return the unresolved <tt>Contact</tt> created from the specified - * <tt>address</tt> and <tt>persistentData</tt> - */ - public Contact createUnresolvedContact(String address, - String persistentData, - ContactGroup parentGroup) - { - if(! (parentGroup instanceof ContactGroupMsnImpl || - parentGroup instanceof RootContactGroupMsnImpl) ) - throw new IllegalArgumentException( - "Argument is not an msn contact group (group=" - + parentGroup + ")"); - - ContactMsnImpl contact = - ssContactList.createUnresolvedContact(parentGroup, address); - - contact.setPersistentData(persistentData); - - return contact; - } - - /** - * Creates and returns a unresolved contact from the specified - * <tt>address</tt> and <tt>persistentData</tt>. - * - * @param address an identifier of the contact that we'll be creating. - * @param persistentData a String returned Contact's getPersistentData() - * method during a previous run and that has been persistently stored - * locally. - * @return the unresolved <tt>Contact</tt> created from the specified - * <tt>address</tt> and <tt>persistentData</tt> - */ - public Contact createUnresolvedContact(String address, - String persistentData) - { - return createUnresolvedContact( address - , persistentData - , getServerStoredContactListRoot()); - } - - /** - * Creates and returns a unresolved contact group from the specified - * <tt>address</tt> and <tt>persistentData</tt>. - * - * @param groupUID an identifier, returned by ContactGroup's - * getGroupUID, that the protocol provider may use in order to create - * the group. - * @param persistentData a String returned ContactGroups's - * getPersistentData() method during a previous run and that has been - * persistently stored locally. - * @param parentGroup the group under which the new group is to be - * created or null if this is group directly underneath the root. - * @return the unresolved <tt>ContactGroup</tt> created from the - * specified <tt>uid</tt> and <tt>persistentData</tt> - */ - public ContactGroup createUnresolvedContactGroup(String groupUID, - String persistentData, ContactGroup parentGroup) - { - return ssContactList.createUnresolvedContactGroup(groupUID); - } - - /** - * Returns a reference to the contact with the specified ID in case we - * have a subscription for it and null otherwise/ - * - * @param contactID a String identifier of the contact which we're - * seeking a reference of. - * @return a reference to the Contact with the specified - * <tt>contactID</tt> or null if we don't have a subscription for the - * that identifier. - */ - public Contact findContactByID(String contactID) - { - return ssContactList.findContactById(contactID); - } - - /** - * Returns the status message that was confirmed by the server - * - * @return the last status message that we have requested and the aim - * server has confirmed. - */ - public String getCurrentStatusMessage() - { - return currentStatusMessage; - } - - /** - * Returns the protocol specific contact instance representing the local - * user. - * - * @return the Contact (address, phone number, or uin) that the Provider - * implementation is communicating on behalf of. - */ - public Contact getLocalContact() - { - return null; - } - - /** - * Returns a PresenceStatus instance representing the state this provider - * is currently in. - * - * @return the PresenceStatus last published by this provider. - */ - public PresenceStatus getPresenceStatus() - { - return currentStatus; - } - - /** - * Returns the root group of the server stored contact list. - * - * @return the root ContactGroup for the ContactList stored by this - * service. - */ - public ContactGroup getServerStoredContactListRoot() - { - return ssContactList.getRootGroup(); - } - - /** - * Returns the set of PresenceStatus objects that a user of this service - * may request the provider to enter. - * - * @return Iterator a PresenceStatus array containing "enterable" status - * instances. - */ - public Iterator<PresenceStatus> getSupportedStatusSet() - { - return supportedPresenceStatusSet.iterator(); - } - - /** - * Removes the specified contact from its current parent and places it - * under <tt>newParent</tt>. - * - * @param contactToMove the <tt>Contact</tt> to move - * @param newParent the <tt>ContactGroup</tt> where <tt>Contact</tt> - * would be placed. - */ - public void moveContactToGroup(Contact contactToMove, - ContactGroup newParent) - { - assertConnected(); - - if( !(contactToMove instanceof ContactMsnImpl) ) - throw new IllegalArgumentException( - "The specified contact is not an msn contact." + contactToMove); - if( !(newParent instanceof ContactGroupMsnImpl) ) - throw new IllegalArgumentException( - "The specified group is not an msn contact group." - + newParent); - - ssContactList.moveContact((ContactMsnImpl)contactToMove, - (ContactGroupMsnImpl)newParent); - } - - /** - * Requests the provider to enter into a status corresponding to the - * specified parameters. - * - * @param status the PresenceStatus as returned by - * getRequestableStatusSet - * @param statusMessage the message that should be set as the reason to - * enter that status - * @throws IllegalArgumentException if the status requested is not a - * valid PresenceStatus supported by this provider. - * @throws IllegalStateException if the provider is not currently - * registered. - * @throws OperationFailedException with code NETWORK_FAILURE if - * publishing the status fails due to a network error. - */ - public void publishPresenceStatus(PresenceStatus status, - String statusMessage) throws - IllegalArgumentException, IllegalStateException, - OperationFailedException - { - assertConnected(); - - if (!(status instanceof MsnStatusEnum)) - throw new IllegalArgumentException( - status + " is not a valid Msn status"); - - if(status.equals(MsnStatusEnum.OFFLINE)) - { - parentProvider.unregister(); - return; - } - - // if the contact list is inited set the state - // otherwise just set the init status - //(as if set the status too early the server does not provide - // any status information about the contacts in our list) - if(ssContactList.isInitialized()) - { - parentProvider.getMessenger().getOwner(). - setStatus(scToMsnModesMappings.get(status)); - - if(statusMessage != null) - parentProvider.getMessenger().getOwner() - .setPersonalMessage(statusMessage); - } - else - { - parentProvider.getMessenger().getOwner(). - setInitStatus(scToMsnModesMappings.get(status)); - - if(statusMessage != null) - parentProvider.getMessenger().getOwner() - .setInitPersonalMessage(statusMessage); - } - } - - /** - * Get the PresenceStatus for a particular contact. - * - * @param contactIdentifier the identifier of the contact whose status - * we're interested in. - * @return PresenceStatus the <tt>PresenceStatus</tt> of the specified - * <tt>contact</tt> - * @throws IllegalArgumentException if <tt>contact</tt> is not a contact - * known to the underlying protocol provider - * @throws IllegalStateException if the underlying protocol provider is - * not registered/signed on a public service. - * @throws OperationFailedException with code NETWORK_FAILURE if - * retrieving the status fails due to errors experienced during - * network communication - */ - public PresenceStatus queryContactStatus(String contactIdentifier) throws - IllegalArgumentException, IllegalStateException, - OperationFailedException - { - ContactMsnImpl contact = ssContactList.findContactById(contactIdentifier); - if(contact == null) - { - if (logger.isInfoEnabled()) - logger.info("Contact not found id :" + contactIdentifier); - return null; - } - else - return msnStatusToPresenceStatus(contact.getSourceContact().getStatus()); - } - - /** - * Removes the specified group from the server stored contact list. - * - * @param group the group to remove. - */ - public void removeServerStoredContactGroup(ContactGroup group) - { - assertConnected(); - - if( !(group instanceof ContactGroupMsnImpl) ) - throw new IllegalArgumentException( - "The specified group is not an msn contact group: " + group); - - ssContactList.removeGroup(((ContactGroupMsnImpl)group)); - } - - /** - * Removes the specified group change listener so that it won't receive - * any further events. - * - * @param listener the ServerStoredGroupChangeListener to remove - */ - @Override - public void removeServerStoredGroupChangeListener(ServerStoredGroupListener - listener) - { - ssContactList.removeGroupListener(listener); - } - - /** - * Renames the specified group from the server stored contact list. - * - * @param group the group to rename. - * @param newName the new name of the group. - */ - public void renameServerStoredContactGroup(ContactGroup group, - String newName) - { - assertConnected(); - - if( !(group instanceof ContactGroupMsnImpl) ) - throw new IllegalArgumentException( - "The specified group is not an msn contact group: " + group); - - ssContactList.renameGroup((ContactGroupMsnImpl)group, newName); - } - - /** - * Handler for incoming authorization requests. - * - * @param handler an instance of an AuthorizationHandler for - * authorization requests coming from other users requesting - * permission add us to their contact list. - */ - public void setAuthorizationHandler(AuthorizationHandler handler) - { - this.authorizationHandler = handler; - } - - /** - * Returns the AuthorizationHandler. - * @return AuthorizationHandler - */ - AuthorizationHandler getAuthorizationHandler() - { - return this.authorizationHandler; - } - - /** - * Persistently adds a subscription for the presence status of the - * contact corresponding to the specified contactIdentifier and indicates - * that it should be added to the specified group of the server stored - * contact list. - * - * @param parent the parent group of the server stored contact list - * where the contact should be added. <p> - * @param contactIdentifier the contact whose status updates we are - * subscribing for. - * @throws IllegalArgumentException if <tt>contact</tt> or - * <tt>parent</tt> are not a contact known to the underlying protocol - * provider. - * @throws IllegalStateException if the underlying protocol provider is - * not registered/signed on a public service. - * @throws OperationFailedException with code NETWORK_FAILURE if - * subscribing fails due to errors experienced during network - * communication - */ - public void subscribe(ContactGroup parent, String contactIdentifier) throws - IllegalArgumentException, IllegalStateException, - OperationFailedException - { - assertConnected(); - - if(! (parent instanceof ContactGroupMsnImpl) ) - throw new IllegalArgumentException( - "Argument is not an msn contact group (group=" + parent + ")"); - - ssContactList.addContact((ContactGroupMsnImpl)parent, contactIdentifier); - } - - /** - * Adds a subscription for the presence status of the contact - * corresponding to the specified contactIdentifier. - * - * @param contactIdentifier the identifier of the contact whose status - * updates we are subscribing for. <p> - * @throws IllegalArgumentException if <tt>contact</tt> is not a contact - * known to the underlying protocol provider - * @throws IllegalStateException if the underlying protocol provider is - * not registered/signed on a public service. - * @throws OperationFailedException with code NETWORK_FAILURE if - * subscribing fails due to errors experienced during network - * communication - */ - public void subscribe(String contactIdentifier) throws - IllegalArgumentException, IllegalStateException, - OperationFailedException - { - assertConnected(); - - ssContactList.addContact(contactIdentifier); - } - - /** - * Removes a subscription for the presence status of the specified - * contact. - * - * @param contact the contact whose status updates we are unsubscribing - * from. - * @throws IllegalArgumentException if <tt>contact</tt> is not a contact - * known to the underlying protocol provider - * @throws IllegalStateException if the underlying protocol provider is - * not registered/signed on a public service. - * @throws OperationFailedException with code NETWORK_FAILURE if - * unsubscribing fails due to errors experienced during network - * communication - */ - public void unsubscribe(Contact contact) throws IllegalArgumentException, - IllegalStateException, OperationFailedException - { - assertConnected(); - - if(! (contact instanceof ContactMsnImpl) ) - throw new IllegalArgumentException( - "Argument is not an msn contact (contact=" + contact + ")"); - - ssContactList.removeContact((ContactMsnImpl)contact); - } - - /** - * Converts the specified msn status to one of the status fields of the - * MsnStatusEnum class. - * - * @param status the msn Status - * @return a PresenceStatus instance representation of the Msn Status - * parameter. The returned result is one of the MsnStatusEnum fields. - */ - MsnStatusEnum msnStatusToPresenceStatus(MsnUserStatus status) - { - if(status.equals(MsnUserStatus.ONLINE)) - return MsnStatusEnum.ONLINE; - else if(status.equals(MsnUserStatus.AWAY)) - return MsnStatusEnum.AWAY; - else if(status.equals(MsnUserStatus.BE_RIGHT_BACK)) - return MsnStatusEnum.BE_RIGHT_BACK; - else if(status.equals(MsnUserStatus.BUSY)) - return MsnStatusEnum.BUSY; - else if(status.equals(MsnUserStatus.HIDE)) - return MsnStatusEnum.HIDE; - else if(status.equals(MsnUserStatus.IDLE)) - return MsnStatusEnum.IDLE; - else if(status.equals(MsnUserStatus.ON_THE_PHONE)) - return MsnStatusEnum.ON_THE_PHONE; - else if(status.equals(MsnUserStatus.OUT_TO_LUNCH)) - return MsnStatusEnum.OUT_TO_LUNCH; - else return MsnStatusEnum.OFFLINE; - } - - /** - * Utility method throwing an exception if the stack is not properly - * initialized. - * @throws java.lang.IllegalStateException if the underlying stack is - * not registered and initialized. - */ - private void assertConnected() throws IllegalStateException - { - if (parentProvider == null) - throw new IllegalStateException( - "The provider must be non-null and signed on the msn " - +"service before being able to communicate."); - if (!parentProvider.isRegistered()) - throw new IllegalStateException( - "The provider must be signed on the msn service before " - +"being able to communicate."); - } - - /** - * Notify all provider presence listeners of the corresponding event change - * - * @param oldStatus - * the status our stack had so far - * @param newStatus - * the status we have from now on - */ - @Override - protected void fireProviderStatusChangeEvent( - PresenceStatus oldStatus, - PresenceStatus newStatus) - { - if (!oldStatus.equals(newStatus)) { - currentStatus = newStatus; - - super.fireProviderStatusChangeEvent(oldStatus, newStatus); - } - } - - /** - * Sets the display name for <tt>contact</tt> to be <tt>newName</tt>. - * <p> - * @param contact the <tt>Contact</tt> that we are renaming - * @param newName a <tt>String</tt> containing the new display name for - * <tt>metaContact</tt>. - * @throws IllegalArgumentException if <tt>contact</tt> is not an - * instance that belongs to the underlying implementation. - */ - @Override - public void setDisplayName(Contact contact, String newName) - throws IllegalArgumentException - { - assertConnected(); - - if( !(contact instanceof ContactMsnImpl) ) - throw new IllegalArgumentException( - "The specified contact is not an msn contact." + contact); - - ssContactList.setDisplayName((ContactMsnImpl)contact, newName); - } - - /** - * Our listener that will tell us when we're registered to server - * and is ready to accept us as a listener. - */ - private class RegistrationStateListener - implements RegistrationStateChangeListener - { - /** - * The method is called by a ProtocolProvider implementation whenever - * a change in the registration state of the corresponding provider had - * occurred. - * @param evt ProviderStatusChangeEvent the event describing the status - * change. - */ - public void registrationStateChanged(RegistrationStateChangeEvent evt) - { - if (logger.isDebugEnabled()) - logger.debug("The msn provider changed state from: " - + evt.getOldState() - + " to: " + evt.getNewState()); - - if(evt.getNewState() == RegistrationState.REGISTERED) - { - if(parentProvider.getMessenger() != null) - { - parentProvider.getMessenger(). - addContactListListener(new StatusChangedListener()); - } - else if(logger.isInfoEnabled()) - logger.info("Registered but msnMessenger is missing!", - new Exception()); - } - else if(evt.getNewState() == RegistrationState.UNREGISTERED - || evt.getNewState() == RegistrationState.AUTHENTICATION_FAILED - || evt.getNewState() == RegistrationState.CONNECTION_FAILED) - { - //since we are disconnected, we won't receive any further status - //updates so we need to change by ourselves our own status as - //well as set to offline all contacts in our contact list that - //were online - PresenceStatus oldStatus = currentStatus; - currentStatus = MsnStatusEnum.OFFLINE; - - fireProviderStatusChangeEvent(oldStatus, currentStatus); - - //send event notifications saying that all our buddies are - //offline. - Iterator<Contact> rootContactsIter - = getServerStoredContactListRoot().contacts(); - while(rootContactsIter.hasNext()) - { - ContactMsnImpl contact - = (ContactMsnImpl)rootContactsIter.next(); - - PresenceStatus oldContactStatus - = contact.getPresenceStatus(); - - if(!oldContactStatus.isOnline()) - continue; - - contact.updatePresenceStatus(MsnStatusEnum.OFFLINE); - - fireContactPresenceStatusChangeEvent( - contact - , contact.getParentContactGroup() - , oldContactStatus, MsnStatusEnum.OFFLINE); - } - - Iterator<ContactGroup> groupsIter - = getServerStoredContactListRoot().subgroups(); - while(groupsIter.hasNext()) - { - ContactGroupMsnImpl group - = (ContactGroupMsnImpl)groupsIter.next(); - - Iterator<Contact> contactsIter = group.contacts(); - - while(contactsIter.hasNext()) - { - ContactMsnImpl contact - = (ContactMsnImpl)contactsIter.next(); - - PresenceStatus oldContactStatus - = contact.getPresenceStatus(); - - if(!oldContactStatus.isOnline()) - continue; - - contact.updatePresenceStatus(MsnStatusEnum.OFFLINE); - - fireContactPresenceStatusChangeEvent( - contact - , contact.getParentContactGroup() - , oldContactStatus, MsnStatusEnum.OFFLINE); - } - } - } - } - } - - /** - * Sets the messenger instance impl of the lib - * which communicates with the server - * @param messenger MsnMessenger - */ - void setMessenger(MsnMessenger messenger) - { - ssContactList.setMessenger(messenger); - } - - /** - * Fires all the saved statuses which were received before - * contact list init - */ - void earlyStatusesDispatch() - { - Iterator<String> iter = earlyStatusChange.keySet().iterator(); - while (iter.hasNext()) - { - String contactEmail = iter.next(); - - ContactMsnImpl sourceContact - = ssContactList.findContactById(contactEmail); - - if (sourceContact == null) - { - return; - } - - PresenceStatus oldStatus - = sourceContact.getPresenceStatus(); - - PresenceStatus newStatus - = msnStatusToPresenceStatus(earlyStatusChange.get(contactEmail)); - - // when old and new status are the same do nothing - // no change - if(oldStatus.equals(newStatus)) - return; - - sourceContact.updatePresenceStatus(newStatus); - - ContactGroup parent - = ssContactList.findContactGroup(sourceContact); - - if (logger.isDebugEnabled()) - logger.debug("Will Dispatch the contact status event."); - fireContactPresenceStatusChangeEvent(sourceContact, parent, - oldStatus, newStatus); - } - earlyStatusChange.clear(); - } - - /** - * Returns the server stored contact list registered in this operation set. - * @return the server stored contact list registered in this operation set. - */ - ServerStoredContactListMsnImpl getServerStoredContactList() - { - return ssContactList; - } - - /** - * Waits for status changes from the contacts in the list - * or own account - */ - private class StatusChangedListener - extends MsnContactListAdapter - { - /** - * Indicates that owner status changed - * @param messenger the messenger changing the status - */ - @Override - public void ownerStatusChanged(MsnMessenger messenger) - { - if (logger.isTraceEnabled()) - logger.trace("Own status changed to " + messenger.getOwner().getStatus()); - PresenceStatus oldStatus = currentStatus; - currentStatus = - msnStatusToPresenceStatus(messenger.getOwner().getStatus()); - fireProviderStatusChangeEvent(oldStatus, currentStatus); - } - - /** - * Called from the lib when a contact status changes - * @param messenger MsnMessenger - * @param contact MsnContact - */ - @Override - public void contactStatusChanged( MsnMessenger messenger, - MsnContact contact) - { - if (logger.isDebugEnabled()) - logger.debug("Received a status update for contact=" + contact); - - ContactMsnImpl sourceContact - = ssContactList - .findContactById(contact.getEmail().getEmailAddress()); - - if (sourceContact == null) - { - if (logger.isDebugEnabled()) - logger.debug("No source contact found for msncontact=" + contact); - - // maybe list is not inited yet will store till init - earlyStatusChange.put(contact.getEmail().getEmailAddress(), - contact.getStatus()); - - return; - } - - PresenceStatus oldStatus - = sourceContact.getPresenceStatus(); - - PresenceStatus newStatus - = msnStatusToPresenceStatus(contact.getStatus()); - - // when old and new status are the same do nothing - // no change - if(oldStatus.equals(newStatus)) - return; - - sourceContact.updatePresenceStatus(newStatus); - - ContactGroup parent - = ssContactList.findContactGroup(sourceContact); - - if (logger.isDebugEnabled()) - logger.debug("Will Dispatch the contact status event."); - fireContactPresenceStatusChangeEvent(sourceContact, parent, - oldStatus, newStatus); - } - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetServerStoredAccountInfoMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetServerStoredAccountInfoMsnImpl.java deleted file mode 100644 index 706caf7..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetServerStoredAccountInfoMsnImpl.java +++ /dev/null @@ -1,608 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.io.*; -import java.util.*; - -import javax.imageio.*; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.ServerStoredDetails.DisplayNameDetail; -import net.java.sip.communicator.service.protocol.ServerStoredDetails.GenericDetail; -import net.java.sip.communicator.service.protocol.ServerStoredDetails.ImageDetail; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.util.*; -import net.sf.jml.*; - -import org.jitsi.service.fileaccess.*; - -/** - * Saves account avatar image. If one is already saved we set it as initial one - * for the MsnOwner. - * - * @author SR - * @author Damian Minkov - */ -public class OperationSetServerStoredAccountInfoMsnImpl - extends AbstractOperationSetServerStoredAccountInfo - implements RegistrationStateChangeListener -{ - /** - * Logger for this class. - */ - private static final Logger logger = - Logger.getLogger(OperationSetServerStoredAccountInfoMsnImpl.class); - - /** - * The msn provider that created us. - */ - private ProtocolProviderServiceMsnImpl msnProvider = null; - /** - * Our account uin=email address. - */ - private String uin = null; - - /** - * A place to store our own picture. - */ - private static final String STORE_DIR = "avatarcache" + File.separator; - - /** - * Here is kept all the details retrieved so far. - */ - private Hashtable<String,List<GenericDetail>> retrievedDetails - = new Hashtable<String,List<GenericDetail>>(); - - /** - * Constructor. - * @param msnProvider MSN service provider - * @param uin MSN UIN - */ - protected OperationSetServerStoredAccountInfoMsnImpl( - ProtocolProviderServiceMsnImpl msnProvider, - String uin) - { - this.msnProvider = msnProvider; - this.uin = uin; - - this.msnProvider.addRegistrationStateChangeListener(this); - } - - /** - * Returns an iterator over all details that are instances or descendants of - * the specified class. If for example an our account has a work address - * and an address detail, a call to this method with AddressDetail.class - * would return both of them. - * <p> - * @param detailClass one of the detail classes defined in the - * ServerStoredDetails class, indicating the kind of details we're - * interested in. - * <p> - * @return a java.util.Iterator over all details that are instances or - * descendants of the specified class. - */ - public <T extends GenericDetail> Iterator<T> getDetailsAndDescendants( - Class<T> detailClass) - { - assertConnected(); - - List<GenericDetail> details = getContactDetails(uin); - List<T> result = new LinkedList<T>(); - - Iterator<GenericDetail> iter = details.iterator(); - while (iter.hasNext()) - { - GenericDetail item = iter.next(); - if (detailClass.isInstance(item)) - { - @SuppressWarnings("unchecked") - T t = (T) item; - - result.add(t); - } - } - - return result.iterator(); - } - - /** - * request the full info for the given contactAddress - * waits and return this details - * - * @param contactAddress String - * @return Vector the details - */ - List<GenericDetail> getContactDetails(String contactAddress) - { - List<GenericDetail> result = retrievedDetails.get(contactAddress); - - if (result == null) - { - result = new LinkedList<GenericDetail>(); - try - { - MsnMessenger messenger = msnProvider.getMessenger(); - - if (messenger == null) - { - return null; - } - - Email email = Email.parseStr(contactAddress); - - String tmp = null; - byte[] imageBytes; - if (messenger.getOwner().getEmail().equals(email)) - { - MsnOwner owner = messenger.getOwner(); - tmp = owner.getDisplayName(); - result.add(new ServerStoredDetails.DisplayNameDetail(tmp)); - - MsnObject image = owner.getDisplayPicture(); - if (image != null) - { - imageBytes = image.getMsnObj(); - if (imageBytes != null && imageBytes.length > 0) - { - result.add(new ServerStoredDetails.ImageDetail( - "Image", imageBytes)); - } - } - } else - { - MsnContact contact = - messenger.getContactList().getContactByEmail(email); - tmp = contact.getDisplayName(); - result.add(new ServerStoredDetails.DisplayNameDetail(tmp)); - imageBytes = contact.getAvatar().getMsnObj(); - if (imageBytes != null && imageBytes.length > 0) - { - result.add(new ServerStoredDetails.ImageDetail( - "Image", imageBytes)); - } - } - - } catch (Exception exc) - { - logger.error("Cannot load details for contact " + this - + " : " + exc.getMessage(), exc); - } - } - - retrievedDetails.put(contactAddress, result); - - return new LinkedList<GenericDetail>(result); - } - - /** - * Returns an iterator over all details that are instances of exactly the - * same class as the one specified. Not that, contrary to the - * getDetailsAndDescendants() method this one would only return details - * that are instances of the specified class and not only its descendants. - * If for example our account has both a work address and an address detail, - * a call to this method with AddressDetail.class would return only the - * AddressDetail instance and not the WorkAddressDetail instance. - * <p> - * @param detailClass one of the detail classes defined in the - * ServerStoredDetails class, indicating the kind of details we're - * interested in. - * <p> - * @return a java.util.Iterator over all details of specified class. - */ - public Iterator<GenericDetail> getDetails( - Class<? extends GenericDetail> detailClass) - { - assertConnected(); - - return getDetails(uin, detailClass); - } - - /** - * Returns all details currently available and set for our account. - * <p> - * @return a java.util.Iterator over all details currently set our account. - */ - public Iterator<GenericDetail> getAllAvailableDetails() - { - assertConnected(); - - return getContactDetails(uin).iterator(); - } - - /** - * Returns all detail Class-es that the underlying implementation supports - * setting. Note that if you call one of the modification methods (add - * remove or replace) with a detail not contained by the iterator returned - * by this method, an IllegalArgumentException will be thrown. - * <p> - * @return a java.util.Iterator over all detail classes supported by the - * implementation. - */ - public Iterator<Class<? extends GenericDetail>> getSupportedDetailTypes() - { - List<GenericDetail> details = getContactDetails(uin); - List<Class<? extends GenericDetail>> result - = new LinkedList<Class<? extends GenericDetail>>(); - - Iterator<GenericDetail> iter = details.iterator(); - while (iter.hasNext()) - { - GenericDetail obj = iter.next(); - result.add(obj.getClass()); - } - - return result.iterator(); - } - - /** - * Determines whether a detail class represents a detail supported by the - * underlying implementation or not. Note that if you call one of the - * modification methods (add remove or replace) with a detail that this - * method has determined to be unsupported (returned false) this would lead - * to an IllegalArgumentException being thrown. - * <p> - * @param detailClass the class the support for which we'd like to - * determine. - * <p> - * @return true if the underlying implementation supports setting details of - * this type and false otherwise. - */ - public boolean isDetailClassSupported( - Class<? extends GenericDetail> detailClass) - { - return ImageDetail.class.isAssignableFrom(detailClass) || - DisplayNameDetail.class.isAssignableFrom(detailClass); - } - - /** - * Determines whether the underlying implementation supports edition - * of this detail class. - * <p> - * @param detailClass the class whose edition we'd like to determine if it's - * possible - * @return true if the underlying implementation supports edition of this - * type of detail and false otherwise. - */ - public boolean isDetailClassEditable( - Class<? extends GenericDetail> detailClass) - { - return - isDetailClassSupported(detailClass) - && ImageDetail.class.isAssignableFrom(detailClass); - } - - /** - * The method returns the number of instances supported for a particular - * detail type. Some protocols offer storing multiple values for a - * particular detail type. Spoken languages are a good example. - * @param detailClass the class whose max instance number we'd like to find - * out. - * <p> - * @return int the maximum number of detail instances. - */ - public int getMaxDetailInstances(Class<? extends GenericDetail> detailClass) - { - return 1; - } - - /** - * returns the user details from the specified class - * exactly that class not its descendants - * - * @param uin String - * @param detailClass Class - * @return Iterator - */ - private Iterator<GenericDetail> getDetails(String uin, - Class<? extends GenericDetail> detailClass) - { - List<GenericDetail> details = getContactDetails(uin); - List<GenericDetail> result = new LinkedList<GenericDetail>(); - - Iterator<GenericDetail> iter = details.iterator(); - while (iter.hasNext()) - { - GenericDetail item = iter.next(); - if (detailClass.equals(item.getClass())) - { - result.add(item); - } - } - - return result.iterator(); - } - - /** - * Adds the specified detail to the list of details registered on-line - * for this account. If such a detail already exists its max instance number - * is consulted and if it allows it - a second instance is added or otherwise - * and illegal argument exception is thrown. An IllegalArgumentException is - * also thrown in case the class of the specified detail is not supported by - * the underlying implementation, i.e. its class name was not returned by the - * getSupportedDetailTypes() method. - * <p> - * @param detail the detail that we'd like registered on the server. - * <p> - * @throws IllegalArgumentException if such a detail already exists and its - * max instances number has been attained or if the underlying - * implementation does not support setting details of the corresponding - * class. - * @throws OperationFailedException with code Network Failure if putting the - * new value online has failed - * @throws java.lang.ArrayIndexOutOfBoundsException if the number of - * instances currently registered by the application is already equal to the - * maximum number of supported instances (@see getMaxDetailInstances()) - */ - public void addDetail(ServerStoredDetails.GenericDetail detail) - throws IllegalArgumentException, - OperationFailedException, - ArrayIndexOutOfBoundsException - { - assertConnected(); - - /*Currently as the function only provied the list of classes that currently have data associatd with them - * in Jabber InfoRetreiver we have to skip this check*/ -// if (!isDetailClassSupported(detail.getClass())) { -// throw new IllegalArgumentException( -// "implementation does not support such details " + -// detail.getClass()); -// } - - Iterator<GenericDetail> iter = getDetails(detail.getClass()); - int currentDetailsSize = 0; - while (iter.hasNext()) - { - currentDetailsSize++; - } - if (currentDetailsSize >= getMaxDetailInstances(detail.getClass())) { - throw new ArrayIndexOutOfBoundsException( - "Max count for this detail is already reached"); - } - - MsnOwner owner = msnProvider.getMessenger().getOwner(); - - if (detail instanceof ImageDetail) - { - try - { - String path = storePicture(((ImageDetail) detail).getBytes()); - - FileInputStream in = new FileInputStream(path); - byte[] b = new byte[in.available()]; - in.read(b); - in.close(); - - owner.setDisplayPicture(MsnObject.getInstance( - owner.getEmail().getEmailAddress(), - b)); - } catch(Exception e) - { - logger.error("Error setting own avatar.", e); - - // on error return to skip details change - return; - } - } - - fireServerStoredDetailsChangeEvent(msnProvider, - ServerStoredDetailsChangeEvent.DETAIL_ADDED, - null, - detail); - } - - /** - * Stores the picture. - * @param data data to store - * @return the picture path. - * @throws Exception if the storage of the picture failed - */ - private String storePicture(byte[] data) - throws Exception - { - String imagePath = STORE_DIR - + msnProvider.getAccountID().getAccountUniqueID() + ".jpg"; - - File storeDir = MsnActivator.getFileAccessService() - .getPrivatePersistentDirectory(STORE_DIR, FileCategory.CACHE); - - // if dir doesn't exist create it - storeDir.mkdirs(); - - File file = MsnActivator.getFileAccessService() - .getPrivatePersistentFile(imagePath, FileCategory.CACHE); - - ImageIO.write( - ImageIO.read(new ByteArrayInputStream(data)), - "jpg", - file); - - return file.getPath(); - } - - /** - * Removes the specified detail from the list of details stored online for - * this account. The method returns a boolean indicating if such a detail - * was found (and removed) or not. - * <p> - * @param detail the detail to remove - * @return true if the specified detail existed and was successfully removed - * and false otherwise. - * @throws OperationFailedException with code Network Failure if removing the - * detail from the server has failed - */ - public boolean removeDetail(ServerStoredDetails.GenericDetail detail) - throws OperationFailedException - { - return false; - } - - /** - * Replaces the currentDetailValue detail with newDetailValue and returns - * true if the operation was a success or false if currentDetailValue did - * not previously exist (in this case an additional call to addDetail is - * required). - * <p> - * @param currentDetailValue the detail value we'd like to replace. - * @param newDetailValue the value of the detail that we'd like to replace - * currentDetailValue with. - * @return true if the operation was a success or false if - * currentDetailValue did not previously exist (in this case an additional - * call to addDetail is required). - * @throws ClassCastException if newDetailValue is not an instance of the - * same class as currentDetailValue. - * @throws OperationFailedException with code Network Failure if putting the - * new value back online has failed - */ - public boolean replaceDetail( - ServerStoredDetails.GenericDetail currentDetailValue, - ServerStoredDetails.GenericDetail newDetailValue) - throws ClassCastException, OperationFailedException - { - assertConnected(); - - if (!newDetailValue.getClass().equals(currentDetailValue.getClass())) - { - throw new ClassCastException("New value to be replaced is not " + - "as the current one"); - } - // if values are the same no change - if (currentDetailValue.equals(newDetailValue)) - { - return true; - } - - boolean isFound = false; - Iterator<GenericDetail> iter = getDetails(uin, currentDetailValue.getClass()); - while (iter.hasNext()) - { - GenericDetail item = iter.next(); - if (item.equals(currentDetailValue)) - { - isFound = true; - break; - - } - } - // current detail value does not exist - if (!isFound) - { - return false; - } - - MsnOwner owner = msnProvider.getMessenger().getOwner(); - - if (newDetailValue instanceof ImageDetail) - { - try - { - String path = storePicture( - ((ImageDetail) newDetailValue).getBytes()); - - FileInputStream in = new FileInputStream(path); - byte[] b = new byte[in.available()]; - in.read(b); - in.close(); - - owner.setDisplayPicture(MsnObject.getInstance( - owner.getEmail().getEmailAddress(), - b)); - - fireServerStoredDetailsChangeEvent(msnProvider, - ServerStoredDetailsChangeEvent.DETAIL_REPLACED, - currentDetailValue, - newDetailValue); - - return true; - } catch(Exception e) - { - logger.error("Error setting own avatar.", e); - } - } - - return false; - } - - /* - * (non-Javadoc) - * @see net.java.sip.communicator.service.protocol.OperationSetServerStoredAccountInfo#save() - * This method is currently unimplemented. - * The idea behind this method is for users to call it only once, meaning - * that all ServerStoredDetails previously modified by addDetail/removeDetail - * and/or replaceDetail will be saved online on the server in one step. - * Currently, addDetail/removeDetail/replaceDetail methods are doing the - * actual saving but in the future the saving part must be carried here. - */ - public void save() throws OperationFailedException {} - - /** - * Utility method throwing an exception if the icq stack is not properly - * initialized. - * @throws java.lang.IllegalStateException if the underlying ICQ stack is - * not registered and initialized. - */ - private void assertConnected() - throws IllegalStateException - { - if (msnProvider == null) - { - throw new IllegalStateException( - "The msn provider must be non-null and signed on " - + "before being able to communicate."); - } - - if (!msnProvider.isRegistered()) - { - throw new IllegalStateException( - "The msn provider must be signed on before " - + "being able to communicate."); - } - } - - /** - * The method is called by a <code>ProtocolProviderService</code> - * implementation whenever a change in the registration state of the - * corresponding provider had occurred. - * - * @param evt the event describing the status change. - */ - public void registrationStateChanged(RegistrationStateChangeEvent evt) - { - if(evt.getNewState() == RegistrationState.REGISTERING) - { - try - { - String imagePath = STORE_DIR - + msnProvider.getAccountID().getAccountUniqueID() + ".jpg"; - - File file = MsnActivator.getFileAccessService() - .getPrivatePersistentFile(imagePath, FileCategory.CACHE); - - if(file.exists()) - { - FileInputStream in = new FileInputStream(file); - byte[] b = new byte[in.available()]; - in.read(b); - in.close(); - - if(msnProvider.getMessenger() != null) - { - MsnOwner owner = msnProvider.getMessenger().getOwner(); - - owner.setInitDisplayPicture(MsnObject.getInstance( - owner.getEmail().getEmailAddress(), - b)); - } - } - } - catch(Exception ex) - { - logger.error("Cannot obtain own avatar image.", ex); - } - } - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetTypingNotificationsMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/OperationSetTypingNotificationsMsnImpl.java deleted file mode 100644 index ebca1ea..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/OperationSetTypingNotificationsMsnImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.util.*; -import net.sf.jml.*; -import net.sf.jml.event.*; -import net.sf.jml.message.*; - -/** - * Maps SIP Communicator typing notifications to those going and coming from - * smack lib. - * - * @author Damian Minkov - */ -public class OperationSetTypingNotificationsMsnImpl - extends AbstractOperationSetTypingNotifications<ProtocolProviderServiceMsnImpl> -{ - /** - * This class logger. - */ - private static final Logger logger = - Logger.getLogger(OperationSetTypingNotificationsMsnImpl.class); - - /** - * An active instance of the opSetPersPresence operation set. We're using - * it to map incoming events to contacts in our contact list. - */ - private OperationSetPersistentPresenceMsnImpl opSetPersPresence = null; - - /** - * The messenger. - */ - private MsnMessenger messenger = null; - - /** - * @param provider a ref to the <tt>ProtocolProviderServiceImpl</tt> - * that created us and that we'll use for retrieving the underlying aim - * connection. - */ - OperationSetTypingNotificationsMsnImpl( - ProtocolProviderServiceMsnImpl provider) - { - super(provider); - - provider.addRegistrationStateChangeListener(new ProviderRegListener()); - } - - /** - * Sends a notification to <tt>notifiedContatct</tt> that we have entered - * <tt>typingState</tt>. - * - * @param notifiedContact the <tt>Contact</tt> to notify - * @param typingState the typing state that we have entered. - * - * @throws java.lang.IllegalStateException if the underlying stack is - * not registered and initialized. - * @throws java.lang.IllegalArgumentException if <tt>notifiedContact</tt> is - * not an instance belonging to the underlying implementation. - */ - public void sendTypingNotification(Contact notifiedContact, int typingState) - throws IllegalStateException, IllegalArgumentException - { - assertConnected(); - - if( !(notifiedContact instanceof ContactMsnImpl) ) - throw new IllegalArgumentException( - "The specified contact is not an MSN contact." - + notifiedContact); - - if(typingState == OperationSetTypingNotifications.STATE_TYPING) - { - MsnControlMessage msg = new MsnControlMessage(); - msg.setTypingUser(messenger.getOwner().getEmail().getEmailAddress()); - - Email targetContactEmail = - ( (ContactMsnImpl) notifiedContact).getSourceContact().getEmail(); - - MsnSwitchboard[] activSB = messenger.getActiveSwitchboards(); - - MsnSwitchboard tempSB = null; - for (int i = 0; i < activSB.length; i++) - { - tempSB = activSB[i]; - - if (tempSB.containContact(targetContactEmail)) - tempSB.sendMessage(msg, true); - } - } - } - - /** - * Sets the messenger instance impl of the lib which communicates with the - * server - * - * @param messenger - * MsnMessenger - */ - void setMessenger(MsnMessenger messenger) - { - this.messenger = messenger; - - if(messenger != null) - messenger.addMessageListener(new TypingListener()); - } - - /** - * Listens for typing notifications coming from the protocol. - */ - private class TypingListener - extends MsnAdapter - { - /** - * Control message may indicate typing notification. - * @param switchboard - * @param message - * @param contact - */ - @Override - public void controlMessageReceived(MsnSwitchboard switchboard, - MsnControlMessage message, - MsnContact contact) - { - String typingUserID = message.getTypingUser(); - - if(typingUserID != null) - { - Contact sourceContact = opSetPersPresence.findContactByID(typingUserID); - - if(sourceContact == null) - return; - - fireTypingNotificationsEvent(sourceContact, STATE_TYPING); - } - } - } - - /** - * Our listener that will tell us when we're registered and - * ready to accept us as a listener. - */ - private class ProviderRegListener - implements RegistrationStateChangeListener - { - /** - * The method is called by a ProtocolProvider implementation whenever - * a change in the registration state of the corresponding provider had - * occurred. - * @param evt ProviderStatusChangeEvent the event describing the status - * change. - */ - public void registrationStateChanged(RegistrationStateChangeEvent evt) - { - if (logger.isDebugEnabled()) - logger.debug("The provider changed state from: " - + evt.getOldState() - + " to: " + evt.getNewState()); - if (evt.getNewState() == RegistrationState.REGISTERED) - { - opSetPersPresence = - (OperationSetPersistentPresenceMsnImpl) parentProvider - .getOperationSet(OperationSetPersistentPresence.class); - } - } - } - -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ProtocolIconMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ProtocolIconMsnImpl.java deleted file mode 100644 index b8e7bb2..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/ProtocolIconMsnImpl.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.io.*; -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.util.*; - -/** - * Represents the MSN protocol icon. Implements the <tt>ProtocolIcon</tt> - * interface in order to provide a MSN icon image in two different sizes. - * - * @author Yana Stamcheva - */ -public class ProtocolIconMsnImpl - implements ProtocolIcon -{ - private static Logger logger = Logger.getLogger(ProtocolIconMsnImpl.class); - - /** - * A hash table containing the protocol icon in different sizes. - */ - private static Hashtable<String, byte[]> iconsTable - = new Hashtable<String, byte[]>(); - static - { - iconsTable.put(ProtocolIcon.ICON_SIZE_16x16, - getImageInBytes("service.protocol.msn.MSN_16x16")); - - iconsTable.put(ProtocolIcon.ICON_SIZE_32x32, - getImageInBytes("service.protocol.msn.MSN_32x32")); - - iconsTable.put(ProtocolIcon.ICON_SIZE_48x48, - getImageInBytes("service.protocol.msn.MSN_48x48")); - - iconsTable.put(ProtocolIcon.ICON_SIZE_64x64, - getImageInBytes("service.protocol.msn.MSN_64x64")); - } - - /** - * A hash table containing the path to the protocol icon in different sizes. - */ - private static Hashtable<String, String> iconPathsTable - = new Hashtable<String, String>(); - static - { - iconPathsTable.put(ProtocolIcon.ICON_SIZE_16x16, - MsnActivator.getResources().getImagePath( - "service.protocol.msn.MSN_16x16")); - - iconPathsTable.put(ProtocolIcon.ICON_SIZE_32x32, - MsnActivator.getResources().getImagePath( - "service.protocol.msn.MSN_32x32")); - - iconPathsTable.put(ProtocolIcon.ICON_SIZE_48x48, - MsnActivator.getResources().getImagePath( - "service.protocol.msn.MSN_48x48")); - - iconPathsTable.put(ProtocolIcon.ICON_SIZE_64x64, - MsnActivator.getResources().getImagePath( - "service.protocol.msn.MSN_64x64")); - } - - /** - * Implements the <tt>ProtocolIcon.getSupportedSizes()</tt> method. Returns - * an iterator to a set containing the supported icon sizes. - * @return an iterator to a set containing the supported icon sizes - */ - public Iterator<String> getSupportedSizes() - { - return iconsTable.keySet().iterator(); - } - - /** - * Returne TRUE if a icon with the given size is supported, FALSE-otherwise. - */ - public boolean isSizeSupported(String iconSize) - { - return iconsTable.containsKey(iconSize); - } - - /** - * Returns the icon image in the given size. - * @param iconSize the icon size; one of ICON_SIZE_XXX constants - */ - public byte[] getIcon(String iconSize) - { - return iconsTable.get(iconSize); - } - - /** - * Returns a path to the icon with the given size. - * @param iconSize the size of the icon we're looking for - * @return the path to the icon with the given size - */ - public String getIconPath(String iconSize) - { - return iconPathsTable.get(iconSize); - } - - /** - * Returns the icon image used to represent the protocol connecting state. - * @return the icon image used to represent the protocol connecting state - */ - public byte[] getConnectingIcon() - { - return getImageInBytes("msnConnectingIcon"); - } - - /** - * Returns the byte representation of the image corresponding to the given - * identifier. - * - * @param imageID the identifier of the image - * @return the byte representation of the image corresponding to the given - * identifier. - */ - private static byte[] getImageInBytes(String imageID) - { - InputStream in = MsnActivator.getResources(). - getImageInputStream(imageID); - - if (in == null) - return null; - byte[] image = null; - try - { - image = new byte[in.available()]; - - in.read(image); - } - catch (IOException e) - { - logger.error("Failed to load image:" + imageID, e); - } - - return image; - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ProtocolProviderFactoryMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ProtocolProviderFactoryMsnImpl.java deleted file mode 100644 index de27968..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/ProtocolProviderFactoryMsnImpl.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; - -import org.osgi.framework.*; - -/** - * The Msn implementation of the ProtocolProviderFactory. - * @author Damian Minkov - */ -public class ProtocolProviderFactoryMsnImpl - extends ProtocolProviderFactory -{ - - /** - * Creates an instance of the ProtocolProviderFactoryMsnImpl. - */ - protected ProtocolProviderFactoryMsnImpl() - { - super(MsnActivator.getBundleContext(), ProtocolNames.MSN); - } - - /** - * Initializes and creates an account corresponding to the specified - * accountProperties and registers the resulting ProtocolProvider in the - * <tt>context</tt> BundleContext parameter. This method has a persistent - * effect. Once created the resulting account will remain installed until - * removed through the uninstall account method. - * - * @param userIDStr the user identifier for the new account - * @param accountProperties a set of protocol (or implementation) - * specific properties defining the new account. - * @return the AccountID of the newly created account - */ - @Override - public AccountID installAccount( String userIDStr, - Map<String, String> accountProperties) - { - BundleContext context - = MsnActivator.getBundleContext(); - if (context == null) - throw new NullPointerException("The specified BundleContext was null"); - - if (userIDStr == null) - throw new NullPointerException("The specified AccountID was null"); - - if (accountProperties == null) - throw new NullPointerException("The specified property map was null"); - - accountProperties.put(USER_ID, userIDStr); - - AccountID accountID = new MsnAccountID(userIDStr, accountProperties); - - //make sure we haven't seen this account id before. - if( registeredAccounts.containsKey(accountID) ) - throw new IllegalStateException( - "An account for id " + userIDStr + " was already installed!"); - - //first store the account and only then load it as the load generates - //an osgi event, the osgi event triggers (trhgough the UI) a call to - //the register() method and it needs to acces the configuration service - //and check for a password. - this.storeAccount(accountID, false); - - accountID = loadAccount(accountProperties); - - return accountID; - } - - @Override - protected AccountID createAccountID(String userID, Map<String, String> accountProperties) - { - return new MsnAccountID(userID, accountProperties); - } - - @Override - protected ProtocolProviderService createService(String userID, - AccountID accountID) - { - ProtocolProviderServiceMsnImpl service = - new ProtocolProviderServiceMsnImpl(); - - service.initialize(userID, accountID); - return service; - } - - @Override - public void modifyAccount( ProtocolProviderService protocolProvider, - Map<String, String> accountProperties) - throws NullPointerException - { - BundleContext context - = MsnActivator.getBundleContext(); - - if (context == null) - throw new NullPointerException( - "The specified BundleContext was null"); - - if (protocolProvider == null) - throw new NullPointerException( - "The specified Protocol Provider was null"); - - MsnAccountID accountID = (MsnAccountID) protocolProvider.getAccountID(); - - // If the given accountID doesn't correspond to an existing account - // we return. - if(!registeredAccounts.containsKey(accountID)) - return; - - ServiceRegistration registration = registeredAccounts.get(accountID); - - // kill the service - if (registration != null) - registration.unregister(); - - if (accountProperties == null) - throw new NullPointerException( - "The specified property map was null"); - - accountProperties.put(USER_ID, accountID.getUserID()); - - if (!accountProperties.containsKey(PROTOCOL)) - accountProperties.put(PROTOCOL, ProtocolNames.MSN); - - accountID.setAccountProperties(accountProperties); - - // First store the account and only then load it as the load generates - // an osgi event, the osgi event triggers (through the UI) a call to - // the register() method and it needs to access the configuration service - // and check for a password. - this.storeAccount(accountID); - - Hashtable<String, String> properties = new Hashtable<String, String>(); - properties.put(PROTOCOL, ProtocolNames.MSN); - properties.put(USER_ID, accountID.getUserID()); - - ((ProtocolProviderServiceMsnImpl)protocolProvider) - .initialize(accountID.getUserID(), accountID); - - // We store again the account in order to store all properties added - // during the protocol provider initialization. - this.storeAccount(accountID); - - registration - = context.registerService( - ProtocolProviderService.class.getName(), - protocolProvider, - properties); - - registeredAccounts.put(accountID, registration); - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ProtocolProviderServiceMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ProtocolProviderServiceMsnImpl.java deleted file mode 100644 index 9b8d1e9..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/ProtocolProviderServiceMsnImpl.java +++ /dev/null @@ -1,612 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.net.*; -import java.nio.channels.*; - -import net.java.sip.communicator.service.dns.*; -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.util.*; -import net.sf.jml.*; -import net.sf.jml.event.*; -import net.sf.jml.exception.*; -import net.sf.jml.impl.*; - -/** - * An implementation of the protocol provider service over the Msn protocol - * - * @author Damian Minkov - * @author Lubomir Marinov - */ -public class ProtocolProviderServiceMsnImpl - extends AbstractProtocolProviderService -{ - /** - * Logger of this class - */ - private static final Logger logger - = Logger.getLogger(ProtocolProviderServiceMsnImpl.class); - - /** - * The lib messenger. - */ - private MsnMessenger messenger = null; - - /** - * We use this to lock access to initialization. - */ - private final Object initializationLock = new Object(); - - /** - * The identifier of the account that this provider represents. - */ - private AccountID accountID = null; - - /** - * Used when we need to re-register - */ - private SecurityAuthority authority = null; - - /** - * Operation set for persistent presence. - */ - private OperationSetPersistentPresenceMsnImpl persistentPresence = null; - - /** - * Operation set for typing notifications. - */ - private OperationSetTypingNotificationsMsnImpl typingNotifications = null; - - /** - * The icon corresponding to the msn protocol. - */ - private final ProtocolIconMsnImpl msnIcon = new ProtocolIconMsnImpl(); - - /** - * The indicator which determines whether - * {@link MsnMessengerListener#logout(MsnMessenger)} has been received for - * {@link #messenger} and it is thus an error to call - * {@link MsnMessenger#logout()} on it. - */ - private boolean logoutReceived = false; - - /** - * Returns the state of the registration of this protocol provider - * @return the <tt>RegistrationState</tt> that this provider is - * currently in or null in case it is in a unknown state. - */ - public RegistrationState getRegistrationState() - { - if(messenger == null || messenger.getConnection() == null) - return RegistrationState.UNREGISTERED; - else - return RegistrationState.REGISTERED; - } - - /** - * Starts the registration process. Connection details such as - * registration server, user name/number are provided through the - * configuration service through implementation specific properties. - * - * @param authority the security authority that will be used for resolving - * any security challenges that may be returned during the - * registration or at any moment while wer're registered. - * @throws OperationFailedException with the corresponding code it the - * registration fails for some reason (e.g. a networking error or an - * implementation problem). - */ - public void register(final SecurityAuthority authority) - throws OperationFailedException - { - if(authority == null) - throw new IllegalArgumentException( - "The register method needs a valid non-null authority impl " - + " in order to be able and retrieve passwords."); - - this.authority = authority; - - connectAndLogin(authority, SecurityAuthority.AUTHENTICATION_REQUIRED); - } - - /** - * Reconnects if fails fire connection failed. - * @param reasonCode the appropriate <tt>SecurityAuthority</tt> reasonCode, - * which would specify the reason for which we're re-calling the login. - */ - void reconnect(int reasonCode) - { - try - { - connectAndLogin(authority, reasonCode); - } - catch (OperationFailedException ex) - { - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.CONNECTION_FAILED, - RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, - null); - } - } - - /** - * Connects and logins to the server - * @param authority SecurityAuthority - * @param reasonCode - * @throws OperationFailedException if login parameters - * as server port are not correct - */ - private void connectAndLogin(SecurityAuthority authority, int reasonCode) - throws OperationFailedException - { - synchronized(initializationLock) - { - //verify whether a password has already been stored for this account - ProtocolProviderFactory protocolProviderFactory - = MsnActivator.getProtocolProviderFactory(); - AccountID accountID = getAccountID(); - String password = protocolProviderFactory.loadPassword(accountID); - - //decode - if (password == null) - { - //create a default credentials object - UserCredentials credentials = new UserCredentials(); - credentials.setUserName(accountID.getUserID()); - - //request a password from the user - credentials - = authority - .obtainCredentials( - accountID.getDisplayName(), - credentials, - reasonCode); - - // in case user has canceled the login window - if(credentials == null) - { - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.UNREGISTERED, - RegistrationStateChangeEvent.REASON_USER_REQUEST, - ""); - return; - } - - //extract the password the user passed us. - char[] pass = credentials.getPassword(); - - // the user didn't provide us a password (canceled the operation) - if(pass == null) - { - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.UNREGISTERED, - RegistrationStateChangeEvent.REASON_USER_REQUEST, - ""); - return; - } - password = new String(pass); - - if (credentials.isPasswordPersistent()) - protocolProviderFactory.storePassword(accountID, password); - } - - messenger - = MsnMessengerFactory - .createMsnMessenger(accountID.getUserID(), password); - - /* - * We've just created the messenger so we're sure we haven't - * received a logout for it. - */ - logoutReceived = false; - messenger.addMessengerListener(new MsnConnectionListener()); - - persistentPresence.setMessenger(messenger); - typingNotifications.setMessenger(messenger); - - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.REGISTERING, - RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, - null); - - try - { - messenger.login(); - } - catch (UnresolvedAddressException ex) - { - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.CONNECTION_FAILED, - RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND, - null); - } - catch(DnssecRuntimeException ex) - { - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.UNREGISTERED, - RegistrationStateChangeEvent.REASON_USER_REQUEST, - null); - } - } - } - - /** - * Ends the registration of this protocol provider with the service. - */ - public void unregister() - { - unregisterInternal(true); - } - - /* - * (non-Javadoc) - * - * @see net.java.sip.communicator.service.protocol.ProtocolProviderService# - * isSignallingTransportSecure() - */ - public boolean isSignalingTransportSecure() - { - return false; - } - - /** - * Returns the "transport" protocol of this instance used to carry the - * control channel for the current protocol service. - * - * @return The "transport" protocol of this instance: TCP. - */ - public TransportProtocol getTransportProtocol() - { - return TransportProtocol.TCP; - } - - /** - * Unregister and fire the event if requested - * @param fireEvent boolean - */ - void unregisterInternal(boolean fireEvent) - { - RegistrationState currRegState = getRegistrationState(); - - if(fireEvent) - fireRegistrationStateChanged( - currRegState, - RegistrationState.UNREGISTERING, - RegistrationStateChangeEvent.REASON_USER_REQUEST, - null); - - // The synchronization is for logoutReceived at least. - synchronized (initializationLock) - { - if((messenger != null) && !logoutReceived) - messenger.logout(); - - persistentPresence.setMessenger(null); - typingNotifications.setMessenger(null); - } - - // if messenger is null we have already fired unregister - if(fireEvent && messenger != null) - fireRegistrationStateChanged( - currRegState, - RegistrationState.UNREGISTERED, - RegistrationStateChangeEvent.REASON_USER_REQUEST, - null); - } - - /** - * Returns the short name of the protocol that the implementation of this - * provider is based upon (like SIP, Msn, ICQ/AIM, or others for - * example). - * - * @return a String containing the short name of the protocol this - * service is taking care of. - */ - public String getProtocolName() - { - return ProtocolNames.MSN; - } - - /** - * Initialized the service implementation, and puts it in a sate where it - * could interoperate with other services. It is strongly recomended that - * properties in this Map be mapped to property names as specified by - * <tt>AccountProperties</tt>. - * - * @param screenname the account id/uin/screenname of the account that - * we're about to create - * @param accountID the identifier of the account that this protocol - * provider represents. - * - * @see net.java.sip.communicator.service.protocol.AccountID - */ - protected void initialize(String screenname, AccountID accountID) - { - synchronized(initializationLock) - { - this.accountID = accountID; - - addSupportedOperationSet( - OperationSetInstantMessageTransform.class, - new OperationSetInstantMessageTransformImpl()); - - //initialize the presence operationset - persistentPresence = new OperationSetPersistentPresenceMsnImpl(this); - addSupportedOperationSet( - OperationSetPersistentPresence.class, - persistentPresence); - //register it once again for those that simply need presence - addSupportedOperationSet( - OperationSetPresence.class, - persistentPresence); - - //initialize AccountInfo - OperationSetServerStoredAccountInfoMsnImpl accountInfo - = new OperationSetServerStoredAccountInfoMsnImpl( - this, screenname); - addSupportedOperationSet( - OperationSetServerStoredAccountInfo.class, - accountInfo); - addSupportedOperationSet( - OperationSetAvatar.class, - new OperationSetAvatarMsnImpl(this, accountInfo)); - - addSupportedOperationSet( - OperationSetAdHocMultiUserChat.class, - new OperationSetAdHocMultiUserChatMsnImpl(this)); - - // initialize the IM operation set - addSupportedOperationSet( - OperationSetBasicInstantMessaging.class, - new OperationSetBasicInstantMessagingMsnImpl(this)); - - //initialize the typing notifications operation set - typingNotifications - = new OperationSetTypingNotificationsMsnImpl(this); - addSupportedOperationSet( - OperationSetTypingNotifications.class, - typingNotifications); - - addSupportedOperationSet( - OperationSetFileTransfer.class, - new OperationSetFileTransferMsnImpl(this)); - } - } - - /** - * Makes the service implementation close all open sockets and release - * any resources that it might have taken and prepare for - * shutdown/garbage collection. - */ - public void shutdown() - { - synchronized(initializationLock) - { - unregisterInternal(false); - messenger = null; - } - } - - /** - * Returns the AccountID that uniquely identifies the account represented - * by this instance of the ProtocolProviderService. - * @return the id of the account represented by this provider. - */ - public AccountID getAccountID() - { - return accountID; - } - - /** - * Returns the <tt>XMPPConnection</tt>opened by this provider - * @return a reference to the <tt>XMPPConnection</tt> last opened by this - * provider. - */ - MsnMessenger getMessenger() - { - return messenger; - } - - /** - * Creates a RegistrationStateChange event corresponding to the specified - * old and new states and notifies all currently registered listeners. - * - * @param oldState the state that the provider had before the change - * occurred - * @param newState the state that the provider is currently in. - * @param reasonCode a value corresponding to one of the REASON_XXX fields - * of the RegistrationStateChangeEvent class, indicating the reason for - * this state transition. - * @param reason a String further explaining the reason code or null if - * no such explanation is necessary. - */ - @Override - public void fireRegistrationStateChanged(RegistrationState oldState, - RegistrationState newState, - int reasonCode, - String reason) - { - if (newState.equals(RegistrationState.UNREGISTERED) - || newState.equals(RegistrationState.CONNECTION_FAILED)) - messenger = null; - - super.fireRegistrationStateChanged(oldState, newState, reasonCode, reason); - } - - /** - * Listens when we are logged in or out from the server or incoming - * exception in the lib impl. - */ - private class MsnConnectionListener - implements MsnMessengerListener - { - /** - * Fired when login has completed. - * @param msnMessenger - */ - public void loginCompleted(MsnMessenger msnMessenger) - { - if (logger.isTraceEnabled()) - logger.trace("loginCompleted " + msnMessenger.getActualMsnProtocol()); - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.REGISTERED, - RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, - null); - } - - /** - * Fire when lib logs out. - * @param msnMessenger - */ - public void logout(MsnMessenger msnMessenger) - { - if (logger.isTraceEnabled()) - logger.trace("logout"); - - // The synchronization is for logoutReceived at least. - synchronized (initializationLock) - { - logoutReceived = true; - unregisterInternal(true); - } - } - - /** - * Fired when an exception has occurred. - * @param msnMessenger - * @param throwable - */ - public void exceptionCaught(MsnMessenger msnMessenger, - Throwable throwable) - { - if(throwable instanceof IncorrectPasswordException) - { - unregisterInternal(false); - MsnActivator.getProtocolProviderFactory(). - storePassword(getAccountID(), null); - - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.AUTHENTICATION_FAILED, - RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED, - "Incorrect Password"); - - // We try to reconnect and ask user to retype password. - reconnect(SecurityAuthority.WRONG_PASSWORD); - } - else if(throwable instanceof SocketException) - { - // in case of SocketException just fire event and not trigger - // unregister it will cause SocketException again and will loop - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.CONNECTION_FAILED, - RegistrationStateChangeEvent.REASON_INTERNAL_ERROR, - null); - } - else if(throwable instanceof UnknownHostException) - { - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.CONNECTION_FAILED, - RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND, - "A network error occured. Could not connect to server."); - } - else if(throwable instanceof MsnProtocolException) - { - MsnProtocolException exception = - (MsnProtocolException)throwable; - - logger.error("Error in Msn lib ", exception); - - switch(exception.getErrorCode()) - { - case 500: - case 540: - case 601: - if(isRegistered()) - { - unregisterInternal(false); - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.UNREGISTERED, - RegistrationStateChangeEvent.REASON_INTERNAL_ERROR, - null); - } - break; - case 911: - if(isRegistered()) - { - unregisterInternal(false); - MsnActivator.getProtocolProviderFactory(). - storePassword(getAccountID(), null); - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.AUTHENTICATION_FAILED, - RegistrationStateChangeEvent - .REASON_AUTHENTICATION_FAILED, - null); - - // We try to reconnect and ask user to retype - // password. - reconnect(SecurityAuthority.WRONG_PASSWORD); - } - break; - } - } - else - { - logger.error("Error in Msn lib ", throwable); - - if(throwable instanceof LoginException) - { - MsnActivator.getProtocolProviderFactory(). - storePassword(getAccountID(), null); - - fireRegistrationStateChanged( - getRegistrationState(), - RegistrationState.AUTHENTICATION_FAILED, - RegistrationStateChangeEvent - .REASON_AUTHENTICATION_FAILED, - null); - // We try to reconnect and ask user to retype - // password. - reconnect(SecurityAuthority.WRONG_PASSWORD); - } - -// We don't want to disconnect on any error, that's why we're -// commenting the following lines for now. -// -// if(isRegistered()) -// { -// unregister(false); -// fireRegistrationStateChanged( -// getRegistrationState(), -// RegistrationState.UNREGISTERED, -// RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, null); -// } - } - } - } - - /** - * Returns the msn protocol icon. - * @return the msn protocol icon - */ - public ProtocolIcon getProtocolIcon() - { - return msnIcon; - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ReferenceURLStreamHandlerService.java b/src/net/java/sip/communicator/impl/protocol/msn/ReferenceURLStreamHandlerService.java deleted file mode 100644 index b483c92..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/ReferenceURLStreamHandlerService.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.io.*; -import java.net.*; -import java.util.*; - -import net.java.sip.communicator.util.*; - -import org.osgi.framework.*; -import org.osgi.service.url.*; - -/** - * Implements {@link URLStreamHandlerService} for the "reference" - * protocol used inside felix.client.run.properties in order to fix issue #647 - * (MalformedURLException in java-jml) by translating the URL to the - * "jar" protocol which is natively supported by Java. - * - * @author Lubomir Marinov - */ -public class ReferenceURLStreamHandlerService - extends AbstractURLStreamHandlerService -{ - - /** - * The <tt>Logger</tt> instance used by the - * <tt>ReferenceURLStreamHandlerService</tt> class and instances for logging - * output. - */ - private static final Logger logger - = Logger.getLogger(ReferenceURLStreamHandlerService.class); - - /** - * Registers a new <tt>ReferenceURLStreamHandlerService</tt> instance as an - * implementation of {@link URLStreamHandlerService} in a specific - * <tt>BundleContext</tt> for the "reference" protocol if there is - * no such registered implementation already. Otherwise, the existing - * registered implementation is considered to be more complete in terms of - * features than <tt>ReferenceURLStreamHandlerService</tt> and this method - * does nothing. - * - * @param bundleContext the <tt>BundleContext</tt> in which a new - * <tt>ReferenceURLStreamHandlerService</tt> instance is to be registered - */ - public static void registerService(BundleContext bundleContext) - { - ServiceReference[] serviceReferences; - String clazz = URLStreamHandlerService.class.getName(); - String propertyName = URLConstants.URL_HANDLER_PROTOCOL; - String propertyValue = "reference"; - - try - { - serviceReferences - = bundleContext - .getServiceReferences( - clazz, - "(" + propertyName + "=" + propertyValue + ")"); - } - catch (InvalidSyntaxException ise) - { - logger - .warn( - "Failed to determine whether there are registered " - + "URLStreamHandlerService implementations for the " - + "\"reference\" protocol", - ise); - serviceReferences = null; - } - - if ((serviceReferences != null) && (serviceReferences.length > 0)) - return; - - Dictionary<String, String> properties = new Hashtable<String, String>(); - - properties.put(propertyName, propertyValue); - bundleContext - .registerService( - clazz, - new ReferenceURLStreamHandlerService(), - properties); - } - - /** - * Implements <tt>AbstractURLStreamHandlerService#openConnection(URL)</tt>. - * Opens a connection to the object referenced by the <tt>URL</tt> argument - * by rewriting the "reference" protocol in it with the - * "jar" protocol and then handing it for opening to - * {@link JarURLConnection}. - * - * @param url the <tt>URL</tt> that <tt>this</tt> connects to - * @return an <tt>URLConnection</tt> instance for the specified <tt>URL</tt> - * @throws IOException if an I/O error occurs while opening the connection - */ - @Override - public URLConnection openConnection(URL url) - throws IOException - { - String referenceSpec = url.toString(); - String jarSpec = referenceSpec.replaceFirst("reference:", "jar:"); - String jarSeparator = "!/"; - - // JarURLConnection mandates jarSeparator. - if (!jarSpec.contains(jarSeparator)) - jarSpec += jarSeparator; - - return new URL(jarSpec).openConnection(); - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/RootContactGroupMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/RootContactGroupMsnImpl.java deleted file mode 100644 index c0c5b4a..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/RootContactGroupMsnImpl.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; - -/** - * A dummy ContactGroup implementation representing the ContactList root for - * Msn contact lists. - * @author Damian Minkov - * @author Emil Ivov - */ -public class RootContactGroupMsnImpl - extends AbstractContactGroupMsnImpl -{ - private String ROOT_CONTACT_GROUP_NAME = "ContactListRoot"; - private List<ContactGroup> subGroups = new LinkedList<ContactGroup>(); - private boolean isResolved = false; - - private List<Contact> contacts = new LinkedList<Contact>(); - - private final ProtocolProviderServiceMsnImpl protocolProvider; - - /** - * Creates a ContactGroup instance. - */ - RootContactGroupMsnImpl(ProtocolProviderServiceMsnImpl protocolProvider) - { - this.protocolProvider = protocolProvider; - } - - /** - * The ContactListRoot is the only group that can contain subgroups. - * - * @return true (always) - */ - public boolean canContainSubgroups() - { - return true; - } - - /** - * Returns the name of this group which is always - * <tt>ROOT_CONTACT_GROUP_NAME</tt>. - * - * @return a String containing the name of this group. - */ - public String getGroupName() - { - return ROOT_CONTACT_GROUP_NAME; - } - - /** - * Removes the specified contact from this contact group - * @param contact the contact to remove. - */ - void removeContact(ContactMsnImpl contact) - { - contacts.remove(contact); - } - - /** - * Adds the specified contact to the end of this group. - * @param contact the new contact to add to this group - */ - void addContact(ContactMsnImpl contact) - { - contacts.add(contact); - } - - /** - * Adds the specified group to the end of the list of sub groups. - * @param group the group to add. - */ - void addSubGroup(ContactGroupMsnImpl group) - { - subGroups.add(group); - } - - /** - * Removes the specified from the list of sub groups - * @param group the group to remove. - */ - void removeSubGroup(ContactGroupMsnImpl group) - { - removeSubGroup(subGroups.indexOf(group)); - } - - /** - * Removes the sub group with the specified index. - * @param index the index of the group to remove - */ - void removeSubGroup(int index) - { - subGroups.remove(index); - } - - /** - * Returns the number of subgroups contained by this - * <tt>RootContactGroupImpl</tt>. - * - * @return an int indicating the number of subgroups that this - * ContactGroup contains. - */ - public int countSubgroups() - { - return subGroups.size(); - } - - /** - * Returns null as this is the root contact group. - * @return null as this is the root contact group. - */ - public ContactGroup getParentContactGroup() - { - return null; - } - - /** - * Returns the subgroup with the specified index. - * - * @param index the index of the <tt>ContactGroup</tt> to retrieve. - * @return the <tt>ContactGroup</tt> with the specified index. - */ - public ContactGroup getGroup(int index) - { - return subGroups.get(index); - } - - /** - * Returns the subgroup with the specified name. - * @param groupName the name of the <tt>ContactGroup</tt> to retrieve. - * @return the <tt>ContactGroup</tt> with the specified index. - */ - public ContactGroup getGroup(String groupName) - { - Iterator<ContactGroup> subgroups = subgroups(); - while (subgroups.hasNext()) - { - ContactGroup grp = subgroups.next(); - - if (grp.getGroupName().equals(groupName)) - return grp; - } - - return null; - } - - /** - * Returns an iterator over the sub groups that this - * <tt>ContactGroup</tt> contains. - * - * @return a java.util.Iterator over the <tt>ContactGroup</tt> - * children of this group (i.e. subgroups). - */ - public Iterator<ContactGroup> subgroups() - { - return subGroups.iterator(); - } - - /** - * Returns the number, which is always 0, of <tt>Contact</tt> members - * of this <tt>ContactGroup</tt> - * @return an int indicating the number of <tt>Contact</tt>s, members - * of this <tt>ContactGroup</tt>. - */ - public int countContacts() - { - return contacts.size(); - } - - /** - * Returns an Iterator over all contacts, member of this - * <tt>ContactGroup</tt>. - * @return a java.util.Iterator over all contacts inside this - * <tt>ContactGroup</tt> - */ - public Iterator<Contact> contacts() - { - return contacts.iterator(); - } - - /** - * Returns the <tt>Contact</tt> with the specified address or - * identifier. - * @param id the addres or identifier of the <tt>Contact</tt> we are - * looking for. - * @return the <tt>Contact</tt> with the specified id or address. - */ - public Contact getContact(String id) - { - //no contacts in the root group for this msn impl. - return null; - } - - - /** - * Returns a string representation of the root contact group that contains - * all subgroups and subcontacts of this group. - * - * @return a string representation of this root contact group. - */ - @Override - public String toString() - { - StringBuffer buff = new StringBuffer(getGroupName()); - buff.append(".subGroups=" + countSubgroups() + ":\n"); - - Iterator<ContactGroup> subGroups = subgroups(); - while (subGroups.hasNext()) - { - ContactGroup group = subGroups.next(); - buff.append(group.toString()); - if (subGroups.hasNext()) - buff.append("\n"); - } - return buff.toString(); - } - - /** - * Returns the protocol provider that this group belongs to. - * @return a regerence to the ProtocolProviderService instance that this - * ContactGroup belongs to. - */ - public ProtocolProviderService getProtocolProvider() - { - return protocolProvider; - } - - /** - * Determines whether or not this contact group is being stored by the - * server. Non persistent contact groups exist for the sole purpose of - * containing non persistent contacts. - * @return true if the contact group is persistent and false otherwise. - */ - public boolean isPersistent() - { - return true; - } - - /** - * Returns null as no persistent data is required and the group name is - * sufficient for restoring the contact. - * <p> - * @return null as no such data is needed. - */ - public String getPersistentData() - { - return null; - } - - /** - * Determines whether or not this group has been resolved against the - * server. Unresolved groups are used when initially loading a contact - * list that has been stored in a local file until the presence operation - * set has managed to retrieve all the contact list from the server and has - * properly mapped groups to their on-line buddies. - * @return true if the group has been resolved (mapped against a buddy) - * and false otherwise. - */ - public boolean isResolved() - { - return isResolved; - } - - /** - * Returns a <tt>String</tt> that uniquely represnets the group. In this we - * use the name of the group as an identifier. This may cause problems - * though, in clase the name is changed by some other application between - * consecutive runs of the sip-communicator. - * - * @return a String representing this group in a unique and persistent - * way. - */ - public String getUID() - { - return getGroupName(); - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java b/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java deleted file mode 100644 index bbae5be..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/ServerStoredContactListMsnImpl.java +++ /dev/null @@ -1,1484 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import java.util.*; - -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; -import net.java.sip.communicator.util.*; -import net.sf.jml.*; -import net.sf.jml.impl.*; -import net.sf.jml.message.p2p.*; - -/** - * This class encapsulates the Roster class. Once created, it will - * register itself as a listener to the encapsulated Roster and modify it's - * local copy of Contacts and ContactGroups every time an event is generated - * by the underlying framework. The class would also generate - * corresponding sip-communicator events to all events coming from smack. - * - * @author Damian Minkov - * @author Emil Ivov - */ -public class ServerStoredContactListMsnImpl -{ - private static final Logger logger = - Logger.getLogger(ServerStoredContactListMsnImpl.class); - - /** - * The root group. The container for all msn buddies and groups. - */ - private final RootContactGroupMsnImpl rootGroup; - - /** - * The operation set that created us and that we could use when dispatching - * subscription events. - */ - private OperationSetPersistentPresenceMsnImpl parentOperationSet = null; - - /** - * The provider that is on top of us. - */ - private final ProtocolProviderServiceMsnImpl msnProvider; - - private MsnMessenger messenger = null; - - /** - * Listeners that would receive event notifications for changes in group - * names or other properties, removal or creation of groups. - */ - private Vector<ServerStoredGroupListener> serverStoredGroupListeners - = new Vector<ServerStoredGroupListener>(); - - /** - * Manages and fires contact list modifications - */ - private EventManager contactListModManager = null; - - private ContactListModListenerImpl contactListModListenerImpl - = new ContactListModListenerImpl(); - - /** - * indicates whether or not the contactlist is initialized and ready. - */ - private boolean isInitialized = false; - - private Vector<String> skipAddEvent = new Vector<String>(); - - /** - * Contact list listener. - */ - ContactListListener contactListListener = null; - - /** - * Creates a ServerStoredContactList wrapper for the specified BuddyList. - * - * @param parentOperationSet the operation set that created us and that - * we could use for dispatching subscription events - * @param provider the provider that has instantiated us. - */ - ServerStoredContactListMsnImpl( - OperationSetPersistentPresenceMsnImpl parentOperationSet, - ProtocolProviderServiceMsnImpl provider) - { - //We need to init these as early as possible to ensure that the provider - //and the operationsset would not be null in the incoming events. - this.parentOperationSet = parentOperationSet; - - this.msnProvider = provider; - this.rootGroup = new RootContactGroupMsnImpl(this.msnProvider); - - // listens for provider registered events to set the isInitialized state - // of the contact list - provider.addRegistrationStateChangeListener( - new RegistrationStateChangeListener() - { - public void registrationStateChanged( - RegistrationStateChangeEvent evt) - { - if (evt.getNewState() == RegistrationState.UNREGISTERED - || evt.getNewState() - == RegistrationState.AUTHENTICATION_FAILED - || evt.getNewState() - == RegistrationState.CONNECTION_FAILED) - { - isInitialized = false; - } - } - } - ); - } - - /** - * Returns the root group of the contact list. - * - * @return the root ContactGroup for the ContactList - */ - public ContactGroup getRootGroup() - { - return rootGroup; - } - - /** - * Registers the specified group listener so that it would receive events - * on group modification/creation/destruction. - * @param listener the ServerStoredGroupListener to register for group - * events - */ - void addGroupListener(ServerStoredGroupListener listener) - { - synchronized(serverStoredGroupListeners) - { - if(!serverStoredGroupListeners.contains(listener)) - this.serverStoredGroupListeners.add(listener); - } - } - - /** - * Removes the specified group listener so that it won't receive further - * events on group modification/creation/destruction. - * @param listener the ServerStoredGroupListener to unregister - */ - void removeGroupListener(ServerStoredGroupListener listener) - { - synchronized(serverStoredGroupListeners) - { - this.serverStoredGroupListeners.remove(listener); - } - } - - /** - * Creates the corresponding event and notifies all - * <tt>ServerStoredGroupListener</tt>s that the source group has been - * removed, changed, renamed or whatever happened to it. - * @param group the ContactGroup that has been created/modified/removed - * @param eventID the id of the event to generate. - */ - private void fireGroupEvent(ContactGroupMsnImpl group, int eventID) - { - //bail out if no one's listening - if(parentOperationSet == null){ - if (logger.isDebugEnabled()) - logger.debug("No presence op. set available. Bailing out."); - return; - } - - ServerStoredGroupEvent evt = new ServerStoredGroupEvent( - group - , eventID - , parentOperationSet.getServerStoredContactListRoot() - , msnProvider - , parentOperationSet); - - if (logger.isTraceEnabled()) - logger.trace("Will dispatch the following grp event: " + evt); - - Iterator<ServerStoredGroupListener> listeners = null; - synchronized (serverStoredGroupListeners) - { - listeners = new ArrayList<ServerStoredGroupListener>( - serverStoredGroupListeners).iterator(); - } - - while (listeners.hasNext()) - { - ServerStoredGroupListener listener = listeners.next(); - - if (eventID == ServerStoredGroupEvent.GROUP_REMOVED_EVENT) - listener.groupRemoved(evt); - else if (eventID == ServerStoredGroupEvent.GROUP_RENAMED_EVENT) - listener.groupNameChanged(evt); - else if (eventID == ServerStoredGroupEvent.GROUP_CREATED_EVENT) - listener.groupCreated(evt); - else if (eventID == ServerStoredGroupEvent.GROUP_RESOLVED_EVENT) - listener.groupResolved(evt); - } - } - - /** - * Make the parent persistent presence operation set dispatch a contact - * removed event. - * @param parentGroup the group where that the removed contact belonged to. - * @param contact the contact that was removed. - */ - private void fireContactRemoved( ContactGroup parentGroup, - ContactMsnImpl contact) - { - //bail out if no one's listening - if(parentOperationSet == null){ - if (logger.isDebugEnabled()) - logger.debug("No presence op. set available. Bailing out."); - return; - } - - //dispatch - parentOperationSet.fireSubscriptionEvent( - contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_REMOVED); - } - - /** - * Make the parent persistent presence operation set dispatch a subscription - * moved event. - * @param oldParentGroup the group where the source contact was located - * before being moved - * @param newParentGroup the group that the source contact is currently in. - * @param contact the contact that was added - */ - private void fireContactMoved( ContactGroup oldParentGroup, - ContactGroup newParentGroup, - ContactMsnImpl contact) - { - //bail out if no one's listening - if(parentOperationSet == null){ - if (logger.isDebugEnabled()) - logger.debug("No presence op. set available. Bailing out."); - return; - } - - //dispatch - parentOperationSet.fireSubscriptionMovedEvent( - contact, oldParentGroup, newParentGroup); - } - - /** - * Returns a reference to the provider that created us. - * @return a reference to a ProtocolProviderServiceImpl instance. - */ - ProtocolProviderServiceMsnImpl getParentProvider() - { - return msnProvider; - } - - /** - * Returns the ConntactGroup with the specified name or null if no such - * group was found. - * <p> - * @param name the name of the group we're looking for. - * @return a reference to the ContactGroupMsnImpl instance we're looking for - * or null if no such group was found. - */ - public ContactGroupMsnImpl findContactGroup(String name) - { - Iterator<ContactGroup> contactGroups = rootGroup.subgroups(); - - while(contactGroups.hasNext()) - { - ContactGroup contactGroup = contactGroups.next(); - - if (contactGroup.getGroupName().equals(name)) - return (ContactGroupMsnImpl)contactGroup; - } - - return null; - } - - /** - * Returns the Contact with the specified id or null if - * no such id was found. - * - * @param id the id of the contact to find. - * @return the <tt>Contact</tt> carrying the specified - * <tt>screenName</tt> or <tt>null</tt> if no such contact exits. - */ - public ContactMsnImpl findContactById(String id) - { - Iterator<ContactGroup> contactGroups = rootGroup.subgroups(); - ContactMsnImpl result = null; - - while(contactGroups.hasNext()) - { - ContactGroupMsnImpl contactGroup - = (ContactGroupMsnImpl)contactGroups.next(); - - result = contactGroup.findContact(id); - - if (result != null) - return result; - - } - - Iterator<Contact> rootContacts = rootGroup.contacts(); - while (rootContacts.hasNext()) - { - Contact item = rootContacts.next(); - - if(item.getAddress().equals(id)) - return (ContactMsnImpl)item; - } - - return null; - } - - /** - * Returns the ContactGroup containing the specified contact or null - * if no such group or contact exist. - * - * @param child the contact whose parent group we're looking for. - * @return the <tt>ContactGroup</tt> containing the specified - * <tt>contact</tt> or <tt>null</tt> if no such group or contact - * exist. - */ - public ContactGroup findContactGroup(ContactMsnImpl child) - { - Iterator<ContactGroup> contactGroups = rootGroup.subgroups(); - - while(contactGroups.hasNext()) - { - ContactGroupMsnImpl contactGroup - = (ContactGroupMsnImpl)contactGroups.next(); - - if( contactGroup.findContact(child.getAddress())!= null) - return contactGroup; - } - - Iterator<Contact> contacts = rootGroup.contacts(); - - while(contacts.hasNext()) - { - Contact contact = contacts.next(); - - if( contact.equals(child)) - return rootGroup; - } - - return null; - } - - /** - * Adds a new contact with the specified screenname to the list under a - * default location. - * @param id the id of the contact to add. - * @throws OperationFailedException - */ - public void addContact(String id) - throws OperationFailedException - { - addContact(null, id); - } - - /** - * Adds a new contact with the specified screenname to the list under the - * specified group. - * @param id the id of the contact to add. - * @param parent the group under which we want the new contact placed. - * @throws OperationFailedException if the contact already exist - */ - public void addContact(final ContactGroupMsnImpl parent, final String id) - throws OperationFailedException - { - if (logger.isTraceEnabled()) - logger.trace("Adding contact " + id + " to parent=" + parent); - - //if the contact is already in the contact list and is not volatile, - //then only broadcast an event - ContactMsnImpl existingContact = findContactById(id); - - if( existingContact != null - && existingContact.isPersistent() ) - { - if (logger.isDebugEnabled()) - logger.debug("Contact " + id + " already exists."); - throw new OperationFailedException( - "Contact " + id + " already exists.", - OperationFailedException.SUBSCRIPTION_ALREADY_EXISTS); - } - - if(parent != null) - { - // add the buddy to the list as its not there - msnProvider.getMessenger().unblockFriend(Email.parseStr(id)); - skipAddEvent.add(id); - msnProvider.getMessenger().addFriend(Email.parseStr(id), id); - msnProvider.getMessenger().copyFriend( - Email.parseStr(id), - parent.getSourceGroup().getGroupId()); - } - else - { - // add the buddy to the list as its not there -// msnProvider.getMessenger().unblockFriend(Email.parseStr(id)); - msnProvider.getMessenger().addFriend(Email.parseStr(id), id); - } - } - - /** - * Creates a non persistent contact for the specified address. This would - * also create (if necessary) a group for volatile contacts that would not - * be added to the server stored contact list. This method would have no - * effect on the server stored contact list. - * @param contact the address of the contact to create. - * @return the newly created volatile <tt>ContactImpl</tt> - */ - ContactMsnImpl createVolatileContact(MsnContact contact) - { - return - createVolatileContact( - contact.getId(), - contact.getEmail(), - contact.getDisplayName()); - } - - /** - * Creates a non persistent contact for the specified address. This would - * also create (if necessary) a group for volatile contacts that would not - * be added to the server stored contact list. This method would have no - * effect on the server stored contact list. - * - * @param id the id of the contact to create - * @param email the e-mail address of the contact to create - * @param displayName the display name of the contact to create - * @return the newly created volatile <tt>ContactImpl</tt> - */ - ContactMsnImpl createVolatileContact( - String id, - Email email, - String displayName) - { - //First create the new volatile contact; - VolatileContact volatileBuddy - = new VolatileContact(id, email, displayName); - ContactMsnImpl newVolatileContact - = new ContactMsnImpl(volatileBuddy, this, false, false); - - //Check whether a volatile group already exists and if not create one. - ContactGroupMsnImpl theVolatileGroup = getNonPersistentGroup(); - - //if the parent group is null then add necessary create the group - if (theVolatileGroup == null) - { - MsnContact[] emptyBuddies = new MsnContact[]{}; - - theVolatileGroup = new ContactGroupMsnImpl( - new VolatileGroup(), emptyBuddies, this, false, false); - theVolatileGroup.addContact(newVolatileContact); - - this.rootGroup.addSubGroup(theVolatileGroup); - - fireGroupEvent(theVolatileGroup, - ServerStoredGroupEvent.GROUP_CREATED_EVENT); - } - else - { - theVolatileGroup.addContact(newVolatileContact); - fireContactAdded(theVolatileGroup, newVolatileContact); - } - - return newVolatileContact; - } - - - /** - * Creates a non resolved contact for the specified address and inside the - * specified group. The newly created contact would be added to the local - * contact list as a standard contact but when an event is received from the - * server concerning this contact, then it will be reused and only its - * isResolved field would be updated instead of creating the whole contact - * again. - * - * @param parentGroup the group where the unresolved contact is to be - * created - * @param id the Address of the contact to create. - * @return the newly created unresolved <tt>ContactImpl</tt> - */ - ContactMsnImpl createUnresolvedContact(ContactGroup parentGroup, String id) - { - //First create the new volatile contact; - VolatileContact volatileBuddy = new VolatileContact(id); - - ContactMsnImpl newUnresolvedContact - = new ContactMsnImpl(volatileBuddy, this, false, false); - - if(parentGroup instanceof ContactGroupMsnImpl) - ((ContactGroupMsnImpl)parentGroup). - addContact(newUnresolvedContact); - else if(parentGroup instanceof RootContactGroupMsnImpl) - ((RootContactGroupMsnImpl)parentGroup). - addContact(newUnresolvedContact); - - fireContactAdded( parentGroup - , newUnresolvedContact); - - return newUnresolvedContact; - } - - /** - * Creates a non resolved contact group for the specified name. The newly - * created group would be added to the local contact list as any other group - * but when an event is received from the server concerning this group, then - * it will be reused and only its isResolved field would be updated instead - * of creating the whole group again. - * <p> - * @param groupName the name of the group to create. - * @return the newly created unresolved <tt>ContactGroupImpl</tt> - */ - ContactGroupMsnImpl createUnresolvedContactGroup(String groupName) - { - //First create the new volatile contact; - MsnContact[] emptyBuddies = new MsnContact[]{}; - ContactGroupMsnImpl newUnresolvedGroup = new ContactGroupMsnImpl( - new VolatileGroup(groupName), emptyBuddies, this, false, true); - - this.rootGroup.addSubGroup(newUnresolvedGroup); - - fireGroupEvent(newUnresolvedGroup - , ServerStoredGroupEvent.GROUP_CREATED_EVENT); - - return newUnresolvedGroup; - } - - /** - * Creates the specified group on the server stored contact list. - * @param groupName a String containing the name of the new group. - * @throws OperationFailedException with code CONTACT_GROUP_ALREADY_EXISTS - * if the group we're trying to create is already in our contact list. - */ - public void createGroup(String groupName) - throws OperationFailedException - { - if (logger.isTraceEnabled()) - logger.trace("Creating group: " + groupName); - - ContactGroupMsnImpl existingGroup = findContactGroup(groupName); - - if( existingGroup != null && existingGroup.isPersistent() ) - { - if (logger.isDebugEnabled()) - logger.debug("ContactGroup " + groupName + " already exists."); - throw new OperationFailedException( - "ContactGroup " + groupName + " already exists.", - OperationFailedException.CONTACT_GROUP_ALREADY_EXISTS); - } - - msnProvider.getMessenger().addGroup(groupName); - } - - /** - * Removes the specified group from the buddy list. - * @param groupToRemove the group that we'd like removed. - */ - public void removeGroup(ContactGroupMsnImpl groupToRemove) - { - // there is a default group in the msn lib. we cannot remove it - // as server doesn't know about it - if(groupToRemove.getSourceGroup().getGroupId().equals("0")) - return; - - if (logger.isTraceEnabled()) - logger.trace("removing group " + groupToRemove); - MsnContact[] contacts = groupToRemove.getSourceGroup().getContacts(); - - ModListenerRemoveGroup removedContactsListener = - new ModListenerRemoveGroup(contacts.length); - contactListModManager.addModificationListener(removedContactsListener); - - for (int i = 0; i < contacts.length; i++) - { - if (logger.isTraceEnabled()) - logger.trace("removing contact from group " + contacts[i]); - - msnProvider.getMessenger().removeFriend(contacts[i].getEmail(), - groupToRemove.getSourceGroup().getGroupId()); - } - - // wait max seconds or the last removed contact - removedContactsListener.waitForLastEvent(contacts.length*1000); - contactListModManager.removeModificationListener(removedContactsListener); - - msnProvider.getMessenger(). - removeGroup(groupToRemove.getSourceGroup().getGroupId()); - } - - /** - * Removes a contact from the serverside list - * Event will come for successful operation - * @param contactToRemove ContactMsnImpl - */ - void removeContact(ContactMsnImpl contactToRemove) - { - if (logger.isTraceEnabled()) - logger.trace("Removing msn contact " - + contactToRemove.getSourceContact()); - - Email contactsEmail = contactToRemove.getSourceContact().getEmail(); - - MsnGroup[] belongGroups = - contactToRemove.getSourceContact().getBelongGroups(); - if(belongGroups != null) - for (int i = 0; i < belongGroups.length; i++) - { - msnProvider.getMessenger(). - removeFriend(contactsEmail, belongGroups[i].getGroupId()); - } - - msnProvider.getMessenger(). - removeFriend(contactsEmail, false); - } - - - /** - * Renames the specified group according to the specified new name.. - * @param groupToRename the group that we'd like removed. - * @param newName the new name of the group - */ - public void renameGroup(ContactGroupMsnImpl groupToRename, String newName) - { - //printList(); - msnProvider.getMessenger(). - renameGroup(groupToRename.getSourceGroup().getGroupId(), newName); - } - - /** - * Moves the specified <tt>contact</tt> to the group indicated by - * <tt>newParent</tt>. - * @param contact the contact that we'd like moved under the new group. - * @param newParent the group where we'd like the parent placed. - */ - public void moveContact(ContactMsnImpl contact, - ContactGroup newParent) - { - ContactGroup oldParent = contact.getParentContactGroup(); - - if(oldParent instanceof RootContactGroupMsnImpl) - { - if (logger.isTraceEnabled()) - logger.trace("Will Move from root " + contact); - msnProvider.getMessenger(). - copyFriend( - contact.getSourceContact().getEmail(), - ((ContactGroupMsnImpl)newParent).getSourceGroup() - .getGroupId()); - } - else - { - if(newParent instanceof RootContactGroupMsnImpl && - !contact.isPersistent()) - { - try - { - addContact(contact.getAddress()); - } - catch (OperationFailedException ex) - { - logger.error("Failed to add contact from " + - MsnActivator.getResources().getI18NString( - "service.gui.NOT_IN_CONTACT_LIST_GROUP_NAME") + - " group to new group: " + newParent, ex); - } - - return; - } - - if( !contact.isPersistent() && - !contact.getParentContactGroup().isPersistent()) - { - try - { - addContact( - (ContactGroupMsnImpl)newParent, contact.getAddress()); - } - catch (OperationFailedException ex) - { - logger.error("Failed to add contact from " + - MsnActivator.getResources().getI18NString( - "service.gui.NOT_IN_CONTACT_LIST_GROUP_NAME") + - " group to new group: " + newParent, ex); - } - } - else - { - if (logger.isTraceEnabled()) - logger.trace("Will Move from " - + contact.getParentContactGroup() - + " to : " + newParent + " - contact: " + contact); -// contactListModListenerImpl.waitForMove(contact.getAddress()); - msnProvider.getMessenger().moveFriend( - contact.getSourceContact().getEmail(), - ( (ContactGroupMsnImpl) contact.getParentContactGroup()). - getSourceGroup().getGroupId(), - ((ContactGroupMsnImpl)newParent).getSourceGroup() - .getGroupId()); - } - } - } - - /** - * Returns the volatile group - * - * @return ContactGroupMsnImpl - */ - private ContactGroupMsnImpl getNonPersistentGroup() - { - for (int i = 0; i < getRootGroup().countSubgroups(); i++) - { - ContactGroupMsnImpl gr = - (ContactGroupMsnImpl)getRootGroup().getGroup(i); - - if(!gr.isPersistent()) - return gr; - } - - return null; - } - - /** - * Finds Group by provided its msn ID - * @param id String - * @return ContactGroupMsnImpl - */ - private ContactGroupMsnImpl findContactGroupByMsnId(String id) - { - Iterator<ContactGroup> contactGroups = rootGroup.subgroups(); - - while(contactGroups.hasNext()) - { - ContactGroupMsnImpl contactGroup - = (ContactGroupMsnImpl)contactGroups.next(); - - if (contactGroup.getSourceGroup().getGroupId().equals(id)) - return contactGroup; - } - - return null; - } - - /** - * Make the parent persistent presence operation set dispatch a contact - * added event. - * @param parentGroup the group where the new contact was added - * @param contact the contact that was added - */ - void fireContactAdded( ContactGroup parentGroup, - ContactMsnImpl contact) - { - //bail out if no one's listening - if(parentOperationSet == null){ - if (logger.isDebugEnabled()) - logger.debug("No presence op. set available. Bailing out."); - return; - } - - //dispatch - parentOperationSet.fireSubscriptionEvent( - contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_CREATED); - - // sometimes when adding msn contact - // status updates comes before event for adding contact and so - // statuses are not dispatched, we check this here - MsnUserStatus msnStatus = - contact.getSourceContact().getStatus(); - - // for some reason when creating unresolved contact this status is null - if(msnStatus == null) - return; - - PresenceStatus oldStatus - = contact.getPresenceStatus(); - - PresenceStatus newStatus - = parentOperationSet.msnStatusToPresenceStatus( - contact.getSourceContact().getStatus()); - - if(oldStatus.equals(newStatus)) - return; - - contact.updatePresenceStatus(newStatus); - - parentOperationSet.fireContactPresenceStatusChangeEvent( - contact, - parentGroup, - oldStatus, - newStatus - ); - } - - /** - * Make the parent persistent presence operation set dispatch a contact - * resolved event. - * @param parentGroup the group that the resolved contact belongs to. - * @param contact the contact that was resolved - */ - void fireContactResolved( ContactGroup parentGroup, - ContactMsnImpl contact) - { - //bail out if no one's listening - if(parentOperationSet == null){ - if (logger.isDebugEnabled()) - logger.debug("No presence op. set available. Bailing out."); - return; - } - - //dispatch - parentOperationSet.fireSubscriptionEvent( - contact, parentGroup, SubscriptionEvent.SUBSCRIPTION_RESOLVED); - } - - /** - * Returns true if the contact list is initialized and - * ready for use, and false otherwise. - * - * @return true if the contact list is initialized and ready for use and - * false otherwise - */ - boolean isInitialized() - { - return isInitialized; - } - - /** - * Changes the contact display name on the server. - * @param contact the contact to change, - * @param newName the new name. - */ - void setDisplayName(ContactMsnImpl contact, String newName) - { - messenger.renameFriend(contact.getSourceContact().getEmail(), newName); - } - - /** - * Waits for init in the contact list and populates the contacts and fills - * or resolves our contact list - */ - private class ContactListListener - implements net.sf.jml.event.MsnContactListListener - { - public void contactPersonalMessageChanged(MsnMessenger messenger , - MsnContact contact) - { - ContactMsnImpl contactImpl = - findContactById(contact.getEmail().getEmailAddress()); - - if (contactImpl == null) - return; - - contactImpl.setStatusMessage(contact.getPersonalMessage()); - } - - public void contactListSyncCompleted(MsnMessenger messenger) - { - } - - public void contactListInitCompleted(MsnMessenger messenger) - { - if (logger.isTraceEnabled()) - logger.trace("contactListInitCompleted"); - isInitialized = true; - - if(logger.isDebugEnabled()) - printList(); - - // first init groups - MsnContactList contactList = messenger.getContactList(); - MsnGroup[] groups = contactList.getGroups(); - for (int i = 0; i < groups.length; i++) - { - MsnGroup item = groups[i]; - - if(item.isDefaultGroup()) - continue; - - ContactGroupMsnImpl group - = findContactGroup(item.getGroupName()); - - if (group == null) - { - // create the group as it doesn't exist - ContactGroupMsnImpl newGroup = - new ContactGroupMsnImpl( - item, - item.getContacts(), - ServerStoredContactListMsnImpl.this, - true, - true); - - rootGroup.addSubGroup(newGroup); - - //tell listeners about the added group - fireGroupEvent(newGroup, - ServerStoredGroupEvent.GROUP_CREATED_EVENT); - } - else - { - // the group exist so just resolved. The group will check and - // create or resolve its entries - group.setResolved(item); - - //fire an event saying that the group has been resolved - fireGroupEvent(group, - ServerStoredGroupEvent.GROUP_RESOLVED_EVENT); - - /** @todo if something to delete . delete it */ - } - } - - // so all groups and its contacts are created - // lets create the users that are not in a group - MsnContact[] contacts = - messenger.getContactList().getContactsInList(MsnList.FL); - for (int i = 0; i < contacts.length; i++) - { - MsnContact item = contacts[i]; - - if(item.getBelongGroups().length == 0) - { - ContactMsnImpl contact = - findContactById(item.getEmail().getEmailAddress()); - - if (contact == null) - { - // if there is no such contact create it - contact = new ContactMsnImpl( - item, - ServerStoredContactListMsnImpl.this, - true, - true); - rootGroup.addContact(contact); - - fireContactAdded(rootGroup, contact); - } - else - { - // if contact exist so resolve it - contact.setResolved(item); - } - } - } - - // if we have received status before we have inited the list - // sho them correctly - parentOperationSet.earlyStatusesDispatch(); - - // retreive offline messages - messenger.retreiveOfflineMessages(); - } - - public void contactStatusChanged(MsnMessenger messenger, - MsnContact contact) - { - } - - public void ownerStatusChanged(MsnMessenger messenger) - { - } - - public void contactAddedMe(MsnMessenger messenger, - MsnContactPending[] pendingContacts) - { - if (logger.isTraceEnabled()) - logger.trace("Contact add us "); - /** - * TODO this method introduced for msn15 currently used. - * the old one below no more used. - */ - } - - public void contactAddedMe(MsnMessenger messenger, MsnContact contact) - { -// try -// { - if (logger.isTraceEnabled()) - logger.trace("Contact add us " + contact); - - if(parentOperationSet.getAuthorizationHandler() == null) - return; - - ContactMsnImpl contactImpl = - findContactById(contact.getEmail().getEmailAddress()); - - if (contactImpl != null) - return; - - contactImpl = createVolatileContact(contact); - - AuthorizationRequest authRequest = new AuthorizationRequest(); - - AuthorizationResponse authResponse = - parentOperationSet.getAuthorizationHandler() - .processAuthorisationRequest( authRequest, contactImpl); - - if (authResponse.getResponseCode() - == AuthorizationResponse.IGNORE) - { - return; - } - else if (authResponse.getResponseCode() - == AuthorizationResponse.REJECT) - { - msnProvider.getMessenger().blockFriend(contact.getEmail()); - } - else if (authResponse.getResponseCode() - == AuthorizationResponse.ACCEPT) - { - moveContact(contactImpl, rootGroup); -// addContact(contact.getEmail().getEmailAddress()); -// msnProvider.getMessenger() -// .unblockFriend(contact.getEmail()); - } -// } -// catch (OperationFailedException ex) -// { -// logger.error("cannot add ", ex); -// } - } - - public void contactRemovedMe(MsnMessenger messenger, MsnContact contact) - { - } - - public void contactAddCompleted(MsnMessenger messenger, - MsnContact contact, - MsnList list) - { - String contactID = contact.getEmail().getEmailAddress(); - - if(!skipAddEvent.remove(contactID)) - { - ContactMsnImpl contactToAdd = - findContactById(contact.getEmail().getEmailAddress()); - - if(contactToAdd == null) - { - contactToAdd = - new ContactMsnImpl( - contact, - ServerStoredContactListMsnImpl.this, true, true); - rootGroup.addContact(contactToAdd); - fireContactAdded(rootGroup, contactToAdd); - } - else - { - ContactGroup oldGroup = contactToAdd.getParentContactGroup(); - - fireContactMoved(oldGroup, rootGroup, contactToAdd); - } - } - } - - public void contactRemoveCompleted(MsnMessenger messenger, - MsnContact contact, - MsnList list) - { - ContactMsnImpl contactToRemove = - findContactById(contact.getEmail().getEmailAddress()); - - if(contactToRemove == null) - { - if (logger.isTraceEnabled()) - logger.trace("Contact not found!" + contact); - return; - } - - if(contactToRemove.getParentContactGroup() - instanceof RootContactGroupMsnImpl) - { - rootGroup.removeContact(contactToRemove); - fireContactRemoved(rootGroup, contactToRemove); - } - else - { - ContactGroupMsnImpl parentGroup = (ContactGroupMsnImpl) - contactToRemove.getParentContactGroup(); - parentGroup.removeContact(contactToRemove); - fireContactRemoved(parentGroup, contactToRemove); - } - } - - public void groupAddCompleted(MsnMessenger messenger, MsnGroup group) - { - if (logger.isTraceEnabled()) - logger.trace("groupAdded " + group); - ContactGroupMsnImpl newGroup = - new ContactGroupMsnImpl(group, - new MsnContact[]{}, - ServerStoredContactListMsnImpl.this, - true, - true); - - rootGroup.addSubGroup(newGroup); - fireGroupEvent(newGroup, ServerStoredGroupEvent.GROUP_CREATED_EVENT); - } - public void groupRemoveCompleted(MsnMessenger messenger, MsnGroup g) - { - ContactGroupMsnImpl group = findContactGroupByMsnId(g.getGroupId()); - - if(group == null) - { - if (logger.isTraceEnabled()) - logger.trace("Group not found!" + g); - return; - } - - rootGroup.removeSubGroup(group); - fireGroupEvent(group, ServerStoredGroupEvent.GROUP_REMOVED_EVENT); - } - - /** - * Called when a contact has been added to a group. Note that this - * method would also be called after moving a contact. - * - * @param messenger a reference to the currently valid messenger - * @param c the contact that has been added - * @param g the group that the contact was added to - */ - public void contactAddInGroupCompleted( MsnMessenger messenger, - MsnContact c, - MsnGroup g) - { - ContactMsnImpl contactToAdd = - findContactById(c.getEmail().getEmailAddress()); - - if(contactToAdd == null) - { - //this is really a new contact - contactToAdd = - new ContactMsnImpl( - c, - ServerStoredContactListMsnImpl.this, true, true); - - ContactGroupMsnImpl group = - findContactGroupByMsnId(g.getGroupId()); - - if(group == null) - { - logger.error("Group is missing!"); - return; - } - - group.addContact(contactToAdd); - - fireContactAdded(group, contactToAdd); - } - else - { - //the contact was added here. - ContactGroup oldGroup = - contactToAdd.getParentContactGroup(); - - ContactGroupMsnImpl group = - findContactGroupByMsnId(g.getGroupId()); - - if(group == null) - { - logger.error("Group is missing!"); - return; - } - - group.addContact(contactToAdd); - - - if(oldGroup instanceof RootContactGroupMsnImpl) - { - ((RootContactGroupMsnImpl)oldGroup) - .removeContact(contactToAdd); - } - else - { - ((ContactGroupMsnImpl)oldGroup).removeContact(contactToAdd); - } - - fireContactMoved(oldGroup, group, contactToAdd); - } - } - - public void contactRemoveFromGroupCompleted(MsnMessenger messenger, - MsnContact c, MsnGroup g) - { - String contactID = c.getEmail().getEmailAddress(); - ContactMsnImpl contactToRemove = findContactById(contactID); - - if(g == null) - { - if (logger.isTraceEnabled()) - logger.trace("Group is null! "); - return; - } - - ContactGroupMsnImpl dstGroup = - findContactGroupByMsnId(g.getGroupId()); - - if(contactToRemove == null) - { - if (logger.isTraceEnabled()) - logger.trace("Contact not found " + c); - return; - } - - if(dstGroup == null) - { - if (logger.isTraceEnabled()) - logger.trace("Group not found " + g); - return; - } - - //make sure that the contact was really in the group because when - //moving contacts with multiple parent groups we get multiple - //removal events. That's a problem because we don't support multiple - //parent groups and we only show a single parent so all remove - //events for the parent groups we are not displaying will cause - //exceptions - if(dstGroup.removeContact(contactToRemove)) - fireContactRemoved(dstGroup, contactToRemove); - } - - public void ownerDisplayNameChanged(MsnMessenger arg0) - { - } - } - - /** - * Waits for removing a group - */ - private static class ModListenerRemoveGroup - extends EventAdapter - { - private int contactCount = 0; - - public ModListenerRemoveGroup(int c) - { - this.contactCount = c; - } - - public void contactRemoved(MsnContact contact) - { - synchronized(this) - { - contactCount--; - - if(contactCount == 0) - notifyAll(); - } - } - - public void waitForLastEvent(long waitFor) - { - synchronized(this) - { - if(contactCount == 0) - return; - - try{ - wait(waitFor); - } - catch (InterruptedException ex) - { - if (logger.isDebugEnabled()) - logger.debug( - "Interrupted while waiting for a subscription evt", ex); - } - } - } - } - - /** - * Emulates firing adding contact in group and moving contact to group. - * When moving contact it is first adding to the new group then - * it is removed from the old one. - */ - private class ContactListModListenerImpl - extends EventAdapter - { - @Override - public void groupRenamed(MsnGroup group) - { - ContactGroupMsnImpl groupToRename = - findContactGroupByMsnId(group.getGroupId()); - - if(groupToRename == null) - { - if (logger.isTraceEnabled()) - logger.trace("Group not found!" + group); - return; - } - - groupToRename.setSourceGroup(group); - - fireGroupEvent(groupToRename, - ServerStoredGroupEvent.GROUP_RENAMED_EVENT); - } - - @Override - public void loggingFromOtherLocation() - { - msnProvider.unregisterInternal(false); - msnProvider.fireRegistrationStateChanged( - msnProvider.getRegistrationState(), - RegistrationState.UNREGISTERED, - RegistrationStateChangeEvent.REASON_MULTIPLE_LOGINS, null); - } - } - - /** - * Sets the messenger instance impl of the lib - * which communicates with the server - * @param messenger MsnMessenger - */ - void setMessenger(MsnMessenger messenger) - { - if (this.messenger == messenger) - return; - - if (this.messenger != null) - { - if (contactListModManager != null) - { - contactListModManager.removeModificationListener( - contactListModListenerImpl); - contactListModManager = null; - } - if (contactListListener != null) - { - this.messenger.removeContactListListener(contactListListener); - contactListListener = null; - } - } - - this.messenger = messenger; - - if (this.messenger != null) - { - contactListModManager - = new EventManager( - msnProvider, - (BasicMessenger) this.messenger); - contactListModManager.addModificationListener( - contactListModListenerImpl); - - contactListListener = new ContactListListener(); - this.messenger.addContactListListener(contactListListener); - } - } - - /** - * when there is no image for contact we must retrieve it - * add contacts for image update - * - * @param c ContactMsnImpl - */ - protected void addContactForImageUpdate(ContactMsnImpl c) - { - if (messenger != null) - { - // Get the MsnObject - MsnObject avatar = c.getSourceContact().getAvatar(); - - if (avatar != null) - { - messenger.retrieveDisplayPicture( - avatar, - new ImageUpdater(c)); - } - } - } - - /** - * used for debugging. Printing the serverside lists that msn supports - */ - public void printList() - { - MsnMessenger messenger = msnProvider.getMessenger(); - - if (logger.isInfoEnabled()) - logger.info("---=Start Printing contact list=---"); - - MsnContactList list = messenger.getContactList(); - - if (logger.isInfoEnabled()) - logger.info("Forward list"); - MsnContact[] c = list.getContactsInList(MsnList.FL); - for(int i = 0; i < c.length; i++) - { - if (logger.isInfoEnabled()) - logger.info("c : " + c[i]); - MsnGroup[] groups = c[i].getBelongGroups(); - for(int j = 0; j < groups.length; j++) - { - if (logger.isInfoEnabled()) - logger.info("in group " + groups[j]); - } - } - - if (logger.isInfoEnabled()) - logger.info("Allow list"); - c = list.getContactsInList(MsnList.AL); - for(int i = 0; i < c.length; i++) - { - if (logger.isInfoEnabled()) - logger.info("c : " + c[i] + " g:" + c[i].getBelongGroups().length); - } - - if (logger.isInfoEnabled()) - logger.info("Block list"); - c = list.getContactsInList(MsnList.BL); - for(int i = 0; i < c.length; i++) - { - if (logger.isInfoEnabled()) - logger.info("c : " + c[i] + " g:" + c[i].getBelongGroups().length); - } - - if (logger.isInfoEnabled()) - logger.info("pending list"); - c = list.getContactsInList(MsnList.PL); - for(int i = 0; i < c.length; i++) - { - if (logger.isInfoEnabled()) - logger.info("c : " + c[i] + " g:" + c[i].getBelongGroups().length); - } - - if (logger.isInfoEnabled()) - logger.info("Reverse list"); - c = list.getContactsInList(MsnList.RL); - for(int i = 0; i < c.length; i++) - { - if (logger.isInfoEnabled()) - logger.info("c : " + c[i] + " g:" + - c[i].getBelongGroups().length); - } - - if (logger.isInfoEnabled()) - logger.info("Number of groups : " - + messenger.getContactList().getGroups().length); - MsnGroup[] groups = messenger.getContactList().getGroups(); - for(int j = 0; j < groups.length; j++) - { - if (logger.isInfoEnabled()) - logger.info("group " + groups[j]); - } - if (logger.isInfoEnabled()) - logger.info("---=End Printing contact list=---"); - } - - private class ImageUpdater - implements DisplayPictureListener - { - private ContactMsnImpl contact; - ImageUpdater(ContactMsnImpl contact) - { - this.contact = contact; - } - - public void notifyMsnObjectRetrieval( - MsnMessenger arg0messenger, - DisplayPictureRetrieveWorker worker, - MsnObject msnObject, - ResultStatus result, - byte[] resultBytes, - Object context) - { - if (result == ResultStatus.GOOD) - { - byte[] oldImage = contact.getImage(false); - - contact.setImage(resultBytes); - - parentOperationSet.fireContactPropertyChangeEvent( - ContactPropertyChangeEvent.PROPERTY_IMAGE, - contact, oldImage, resultBytes); - } - } - - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/VolatileContact.java b/src/net/java/sip/communicator/impl/protocol/msn/VolatileContact.java deleted file mode 100644 index 992a111..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/VolatileContact.java +++ /dev/null @@ -1,75 +0,0 @@ - -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import net.sf.jml.*; - -/** - * The Msn implementation for Volatile Contact - * @author Damian Minkov - */ -public class VolatileContact - implements MsnContact -{ - private final String contactId; - private final String displayName; - private Email email; - - VolatileContact(String id, Email email, String displayName) - { - this.contactId = id; - this.email = email; - this.displayName = displayName; - } - - VolatileContact(String id) - { - this(id, null, id); - } - - public MsnContactList getContactList(){return null;} - - public String getId() - { - return contactId; - } - - public String getFriendlyName() - { - return displayName; - } - - public boolean isInList(MsnList msnList){return false;} - - public MsnGroup[] getBelongGroups(){return null;} - - public boolean belongGroup(MsnGroup msnGroup){return false;} - - public Email getEmail() - { - if (email == null) - email = Email.parseStr(contactId); - return email; - } - - public String getDisplayName(){return displayName;} - - public MsnUserStatus getStatus(){return null;} - - public MsnClientId getClientId(){return null;} - - public MsnUserProperties getProperties(){return null;} - - public String getOldDisplayName(){return "";} - - public MsnUserStatus getOldStatus(){return null;} - - public String getPersonalMessage(){return "";} - - public MsnObject getAvatar(){return null;} -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/VolatileGroup.java b/src/net/java/sip/communicator/impl/protocol/msn/VolatileGroup.java deleted file mode 100644 index e8fd8aa..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/VolatileGroup.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.msn; - -import net.sf.jml.*; - -/** - * The Msn implementation of the Volatile ContactGroup interface. - * - * @author Damian Minkov - */ -public class VolatileGroup - implements MsnGroup -{ - private String groupName = MsnActivator.getResources().getI18NString( - "service.gui.NOT_IN_CONTACT_LIST_GROUP_NAME"); - - VolatileGroup(){} - - VolatileGroup(String groupName) - { - this.groupName = groupName; - } - - public MsnContactList getContactList(){return null;} - - public String getGroupId() - { - return groupName; - } - - public String getGroupName() - { - return getGroupId(); - } - - public MsnContact[] getContacts(){return null;} - - public boolean containContact(MsnContact contact){return false;} - - public boolean isDefaultGroup(){return false;} -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/Base64InputStream.java b/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/Base64InputStream.java deleted file mode 100644 index 07aaf92..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/Base64InputStream.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Base64InputStream.java - * Copyright(C) 2002 The Free Software Foundation - * - * This file is part of GNU JavaMail, a library. - * - * GNU JavaMail is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - *(at your option) any later version. - * - * GNU JavaMail is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, if you link this library with other files to - * produce an executable, this library does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * This exception does not however invalidate any other reasons why the - * executable file might be covered by the GNU General Public License. - */ - -package net.java.sip.communicator.impl.protocol.msn.mail.utils; - -import java.io.*; - -/** - * A Base64 content transfer encoding filter stream. - * <p> - * From RFC 2045, section 6.8: - * <p> - * The Base64 Content-Transfer-Encoding is designed to represent - * arbitrary sequences of octets in a form that need not be humanly - * readable. The encoding and decoding algorithms are simple, but the - * encoded data are consistently only about 33 percent larger than the - * unencoded data. - * - * @author <a href="mailto:dog@gnu.org">Chris Burdess</a> - */ -public class Base64InputStream - extends FilterInputStream -{ - - private byte[] buffer; - private int buflen; - private int index; - private byte[] decodeBuf; - - private static final char[] src = - { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', - 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', - 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', - 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', - 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', '+', '/' - }; - private static final byte[] dst; - - private static final int LF = 10, CR = 13, EQ = 61; - - static - { - dst = new byte[256]; - for (int i = 0; i<255; i++) - dst[i] = -1; - for (int i = 0; i<src.length; i++) - dst[src[i]] = (byte)i; - - } - - /** - * Constructs an input stream that decodes an underlying Base64-encoded - * stream. - * @param in the Base64-encoded stream - */ - public Base64InputStream(InputStream in) - { - super(in); - decodeBuf = new byte[4]; - buffer = new byte[3]; - } - - /** - * Reads the next byte of data from the input stream. - */ - @Override -public int read() - throws IOException - { - if (index>=buflen) - { - decode(); - if (buflen==0) - return -1; - index = 0; - } - return buffer[index++] & 0xff; - } - - /** - * Reads up to len bytes of data from the input stream into an array of - * bytes. - */ - @Override -public int read(byte[] b, int off, int len) - throws IOException - { - try - { - int l = 0; - for (; l<len; l++) - { - int c; - if ((c=read())==-1) - { - if (l==0) - l = -1; - break; - } - b[off+l] = (byte)c; - } - return l; - } - catch (IOException e) - { - return -1; - } - } - - /** - * Returns the number of bytes that can be read(or skipped over) from this - * input stream without blocking by the next caller of a method for this - * input stream. - */ - @Override -public int available() - throws IOException - { - return (in.available()*3)/4+(buflen-index); - } - - private void decode() - throws IOException - { - buflen = 0; - int c; - do - { - c = in.read(); - if (c==-1) - return; - } - while (c==LF || c==CR); - decodeBuf[0] = (byte)c; - int j = 3, l; - for (int k=1;(l=in.read(decodeBuf, k, j))!=j; k += l) - { - if (l==-1) - throw new IOException("Base64 encoding error"); - j -= l; - } - - byte b0 = dst[decodeBuf[0] & 0xff]; - byte b2 = dst[decodeBuf[1] & 0xff]; - buffer[buflen++] = (byte)(b0<<2 & 0xfc | b2>>>4 & 0x3); - if (decodeBuf[2]!=EQ) - { - b0 = b2; - b2 = dst[decodeBuf[2] & 0xff]; - buffer[buflen++] = (byte)(b0<<4 & 0xf0 | b2>>>2 & 0xf); - if (decodeBuf[3]!=EQ) - { - b0 = b2; - b2 = dst[decodeBuf[3] & 0xff]; - buffer[buflen++] = (byte)(b0<<6 & 0xc0 | b2 & 0x3f); - } - } - } - -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/MimeUtility.java b/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/MimeUtility.java deleted file mode 100644 index f22df92..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/MimeUtility.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * MimeUtility.java - * Copyright (C) 2002, 2004, 2005 The Free Software Foundation - * - * This file is part of GNU JavaMail, a library. - * - * GNU JavaMail is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * GNU JavaMail is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, if you link this library with other files to - * produce an executable, this library does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * This exception does not however invalidate any other reasons why the - * executable file might be covered by the GNU General Public License. - */ - -package net.java.sip.communicator.impl.protocol.msn.mail.utils; - -import java.io.*; -import java.util.*; - -/** - * This is a utility class providing micellaneous MIME-related functionality. - * - * @author <a href="mailto:dog@gnu.org">Chris Burdess</a> - * @version 1.4 - */ -public class MimeUtility -{ - - /* - * Uninstantiable. - */ - private MimeUtility() - { - } - - /** - * Decodes headers that are defined as '*text' in RFC 822. - * @param etext the possibly encoded value - * @return decoded text - * @exception UnsupportedEncodingException if the charset conversion failed - */ - public static String decodeText(String etext) - throws UnsupportedEncodingException - { - String delimiters = "\t\n\r "; - if (etext.indexOf("=?") == -1) - { - return etext; - } - StringTokenizer st = new StringTokenizer(etext, delimiters, true); - StringBuffer buffer = new StringBuffer(); - StringBuffer extra = new StringBuffer(); - boolean decoded = false; - while (st.hasMoreTokens()) - { - String token = st.nextToken(); - char c = token.charAt(0); - if (delimiters.indexOf(c) > -1) - { - extra.append(c); - } - else - { - try - { - token = decodeWord(token); - if (!decoded && extra.length() > 0) - { - buffer.append(extra); - } - decoded = true; - } - catch (Exception e) - { - if (extra.length() > 0) - { - buffer.append(extra); - } - decoded = false; - } - buffer.append(token); - extra.setLength(0); - } - } - return buffer.toString(); - } - - /** - * Decodes the specified string using the RFC 2047 rules for parsing an - * "encoded-word". - * @param text the possibly encoded value - * @return decoded word - * @exception Exception if the string is not an encoded-word - * @exception UnsupportedEncodingException if the decoding failed - */ - public static String decodeWord(String text) - throws Exception, UnsupportedEncodingException - { - if (!text.startsWith("=?")) - { - throw new Exception(); - } - int start = 2; - int end = text.indexOf('?', start); - if (end < 0) - { - throw new Exception(); - } - String charset = text.substring(start, end); - // Allow for RFC2231 language - int si = charset.indexOf('*'); - if (si != -1) - { - charset = charset.substring(0, si); - } - - start = end + 1; - end = text.indexOf('?', start); - if (end < 0) - { - throw new Exception(); - } - String encoding = text.substring(start, end); - start = end + 1; - end = text.indexOf("?=", start); - if (end < 0) - { - throw new Exception(); - } - text = text.substring(start, end); - - InputStream is = null; - - try - { - // The characters in the remaining string must all be 7-bit clean. - // Therefore it is safe just to copy them verbatim into a byte array. - char[] chars = text.toCharArray(); - int len = chars.length; - byte[] bytes = new byte[len]; - for (int i = 0; i < len; i++) - { - bytes[i] = (byte) chars[i]; - } - - ByteArrayInputStream bis = new ByteArrayInputStream(bytes); - if (encoding.equalsIgnoreCase("B")) - { - is = new Base64InputStream(bis); - } - else if (encoding.equalsIgnoreCase("Q")) - { - is = new QInputStream(bis); - } - else - { - throw new UnsupportedEncodingException( - "Unknown encoding: " + encoding); - } - len = bis.available(); - bytes = new byte[len]; - len = is.read(bytes, 0, len); - String ret = new String(bytes, 0, len, charset); - if (text.length() > end + 2) - ret = ret + /* extra */ text.substring(end + 2); - return ret; - } - catch (IOException e) - { - throw new Exception(); - } - catch (IllegalArgumentException e) - { - throw new UnsupportedEncodingException(); - } - finally - { - /* - * Without knowing whether it is practically necessary, it - * technically silences a compile-time warning. - */ - if (is != null) - is.close(); - } - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/QInputStream.java b/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/QInputStream.java deleted file mode 100644 index ce9f550..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/QInputStream.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * QInputStream.java - * Copyright(C) 2002 The Free Software Foundation - * - * This file is part of GNU JavaMail, a library. - * - * GNU JavaMail is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - *(at your option) any later version. - * - * GNU JavaMail is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, if you link this library with other files to - * produce an executable, this library does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * This exception does not however invalidate any other reasons why the - * executable file might be covered by the GNU General Public License. - */ - -package net.java.sip.communicator.impl.protocol.msn.mail.utils; - -import java.io.*; - -/** - * Provides RFC 2047 "B" transfer encoding. - * See section 4.2: - * <p> - * The "Q" encoding is similar to the "Quoted-Printable" content- - * transfer-encoding defined in RFC 2045. It is designed to allow text - * containing mostly ASCII characters to be decipherable on an ASCII - * terminal without decoding. - * <ol> - * <li>Any 8-bit value may be represented by a "=" followed by two - * hexadecimal digits. For example, if the character set in use - * were ISO-8859-1, the "=" character would thus be encoded as - * "=3D", and a SPACE by "=20". (Upper case should be used for - * hexadecimal digits "A" through "F".) - * <li>The 8-bit hexadecimal value 20(e.g., ISO-8859-1 SPACE) may be - * represented as "_"(underscore, ASCII 95.). (This character may - * not pass through some internetwork mail gateways, but its use - * will greatly enhance readability of "Q" encoded data with mail - * readers that do not support this encoding.) Note that the "_" - * always represents hexadecimal 20, even if the SPACE character - * occupies a different code position in the character set in use. - * <li>8-bit values which correspond to printable ASCII characters other - * than "=", "?", and "_"(underscore), MAY be represented as those - * characters. (But see section 5 for restrictions.) In - * particular, SPACE and TAB MUST NOT be represented as themselves - * within encoded words. - * - * @author <a href="mailto:dog@gnu.org">Chris Burdess</a> - */ -public class QInputStream - extends QPInputStream -{ - - private static final int SPACE = 32; - private static final int EQ = 61; - private static final int UNDERSCORE = 95; - - /** - * Constructor. - * @param in the underlying input stream. - */ - public QInputStream(InputStream in) - { - super(in); - } - - /** - * Read a character. - */ - @Override -public int read() - throws IOException - { - int c = in.read(); - if (c==UNDERSCORE) - return SPACE; - if (c==EQ) - { - buf[0] = (byte)in.read(); - buf[1] = (byte)in.read(); - try - { - return Integer.parseInt(new String(buf, 0, 2), 16); - } - catch (NumberFormatException e) - { - throw new IOException("Quoted-Printable encoding error: "+ - e.getMessage()); - } - } - return c; - } - -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/QPInputStream.java b/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/QPInputStream.java deleted file mode 100644 index caf887b..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/mail/utils/QPInputStream.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * QPInputStream.java - * Copyright(C) 2002 The Free Software Foundation - * - * This file is part of GNU JavaMail, a library. - * - * GNU JavaMail is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - *(at your option) any later version. - * - * GNU JavaMail is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * As a special exception, if you link this library with other files to - * produce an executable, this library does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * This exception does not however invalidate any other reasons why the - * executable file might be covered by the GNU General Public License. - */ - -package net.java.sip.communicator.impl.protocol.msn.mail.utils; - -import java.io.*; - -/** - * A Quoted-Printable decoder stream. - * - * @author <a href="mailto:dog@gnu.org">Chris Burdess</a> - */ -public class QPInputStream - extends FilterInputStream -{ - - protected byte[] buf; - - /** - * The number of times read() will return a space. - */ - protected int spaceCount; - - private static final int LF = 10; - private static final int CR = 13; - private static final int SPACE = 32; - private static final int EQ = 61; - - /** - * Constructor. - * @param in the underlying input stream. - */ - public QPInputStream(InputStream in) - { - super(new PushbackInputStream(in, 2)); - buf = new byte[2]; - } - - /** - * Read a character from the stream. - */ - @Override -public int read() - throws IOException - { - if (spaceCount>0) - { - spaceCount--; - return SPACE; - } - - int c = in.read(); - if (c==SPACE) - { - while ((c = in.read())==SPACE) - spaceCount++; - if (c==LF || c==CR || c==-1) - spaceCount = 0; - else - { - ((PushbackInputStream)in).unread(c); - c = SPACE; - } - return c; - } - if (c==EQ) - { - int c2 = super.in.read(); - if (c2==LF) - return read(); - if (c2==CR) - { - int peek = in.read(); - if (peek!=LF) - ((PushbackInputStream)in).unread(peek); - return read(); - } - if (c2==-1) - return c2; - - buf[0] = (byte)c2; - buf[1] = (byte)in.read(); - try - { - return Integer.parseInt(new String(buf, 0, 2), 16); - } - catch (NumberFormatException e) - { - ((PushbackInputStream)in).unread(buf); - } - return c; - } - else - return c; - } - - /** - * Reads from the underlying stream into the specified byte array. - */ - @Override -public int read(byte[] bytes, int off, int len) - throws IOException - { - int pos = 0; - try - { - while (pos<len) - { - int c = read(); - if (c==-1) - { - if (pos==0) - pos = -1; - break; - } - bytes[off+pos] = (byte)c; - pos++; - } - - } - catch (IOException e) - { - pos = -1; - } - return pos; - } - - /** - * Mark is not supported. - */ - @Override -public boolean markSupported() - { - return false; - } - - /** - * Returns the number of bytes that can be read without blocking. - */ - @Override -public int available() - throws IOException - { - return in.available(); - } - -} diff --git a/src/net/java/sip/communicator/impl/protocol/msn/msn.provider.manifest.mf b/src/net/java/sip/communicator/impl/protocol/msn/msn.provider.manifest.mf deleted file mode 100644 index d07b4f1..0000000 --- a/src/net/java/sip/communicator/impl/protocol/msn/msn.provider.manifest.mf +++ /dev/null @@ -1,40 +0,0 @@ -Bundle-Activator: net.java.sip.communicator.impl.protocol.msn.MsnActivator -Bundle-Name: Msn Protocol Provider Implementation -Bundle-Description: An Msn implementation of the Protocol Provider Service. -Bundle-Vendor: jitsi.org -Bundle-Version: 0.0.1 -Bundle-SymbolicName: net.java.sip.communicator.protocol.msn -Import-Package: org.apache.commons.logging, - org.apache.http, - org.apache.http.entity, - org.apache.http.impl, - org.apache.http.impl.entity, - org.apache.http.impl.io, - org.apache.http.io, - org.apache.http.message, - org.apache.http.params, - org.apache.http.protocol, - org.apache.http.util, - org.osgi.framework, - org.osgi.service.url, - org.w3c.dom, - org.xml.sax, - javax.crypto, - javax.crypto.spec, - javax.naming, - javax.naming.directory, - javax.net.ssl, - javax.swing, - javax.xml.parsers, - javax.xml.datatype, - sun.security.action, - javax.imageio, - org.jitsi.service.configuration, - org.jitsi.service.fileaccess, - org.jitsi.service.resources, - net.java.sip.communicator.service.resources, - net.java.sip.communicator.util, - net.java.sip.communicator.service.dns, - net.java.sip.communicator.service.protocol, - net.java.sip.communicator.service.protocol.msnconstants, - net.java.sip.communicator.service.protocol.event |