From a976ca60c1c638e85c2c8f3505f52019523ae506 Mon Sep 17 00:00:00 2001 From: Emil Ivov Date: Mon, 26 May 2008 14:34:49 +0000 Subject: rolling back until fixed --- .../OperationSetBasicInstantMessagingDictImpl.java | 421 --------------------- 1 file changed, 421 deletions(-) delete mode 100644 src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java (limited to 'src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java') diff --git a/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java b/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java deleted file mode 100644 index 4dc2848..0000000 --- a/src/net/java/sip/communicator/impl/protocol/dict/OperationSetBasicInstantMessagingDictImpl.java +++ /dev/null @@ -1,421 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.dict; - -import java.util.*; -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.service.protocol.event.*; - -import net.java.sip.communicator.util.*; - -/** - * Instant messaging functionalities for the Dict protocol. - * - * @author ROTH Damien - * @author LITZELMANN Cédric - */ -public class OperationSetBasicInstantMessagingDictImpl - implements OperationSetBasicInstantMessaging, - RegistrationStateChangeListener -{ - private static final Logger logger - = Logger.getLogger(OperationSetBasicInstantMessagingDictImpl.class); - - /** - * Currently registered message listeners. - */ - private Vector messageListeners = new Vector(); - - /** - * The currently valid persistent presence operation set. - */ - private OperationSetPersistentPresenceDictImpl opSetPersPresence = null; - - /** - * The protocol provider that created us. - */ - private ProtocolProviderServiceDictImpl parentProvider = null; - - /** - * Creates an instance of this operation set keeping a reference to the - * parent protocol provider and presence operation set. - * - * @param provider The provider instance that creates us. - * @param opSetPersPresence the currently valid - * OperationSetPersistentPresenceDictImpl instance. - */ - public OperationSetBasicInstantMessagingDictImpl( - ProtocolProviderServiceDictImpl provider, - OperationSetPersistentPresenceDictImpl opSetPersPresence) - { - this.opSetPersPresence = opSetPersPresence; - this.parentProvider = provider; - - parentProvider.addRegistrationStateChangeListener(this); - } - - /** - * Registers a MessageListener with this operation set so that it gets - * notifications of successful message delivery, failure or reception of - * incoming messages. - * - * @param listener the MessageListener to register. - */ - public void addMessageListener(MessageListener listener) - { - if(!messageListeners.contains(listener)) - { - messageListeners.add(listener); - } - } - - /** - * Create a Message instance for sending arbitrary MIME-encoding content. - * - * @param content content value - * @param contentType the MIME-type for content - * @param contentEncoding encoding used for content - * @param subject a String subject or null for now - * subject. - * @return the newly created message. - */ - public Message createMessage(byte[] content, String contentType, - String contentEncoding, String subject) - { - return new MessageDictImpl(new String(content), contentType, - contentEncoding, subject); - } - - /** - * Create a Message instance for sending a simple text messages with - * default (text/plain) content type and encoding. - * - * @param messageText the string content of the message. - * @return Message the newly created message - */ - public Message createMessage(String messageText) - { - return new MessageDictImpl(messageText, DEFAULT_MIME_TYPE, - DEFAULT_MIME_ENCODING, null); - } - - /** - * Unregisters listener so that it won't receive any further - * notifications upon successful message delivery, failure or reception - * of incoming messages.. - * - * @param listener the MessageListener to unregister. - */ - public void removeMessageListener(MessageListener listener) - { - messageListeners.remove(listener); - } - - /** - * Sends the message to the destination indicated by the - * to contact. - * - * @param to the Contact to send message to - * @param message the Message to send. - * @throws IllegalStateException if the underlying ICQ stack is not - * registered and initialized. - * @throws IllegalArgumentException if to is not an instance - * belonging to the underlying implementation. - */ - public void sendInstantMessage(Contact to, Message message) - throws IllegalStateException, - IllegalArgumentException - { - if( !(to instanceof ContactDictImpl) ) - { - throw new IllegalArgumentException( - "The specified contact is not a Dict contact." - + to); - } - - // Display the queried word - fireMessageDelivered(message, to); - - this.submitDictQuery((ContactDictImpl) to, message); - } - - /** - * Notifies all registered message listeners that a message has been - * delivered successfully to its addressee.. - * - * @param message the Message that has been delivered. - * @param to the Contact that message was delivered to. - */ - private void fireMessageDelivered(Message message, Contact to) - { - MessageDeliveredEvent evt - = new MessageDeliveredEvent(message, to, new Date()); - - Iterator listeners = null; - synchronized (messageListeners) - { - listeners = new ArrayList(messageListeners).iterator(); - } - - while (listeners.hasNext()) - { - MessageListener listener - = (MessageListener) listeners.next(); - - listener.messageDelivered(evt); - } - } - - /** - * Notifies all registered message listeners that a message has been - * received. - * - * @param message the Message that has been received. - * @param from the Contact that message was received from. - */ - private void fireMessageReceived(Message message, Contact from) - { - MessageReceivedEvent evt - = new MessageReceivedEvent(message, from, new Date()); - - Iterator listeners = null; - synchronized (messageListeners) - { - listeners = new ArrayList(messageListeners).iterator(); - } - - while (listeners.hasNext()) - { - MessageListener listener - = (MessageListener) listeners.next(); - - listener.messageReceived(evt); - } - } - - /** - * Determines whether the protocol provider (or the protocol itself) supports - * sending and receiving offline messages. Most often this method would - * return true for protocols that support offline messages and false for - * 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 true if the protocol supports offline messages and - * false otherwise. - */ - public boolean isOfflineMessagingSupported() - { - return false; - } - - /** - * Determines whether the protocol supports the supplied content type. - * - * @param contentType the type we want to check - * @return true if the protocol supports it and - * false otherwise. - */ - public boolean isContentTypeSupported(String contentType) - { - if(contentType.equals(DEFAULT_MIME_TYPE)) - return true; - else if(contentType.equals("text/html")) - return true; - else - return false; - } - - /** - * Returns the protocol provider that this operation set belongs to. - * - * @return a reference to the ProtocolProviderServiceDictImpl - * instance that this operation set belongs to. - */ - public ProtocolProviderServiceDictImpl getParentProvider() - { - return this.parentProvider; - } - - /** - * Returns a reference to the presence operation set instance used by our - * source provider. - * - * @return a reference to the OperationSetPersistentPresenceDictImpl - * instance used by this provider. - */ - public OperationSetPersistentPresenceDictImpl getOpSetPersPresence() - { - return this.opSetPersPresence; - } - - /** - * The method is called by the ProtocolProvider whenever a change in the - * registration state of the corresponding provider has occurred. - * - * @param evt ProviderStatusChangeEvent the event describing the status - * change. - */ - public void registrationStateChanged(RegistrationStateChangeEvent evt) - { - - } - - - /** - * Create, execute and display a query to a dictionary (ContactDictImpl) - * - * @param dictContact the contact containing the database name - * @param message the message containing the word - */ - private void submitDictQuery(ContactDictImpl dictContact, Message message) - { - Message msg = this.createMessage(""); - - String database = dictContact.getContactID(); - DictAdapter dictAdapter = dictContact.getDictAdapter(); - boolean doMatch = false; - DictResultset fctResult; - - String word; - - // Formatting the query message, if the word as one or more spaces we - // put it between quotes to prevent errors - word = message.getContent().replace("\"", "").trim(); - if (word.indexOf(' ') > 0) - { - word = "\"" + word + "\""; - } - - // Try to get the definition of the work - try - { - fctResult = dictAdapter.define(database, word); - msg = this.createMessage(this.retrieveDefine(fctResult, word)); - } - catch(DictException dex) - { - if (dex.getErrorCode() == 552) - { // No word found, we are going to try the match command - doMatch = true; - } - else - { // Otherwise we display the error returned by the server - msg = this.createMessage(dex.getErrorMessage()); - } - } - catch(Exception ex) - { - logger.error("Failed to retrieve Definition. Error was: " - + ex.getMessage() - , ex); - } - - if (doMatch) - { - // Trying the match command - try - { - fctResult = dictAdapter.match(database, word); - msg = this.createMessage(this.retrieveMatch(fctResult, word)); - } - catch(DictException dex) - { - msg = this.createMessage(dex.getErrorMessage()); - } - catch(Exception ex) - { - logger.error("Failed to retrieve Match. Error was: " - + ex.getMessage() - , ex); - } - } - - // Send message - fireMessageReceived(msg, dictContact); - } - - /** - * Generate the display of the results of the Define command - * - * @param data the result of the Define command - * @param word the queried word - * @return the formatted result - */ - private String retrieveDefine(DictResultset data, String word) - { - String result; - DictResult resultData; - - result = data.getNbResults() + " definitions found for \"" + word + "\""; - - for (int i=0; i