aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/notification
diff options
context:
space:
mode:
authorYana Stamcheva <yana@jitsi.org>2007-08-22 15:58:08 +0000
committerYana Stamcheva <yana@jitsi.org>2007-08-22 15:58:08 +0000
commit5c8f2119360d839ae007ec5ba36855668f212637 (patch)
treed9de819667695ea07af3b37f81163354d7343583 /src/net/java/sip/communicator/impl/notification
parent80b489dfea8ab16d81a958b9c8a033ff844bee97 (diff)
downloadjitsi-5c8f2119360d839ae007ec5ba36855668f212637.zip
jitsi-5c8f2119360d839ae007ec5ba36855668f212637.tar.gz
jitsi-5c8f2119360d839ae007ec5ba36855668f212637.tar.bz2
notification service implementation
Diffstat (limited to 'src/net/java/sip/communicator/impl/notification')
-rw-r--r--src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java66
-rw-r--r--src/net/java/sip/communicator/impl/notification/EventNotification.java166
-rw-r--r--src/net/java/sip/communicator/impl/notification/LogMessageNotificationHandlerImpl.java63
-rw-r--r--src/net/java/sip/communicator/impl/notification/NotificationActivator.java125
-rw-r--r--src/net/java/sip/communicator/impl/notification/NotificationServiceImpl.java619
-rw-r--r--src/net/java/sip/communicator/impl/notification/PopupMessageNotificationHandlerImpl.java61
-rw-r--r--src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java109
-rw-r--r--src/net/java/sip/communicator/impl/notification/notification.manifest.mf13
8 files changed, 1222 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java
new file mode 100644
index 0000000..fe01332
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/notification/CommandNotificationHandlerImpl.java
@@ -0,0 +1,66 @@
+/*
+ * 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.notification;
+
+import java.io.*;
+
+import net.java.sip.communicator.service.notification.*;
+import net.java.sip.communicator.util.*;
+
+/**
+ * An implementation of the <tt>CommandNotificationHandler</tt> interface.
+ *
+ * @author Yana Stamcheva
+ */
+public class CommandNotificationHandlerImpl
+ implements CommandNotificationHandler
+{
+ private Logger logger
+ = Logger.getLogger(CommandNotificationHandlerImpl.class);
+
+ private String commandDescriptor;
+
+ /**
+ * Creates an instance of <tt>CommandNotificationHandlerImpl</tt> by
+ * specifying the <tt>commandDescriptor</tt>, which will point us to the
+ * command to execute.
+ *
+ * @param commandDescriptor a String that should point us to the command to
+ * execute
+ */
+ public CommandNotificationHandlerImpl(String commandDescriptor)
+ {
+ this.commandDescriptor = commandDescriptor;
+ }
+
+ /**
+ * Executes the <tt>command</tt>, given by the containing
+ * <tt>commandDescriptor</tt>.
+ */
+ public void execute()
+ {
+ try
+ {
+ Runtime.getRuntime().exec(commandDescriptor);
+ }
+ catch (IOException e)
+ {
+ logger.error("Failed execute the following command: "
+ + commandDescriptor, e);
+ }
+ }
+
+ /**
+ * Returns the command descriptor.
+ *
+ * @return the command descriptor
+ */
+ public String getDescriptor()
+ {
+ return commandDescriptor;
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/notification/EventNotification.java b/src/net/java/sip/communicator/impl/notification/EventNotification.java
new file mode 100644
index 0000000..2e6cca7
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/notification/EventNotification.java
@@ -0,0 +1,166 @@
+/*
+ * 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.notification;
+
+import java.util.*;
+
+import net.java.sip.communicator.service.notification.*;
+
+/**
+ * Represents an event notification.
+ *
+ * @author Yana Stamcheva
+ */
+public class EventNotification
+{
+ /**
+ * The event type as declared by the bundle registering it.
+ */
+ private String eventType;
+
+ /**
+ * Indicates if this event notification is currently active. By default all
+ * notifications are active.
+ */
+ private boolean isActive = true;
+
+ /**
+ * Contains all actions which will be executed when this event notification
+ * is fired.
+ */
+ private Hashtable actionsTable = new Hashtable();
+
+ /**
+ * Creates an instance of <tt>EventNotification</tt> by specifying the
+ * event type as declared by the bundle registering it.
+ *
+ * @param eventType the name of the event
+ */
+ public EventNotification(String eventType)
+ {
+ this.eventType = eventType;
+ }
+
+ /**
+ * Adds the given <tt>actionType</tt> to the list of actions for this event
+ * notifications.
+ *
+ * @param actionType one of NotificationService.ACTION_XXX constants
+ * @param actionHandler the the handler that will process the given action
+ * type.
+ */
+ public void addAction( String actionType,
+ NotificationActionHandler actionHandler)
+ {
+ Action action
+ = new Action(actionType, actionHandler);
+
+ actionsTable.put(actionType, action);
+ }
+
+ /**
+ * Removes the action corresponding to the given <tt>actionType</tt>.
+ *
+ * @param actionType one of NotificationService.ACTION_XXX constants
+ */
+ public void removeAction(String actionType)
+ {
+ actionsTable.remove(actionType);
+ }
+
+ /**
+ * Returns the set of actions registered for this event notification.
+ *
+ * @return the set of actions registered for this event notification
+ */
+ public Map getActions()
+ {
+ return actionsTable;
+ }
+
+ /**
+ * Returns the <tt>Action</tt> corresponding to the given
+ * <tt>actionType</tt>.
+ *
+ * @param actionType one of NotificationService.ACTION_XXX constants
+ *
+ * @return the <tt>Action</tt> corresponding to the given
+ * <tt>actionType</tt>
+ */
+ public Action getAction(String actionType)
+ {
+ return (Action) actionsTable.get(actionType);
+ }
+
+ /**
+ * The representation of an action, containing the corresponding
+ * action type, action descriptor and the default message associated with
+ * the action.
+ */
+ public class Action
+ {
+ private String actionType;
+
+ private NotificationActionHandler actionHandler;
+
+ /**
+ * Creates an instance of <tt>Action</tt> by specifying the type of the
+ * action, the descriptor and the default message.
+ *
+ * @param actionType one of NotificationService.ACTION_XXX constants
+ * @param actionHandler the handler that will process the given action
+ * type
+ */
+ Action( String actionType,
+ NotificationActionHandler actionHandler)
+ {
+ this.actionType = actionType;
+
+ this.actionHandler = actionHandler;
+ }
+
+ /**
+ * Returns the the handler that will process the given action
+ * type.
+ * @return the the handler that will process the given action
+ * type.
+ */
+ public NotificationActionHandler getActionHandler()
+ {
+ return actionHandler;
+ }
+
+ /**
+ * Return the action type name.
+ * @return the action type name.
+ */
+ public String getActionType()
+ {
+ return actionType;
+ }
+ }
+
+ /**
+ * Indicates if this event notification is currently active.
+ *
+ * @return true if this event notification is active, false otherwise.
+ */
+ public boolean isActive()
+ {
+ return isActive;
+ }
+
+ /**
+ * Activates or desactivates this event notification.
+ *
+ * @param isActive indicates if this event notification is active
+ */
+ public void setActive(boolean isActive)
+ {
+ this.isActive = isActive;
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/notification/LogMessageNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/LogMessageNotificationHandlerImpl.java
new file mode 100644
index 0000000..f6560ad
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/notification/LogMessageNotificationHandlerImpl.java
@@ -0,0 +1,63 @@
+/*
+ * 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.notification;
+
+import net.java.sip.communicator.service.notification.*;
+import net.java.sip.communicator.util.*;
+
+/**
+ * An implementation of the <tt>LogMessageNotificationHandler</tt> interface.
+ *
+ * @author Yana Stamcheva
+ */
+public class LogMessageNotificationHandlerImpl
+ implements LogMessageNotificationHandler
+{
+ /**
+ * The logger that will be used to log messages.
+ */
+ private Logger logger
+ = Logger.getLogger(LogMessageNotificationHandlerImpl.class);
+
+ private String logType;
+
+ /**
+ * Creates an instance of <tt>LogMessageNotificationHandlerImpl</tt> by
+ * specifying the log type.
+ *
+ * @param logType the type of the log
+ */
+ public LogMessageNotificationHandlerImpl(String logType)
+ {
+ this.logType = logType;
+ }
+
+ /**
+ * Returns the type of the log
+ *
+ * @return the type of the log
+ */
+ public String getLogType()
+ {
+ return logType;
+ }
+
+ /**
+ * Logs a message through the sip communicator Logger.
+ *
+ * @param message the message coming from the event
+ */
+ public void logMessage(String message)
+ {
+ if (logType.equals(LogMessageNotificationHandler.ERROR_LOG_TYPE))
+ logger.error(message);
+ else if(logType.equals(LogMessageNotificationHandler.INFO_LOG_TYPE))
+ logger.info(message);
+ else if(logType.equals(LogMessageNotificationHandler.TRACE_LOG_TYPE))
+ logger.trace(message);
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/notification/NotificationActivator.java b/src/net/java/sip/communicator/impl/notification/NotificationActivator.java
new file mode 100644
index 0000000..45095ae
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/notification/NotificationActivator.java
@@ -0,0 +1,125 @@
+/*
+ * 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.notification;
+
+import net.java.sip.communicator.service.audionotifier.*;
+import net.java.sip.communicator.service.configuration.*;
+import net.java.sip.communicator.service.notification.*;
+import net.java.sip.communicator.service.systray.*;
+import net.java.sip.communicator.util.*;
+
+import org.osgi.framework.*;
+
+/**
+ * The <tt>NotificationActivator</tt> is the activator of the notification
+ * bundle.
+ *
+ * @author Yana Stamcheva
+ */
+public class NotificationActivator
+ implements BundleActivator
+{
+ private Logger logger = Logger.getLogger(NotificationActivator.class);
+
+ private static BundleContext bundleContext;
+
+ private static ConfigurationService configService;
+
+ private NotificationServiceImpl notificationService;
+
+ private static AudioNotifierService audioNotifierService;
+
+ private static SystrayService systrayService;
+
+ public void start(BundleContext bc) throws Exception
+ {
+ bundleContext = bc;
+
+ try {
+ // Create the notification service implementation
+ this.notificationService = new NotificationServiceImpl();
+
+ logger.info("Notification Service...[ STARTED ]");
+
+ bundleContext.registerService(
+ NotificationService.class.getName(),
+ this.notificationService,
+ null);
+
+ logger.info("Notification Service ...[REGISTERED]");
+
+ logger.logEntry();
+ }
+ finally {
+ logger.logExit();
+ }
+ }
+
+ public void stop(BundleContext bc) throws Exception
+ {
+ logger.info("UI Service ...[STOPPED]");
+ }
+
+ /**
+ * Returns the <tt>ConfigurationService</tt> obtained from the bundle
+ * context.
+ * @return the <tt>ConfigurationService</tt> obtained from the bundle
+ * context
+ */
+ public static ConfigurationService getConfigurationService()
+ {
+ if(configService == null)
+ {
+ ServiceReference configReference = bundleContext
+ .getServiceReference(ConfigurationService.class.getName());
+
+ configService = (ConfigurationService) bundleContext
+ .getService(configReference);
+ }
+
+ return configService;
+ }
+
+ /**
+ * Returns the <tt>AudioNotifierService</tt> obtained from the bundle
+ * context.
+ * @return the <tt>AudioNotifierService</tt> obtained from the bundle
+ * context
+ */
+ public static AudioNotifierService getAudioNotifier()
+ {
+ if (audioNotifierService == null)
+ {
+ ServiceReference serviceReference = bundleContext
+ .getServiceReference(AudioNotifierService.class.getName());
+
+ audioNotifierService = (AudioNotifierService) bundleContext
+ .getService(serviceReference);
+ }
+
+ return audioNotifierService;
+ }
+
+ /**
+ * Returns the <tt>SystrayService</tt> obtained from the bundle context.
+ *
+ * @return the <tt>SystrayService</tt> obtained from the bundle context
+ */
+ public static SystrayService getSystray()
+ {
+ if (systrayService == null)
+ {
+ ServiceReference serviceReference = bundleContext
+ .getServiceReference(SystrayService.class.getName());
+
+ systrayService = (SystrayService) bundleContext
+ .getService(serviceReference);
+ }
+
+ return systrayService;
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/notification/NotificationServiceImpl.java b/src/net/java/sip/communicator/impl/notification/NotificationServiceImpl.java
new file mode 100644
index 0000000..32316c0
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/notification/NotificationServiceImpl.java
@@ -0,0 +1,619 @@
+/*
+ * 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.notification;
+
+import java.util.*;
+
+import net.java.sip.communicator.impl.notification.EventNotification.*;
+import net.java.sip.communicator.service.configuration.*;
+import net.java.sip.communicator.service.notification.*;
+import net.java.sip.communicator.util.*;
+
+/**
+ * The implementation of the <tt>NotificationService</tt>.
+ *
+ * @author Yana Stamcheva
+ */
+public class NotificationServiceImpl
+ implements NotificationService
+{
+ private Logger logger = Logger.getLogger(NotificationServiceImpl.class);
+
+ /**
+ * A set of all registered event notifications.
+ */
+ private Hashtable notificationsTable = new Hashtable();
+
+ /**
+ * A list of all registered <tt>NotificationChangeListener</tt>s.
+ */
+ private Vector changeListeners = new Vector();
+
+ /**
+ * Creates an instance of <tt>NotificationServiceImpl</tt> by loading all
+ * previously saved notifications.
+ */
+ public NotificationServiceImpl()
+ {
+ // Load all previously saved notifications.
+ this.loadNotifications();
+ }
+
+ /**
+ * Returns an instance of <tt>CommandNotificationHandlerImpl</tt>.
+ *
+ * @return an instance of <tt>CommandNotificationHandlerImpl</tt>.
+ */
+ public CommandNotificationHandler createCommandNotificationHandler(
+ String commandDescriptor)
+ {
+ return new CommandNotificationHandlerImpl(commandDescriptor);
+ }
+
+ /**
+ * Returns an instance of <tt>LogMessageNotificationHandlerImpl</tt>.
+ *
+ * @return an instance of <tt>LogMessageNotificationHandlerImpl</tt>.
+ */
+ public LogMessageNotificationHandler createLogMessageNotificationHandler(
+ String logType)
+ {
+ return new LogMessageNotificationHandlerImpl(logType);
+ }
+
+ /**
+ * Returns an instance of <tt>PopupMessageNotificationHandlerImpl</tt>.
+ *
+ * @return an instance of <tt>PopupMessageNotificationHandlerImpl</tt>.
+ */
+ public PopupMessageNotificationHandler createPopupMessageNotificationHandler(
+ String defaultMessage)
+ {
+ return new PopupMessageNotificationHandlerImpl(defaultMessage);
+ }
+
+ /**
+ * Returns an instance of <tt>SoundNotificationHandlerImpl</tt>.
+ *
+ * @return an instance of <tt>SoundNotificationHandlerImpl</tt>.
+ */
+ public SoundNotificationHandler createSoundNotificationHandler(
+ String soundFileDescriptor, int loopInterval)
+ {
+ return new SoundNotificationHandlerImpl(
+ soundFileDescriptor, loopInterval);
+ }
+
+ /**
+ * Creates a new <tt>EventNotification</tt> or obtains the corresponding
+ * existing one and registers a new action in it.
+ *
+ * @param eventType the name of the event (as defined by the plugin that's
+ * registering it) that we are setting an action for.
+ * @param actionType the type of the action that is to be executed when the
+ * specified event occurs (could be one of the ACTION_XXX fields).
+ * @param handler the <tt>NotificationActionHandler</tt> responsible for
+ * handling the given <tt>actionType</tt>
+ */
+ public void registerNotificationForEvent( String eventType,
+ String actionType,
+ NotificationActionHandler handler)
+ {
+ EventNotification notification = null;
+
+ if(notificationsTable.containsKey(eventType))
+ notification = (EventNotification) notificationsTable.get(eventType);
+ else
+ {
+ notification = new EventNotification(eventType);
+
+ notificationsTable.put(eventType, notification);
+
+ // Save the notification through the ConfigurationService.
+ this.saveNotification( eventType,
+ actionType,
+ handler);
+ }
+
+ notification.addAction(actionType, handler);
+ }
+
+ /**
+ * Creates a new <tt>EventNotification</tt> or obtains the corresponding
+ * existing one and registers a new action in it.
+ *
+ * @param eventType the name of the event (as defined by the plugin that's
+ * registering it) that we are setting an action for.
+ * @param actionType the type of the action that is to be executed when the
+ * specified event occurs (could be one of the ACTION_XXX fields).
+ * @param actionDescriptor a String containing a description of the action
+ * (a URI to the sound file for audio notifications or a command line for
+ * exec action types) that should be executed when the action occurs.
+ * @param defaultMessage the default message to use if no specific message
+ * has been provided when firing the notification.
+ */
+ public void registerNotificationForEvent( String eventType,
+ String actionType,
+ String actionDescriptor,
+ String defaultMessage)
+ {
+ if (actionType.equals(NotificationService.ACTION_SOUND))
+ {
+ registerNotificationForEvent (eventType, actionType,
+ new SoundNotificationHandlerImpl(actionDescriptor, -1));
+ }
+ else if (actionType.equals(NotificationService.ACTION_LOG_MESSAGE))
+ {
+ registerNotificationForEvent (eventType, actionType,
+ new LogMessageNotificationHandlerImpl(
+ LogMessageNotificationHandler.INFO_LOG_TYPE));
+ }
+ else if (actionType.equals(NotificationService.ACTION_POPUP_MESSAGE))
+ {
+ registerNotificationForEvent (eventType, actionType,
+ new PopupMessageNotificationHandlerImpl(defaultMessage));
+ }
+ else if (actionType.equals(NotificationService.ACTION_COMMAND))
+ {
+ registerNotificationForEvent (eventType, actionType,
+ new CommandNotificationHandlerImpl(actionDescriptor));
+ }
+ }
+
+ /**
+ * Removes the <tt>EventNotification</tt> corresponding to the given
+ * <tt>eventType</tt> from the table of registered event notifications.
+ *
+ * @param eventType the name of the event (as defined by the plugin that's
+ * registering it) to be removed.
+ */
+ public void removeEventNotification(String eventType)
+ {
+ notificationsTable.remove(eventType);
+ }
+
+ /**
+ * Removes the given actionType from the list of actions registered for the
+ * given <tt>eventType</tt>.
+ *
+ * @param eventType the name of the event (as defined by the plugin that's
+ * registering it) for which we'll remove the notification.
+ * @param actionType the type of the action that is to be executed when the
+ * specified event occurs (could be one of the ACTION_XXX fields).
+ */
+ public void removeEventNotificationAction(String eventType,
+ String actionType)
+ {
+ EventNotification notification
+ = (EventNotification) notificationsTable.get(eventType);
+
+ if(notification == null)
+ return;
+
+ notification.removeAction(actionType);
+ }
+
+ /**
+ * Returns an iterator over a list of all events registered in this
+ * notification service. Each line in the returned list consists of
+ * a String, representing the name of the event (as defined by the plugin
+ * that registered it).
+ *
+ * @return an iterator over a list of all events registered in this
+ * notifications service
+ */
+ public Iterator getRegisteredEvents()
+ {
+ return Collections.unmodifiableSet(
+ notificationsTable.keySet()).iterator();
+ }
+
+ /**
+ * Goes through all actions registered for the given <tt>eventType</tt> and
+ * returns a Map of all (actionType, actionDescriptor) key-value pairs.
+ *
+ * @param eventType the name of the event that we'd like to retrieve actions
+ * for
+ * @return a <tt>Map</tt> containing the <tt>actionType</tt>s (as keys) and
+ * <tt>actionHandler</tt>s (as values) that should be executed when
+ * an event with the specified name has occurred, or null if no actions
+ * have been defined for <tt>eventType</tt>.
+ */
+ public Map getEventNotifications(String eventType)
+ {
+ EventNotification notification
+ = (EventNotification) notificationsTable.get(eventType);
+
+ if(notification == null)
+ return null;
+
+ Hashtable actions = new Hashtable();
+ Iterator srcActions = notification.getActions().values().iterator();
+
+ while(srcActions.hasNext())
+ {
+ Action action = (Action) srcActions.next();
+
+ actions.put(action.getActionType(), action.getActionHandler());
+ }
+
+ return actions;
+ }
+
+ /**
+ * Returns the notification handler corresponding to the given
+ * <tt>eventType</tt> and <tt>actionType</tt>.
+ *
+ * @param eventType the type of the event that we'd like to retrieve.
+ * @param actionType the type of the action that we'd like to retrieve a
+ * descriptor for.
+ * @return the notification handler of the action to be executed
+ * when an event of the specified type has occurred.
+ */
+ public NotificationActionHandler getEventNotificationActionHandler(
+ String eventType,
+ String actionType)
+ {
+ EventNotification notification
+ = (EventNotification) notificationsTable.get(eventType);
+
+ if(notification == null)
+ return null;
+
+ EventNotification.Action action = notification.getAction(actionType);
+
+ if(action == null)
+ return null;
+
+ return action.getActionHandler();
+ }
+
+ /**
+ * Adds the given <tt>listener</tt> to the list of change listeners.
+ *
+ * @param listener the listener that we'd like to register to listen for
+ * changes in the event notifications stored by this service.
+ */
+ public void addEventNotificationChangeListener(Object listener)
+ {
+ synchronized (changeListeners)
+ {
+ changeListeners.add(listener);
+ }
+ }
+
+ /**
+ * Removes the given <tt>listener</tt> from the list of change listeners.
+ *
+ * @param listener the listener that we'd like to remove
+ */
+ public void removeEventNotificationChangeListener(Object listener)
+ {
+ synchronized (changeListeners)
+ {
+ changeListeners.remove(listener);
+ }
+ }
+
+ /**
+ * If there is a registered event notification of the given
+ * <tt>eventType</tt> and the event notification is currently activated, we
+ * go through the list of registered actions and execute them.
+ *
+ * @param eventType the type of the event that we'd like to fire a
+ * notification for.
+ * @param message the message to use if and where appropriate (e.g. with
+ * systray or log notification.)
+ */
+ public void fireNotification(String eventType, String title, String message)
+ {
+ EventNotification notification
+ = (EventNotification) notificationsTable.get(eventType);
+
+ if(notification == null || !notification.isActive())
+ return;
+
+ Iterator actions = notification.getActions().values().iterator();
+
+ while(actions.hasNext())
+ {
+ Action action = (Action) actions.next();
+
+ String actionType = action.getActionType();
+
+ if (actionType.equals(NotificationService.ACTION_POPUP_MESSAGE))
+ {
+ System.out.println("POPUP MESSAGE ");
+ ((PopupMessageNotificationHandler) action.getActionHandler())
+ .popupMessage(title, message);
+ }
+ else if (actionType.equals(NotificationService.ACTION_LOG_MESSAGE))
+ {
+ ((LogMessageNotificationHandler) action.getActionHandler())
+ .logMessage(message);
+ }
+ else if (actionType.equals(NotificationService.ACTION_SOUND))
+ {
+ ((SoundNotificationHandler) action.getActionHandler())
+ .start();
+ }
+ else if (actionType.equals(NotificationService.ACTION_COMMAND))
+ {
+ ((CommandNotificationHandler) action.getActionHandler())
+ .execute();
+ }
+ }
+ }
+
+ /**
+ * If there is a registered event notification of the given
+ * <tt>eventType</tt> and the event notification is currently activated, we
+ * go through the list of registered actions and execute them.
+ *
+ * @param eventType the type of the event that we'd like to fire a
+ * notification for.
+ */
+ public void fireNotification(String eventType)
+ {
+ this.fireNotification(eventType, null, null);
+ }
+
+ /**
+ * Saves the event notification given by these parameters through the
+ * <tt>ConfigurationService</tt>.
+ *
+ * @param eventType the name of the event
+ * @param actionType the type of action
+ * @param actionHandler the notification action handler responsible for
+ * handling the given <tt>actionType</tt>
+ */
+ private void saveNotification( String eventType,
+ String actionType,
+ NotificationActionHandler actionHandler)
+ {
+ ConfigurationService configService
+ = NotificationActivator.getConfigurationService();
+
+ String eventPrefix = "net.java.sip.communicator.impl.notifications";
+
+ String eventTypeNodeName = null;
+ String actionTypeNodeName = null;
+
+ List eventTypes = configService
+ .getPropertyNamesByPrefix(eventPrefix, true);
+
+ Iterator eventTypesIter = eventTypes.iterator();
+
+ while(eventTypesIter.hasNext())
+ {
+ String eventTypeRootPropName
+ = (String) eventTypesIter.next();
+
+ String eType
+ = configService.getString(eventTypeRootPropName);
+
+ if(eType.equals(eventType))
+ eventTypeNodeName = eventTypeRootPropName;
+ }
+
+ // If we didn't find the given event type in the configuration we save
+ // it here.
+ if(eventTypeNodeName == null)
+ {
+ eventTypeNodeName = eventPrefix
+ + ".eventType"
+ + Long.toString(System.currentTimeMillis());
+
+ configService.setProperty(eventTypeNodeName, eventType);
+ }
+
+ // Go through contained actions.
+ String actionPrefix = eventTypeNodeName + ".actions";
+
+ List actionTypes = configService
+ .getPropertyNamesByPrefix(actionPrefix, true);
+
+ Iterator actionTypesIter = actionTypes.iterator();
+
+ while(actionTypesIter.hasNext())
+ {
+ String actionTypeRootPropName
+ = (String) actionTypesIter.next();
+
+ String aType
+ = configService.getString(actionTypeRootPropName);
+
+ if(aType.equals(actionType))
+ actionTypeNodeName = actionTypeRootPropName;
+ }
+
+ // If we didn't find the given actionType in the configuration we save
+ // it here.
+ if(actionTypeNodeName == null)
+ {
+ actionTypeNodeName = actionPrefix
+ + ".actionType"
+ + Long.toString(System.currentTimeMillis());
+
+ configService.setProperty(actionTypeNodeName, actionType);
+ }
+
+ if(actionHandler instanceof SoundNotificationHandler)
+ {
+ SoundNotificationHandler soundHandler
+ = (SoundNotificationHandler) actionHandler;
+
+ configService.setProperty(
+ actionTypeNodeName + ".soundFileDescriptor",
+ soundHandler.getDescriptor());
+
+ configService.setProperty(
+ actionTypeNodeName + ".loopInterval",
+ new Integer(soundHandler.getLoopInterval()));
+ }
+ else if(actionHandler instanceof PopupMessageNotificationHandler)
+ {
+ PopupMessageNotificationHandler messageHandler
+ = (PopupMessageNotificationHandler) actionHandler;
+
+ configService.setProperty(
+ actionTypeNodeName + ".defaultMessage",
+ messageHandler.getDefaultMessage());
+ }
+ else if(actionHandler instanceof LogMessageNotificationHandler)
+ {
+ LogMessageNotificationHandler logMessageHandler
+ = (LogMessageNotificationHandler) actionHandler;
+
+ configService.setProperty(
+ actionTypeNodeName + ".logType",
+ logMessageHandler.getLogType());
+ }
+ else if(actionHandler instanceof CommandNotificationHandler)
+ {
+ CommandNotificationHandler commandHandler
+ = (CommandNotificationHandler) actionHandler;
+
+ configService.setProperty(
+ actionTypeNodeName + ".commandDescriptor",
+ commandHandler.getDescriptor());
+ }
+ }
+
+ /**
+ * Loads all previously saved event notifications.
+ */
+ private void loadNotifications()
+ {
+ ConfigurationService configService
+ = NotificationActivator.getConfigurationService();
+
+ String prefix = "net.java.sip.communicator.impl.notifications";
+
+ List eventTypes = configService
+ .getPropertyNamesByPrefix(prefix, true);
+
+ Iterator eventTypesIter = eventTypes.iterator();
+
+ while(eventTypesIter.hasNext())
+ {
+ String eventTypeRootPropName
+ = (String) eventTypesIter.next();
+
+ String eventType
+ = configService.getString(eventTypeRootPropName);
+
+ List actions = configService
+ .getPropertyNamesByPrefix(
+ eventTypeRootPropName + ".actions", true);
+
+ Iterator actionsIter = actions.iterator();
+
+ while(actionsIter.hasNext())
+ {
+ String actionPropName
+ = (String) actionsIter.next();
+
+ String actionType
+ = configService.getString(actionPropName);
+
+ NotificationActionHandler handler = null;
+
+ if(actionType.equals(ACTION_SOUND))
+ {
+ String soundFileDescriptor
+ = configService.getString(
+ actionPropName + ".soundFileDescriptor");
+
+ String loopInterval
+ = configService.getString(
+ actionPropName + ".loopInterval");
+
+ handler = new SoundNotificationHandlerImpl(
+ soundFileDescriptor,
+ new Integer(loopInterval).intValue());
+ }
+ else if(handler instanceof PopupMessageNotificationHandler)
+ {
+ String defaultMessage
+ = configService.getString(
+ actionPropName + ".defaultMessage");
+
+ handler = new PopupMessageNotificationHandlerImpl(
+ defaultMessage);
+ }
+ else if(handler instanceof LogMessageNotificationHandler)
+ {
+ String logType
+ = configService.getString(
+ actionPropName + ".logType");
+
+ handler = new LogMessageNotificationHandlerImpl(logType);
+ }
+ else if(handler instanceof CommandNotificationHandler)
+ {
+ String commandDescriptor
+ = configService.getString(
+ actionPropName + ".commandDescriptor");
+
+ handler = new LogMessageNotificationHandlerImpl(
+ commandDescriptor);
+ }
+
+ // Load the data in the notifications table.
+ EventNotification notification
+ = new EventNotification(eventType);
+
+ notificationsTable.put(eventType, notification);
+
+ notification.addAction(actionType, handler);
+ }
+ }
+ }
+
+ /**
+ * Finds the <tt>EventNotification</tt> corresponding to the given
+ * <tt>eventType</tt> and marks it as activated/desactivated.
+ *
+ * @param eventType the name of the event, which actions should be activated
+ * /desactivated.
+ * @param isActive indicates whether to activate or desactivate the actions
+ * related to the specified <tt>eventType</tt>.
+ */
+ public void setActive(String eventType, boolean isActive)
+ {
+ EventNotification eventNotification
+ = (EventNotification) notificationsTable.get(eventType);
+
+ if(eventNotification == null)
+ return;
+
+ eventNotification.setActive(isActive);
+ }
+
+ /**
+ * Finds the <tt>EventNotification</tt> corresponding to the given
+ * <tt>eventType</tt> and returns its isActive status.
+ *
+ * @param eventType the name of the event (as defined by the plugin that's
+ * registered it) that we are checking.
+ * @return <code>true</code> if actions for the specified <tt>eventType</tt>
+ * are activated, <code>false</code> - otherwise. If the given
+ * <tt>eventType</tt> is not contained in the list of registered event
+ * types - returns <code>false</code>.
+ */
+ public boolean isActive(String eventType)
+ {
+ EventNotification eventNotification
+ = (EventNotification) notificationsTable.get(eventType);
+
+ if(eventNotification == null)
+ return false;
+
+ return eventNotification.isActive();
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/notification/PopupMessageNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/PopupMessageNotificationHandlerImpl.java
new file mode 100644
index 0000000..099bb0a
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/notification/PopupMessageNotificationHandlerImpl.java
@@ -0,0 +1,61 @@
+/*
+ * 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.notification;
+
+import net.java.sip.communicator.service.notification.*;
+import net.java.sip.communicator.service.systray.*;
+
+
+/**
+ * An implementation of the <tt>PopupMessageNotificationHandler</tt> interface.
+ *
+ * @author Yana Stamcheva
+ */
+public class PopupMessageNotificationHandlerImpl
+ implements PopupMessageNotificationHandler
+{
+ private String defaultMessage;
+
+ /**
+ * Creates an instance of <tt>PopupMessageNotificationHandlerImpl</tt> by
+ * specifying the default message to use if no message is specified.
+ *
+ * @param defaultMessage the default message to use if no message is
+ * specified
+ */
+ public PopupMessageNotificationHandlerImpl(String defaultMessage)
+ {
+ this.defaultMessage = defaultMessage;
+ }
+
+ /**
+ * Return the default message to use if no message is specified.
+ *
+ * @return the default message to use if no message is specified.
+ */
+ public String getDefaultMessage()
+ {
+ return defaultMessage;
+ }
+
+ /**
+ * Shows a popup message through the <tt>SystrayService</tt>.
+ *
+ * @param title the title of the popup
+ * @param message the message to show in the popup
+ */
+ public void popupMessage(String title, String message)
+ {
+ SystrayService systray = NotificationActivator.getSystray();
+
+ if(systray == null)
+ return;
+
+ systray.showPopupMessage(title, message,
+ SystrayService.NONE_MESSAGE_TYPE);
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java
new file mode 100644
index 0000000..50331f9
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java
@@ -0,0 +1,109 @@
+/*
+ * 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.notification;
+
+import net.java.sip.communicator.service.audionotifier.*;
+import net.java.sip.communicator.service.notification.*;
+
+/**
+ * An implementation of the <tt>SoundNotificationHandlerImpl</tt> interface.
+ *
+ * @author Yana Stamcheva
+ */
+public class SoundNotificationHandlerImpl
+ implements SoundNotificationHandler
+{
+ private String soundFileDescriptor;
+
+ /**
+ * By default we don't play sounds in loop.
+ */
+ private int loopInterval = -1;
+
+ private SCAudioClip audio;
+
+ /**
+ * Creates an instance of <tt>SoundNotificationHandlerImpl</tt> by
+ * specifying the sound file descriptor.
+ *
+ * @param soundDescriptor the sound file descriptor
+ */
+ public SoundNotificationHandlerImpl(String soundDescriptor)
+ {
+ this.soundFileDescriptor = soundDescriptor;
+ }
+
+ /**
+ * Creates an instance of <tt>SoundNotificationHandlerImpl</tt> by
+ * specifying the sound file descriptor and the loop interval.
+ *
+ * @param soundDescriptor the sound file descriptor
+ * @param loopInterval the loop interval
+ */
+ public SoundNotificationHandlerImpl( String soundDescriptor,
+ int loopInterval)
+ {
+ this.soundFileDescriptor = soundDescriptor;
+ this.loopInterval = loopInterval;
+ }
+
+ /**
+ * Returns the loop interval. This is the interval of milliseconds to wait
+ * before repeating the sound, when playing a sound in loop. By default this
+ * method returns -1.
+ *
+ * @return the loop interval
+ */
+ public int getLoopInterval()
+ {
+ return loopInterval;
+ }
+
+ /**
+ * Plays the sound given by the containing <tt>soundFileDescriptor</tt>. The
+ * sound is played in loop if the loopInterval is defined.
+ */
+ public void start()
+ {
+ AudioNotifierService audioNotifService
+ = NotificationActivator.getAudioNotifier();
+
+ if(audioNotifService == null)
+ return;
+
+ audio = audioNotifService.createAudio(soundFileDescriptor);
+
+ if(loopInterval > -1)
+ audio.playInLoop(loopInterval);
+ else
+ audio.play();
+ }
+
+ /**
+ * Stops the sound.
+ */
+ public void stop()
+ {
+ AudioNotifierService audioNotifService
+ = NotificationActivator.getAudioNotifier();
+
+ if(audioNotifService == null)
+ return;
+
+ audioNotifService.destroyAudio(audio);
+ }
+
+ /**
+ * Returns the descriptor pointing to the sound to be played.
+ *
+ * @return the descriptor pointing to the sound to be played.
+ */
+ public String getDescriptor()
+ {
+ return soundFileDescriptor;
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/notification/notification.manifest.mf b/src/net/java/sip/communicator/impl/notification/notification.manifest.mf
new file mode 100644
index 0000000..400458d
--- /dev/null
+++ b/src/net/java/sip/communicator/impl/notification/notification.manifest.mf
@@ -0,0 +1,13 @@
+Bundle-Activator: net.java.sip.communicator.impl.notification.NotificationActivator
+Bundle-Name: Notifications
+Bundle-Description: An implementation of the Notification service.
+Bundle-Vendor: sip-communicator.org
+Bundle-Version: 0.0.1
+Export-Package: net.java.sip.communicator.service.notification,
+ net.java.sip.communicator.service.notification.event
+Import-Package: org.osgi.framework,
+ net.java.sip.communicator.util,
+ net.java.sip.communicator.service.configuration,
+ net.java.sip.communicator.service.configuration.event,
+ net.java.sip.communicator.service.audionotifier,
+ net.java.sip.communicator.service.systray