aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/service/contactsource
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/java/sip/communicator/service/contactsource')
-rw-r--r--src/net/java/sip/communicator/service/contactsource/AbstractContactQuery.java568
-rw-r--r--src/net/java/sip/communicator/service/contactsource/AsyncContactQuery.java816
-rw-r--r--src/net/java/sip/communicator/service/contactsource/AsyncContactSourceService.java136
-rw-r--r--src/net/java/sip/communicator/service/contactsource/ContactDetail.java14
-rw-r--r--src/net/java/sip/communicator/service/contactsource/GenericSourceContact.java586
5 files changed, 1064 insertions, 1056 deletions
diff --git a/src/net/java/sip/communicator/service/contactsource/AbstractContactQuery.java b/src/net/java/sip/communicator/service/contactsource/AbstractContactQuery.java
index 2c14e52..be9de8a 100644
--- a/src/net/java/sip/communicator/service/contactsource/AbstractContactQuery.java
+++ b/src/net/java/sip/communicator/service/contactsource/AbstractContactQuery.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,286 +15,286 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-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>();
-
- /**
- * The status of this <tt>ContactQuery</tt> which is one of the
- * <tt>QUERY_XXX</tt> constants defined by the <tt>ContactQuery</tt> class.
- */
- private int status = QUERY_IN_PROGRESS;
-
- /**
- * Initializes a new <tt>AbstractContactQuery</tt> which is to be performed
- * by a specific <tt>ContactSourceService</tt>. The status of the new
- * instance is {@link ContactQuery#QUERY_IN_PROGRESS}.
- *
- * @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);
- }
- }
- }
-
- /**
- * Cancels this <tt>ContactQuery</tt>.
- *
- * @see ContactQuery#cancel()
- */
- public void cancel()
- {
- if (getStatus() == QUERY_IN_PROGRESS)
- setStatus(QUERY_CANCELED);
- }
-
- /**
- * 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
- * @param showMoreEnabled indicates whether show more label should be shown
- * or not.
- */
- protected void fireContactReceived(SourceContact contact,
- boolean showMoreEnabled)
- {
- ContactQueryListener[] ls;
-
- synchronized (listeners)
- {
- ls = listeners.toArray(new ContactQueryListener[listeners.size()]);
- }
-
- ContactReceivedEvent ev
- = new ContactReceivedEvent(this, contact, showMoreEnabled);
-
- for (ContactQueryListener l : ls)
- {
- l.contactReceived(ev);
- }
- }
-
- /**
- * 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)
- {
- fireContactReceived(contact, true);
- }
-
- /**
- * Notifies the <tt>ContactQueryListener</tt>s registered with this
- * <tt>ContactQuery</tt> that a <tt>SourceContact</tt> has been
- * removed.
- *
- * @param contact the <tt>SourceContact</tt> which has been removed and
- * which the registered <tt>ContactQueryListener</tt>s are to be notified
- * about
- */
- protected void fireContactRemoved(SourceContact contact)
- {
- ContactQueryListener[] ls;
-
- synchronized (listeners)
- {
- ls = listeners.toArray(new ContactQueryListener[listeners.size()]);
- }
-
- ContactRemovedEvent ev = new ContactRemovedEvent(this, contact);
-
- for (ContactQueryListener l : ls)
- l.contactRemoved(ev);
- }
-
- /**
- * Notifies the <tt>ContactQueryListener</tt>s registered with this
- * <tt>ContactQuery</tt> that a <tt>SourceContact</tt> has been
- * changed.
- *
- * @param contact the <tt>SourceContact</tt> which has been changed and
- * which the registered <tt>ContactQueryListener</tt>s are to be notified
- * about
- */
- protected void fireContactChanged(SourceContact contact)
- {
- ContactQueryListener[] ls;
-
- synchronized (listeners)
- {
- ls = listeners.toArray(new ContactQueryListener[listeners.size()]);
- }
-
- ContactChangedEvent ev = new ContactChangedEvent(this, contact);
-
- for (ContactQueryListener l : ls)
- l.contactChanged(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;
- }
-
- /**
- * 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()
- {
- return status;
- }
-
- /**
- * 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);
- }
- }
- }
-
- /**
- * Sets the status of this <tt>ContactQuery</tt>.
- *
- * @param status {@link ContactQuery#QUERY_CANCELED},
- * {@link ContactQuery#QUERY_COMPLETED}, or
- * {@link ContactQuery#QUERY_ERROR}
- */
- public void setStatus(int status)
- {
- if (this.status != status)
- {
- int eventType;
-
- switch (status)
- {
- case QUERY_CANCELED:
- eventType = ContactQueryStatusEvent.QUERY_CANCELED;
- break;
- case QUERY_COMPLETED:
- eventType = ContactQueryStatusEvent.QUERY_COMPLETED;
- break;
- case QUERY_ERROR:
- eventType = ContactQueryStatusEvent.QUERY_ERROR;
- break;
- case QUERY_IN_PROGRESS:
- default:
- throw new IllegalArgumentException("status");
- }
-
- this.status = status;
- fireQueryStatusChanged(eventType);
- }
- }
-}
+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>();
+
+ /**
+ * The status of this <tt>ContactQuery</tt> which is one of the
+ * <tt>QUERY_XXX</tt> constants defined by the <tt>ContactQuery</tt> class.
+ */
+ private int status = QUERY_IN_PROGRESS;
+
+ /**
+ * Initializes a new <tt>AbstractContactQuery</tt> which is to be performed
+ * by a specific <tt>ContactSourceService</tt>. The status of the new
+ * instance is {@link ContactQuery#QUERY_IN_PROGRESS}.
+ *
+ * @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);
+ }
+ }
+ }
+
+ /**
+ * Cancels this <tt>ContactQuery</tt>.
+ *
+ * @see ContactQuery#cancel()
+ */
+ public void cancel()
+ {
+ if (getStatus() == QUERY_IN_PROGRESS)
+ setStatus(QUERY_CANCELED);
+ }
+
+ /**
+ * 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
+ * @param showMoreEnabled indicates whether show more label should be shown
+ * or not.
+ */
+ protected void fireContactReceived(SourceContact contact,
+ boolean showMoreEnabled)
+ {
+ ContactQueryListener[] ls;
+
+ synchronized (listeners)
+ {
+ ls = listeners.toArray(new ContactQueryListener[listeners.size()]);
+ }
+
+ ContactReceivedEvent ev
+ = new ContactReceivedEvent(this, contact, showMoreEnabled);
+
+ for (ContactQueryListener l : ls)
+ {
+ l.contactReceived(ev);
+ }
+ }
+
+ /**
+ * 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)
+ {
+ fireContactReceived(contact, true);
+ }
+
+ /**
+ * Notifies the <tt>ContactQueryListener</tt>s registered with this
+ * <tt>ContactQuery</tt> that a <tt>SourceContact</tt> has been
+ * removed.
+ *
+ * @param contact the <tt>SourceContact</tt> which has been removed and
+ * which the registered <tt>ContactQueryListener</tt>s are to be notified
+ * about
+ */
+ protected void fireContactRemoved(SourceContact contact)
+ {
+ ContactQueryListener[] ls;
+
+ synchronized (listeners)
+ {
+ ls = listeners.toArray(new ContactQueryListener[listeners.size()]);
+ }
+
+ ContactRemovedEvent ev = new ContactRemovedEvent(this, contact);
+
+ for (ContactQueryListener l : ls)
+ l.contactRemoved(ev);
+ }
+
+ /**
+ * Notifies the <tt>ContactQueryListener</tt>s registered with this
+ * <tt>ContactQuery</tt> that a <tt>SourceContact</tt> has been
+ * changed.
+ *
+ * @param contact the <tt>SourceContact</tt> which has been changed and
+ * which the registered <tt>ContactQueryListener</tt>s are to be notified
+ * about
+ */
+ protected void fireContactChanged(SourceContact contact)
+ {
+ ContactQueryListener[] ls;
+
+ synchronized (listeners)
+ {
+ ls = listeners.toArray(new ContactQueryListener[listeners.size()]);
+ }
+
+ ContactChangedEvent ev = new ContactChangedEvent(this, contact);
+
+ for (ContactQueryListener l : ls)
+ l.contactChanged(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;
+ }
+
+ /**
+ * 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()
+ {
+ return status;
+ }
+
+ /**
+ * 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);
+ }
+ }
+ }
+
+ /**
+ * Sets the status of this <tt>ContactQuery</tt>.
+ *
+ * @param status {@link ContactQuery#QUERY_CANCELED},
+ * {@link ContactQuery#QUERY_COMPLETED}, or
+ * {@link ContactQuery#QUERY_ERROR}
+ */
+ public void setStatus(int status)
+ {
+ if (this.status != status)
+ {
+ int eventType;
+
+ switch (status)
+ {
+ case QUERY_CANCELED:
+ eventType = ContactQueryStatusEvent.QUERY_CANCELED;
+ break;
+ case QUERY_COMPLETED:
+ eventType = ContactQueryStatusEvent.QUERY_COMPLETED;
+ break;
+ case QUERY_ERROR:
+ eventType = ContactQueryStatusEvent.QUERY_ERROR;
+ break;
+ case QUERY_IN_PROGRESS:
+ default:
+ throw new IllegalArgumentException("status");
+ }
+
+ this.status = status;
+ fireQueryStatusChanged(eventType);
+ }
+ }
+}
diff --git a/src/net/java/sip/communicator/service/contactsource/AsyncContactQuery.java b/src/net/java/sip/communicator/service/contactsource/AsyncContactQuery.java
index 1eb38f8..9570dad 100644
--- a/src/net/java/sip/communicator/service/contactsource/AsyncContactQuery.java
+++ b/src/net/java/sip/communicator/service/contactsource/AsyncContactQuery.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,410 +15,410 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.service.contactsource;
-
-import java.util.*;
-import java.util.regex.*;
-
-/**
- * Provides an abstract implementation of a <tt>ContactQuery</tt> which runs in
- * a separate <tt>Thread</tt>.
- *
- * @author Lyubomir Marinov
- * @param <T> the very type of <tt>ContactSourceService</tt> which performs the
- * <tt>ContactQuery</tt>
- */
-public abstract class AsyncContactQuery<T extends ContactSourceService>
- extends AbstractContactQuery<T>
-{
- /**
- * The {@link #query} in the form of a <tt>String</tt> telephone number if
- * such parsing, formatting and validation is possible; otherwise,
- * <tt>null</tt>.
- */
- private String phoneNumberQuery;
-
- /**
- * The <tt>Pattern</tt> for which the associated
- * <tt>ContactSourceService</tt> is being queried.
- */
- protected final Pattern query;
-
- /**
- * The indicator which determines whether there has been an attempt to
- * convert {@link #query} to {@link #phoneNumberQuery}. If the conversion has
- * been successful, <tt>phoneNumberQuery</tt> will be non-<tt>null</tt>.
- */
- private boolean queryIsConvertedToPhoneNumber;
-
- /**
- * The <tt>SourceContact</tt>s which match {@link #query}.
- */
- private Collection<SourceContact> queryResults
- = new LinkedList<SourceContact>();
-
- /**
- * The <tt>Thread</tt> in which this <tt>AsyncContactQuery</tt> is
- * performing {@link #query}.
- */
- private Thread thread;
-
- /**
- * Initializes a new <tt>AsyncContactQuery</tt> instance which is to perform
- * a specific <tt>query</tt> on behalf of a specific <tt>contactSource</tt>.
- *
- * @param contactSource the <tt>ContactSourceService</tt> which is to
- * perform the new <tt>ContactQuery</tt> instance
- * @param query the <tt>Pattern</tt> for which <tt>contactSource</tt> is
- * being queried
- * @param isSorted indicates if the results of this query should be sorted
- */
- protected AsyncContactQuery(T contactSource,
- Pattern query,
- boolean isSorted)
- {
- super(contactSource);
-
- this.query = query;
-
- if (isSorted)
- queryResults = new TreeSet<SourceContact>();
- }
-
- /**
- * Initializes a new <tt>AsyncContactQuery</tt> instance which is to perform
- * a specific <tt>query</tt> on behalf of a specific <tt>contactSource</tt>.
- *
- * @param contactSource the <tt>ContactSourceService</tt> which is to
- * perform the new <tt>ContactQuery</tt> instance
- * @param query the <tt>Pattern</tt> for which <tt>contactSource</tt> is
- * being queried
- */
- protected AsyncContactQuery(T contactSource, Pattern query)
- {
- super(contactSource);
-
- this.query = query;
- }
-
- /**
- * Adds a specific <tt>SourceContact</tt> to the list of
- * <tt>SourceContact</tt>s to be returned by this <tt>ContactQuery</tt> in
- * response to {@link #getQueryResults()}.
- *
- * @param sourceContact the <tt>SourceContact</tt> to be added to the
- * <tt>queryResults</tt> of this <tt>ContactQuery</tt>
- * @param showMoreEnabled indicates whether show more label should be shown
- * or not.
- * @return <tt>true</tt> if the <tt>queryResults</tt> of this
- * <tt>ContactQuery</tt> has changed in response to the call
- */
- protected boolean addQueryResult(SourceContact sourceContact,
- boolean showMoreEnabled)
- {
- boolean changed;
-
- synchronized (queryResults)
- {
- changed = queryResults.add(sourceContact);
- }
- if (changed)
- fireContactReceived(sourceContact, showMoreEnabled);
-
- return changed;
- }
-
- /**
- * Adds a specific <tt>SourceContact</tt> to the list of
- * <tt>SourceContact</tt>s to be returned by this <tt>ContactQuery</tt> in
- * response to {@link #getQueryResults()}.
- *
- * @param sourceContact the <tt>SourceContact</tt> to be added to the
- * <tt>queryResults</tt> of this <tt>ContactQuery</tt>
- * @return <tt>true</tt> if the <tt>queryResults</tt> of this
- * <tt>ContactQuery</tt> has changed in response to the call
- */
- protected boolean addQueryResult(SourceContact sourceContact)
- {
- boolean changed;
-
- synchronized (queryResults)
- {
- changed = queryResults.add(sourceContact);
- }
- if (changed)
- fireContactReceived(sourceContact);
-
- return changed;
- }
-
- /**
- * Removes a specific <tt>SourceContact</tt> from the list of
- * <tt>SourceContact</tt>s.
- *
- * @param sourceContact the <tt>SourceContact</tt> to be removed from the
- * <tt>queryResults</tt> of this <tt>ContactQuery</tt>
- * @return <tt>true</tt> if the <tt>queryResults</tt> of this
- * <tt>ContactQuery</tt> has changed in response to the call
- */
- protected boolean removeQueryResult(SourceContact sourceContact)
- {
- boolean changed;
-
- synchronized (queryResults)
- {
- changed = queryResults.remove(sourceContact);
- }
- if (changed)
- fireContactRemoved(sourceContact);
-
- return changed;
- }
-
- /**
- * Adds a set of <tt>SourceContact</tt> instances to the list of
- * <tt>SourceContact</tt>s to be returned by this <tt>ContactQuery</tt> in
- * response to {@link #getQueryResults()}.
- *
- * @param sourceContacts the set of <tt>SourceContact</tt> to be added to
- * the <tt>queryResults</tt> of this <tt>ContactQuery</tt>
- * @return <tt>true</tt> if the <tt>queryResults</tt> of this
- * <tt>ContactQuery</tt> has changed in response to the call
- */
- protected boolean addQueryResults(
- final Set<? extends SourceContact> sourceContacts)
- {
- final boolean changed;
-
- synchronized (queryResults)
- {
- changed = queryResults.addAll(sourceContacts);
- }
-
- if (changed)
- {
- // TODO Need something to fire one event for multiple contacts.
- for (SourceContact contact : sourceContacts)
- {
- fireContactReceived(contact, false);
- }
- }
-
- return changed;
- }
-
-
- /**
- * Gets the {@link #query} of this <tt>AsyncContactQuery</tt> as a
- * <tt>String</tt> which represents a phone number (if possible).
- *
- * @return a <tt>String</tt> which represents the <tt>query</tt> of this
- * <tt>AsyncContactQuery</tt> as a phone number if such parsing, formatting
- * and validation is possible; otherwise, <tt>null</tt>
- */
- protected String getPhoneNumberQuery()
- {
- if ((phoneNumberQuery == null) && !queryIsConvertedToPhoneNumber)
- {
- try
- {
- String pattern = query.pattern();
-
- if (pattern != null)
- {
- int patternLength = pattern.length();
-
- if ((patternLength > 2)
- && (pattern.charAt(0) == '^')
- && (pattern.charAt(patternLength - 1) == '$'))
- {
- phoneNumberQuery
- = pattern.substring(1, patternLength - 1);
- }
- else if ((patternLength > 4)
- && (pattern.charAt(0) == '\\')
- && (pattern.charAt(1) == 'Q')
- && (pattern.charAt(patternLength - 2) == '\\')
- && (pattern.charAt(patternLength - 1) == 'E'))
- {
- phoneNumberQuery
- = pattern.substring(2, patternLength - 2);
- }
-
- }
- }
- finally
- {
- queryIsConvertedToPhoneNumber = true;
- }
- }
- return phoneNumberQuery;
- }
-
- /**
- * Gets the number of <tt>SourceContact</tt>s which match this
- * <tt>ContactQuery</tt>.
- *
- * @return the number of <tt>SourceContact</tt> which match this
- * <tt>ContactQuery</tt>
- */
- public int getQueryResultCount()
- {
- synchronized (queryResults)
- {
- return queryResults.size();
- }
- }
-
- /**
- * 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()
- {
- List<SourceContact> qr;
-
- synchronized (queryResults)
- {
- qr = new ArrayList<SourceContact>(queryResults.size());
- qr.addAll(queryResults);
- }
- return qr;
- }
-
- /**
- * Returns the query string, this query was created for.
- *
- * @return the query string, this query was created for
- */
- public String getQueryString()
- {
- return query.toString();
- }
-
- /**
- * Performs this <tt>ContactQuery</tt> in a background <tt>Thread</tt>.
- */
- protected abstract void run();
-
- /**
- * Starts this <tt>AsyncContactQuery</tt>.
- */
- public synchronized void start()
- {
- if (thread == null)
- {
- thread
- = new Thread()
- {
- @Override
- public void run()
- {
- boolean completed = false;
-
- try
- {
- AsyncContactQuery.this.run();
- completed = true;
- }
- finally
- {
- synchronized (AsyncContactQuery.this)
- {
- if (thread == Thread.currentThread())
- stopped(completed);
- }
- }
- }
- };
- thread.setDaemon(true);
- thread.start();
- }
- else
- throw new IllegalStateException("thread");
- }
-
- /**
- * Notifies this <tt>AsyncContactQuery</tt> that it has stopped performing
- * in the associated background <tt>Thread</tt>.
- *
- * @param completed <tt>true</tt> if this <tt>ContactQuery</tt> has
- * successfully completed, <tt>false</tt> if an error has been encountered
- * during its execution
- */
- protected void stopped(boolean completed)
- {
- if (getStatus() == QUERY_IN_PROGRESS)
- setStatus(completed ? QUERY_COMPLETED : QUERY_ERROR);
- }
-
- /**
- * Determines whether a specific <tt>String</tt> phone number matches the
- * {@link #query} of this <tt>AsyncContactQuery</tt>.
- *
- * @param phoneNumber the <tt>String</tt> which represents the phone number
- * to match to the <tt>query</tt> of this <tt>AsyncContactQuery</tt>
- * @return <tt>true</tt> if the specified <tt>phoneNumber</tt> matches the
- * <tt>query</tt> of this <tt>AsyncContactQuery</tt>; otherwise,
- * <tt>false</tt>
- */
- protected boolean phoneNumberMatches(String phoneNumber)
- {
- /*
- * PhoneNumberI18nService implements functionality to aid the parsing,
- * formatting and validation of international phone numbers so attempt
- * to use it to determine whether the specified phoneNumber matches the
- * query. For example, check whether the normalized phoneNumber matches
- * the query.
- */
-
- boolean phoneNumberMatches = false;
-
- if (query
- .matcher(ContactSourceActivator.getPhoneNumberI18nService()
- .normalize(phoneNumber)).find())
- {
- phoneNumberMatches = true;
- }
- else
- {
- /*
- * The fact that the normalized form of the phoneNumber doesn't
- * match the query doesn't mean that, for example, it doesn't
- * match the normalized form of the query. The latter, though,
- * requires the query to look like a phone number as well. In
- * order to not accidentally start matching all queries to phone
- * numbers, it seems justified to normalize the query only when
- * it is a phone number, not whenever it looks like a piece of a
- * phone number.
- */
-
- String phoneNumberQuery = getPhoneNumberQuery();
-
- if ((phoneNumberQuery != null)
- && (phoneNumberQuery.length() != 0))
- {
- try
- {
- phoneNumberMatches
- = ContactSourceActivator.getPhoneNumberI18nService()
- .phoneNumbersMatch(
- phoneNumberQuery,
- phoneNumber);
- }
- catch (IllegalArgumentException iaex)
- {
- /*
- * Ignore it, phoneNumberMatches will remain equal to
- * false.
- */
- }
- }
- }
- return phoneNumberMatches;
- }
-}
+package net.java.sip.communicator.service.contactsource;
+
+import java.util.*;
+import java.util.regex.*;
+
+/**
+ * Provides an abstract implementation of a <tt>ContactQuery</tt> which runs in
+ * a separate <tt>Thread</tt>.
+ *
+ * @author Lyubomir Marinov
+ * @param <T> the very type of <tt>ContactSourceService</tt> which performs the
+ * <tt>ContactQuery</tt>
+ */
+public abstract class AsyncContactQuery<T extends ContactSourceService>
+ extends AbstractContactQuery<T>
+{
+ /**
+ * The {@link #query} in the form of a <tt>String</tt> telephone number if
+ * such parsing, formatting and validation is possible; otherwise,
+ * <tt>null</tt>.
+ */
+ private String phoneNumberQuery;
+
+ /**
+ * The <tt>Pattern</tt> for which the associated
+ * <tt>ContactSourceService</tt> is being queried.
+ */
+ protected final Pattern query;
+
+ /**
+ * The indicator which determines whether there has been an attempt to
+ * convert {@link #query} to {@link #phoneNumberQuery}. If the conversion has
+ * been successful, <tt>phoneNumberQuery</tt> will be non-<tt>null</tt>.
+ */
+ private boolean queryIsConvertedToPhoneNumber;
+
+ /**
+ * The <tt>SourceContact</tt>s which match {@link #query}.
+ */
+ private Collection<SourceContact> queryResults
+ = new LinkedList<SourceContact>();
+
+ /**
+ * The <tt>Thread</tt> in which this <tt>AsyncContactQuery</tt> is
+ * performing {@link #query}.
+ */
+ private Thread thread;
+
+ /**
+ * Initializes a new <tt>AsyncContactQuery</tt> instance which is to perform
+ * a specific <tt>query</tt> on behalf of a specific <tt>contactSource</tt>.
+ *
+ * @param contactSource the <tt>ContactSourceService</tt> which is to
+ * perform the new <tt>ContactQuery</tt> instance
+ * @param query the <tt>Pattern</tt> for which <tt>contactSource</tt> is
+ * being queried
+ * @param isSorted indicates if the results of this query should be sorted
+ */
+ protected AsyncContactQuery(T contactSource,
+ Pattern query,
+ boolean isSorted)
+ {
+ super(contactSource);
+
+ this.query = query;
+
+ if (isSorted)
+ queryResults = new TreeSet<SourceContact>();
+ }
+
+ /**
+ * Initializes a new <tt>AsyncContactQuery</tt> instance which is to perform
+ * a specific <tt>query</tt> on behalf of a specific <tt>contactSource</tt>.
+ *
+ * @param contactSource the <tt>ContactSourceService</tt> which is to
+ * perform the new <tt>ContactQuery</tt> instance
+ * @param query the <tt>Pattern</tt> for which <tt>contactSource</tt> is
+ * being queried
+ */
+ protected AsyncContactQuery(T contactSource, Pattern query)
+ {
+ super(contactSource);
+
+ this.query = query;
+ }
+
+ /**
+ * Adds a specific <tt>SourceContact</tt> to the list of
+ * <tt>SourceContact</tt>s to be returned by this <tt>ContactQuery</tt> in
+ * response to {@link #getQueryResults()}.
+ *
+ * @param sourceContact the <tt>SourceContact</tt> to be added to the
+ * <tt>queryResults</tt> of this <tt>ContactQuery</tt>
+ * @param showMoreEnabled indicates whether show more label should be shown
+ * or not.
+ * @return <tt>true</tt> if the <tt>queryResults</tt> of this
+ * <tt>ContactQuery</tt> has changed in response to the call
+ */
+ protected boolean addQueryResult(SourceContact sourceContact,
+ boolean showMoreEnabled)
+ {
+ boolean changed;
+
+ synchronized (queryResults)
+ {
+ changed = queryResults.add(sourceContact);
+ }
+ if (changed)
+ fireContactReceived(sourceContact, showMoreEnabled);
+
+ return changed;
+ }
+
+ /**
+ * Adds a specific <tt>SourceContact</tt> to the list of
+ * <tt>SourceContact</tt>s to be returned by this <tt>ContactQuery</tt> in
+ * response to {@link #getQueryResults()}.
+ *
+ * @param sourceContact the <tt>SourceContact</tt> to be added to the
+ * <tt>queryResults</tt> of this <tt>ContactQuery</tt>
+ * @return <tt>true</tt> if the <tt>queryResults</tt> of this
+ * <tt>ContactQuery</tt> has changed in response to the call
+ */
+ protected boolean addQueryResult(SourceContact sourceContact)
+ {
+ boolean changed;
+
+ synchronized (queryResults)
+ {
+ changed = queryResults.add(sourceContact);
+ }
+ if (changed)
+ fireContactReceived(sourceContact);
+
+ return changed;
+ }
+
+ /**
+ * Removes a specific <tt>SourceContact</tt> from the list of
+ * <tt>SourceContact</tt>s.
+ *
+ * @param sourceContact the <tt>SourceContact</tt> to be removed from the
+ * <tt>queryResults</tt> of this <tt>ContactQuery</tt>
+ * @return <tt>true</tt> if the <tt>queryResults</tt> of this
+ * <tt>ContactQuery</tt> has changed in response to the call
+ */
+ protected boolean removeQueryResult(SourceContact sourceContact)
+ {
+ boolean changed;
+
+ synchronized (queryResults)
+ {
+ changed = queryResults.remove(sourceContact);
+ }
+ if (changed)
+ fireContactRemoved(sourceContact);
+
+ return changed;
+ }
+
+ /**
+ * Adds a set of <tt>SourceContact</tt> instances to the list of
+ * <tt>SourceContact</tt>s to be returned by this <tt>ContactQuery</tt> in
+ * response to {@link #getQueryResults()}.
+ *
+ * @param sourceContacts the set of <tt>SourceContact</tt> to be added to
+ * the <tt>queryResults</tt> of this <tt>ContactQuery</tt>
+ * @return <tt>true</tt> if the <tt>queryResults</tt> of this
+ * <tt>ContactQuery</tt> has changed in response to the call
+ */
+ protected boolean addQueryResults(
+ final Set<? extends SourceContact> sourceContacts)
+ {
+ final boolean changed;
+
+ synchronized (queryResults)
+ {
+ changed = queryResults.addAll(sourceContacts);
+ }
+
+ if (changed)
+ {
+ // TODO Need something to fire one event for multiple contacts.
+ for (SourceContact contact : sourceContacts)
+ {
+ fireContactReceived(contact, false);
+ }
+ }
+
+ return changed;
+ }
+
+
+ /**
+ * Gets the {@link #query} of this <tt>AsyncContactQuery</tt> as a
+ * <tt>String</tt> which represents a phone number (if possible).
+ *
+ * @return a <tt>String</tt> which represents the <tt>query</tt> of this
+ * <tt>AsyncContactQuery</tt> as a phone number if such parsing, formatting
+ * and validation is possible; otherwise, <tt>null</tt>
+ */
+ protected String getPhoneNumberQuery()
+ {
+ if ((phoneNumberQuery == null) && !queryIsConvertedToPhoneNumber)
+ {
+ try
+ {
+ String pattern = query.pattern();
+
+ if (pattern != null)
+ {
+ int patternLength = pattern.length();
+
+ if ((patternLength > 2)
+ && (pattern.charAt(0) == '^')
+ && (pattern.charAt(patternLength - 1) == '$'))
+ {
+ phoneNumberQuery
+ = pattern.substring(1, patternLength - 1);
+ }
+ else if ((patternLength > 4)
+ && (pattern.charAt(0) == '\\')
+ && (pattern.charAt(1) == 'Q')
+ && (pattern.charAt(patternLength - 2) == '\\')
+ && (pattern.charAt(patternLength - 1) == 'E'))
+ {
+ phoneNumberQuery
+ = pattern.substring(2, patternLength - 2);
+ }
+
+ }
+ }
+ finally
+ {
+ queryIsConvertedToPhoneNumber = true;
+ }
+ }
+ return phoneNumberQuery;
+ }
+
+ /**
+ * Gets the number of <tt>SourceContact</tt>s which match this
+ * <tt>ContactQuery</tt>.
+ *
+ * @return the number of <tt>SourceContact</tt> which match this
+ * <tt>ContactQuery</tt>
+ */
+ public int getQueryResultCount()
+ {
+ synchronized (queryResults)
+ {
+ return queryResults.size();
+ }
+ }
+
+ /**
+ * 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()
+ {
+ List<SourceContact> qr;
+
+ synchronized (queryResults)
+ {
+ qr = new ArrayList<SourceContact>(queryResults.size());
+ qr.addAll(queryResults);
+ }
+ return qr;
+ }
+
+ /**
+ * Returns the query string, this query was created for.
+ *
+ * @return the query string, this query was created for
+ */
+ public String getQueryString()
+ {
+ return query.toString();
+ }
+
+ /**
+ * Performs this <tt>ContactQuery</tt> in a background <tt>Thread</tt>.
+ */
+ protected abstract void run();
+
+ /**
+ * Starts this <tt>AsyncContactQuery</tt>.
+ */
+ public synchronized void start()
+ {
+ if (thread == null)
+ {
+ thread
+ = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ boolean completed = false;
+
+ try
+ {
+ AsyncContactQuery.this.run();
+ completed = true;
+ }
+ finally
+ {
+ synchronized (AsyncContactQuery.this)
+ {
+ if (thread == Thread.currentThread())
+ stopped(completed);
+ }
+ }
+ }
+ };
+ thread.setDaemon(true);
+ thread.start();
+ }
+ else
+ throw new IllegalStateException("thread");
+ }
+
+ /**
+ * Notifies this <tt>AsyncContactQuery</tt> that it has stopped performing
+ * in the associated background <tt>Thread</tt>.
+ *
+ * @param completed <tt>true</tt> if this <tt>ContactQuery</tt> has
+ * successfully completed, <tt>false</tt> if an error has been encountered
+ * during its execution
+ */
+ protected void stopped(boolean completed)
+ {
+ if (getStatus() == QUERY_IN_PROGRESS)
+ setStatus(completed ? QUERY_COMPLETED : QUERY_ERROR);
+ }
+
+ /**
+ * Determines whether a specific <tt>String</tt> phone number matches the
+ * {@link #query} of this <tt>AsyncContactQuery</tt>.
+ *
+ * @param phoneNumber the <tt>String</tt> which represents the phone number
+ * to match to the <tt>query</tt> of this <tt>AsyncContactQuery</tt>
+ * @return <tt>true</tt> if the specified <tt>phoneNumber</tt> matches the
+ * <tt>query</tt> of this <tt>AsyncContactQuery</tt>; otherwise,
+ * <tt>false</tt>
+ */
+ protected boolean phoneNumberMatches(String phoneNumber)
+ {
+ /*
+ * PhoneNumberI18nService implements functionality to aid the parsing,
+ * formatting and validation of international phone numbers so attempt
+ * to use it to determine whether the specified phoneNumber matches the
+ * query. For example, check whether the normalized phoneNumber matches
+ * the query.
+ */
+
+ boolean phoneNumberMatches = false;
+
+ if (query
+ .matcher(ContactSourceActivator.getPhoneNumberI18nService()
+ .normalize(phoneNumber)).find())
+ {
+ phoneNumberMatches = true;
+ }
+ else
+ {
+ /*
+ * The fact that the normalized form of the phoneNumber doesn't
+ * match the query doesn't mean that, for example, it doesn't
+ * match the normalized form of the query. The latter, though,
+ * requires the query to look like a phone number as well. In
+ * order to not accidentally start matching all queries to phone
+ * numbers, it seems justified to normalize the query only when
+ * it is a phone number, not whenever it looks like a piece of a
+ * phone number.
+ */
+
+ String phoneNumberQuery = getPhoneNumberQuery();
+
+ if ((phoneNumberQuery != null)
+ && (phoneNumberQuery.length() != 0))
+ {
+ try
+ {
+ phoneNumberMatches
+ = ContactSourceActivator.getPhoneNumberI18nService()
+ .phoneNumbersMatch(
+ phoneNumberQuery,
+ phoneNumber);
+ }
+ catch (IllegalArgumentException iaex)
+ {
+ /*
+ * Ignore it, phoneNumberMatches will remain equal to
+ * false.
+ */
+ }
+ }
+ }
+ return phoneNumberMatches;
+ }
+}
diff --git a/src/net/java/sip/communicator/service/contactsource/AsyncContactSourceService.java b/src/net/java/sip/communicator/service/contactsource/AsyncContactSourceService.java
index 848a723..14d06a4 100644
--- a/src/net/java/sip/communicator/service/contactsource/AsyncContactSourceService.java
+++ b/src/net/java/sip/communicator/service/contactsource/AsyncContactSourceService.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,70 +15,70 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.service.contactsource;
-
-import java.util.regex.*;
-
-/**
- * Declares the interface of a <tt>ContactSourceService</tt> which performs
- * <tt>ContactQuery</tt>s in a separate <tt>Thread</tt>.
- *
- * @author Lyubomir Marinov
- */
-public abstract class AsyncContactSourceService
- implements ExtendedContactSourceService
-{
- /**
- * Creates query that searches 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 createContactQuery(String query)
- {
- return createContactQuery(
- Pattern.compile(query, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
- }
-
- /**
- * Creates query that searches 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
- * @param contactCount the maximum count of result contacts
- * @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 createContactQuery(String query, int contactCount)
- {
- return createContactQuery(
- Pattern.compile(query, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
- }
-
- /**
- * Stops this <tt>ContactSourceService</tt>.
- */
- public abstract void stop();
-
- /**
- * Defines whether using this contact source service (Outlook or MacOSX
- * Contacs) can be used as result for the search field. This is
- * useful when an external plugin looks for result of this contact source
- * service, but want to display the search field result from its own (avoid
- * duplicate results).
- *
- * @return True if this contact source service can be used to perform search
- * for contacts. False otherwise.
- */
- public abstract boolean canBeUsedToSearchContacts();
-}
+package net.java.sip.communicator.service.contactsource;
+
+import java.util.regex.*;
+
+/**
+ * Declares the interface of a <tt>ContactSourceService</tt> which performs
+ * <tt>ContactQuery</tt>s in a separate <tt>Thread</tt>.
+ *
+ * @author Lyubomir Marinov
+ */
+public abstract class AsyncContactSourceService
+ implements ExtendedContactSourceService
+{
+ /**
+ * Creates query that searches 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 createContactQuery(String query)
+ {
+ return createContactQuery(
+ Pattern.compile(query, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
+ }
+
+ /**
+ * Creates query that searches 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
+ * @param contactCount the maximum count of result contacts
+ * @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 createContactQuery(String query, int contactCount)
+ {
+ return createContactQuery(
+ Pattern.compile(query, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
+ }
+
+ /**
+ * Stops this <tt>ContactSourceService</tt>.
+ */
+ public abstract void stop();
+
+ /**
+ * Defines whether using this contact source service (Outlook or MacOSX
+ * Contacs) can be used as result for the search field. This is
+ * useful when an external plugin looks for result of this contact source
+ * service, but want to display the search field result from its own (avoid
+ * duplicate results).
+ *
+ * @return True if this contact source service can be used to perform search
+ * for contacts. False otherwise.
+ */
+ public abstract boolean canBeUsedToSearchContacts();
+}
diff --git a/src/net/java/sip/communicator/service/contactsource/ContactDetail.java b/src/net/java/sip/communicator/service/contactsource/ContactDetail.java
index c062035..362faf4 100644
--- a/src/net/java/sip/communicator/service/contactsource/ContactDetail.java
+++ b/src/net/java/sip/communicator/service/contactsource/ContactDetail.java
@@ -210,11 +210,9 @@ public class ContactDetail
*/
AIM("AIM"),
ICQ("ICQ"),
- MSN("MSN"),
- Jabber("Jabber"),
+ Jabber("XMPP"),
Skype("Skype"),
Yahoo("Yahoo"),
- Facebook("Facebook"),
GoogleTalk("GoogleTalk"),
/**
@@ -438,9 +436,19 @@ public class ContactDetail
this.contactDetailValue = contactDetailValue;
if (!StringUtils.isNullOrEmpty(detailDisplayName))
+ {
this.detailDisplayName = detailDisplayName;
+ }
+ else if (category == Category.Phone)
+ {
+ this.detailDisplayName =
+ ContactSourceActivator.getPhoneNumberI18nService()
+ .formatForDisplay(contactDetailValue);
+ }
else
+ {
this.detailDisplayName = contactDetailValue;
+ }
// category & labels
this.category = category;
diff --git a/src/net/java/sip/communicator/service/contactsource/GenericSourceContact.java b/src/net/java/sip/communicator/service/contactsource/GenericSourceContact.java
index a77adee..0c0cb0d 100644
--- a/src/net/java/sip/communicator/service/contactsource/GenericSourceContact.java
+++ b/src/net/java/sip/communicator/service/contactsource/GenericSourceContact.java
@@ -1,4 +1,4 @@
-/*
+/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
@@ -15,295 +15,295 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.java.sip.communicator.service.contactsource;
-
-import java.util.*;
-
-import net.java.sip.communicator.service.protocol.*;
-import net.java.sip.communicator.util.*;
-
-/**
- * Implements a generic <tt>SourceContact</tt> for the purposes of the support
- * for the OS-specific Address Book.
- *
- * @author Lyubomir Marinov
- */
-public class GenericSourceContact
- extends DataObject
- implements SourceContact
-{
- /**
- * The <tt>ContactDetail</tt>s of this <tt>SourceContact</tt>.
- */
- protected final List<ContactDetail> contactDetails;
-
- /**
- * The <tt>ContactSourceService</tt> which has created this
- * <tt>SourceContact</tt>.
- */
- private final ContactSourceService contactSource;
-
- /**
- * The display name of this <tt>SourceContact</tt>.
- */
- private String displayName;
-
- /**
- * The display details of this contact.
- */
- private String displayDetails;
-
- /**
- * The presence status of this contact.
- */
- private PresenceStatus presenceStatus;
-
- /**
- * The image/avatar of this <tt>SourceContact</tt>
- */
- private byte[] image;
-
- /**
- * The address of the contact.
- */
- private String contactAddress = null;
-
- /**
- * Initializes a new <tt>AddrBookSourceContact</tt> instance.
- *
- * @param contactSource the <tt>ContactSourceService</tt> which is creating
- * the new instance
- * @param displayName the display name of the new instance
- * @param contactDetails the <tt>ContactDetail</tt>s of the new instance
- */
- public GenericSourceContact(
- ContactSourceService contactSource,
- String displayName,
- List<ContactDetail> contactDetails)
- {
- this.contactSource = contactSource;
- this.displayName = displayName;
- this.contactDetails = contactDetails;
- }
-
- /**
- * Returns the address of the contact.
- *
- * @return the contact address.
- */
- public String getContactAddress()
- {
- return contactAddress;
- }
-
- /**
- * Gets the <tt>ContactDetail</tt>s of this <tt>SourceContact</tt>.
- *
- * @return the <tt>ContactDetail</tt>s of this <tt>SourceContact</tt>
- * @see SourceContact#getContactDetails()
- */
- public List<ContactDetail> getContactDetails()
- {
- return Collections.unmodifiableList(contactDetails);
- }
-
- /**
- * Gets the <tt>ContactDetail</tt>s of this <tt>SourceContact</tt> which
- * support a specific <tt>OperationSet</tt>.
- *
- * @param operationSet the <tt>OperationSet</tt> the supporting
- * <tt>ContactDetail</tt>s of which are to be returned
- * @return the <tt>ContactDetail</tt>s of this <tt>SourceContact</tt> which
- * support the specified <tt>operationSet</tt>
- * @see SourceContact#getContactDetails(Class)
- */
- public List<ContactDetail> getContactDetails(
- Class<? extends OperationSet> operationSet)
- {
- List<ContactDetail> contactDetails = new LinkedList<ContactDetail>();
-
- for (ContactDetail contactDetail : getContactDetails())
- {
- List<Class<? extends OperationSet>> supportedOperationSets
- = contactDetail.getSupportedOperationSets();
-
- if ((supportedOperationSets != null)
- && supportedOperationSets.contains(operationSet))
- contactDetails.add(contactDetail);
- }
- return contactDetails;
- }
-
- /**
- * Returns a list of all <tt>ContactDetail</tt>s corresponding to the given
- * category.
- * @param category the <tt>OperationSet</tt> class we're looking for
- * @return a list of all <tt>ContactDetail</tt>s corresponding to the given
- * category
- */
- public List<ContactDetail> getContactDetails(
- ContactDetail.Category category)
- {
- List<ContactDetail> contactDetails = new LinkedList<ContactDetail>();
-
- for (ContactDetail contactDetail : getContactDetails())
- {
- if(contactDetail != null)
- {
- ContactDetail.Category detailCategory
- = contactDetail.getCategory();
- if (detailCategory != null && detailCategory.equals(category))
- contactDetails.add(contactDetail);
- }
- }
- return contactDetails;
- }
-
- /**
- * Gets the <tt>ContactSourceService</tt> which has created this
- * <tt>SourceContact</tt>.
- *
- * @return the <tt>ContactSourceService</tt> which has created this
- * <tt>SourceContact</tt>
- * @see SourceContact#getContactSource()
- */
- public ContactSourceService getContactSource()
- {
- return contactSource;
- }
-
- /**
- * Gets the display details of this <tt>SourceContact</tt>.
- *
- * @return the display details of this <tt>SourceContact</tt>
- * @see SourceContact#getDisplayDetails()
- */
- public String getDisplayDetails()
- {
- return displayDetails;
- }
-
- /**
- * Sets the address of the contact.
- *
- * @param contactAddress the address to set.
- */
- public void setContactAddress(String contactAddress)
- {
- this.contactAddress = contactAddress;
- }
-
- /**
- * Sets the display details of this <tt>SourceContact</tt>.
- *
- * @param displayDetails the display details of this <tt>SourceContact</tt>
- */
- public String setDisplayDetails(String displayDetails)
- {
- return this.displayDetails = displayDetails;
- }
-
- /**
- * Gets the display name of this <tt>SourceContact</tt>.
- *
- * @return the display name of this <tt>SourceContact</tt>
- * @see SourceContact#getDisplayName()
- */
- public String getDisplayName()
- {
- return displayName;
- }
-
- /**
- * Sets the display name of this <tt>SourceContact</tt>.
- *
- * @param displayName The display name of this <tt>SourceContact</tt>
- */
- public void setDisplayName(String displayName)
- {
- this.displayName = displayName;
- }
-
- /**
- * Gets the image/avatar of this <tt>SourceContact</tt>.
- *
- * @return the image/avatar of this <tt>SourceContact</tt>
- * @see SourceContact#getImage()
- */
- public byte[] getImage()
- {
- return image;
- }
-
- /**
- * Gets the preferred <tt>ContactDetail</tt> for a specific
- * <tt>OperationSet</tt>.
- *
- * @param operationSet the <tt>OperationSet</tt> to get the preferred
- * <tt>ContactDetail</tt> for
- * @return the preferred <tt>ContactDetail</tt> for the specified
- * <tt>operationSet</tt>
- * @see SourceContact#getPreferredContactDetail(Class)
- */
- public ContactDetail getPreferredContactDetail(
- Class<? extends OperationSet> operationSet)
- {
- List<ContactDetail> contactDetails = getContactDetails(operationSet);
-
- return contactDetails.isEmpty() ? null : contactDetails.get(0);
- }
-
- /**
- * Sets the image/avatar of this <tt>SourceContact</tt>.
- *
- * @param image the image/avatar to be set on this <tt>SourceContact</tt>
- */
- public void setImage(byte[] image)
- {
- this.image = image;
- }
-
- /**
- * Whether the current image returned by @see #getImage() is the one
- * provided by the SourceContact by default, or is a one used and obtained
- * from external source.
- *
- * @return whether this is the default image for this SourceContact.
- */
- @Override
- public boolean isDefaultImage()
- {
- // in this SourceContact we always show an externally set image or null
- return false;
- }
-
- /**
- * Returns the status of the source contact. And null if such information
- * is not available.
- * @return the PresenceStatus representing the state of this source contact.
- */
- public PresenceStatus getPresenceStatus()
- {
- return presenceStatus;
- }
-
- /**
- * Sets the status of the source contact.
- *
- * @param presenceStatus the status of this contact
- */
- public void setPresenceStatus(PresenceStatus presenceStatus)
- {
- this.presenceStatus = presenceStatus;
- }
-
- /**
- * Returns the index of this source contact in its parent.
- *
- * @return the index of this source contact in its parent
- */
- public int getIndex()
- {
- return -1;
- }
-}
+package net.java.sip.communicator.service.contactsource;
+
+import java.util.*;
+
+import net.java.sip.communicator.service.protocol.*;
+import net.java.sip.communicator.util.*;
+
+/**
+ * Implements a generic <tt>SourceContact</tt> for the purposes of the support
+ * for the OS-specific Address Book.
+ *
+ * @author Lyubomir Marinov
+ */
+public class GenericSourceContact
+ extends DataObject
+ implements SourceContact
+{
+ /**
+ * The <tt>ContactDetail</tt>s of this <tt>SourceContact</tt>.
+ */
+ protected final List<ContactDetail> contactDetails;
+
+ /**
+ * The <tt>ContactSourceService</tt> which has created this
+ * <tt>SourceContact</tt>.
+ */
+ private final ContactSourceService contactSource;
+
+ /**
+ * The display name of this <tt>SourceContact</tt>.
+ */
+ private String displayName;
+
+ /**
+ * The display details of this contact.
+ */
+ private String displayDetails;
+
+ /**
+ * The presence status of this contact.
+ */
+ private PresenceStatus presenceStatus;
+
+ /**
+ * The image/avatar of this <tt>SourceContact</tt>
+ */
+ private byte[] image;
+
+ /**
+ * The address of the contact.
+ */
+ private String contactAddress = null;
+
+ /**
+ * Initializes a new <tt>AddrBookSourceContact</tt> instance.
+ *
+ * @param contactSource the <tt>ContactSourceService</tt> which is creating
+ * the new instance
+ * @param displayName the display name of the new instance
+ * @param contactDetails the <tt>ContactDetail</tt>s of the new instance
+ */
+ public GenericSourceContact(
+ ContactSourceService contactSource,
+ String displayName,
+ List<ContactDetail> contactDetails)
+ {
+ this.contactSource = contactSource;
+ this.displayName = displayName;
+ this.contactDetails = contactDetails;
+ }
+
+ /**
+ * Returns the address of the contact.
+ *
+ * @return the contact address.
+ */
+ public String getContactAddress()
+ {
+ return contactAddress;
+ }
+
+ /**
+ * Gets the <tt>ContactDetail</tt>s of this <tt>SourceContact</tt>.
+ *
+ * @return the <tt>ContactDetail</tt>s of this <tt>SourceContact</tt>
+ * @see SourceContact#getContactDetails()
+ */
+ public List<ContactDetail> getContactDetails()
+ {
+ return Collections.unmodifiableList(contactDetails);
+ }
+
+ /**
+ * Gets the <tt>ContactDetail</tt>s of this <tt>SourceContact</tt> which
+ * support a specific <tt>OperationSet</tt>.
+ *
+ * @param operationSet the <tt>OperationSet</tt> the supporting
+ * <tt>ContactDetail</tt>s of which are to be returned
+ * @return the <tt>ContactDetail</tt>s of this <tt>SourceContact</tt> which
+ * support the specified <tt>operationSet</tt>
+ * @see SourceContact#getContactDetails(Class)
+ */
+ public List<ContactDetail> getContactDetails(
+ Class<? extends OperationSet> operationSet)
+ {
+ List<ContactDetail> contactDetails = new LinkedList<ContactDetail>();
+
+ for (ContactDetail contactDetail : getContactDetails())
+ {
+ List<Class<? extends OperationSet>> supportedOperationSets
+ = contactDetail.getSupportedOperationSets();
+
+ if ((supportedOperationSets != null)
+ && supportedOperationSets.contains(operationSet))
+ contactDetails.add(contactDetail);
+ }
+ return contactDetails;
+ }
+
+ /**
+ * Returns a list of all <tt>ContactDetail</tt>s corresponding to the given
+ * category.
+ * @param category the <tt>OperationSet</tt> class we're looking for
+ * @return a list of all <tt>ContactDetail</tt>s corresponding to the given
+ * category
+ */
+ public List<ContactDetail> getContactDetails(
+ ContactDetail.Category category)
+ {
+ List<ContactDetail> contactDetails = new LinkedList<ContactDetail>();
+
+ for (ContactDetail contactDetail : getContactDetails())
+ {
+ if(contactDetail != null)
+ {
+ ContactDetail.Category detailCategory
+ = contactDetail.getCategory();
+ if (detailCategory != null && detailCategory.equals(category))
+ contactDetails.add(contactDetail);
+ }
+ }
+ return contactDetails;
+ }
+
+ /**
+ * Gets the <tt>ContactSourceService</tt> which has created this
+ * <tt>SourceContact</tt>.
+ *
+ * @return the <tt>ContactSourceService</tt> which has created this
+ * <tt>SourceContact</tt>
+ * @see SourceContact#getContactSource()
+ */
+ public ContactSourceService getContactSource()
+ {
+ return contactSource;
+ }
+
+ /**
+ * Gets the display details of this <tt>SourceContact</tt>.
+ *
+ * @return the display details of this <tt>SourceContact</tt>
+ * @see SourceContact#getDisplayDetails()
+ */
+ public String getDisplayDetails()
+ {
+ return displayDetails;
+ }
+
+ /**
+ * Sets the address of the contact.
+ *
+ * @param contactAddress the address to set.
+ */
+ public void setContactAddress(String contactAddress)
+ {
+ this.contactAddress = contactAddress;
+ }
+
+ /**
+ * Sets the display details of this <tt>SourceContact</tt>.
+ *
+ * @param displayDetails the display details of this <tt>SourceContact</tt>
+ */
+ public String setDisplayDetails(String displayDetails)
+ {
+ return this.displayDetails = displayDetails;
+ }
+
+ /**
+ * Gets the display name of this <tt>SourceContact</tt>.
+ *
+ * @return the display name of this <tt>SourceContact</tt>
+ * @see SourceContact#getDisplayName()
+ */
+ public String getDisplayName()
+ {
+ return displayName;
+ }
+
+ /**
+ * Sets the display name of this <tt>SourceContact</tt>.
+ *
+ * @param displayName The display name of this <tt>SourceContact</tt>
+ */
+ public void setDisplayName(String displayName)
+ {
+ this.displayName = displayName;
+ }
+
+ /**
+ * Gets the image/avatar of this <tt>SourceContact</tt>.
+ *
+ * @return the image/avatar of this <tt>SourceContact</tt>
+ * @see SourceContact#getImage()
+ */
+ public byte[] getImage()
+ {
+ return image;
+ }
+
+ /**
+ * Gets the preferred <tt>ContactDetail</tt> for a specific
+ * <tt>OperationSet</tt>.
+ *
+ * @param operationSet the <tt>OperationSet</tt> to get the preferred
+ * <tt>ContactDetail</tt> for
+ * @return the preferred <tt>ContactDetail</tt> for the specified
+ * <tt>operationSet</tt>
+ * @see SourceContact#getPreferredContactDetail(Class)
+ */
+ public ContactDetail getPreferredContactDetail(
+ Class<? extends OperationSet> operationSet)
+ {
+ List<ContactDetail> contactDetails = getContactDetails(operationSet);
+
+ return contactDetails.isEmpty() ? null : contactDetails.get(0);
+ }
+
+ /**
+ * Sets the image/avatar of this <tt>SourceContact</tt>.
+ *
+ * @param image the image/avatar to be set on this <tt>SourceContact</tt>
+ */
+ public void setImage(byte[] image)
+ {
+ this.image = image;
+ }
+
+ /**
+ * Whether the current image returned by @see #getImage() is the one
+ * provided by the SourceContact by default, or is a one used and obtained
+ * from external source.
+ *
+ * @return whether this is the default image for this SourceContact.
+ */
+ @Override
+ public boolean isDefaultImage()
+ {
+ // in this SourceContact we always show an externally set image or null
+ return false;
+ }
+
+ /**
+ * Returns the status of the source contact. And null if such information
+ * is not available.
+ * @return the PresenceStatus representing the state of this source contact.
+ */
+ public PresenceStatus getPresenceStatus()
+ {
+ return presenceStatus;
+ }
+
+ /**
+ * Sets the status of the source contact.
+ *
+ * @param presenceStatus the status of this contact
+ */
+ public void setPresenceStatus(PresenceStatus presenceStatus)
+ {
+ this.presenceStatus = presenceStatus;
+ }
+
+ /**
+ * Returns the index of this source contact in its parent.
+ *
+ * @return the index of this source contact in its parent
+ */
+ public int getIndex()
+ {
+ return -1;
+ }
+}