diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2010-12-21 09:30:55 +0000 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2010-12-21 09:30:55 +0000 |
commit | 36033a6591985884f972a717278fdd9b4b40a7be (patch) | |
tree | 35e036dbae7c2491fd7f9cd0878215cba8d18933 /src/net/java/sip | |
parent | b55ce1cbd624d889b1299fb7659ce6980ce4b5d3 (diff) | |
download | jitsi-36033a6591985884f972a717278fdd9b4b40a7be.zip jitsi-36033a6591985884f972a717278fdd9b4b40a7be.tar.gz jitsi-36033a6591985884f972a717278fdd9b4b40a7be.tar.bz2 |
Commits work in progress on adding support for the Address Book of Microsoft Outlook.
Diffstat (limited to 'src/net/java/sip')
7 files changed, 488 insertions, 1 deletions
diff --git a/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookActivator.java b/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookActivator.java new file mode 100644 index 0000000..2b55fb9 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookActivator.java @@ -0,0 +1,95 @@ +/*
+ * 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.plugin.msoutlook;
+
+import net.java.sip.communicator.service.contactsource.*;
+
+import org.osgi.framework.*;
+
+/**
+ * Implements <tt>BundleActivator</tt> for the msoutlook plug-in which provides
+ * support for Microsoft Outlook.
+ *
+ * @author Lyubomir Marinov
+ */
+public class MsOutlookActivator
+ implements BundleActivator
+{
+ /**
+ * The <tt>MsOutlookAddressBookContactSourceService</tt> which implements
+ * <tt>ContactSourceService</tt> for the Address Book of Microsoft Outlook.
+ */
+ private MsOutlookAddressBookContactSourceService msoabcss;
+
+ /**
+ * The <tt>ServiceRegistration</tt> of {@link #msoabcss} in the
+ * <tt>BundleContext</tt> in which this <tt>MsOutlookActivator</tt> has been
+ * started.
+ */
+ private ServiceRegistration msoabcssServiceRegistration;
+
+ /**
+ * Starts the msoutlook plug-in.
+ *
+ * @param bundleContext the <tt>BundleContext</tt> in which the msoutlook
+ * plug-in is to be started
+ * @throws Exception if anything goes wrong while starting the msoutlook
+ * plug-in
+ * @see BundleActivator#start(BundleContext)
+ */
+ public void start(BundleContext bundleContext)
+ throws Exception
+ {
+ msoabcss = new MsOutlookAddressBookContactSourceService();
+ try
+ {
+ msoabcssServiceRegistration
+ = bundleContext.registerService(
+ ContactSourceService.class.getName(),
+ msoabcss,
+ null);
+ }
+ finally
+ {
+ if (msoabcssServiceRegistration == null)
+ {
+ msoabcss.stop();
+ msoabcss = null;
+ }
+ }
+ }
+
+ /**
+ * Stops the msoutlook plug-in.
+ *
+ * @param bundleContext the <tt>BundleContext</tt> in which the msoutlook
+ * plug-in is to be stopped
+ * @throws Exception if anything goes wrong while stopping the msoutlook
+ * plug-in
+ * @see BundleActivator#stop(BundleContext)
+ */
+ public void stop(BundleContext bundleContext)
+ throws Exception
+ {
+ try
+ {
+ if (msoabcssServiceRegistration != null)
+ {
+ msoabcssServiceRegistration.unregister();
+ msoabcssServiceRegistration = null;
+ }
+ }
+ finally
+ {
+ if (msoabcss != null)
+ {
+ msoabcss.stop();
+ msoabcss = null;
+ }
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookAddressBookContactQuery.java b/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookAddressBookContactQuery.java new file mode 100644 index 0000000..de037cb --- /dev/null +++ b/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookAddressBookContactQuery.java @@ -0,0 +1,72 @@ +/*
+ * 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.plugin.msoutlook;
+
+import java.util.*;
+
+import net.java.sip.communicator.service.contactsource.*;
+
+/**
+ * Implements <tt>ContactQuery</tt> for the Address Book of Microsoft Outlook.
+ *
+ * @author Lyubomir Marinov
+ */
+public class MsOutlookAddressBookContactQuery
+ extends AbstractContactQuery<MsOutlookAddressBookContactSourceService>
+{
+ /**
+ * Initializes a new <tt>MsOutlookAddressBookContactQuery</tt> instance to
+ * be performed by a specific
+ * <tt>MsOutlookAddressBookContactSourceService</tt>.
+ *
+ * @param msoabcss the <tt>MsOutlookAddressBookContactSourceService</tt>
+ * which is to perform the new <tt>ContactQuery</tt>
+ */
+ public MsOutlookAddressBookContactQuery(
+ MsOutlookAddressBookContactSourceService msoabcss)
+ {
+ super(msoabcss);
+ }
+
+ /**
+ * Cancels this <tt>ContactQuery</tt>.
+ *
+ * @see ContactQuery#cancel()
+ */
+ public void cancel()
+ {
+ // TODO Auto-generated method stub
+ }
+
+ /**
+ * Gets the <tt>List</tt> of <tt>SourceContact</tt>s which match this
+ * <tt>ContactQuery</tt>.
+ *
+ * @return the <tt>List</tt> of <tt>SourceContact</tt>s which match this
+ * <tt>ContactQuery</tt>
+ * @see ContactQuery#getQueryResults()
+ */
+ public List<SourceContact> getQueryResults()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Gets the status of this <tt>ContactQuery</tt> which can be one of the
+ * <tt>QUERY_XXX</tt> constants defined by <tt>ContactQuery</tt>.
+ *
+ * @return the status of this <tt>ContactQuery</tt> which can be one of the
+ * <tt>QUERY_XXX</tt> constants defined by <tt>ContactQuery</tt>
+ * @see ContactQuery#getStatus()
+ */
+ public int getStatus()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookAddressBookContactSourceService.java b/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookAddressBookContactSourceService.java new file mode 100644 index 0000000..0343744 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookAddressBookContactSourceService.java @@ -0,0 +1,95 @@ +/*
+ * 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.plugin.msoutlook;
+
+import net.java.sip.communicator.service.contactsource.*;
+
+/**
+ * Implements <tt>ContactSourceService</tt> for the Address Book of Microsoft
+ * Outlook.
+ *
+ * @author Lyubomir Marinov
+ */
+public class MsOutlookAddressBookContactSourceService
+ implements ContactSourceService
+{
+ private static final long MAPI_INIT_VERSION = 0;
+
+ private static final long MAPI_MULTITHREAD_NOTIFICATIONS = 0x00000001;
+
+ /**
+ * Initializes a new <tt>MsOutlookAddressBookContactSourceService</tt>
+ * instance.
+ *
+ * @throws MsOutlookMAPIHResultException if anything goes wrong while
+ * initializing the new <tt>MsOutlookAddressBookContactSourceService</tt>
+ * instance
+ */
+ public MsOutlookAddressBookContactSourceService()
+ throws MsOutlookMAPIHResultException
+ {
+ MAPIInitialize(MAPI_INIT_VERSION, MAPI_MULTITHREAD_NOTIFICATIONS);
+ }
+
+ /**
+ * Gets a human-readable <tt>String</tt> which names this
+ * <tt>ContactSourceService</tt> implementation.
+ *
+ * @return a human-readable <tt>String</tt> which names this
+ * <tt>ContactSourceService</tt> implementation
+ * @see ContactSourceService#getDisplayName()
+ */
+ public String getDisplayName()
+ {
+ return "Microsoft Outlook Address Book";
+ }
+
+ /**
+ * Gets a <tt>String</tt> which uniquely identifies the instances of the
+ * <tt>MsOutlookAddressBookContactSourceService</tt> implementation.
+ *
+ * @return a <tt>String</tt> which uniquely identifies the instances of the
+ * <tt>MsOutlookAddressBookContactSourceService</tt> implementation
+ * @see ContactSourceService#getIdentifier()
+ */
+ public String getIdentifier()
+ {
+ return "MsOutlookAddressBook";
+ }
+
+ private static native void MAPIInitialize(long version, long flags)
+ throws MsOutlookMAPIHResultException;
+
+ private static native void MAPIUninitialize();
+
+ /**
+ * Queries this <tt>ContactSourceService</tt> for <tt>SourceContact</tt>s
+ * which match a specific <tt>query</tt> <tt>String</tt>.
+ *
+ * @param query the <tt>String</tt> which this <tt>ContactSourceService</tt>
+ * is being queried for
+ * @return a <tt>ContactQuery</tt> which represents the query of this
+ * <tt>ContactSourceService</tt> implementation for the specified
+ * <tt>String</tt> and via which the matching <tt>SourceContact</tt>s (if
+ * any) will be returned
+ * @see ContactSourceService#queryContactSource(String)
+ */
+ public ContactQuery queryContactSource(String query)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Stops this <tt>ContactSourceService</tt> implementation and prepares it
+ * for garbage collection.
+ */
+ void stop()
+ {
+ MAPIUninitialize();
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookMAPIHResultException.java b/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookMAPIHResultException.java new file mode 100644 index 0000000..d5a6f6f --- /dev/null +++ b/src/net/java/sip/communicator/plugin/msoutlook/MsOutlookMAPIHResultException.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.plugin.msoutlook;
+
+/**
+ * Represents a specific Microsoft Outlook MAPI <tt>HRESULT</tt> as an
+ * <tt>Exception</tt>.
+ *
+ * @author Lyubomir Marinov
+ */
+public class MsOutlookMAPIHResultException
+ extends Exception
+{
+ /**
+ * The <tt>HRESULT</tt> which is represented by this <tt>Exception</tt>.
+ */
+ private final long hResult;
+
+ /**
+ * Initializes a new <tt>MsOutlookMAPIHResultException</tt> instance which
+ * is to represent a specific <tt>HRESULT</tt>.
+ *
+ * @param hResult the <tt>HRESULT</tt> to be represented by the new instance
+ */
+ public MsOutlookMAPIHResultException(long hResult)
+ {
+ this.hResult = hResult;
+ }
+
+ /**
+ * Initializes a new <tt>MsOutlookMAPIHResultException</tt> instance which
+ * is to represent a specific <tt>HRESULT</tt> and to provide a specific
+ * <tt>String</tt> message.
+ *
+ * @param hResult the <tt>HRESULT</tt> to be represented by the new instance
+ * @param message the <tt>String</tt> message to be provided by the new
+ * instance
+ */
+ public MsOutlookMAPIHResultException(long hResult, String message)
+ {
+ super(message);
+
+ this.hResult = hResult;
+ }
+
+ /**
+ * Gets the <tt>HRESULT</tt> which is represented by this
+ * <tt>Exception</tt>.
+ *
+ * @return the <tt>HRESULT</tt> which is represented by this
+ * <tt>Exception</tt>
+ */
+ public long getHResult()
+ {
+ return hResult;
+ }
+}
diff --git a/src/net/java/sip/communicator/plugin/msoutlook/msoutlook.manifest.mf b/src/net/java/sip/communicator/plugin/msoutlook/msoutlook.manifest.mf new file mode 100644 index 0000000..8909037 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/msoutlook/msoutlook.manifest.mf @@ -0,0 +1,8 @@ +Bundle-Activator: net.java.sip.communicator.plugin.msoutlook.MsOutlookActivator
+Bundle-Description: Microsoft Outlook support
+Bundle-Name: Microsoft Outlook support
+Bundle-Vendor: sip-communicator.org
+Bundle-Version: 0.0.1
+Import-Package: net.java.sip.communicator.service.contactsource,
+ org.osgi.framework
+System-Bundle: yes
diff --git a/src/net/java/sip/communicator/service/contactsource/AbstractContactQuery.java b/src/net/java/sip/communicator/service/contactsource/AbstractContactQuery.java new file mode 100644 index 0000000..94f3212 --- /dev/null +++ b/src/net/java/sip/communicator/service/contactsource/AbstractContactQuery.java @@ -0,0 +1,156 @@ +/*
+ * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.service.contactsource;
+
+import java.util.*;
+
+/**
+ * Provides an abstract implementation of the basic functionality of
+ * <tt>ContactQuery</tt> and allows extenders to focus on the specifics of their
+ * implementation.
+ *
+ * @author Lyubomir Marinov
+ * @param <T> the very type of <tt>ContactSourceService</tt> which performs the
+ * <tt>ContactQuery</tt>
+ */
+public abstract class AbstractContactQuery<T extends ContactSourceService>
+ implements ContactQuery
+{
+ /**
+ * The <tt>ContactSourceService</tt> which is performing this
+ * <tt>ContactQuery</tt>.
+ */
+ private final T contactSource;
+
+ /**
+ * The <tt>List</tt> of <tt>ContactQueryListener</tt>s which are to be
+ * notified by this <tt>ContactQuery</tt> about changes in its status, the
+ * receipt of new <tt>ContactSource</tt>s via this <tt>ContactQuery</tt>,
+ * etc.
+ */
+ private final List<ContactQueryListener> listeners
+ = new LinkedList<ContactQueryListener>();
+
+ /**
+ * Initializes a new <tt>AbstractContactQuery</tt> which is to be performed
+ * by a specific <tt>ContactSourceService</tt>.
+ *
+ * @param contactSource the <tt>ContactSourceService</tt> which is to
+ * perform the new <tt>AbstractContactQuery</tt>
+ */
+ protected AbstractContactQuery(T contactSource)
+ {
+ this.contactSource = contactSource;
+ }
+
+ /**
+ * Adds a <tt>ContactQueryListener</tt> to the list of listeners interested
+ * in notifications about this <tt>ContactQuery</tt> changing its status,
+ * the receipt of new <tt>SourceContact</tt>s via this
+ * <tt>ContactQuery</tt>, etc.
+ *
+ * @param l the <tt>ContactQueryListener</tt> to be added to the list of
+ * listeners interested in the notifications raised by this
+ * <tt>ContactQuery</tt>
+ * @see ContactQuery#addContactQueryListener(ContactQueryListener)
+ */
+ public void addContactQueryListener(ContactQueryListener l)
+ {
+ if (l == null)
+ throw new NullPointerException("l");
+ else
+ {
+ synchronized (listeners)
+ {
+ if (!listeners.contains(l))
+ listeners.add(l);
+ }
+ }
+ }
+
+ /**
+ * Notifies the <tt>ContactQueryListener</tt>s registered with this
+ * <tt>ContactQuery</tt> that a new <tt>SourceContact</tt> has been
+ * received.
+ *
+ * @param contact the <tt>SourceContact</tt> which has been received and
+ * which the registered <tt>ContactQueryListener</tt>s are to be notified
+ * about
+ */
+ protected void fireContactReceived(SourceContact contact)
+ {
+ ContactQueryListener[] ls;
+
+ synchronized (listeners)
+ {
+ ls = listeners.toArray(new ContactQueryListener[listeners.size()]);
+ }
+
+ ContactReceivedEvent ev = new ContactReceivedEvent(this, contact);
+
+ for (ContactQueryListener l : ls)
+ l.contactReceived(ev);
+ }
+
+ /**
+ * Notifies the <tt>ContactQueryListener</tt>s registered with this
+ * <tt>ContactQuery</tt> that its state has changed.
+ *
+ * @param eventType the type of the <tt>ContactQueryStatusEvent</tt> to be
+ * fired which can be one of the <tt>QUERY_XXX</tt> constants defined by
+ * <tt>ContactQueryStatusEvent</tt>
+ */
+ protected void fireQueryStatusChanged(int eventType)
+ {
+ ContactQueryListener[] ls;
+
+ synchronized (listeners)
+ {
+ ls = listeners.toArray(new ContactQueryListener[listeners.size()]);
+ }
+
+ ContactQueryStatusEvent ev
+ = new ContactQueryStatusEvent(this, eventType);
+
+ for (ContactQueryListener l : ls)
+ l.queryStatusChanged(ev);
+ }
+
+ /**
+ * Gets the <tt>ContactSourceService</tt> which is performing this
+ * <tt>ContactQuery</tt>.
+ *
+ * @return the <tt>ContactSourceService</tt> which is performing this
+ * <tt>ContactQuery</tt>
+ * @see ContactQuery#getContactSource()
+ */
+ public T getContactSource()
+ {
+ return contactSource;
+ }
+
+ /**
+ * Removes a <tt>ContactQueryListener</tt> from the list of listeners
+ * interested in notifications about this <tt>ContactQuery</tt> changing its
+ * status, the receipt of new <tt>SourceContact</tt>s via this
+ * <tt>ContactQuery</tt>, etc.
+ *
+ * @param l the <tt>ContactQueryListener</tt> to be removed from the list of
+ * listeners interested in notifications raised by this <tt>ContactQuery</tt>
+ * @see ContactQuery#removeContactQueryListener(ContactQueryListener)
+ */
+ public void removeContactQueryListener(ContactQueryListener l)
+ {
+ if (l != null)
+ {
+ synchronized (listeners)
+ {
+ listeners.remove(l);
+ }
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/service/contactsource/ContactSourceService.java b/src/net/java/sip/communicator/service/contactsource/ContactSourceService.java index 0f612e6..fd568dc 100644 --- a/src/net/java/sip/communicator/service/contactsource/ContactSourceService.java +++ b/src/net/java/sip/communicator/service/contactsource/ContactSourceService.java @@ -35,7 +35,7 @@ public interface ContactSourceService public String getDisplayName(); /** - * Queries this search source for the given <tt>searchString</tt>. + * Queries this search source for the given <tt>queryString</tt>. * @param queryString the string to search for * @return the created query */ |