aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/addrbook
diff options
context:
space:
mode:
authorSebastien Vincent <seb@jitsi.org>2011-03-09 09:30:54 +0000
committerSebastien Vincent <seb@jitsi.org>2011-03-09 09:30:54 +0000
commit5393fc96a763bcf0ecedf95275edc7712f2b897f (patch)
tree9dab2f9963a2aca12b6038ada01165a655141057 /src/net/java/sip/communicator/plugin/addrbook
parentdcb607dd8b10f297af6a590e29a7b9b6f6002aff (diff)
downloadjitsi-5393fc96a763bcf0ecedf95275edc7712f2b897f.zip
jitsi-5393fc96a763bcf0ecedf95275edc7712f2b897f.tar.gz
jitsi-5393fc96a763bcf0ecedf95275edc7712f2b897f.tar.bz2
Ongoing work on LDAP contact source support.
Diffstat (limited to 'src/net/java/sip/communicator/plugin/addrbook')
-rw-r--r--src/net/java/sip/communicator/plugin/addrbook/AddrBookSourceContact.java194
-rw-r--r--src/net/java/sip/communicator/plugin/addrbook/AsyncContactQuery.java325
-rw-r--r--src/net/java/sip/communicator/plugin/addrbook/AsyncContactSourceService.java63
-rw-r--r--src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java97
-rw-r--r--src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactSourceService.java1
-rw-r--r--src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java95
-rw-r--r--src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.java1
7 files changed, 187 insertions, 589 deletions
diff --git a/src/net/java/sip/communicator/plugin/addrbook/AddrBookSourceContact.java b/src/net/java/sip/communicator/plugin/addrbook/AddrBookSourceContact.java
deleted file mode 100644
index 91cfceb..0000000
--- a/src/net/java/sip/communicator/plugin/addrbook/AddrBookSourceContact.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.plugin.addrbook;
-
-import java.util.*;
-
-import net.java.sip.communicator.service.contactsource.*;
-import net.java.sip.communicator.service.protocol.*;
-
-/**
- * Implements a generic <tt>SourceContact</tt> for the purposes of the support
- * for the OS-specific Address Book.
- *
- * @author Lyubomir Marinov
- */
-public class AddrBookSourceContact
- implements SourceContact
-{
- /**
- * The <tt>ContactDetail</tt>s of this <tt>SourceContact</tt>.
- */
- private 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 final String displayName;
-
- /**
- * The image/avatar of this <tt>SourceContact</tt>
- */
- private byte[] image;
-
- /**
- * 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 AddrBookSourceContact(
- ContactSourceService contactSource,
- String displayName,
- List<ContactDetail> contactDetails)
- {
- this.contactSource = contactSource;
- this.displayName = displayName;
- this.contactDetails = contactDetails;
- }
-
- /**
- * 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(String category)
- {
- List<ContactDetail> contactDetails = new LinkedList<ContactDetail>();
-
- for (ContactDetail contactDetail : getContactDetails())
- {
- String 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()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * 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;
- }
-
- /**
- * 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;
- }
-}
diff --git a/src/net/java/sip/communicator/plugin/addrbook/AsyncContactQuery.java b/src/net/java/sip/communicator/plugin/addrbook/AsyncContactQuery.java
deleted file mode 100644
index 502a7d4..0000000
--- a/src/net/java/sip/communicator/plugin/addrbook/AsyncContactQuery.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.plugin.addrbook;
-
-import java.util.*;
-import java.util.regex.*;
-
-import net.java.sip.communicator.service.contactsource.*;
-import net.java.sip.communicator.service.protocol.*;
-
-/**
- * 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 final List<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
- */
- 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>
- * @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;
- }
-
- /**
- * 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);
- }
- }
- }
- 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();
- }
-
- /**
- * Normalizes a <tt>String</tt> phone number by converting alpha characters
- * to their respective digits on a keypad and then stripping non-digit
- * characters.
- *
- * @param phoneNumber a <tt>String</tt> which represents a phone number to
- * normalize
- * @return a <tt>String</tt> which is a normalized form of the specified
- * <tt>phoneNumber</tt>
- */
- protected String normalizePhoneNumber(String phoneNumber)
- {
- PhoneNumberI18nService phoneNumberI18nService
- = AddrBookActivator.getPhoneNumberI18nService();
-
- return
- (phoneNumberI18nService == null)
- ? phoneNumber
- : phoneNumberI18nService.normalize(phoneNumber);
- }
-
- /**
- * 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.
- */
-
- PhoneNumberI18nService phoneNumberI18nService
- = AddrBookActivator.getPhoneNumberI18nService();
- boolean phoneNumberMatches = false;
-
- if (phoneNumberI18nService != null)
- {
- if (query
- .matcher(phoneNumberI18nService.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
- = phoneNumberI18nService.phoneNumbersMatch(
- phoneNumberQuery,
- phoneNumber);
- }
- catch (IllegalArgumentException iaex)
- {
- /*
- * Ignore it, phoneNumberMatches will remain equal to
- * false.
- */
- }
- }
- }
- }
- return phoneNumberMatches;
- }
-
- /**
- * 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);
- }
-}
diff --git a/src/net/java/sip/communicator/plugin/addrbook/AsyncContactSourceService.java b/src/net/java/sip/communicator/plugin/addrbook/AsyncContactSourceService.java
deleted file mode 100644
index c89d9aa..0000000
--- a/src/net/java/sip/communicator/plugin/addrbook/AsyncContactSourceService.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.plugin.addrbook;
-
-import java.util.regex.*;
-
-import net.java.sip.communicator.service.contactsource.*;
-
-/**
- * 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
-{
- /**
- * 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)
- {
- return queryContactSource(
- Pattern.compile(query, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
- }
-
- /**
- * 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
- * @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 queryContactSource(String query, int contactCount)
- {
- return queryContactSource(
- Pattern.compile(query, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
- }
-
- /**
- * Stops this <tt>ContactSourceService</tt>.
- */
- public abstract void stop();
-}
diff --git a/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java b/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java
index 280dc33..8c224c9 100644
--- a/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java
+++ b/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java
@@ -616,7 +616,7 @@ public class MacOSXAddrBookContactQuery
/**
* Determines whether an <tt>ABPerson</tt> represented by the values of its
* {@link #ABPERSON_PROPERTIES} matches {@link #query}.
- *
+ *
* @param values the values of the <tt>ABPERSON_PROPERTIES</tt> which
* represent the <tt>ABPerson</tt> to be determined whether it matches
* <tt>query</tt>
@@ -675,8 +675,8 @@ public class MacOSXAddrBookContactQuery
if (!contactDetails.isEmpty())
{
- AddrBookSourceContact sourceContact
- = new AddrBookSourceContact(
+ GenericSourceContact sourceContact
+ = new GenericSourceContact(
getContactSource(),
displayName,
contactDetails);
@@ -787,4 +787,95 @@ public class MacOSXAddrBookContactQuery
return contactDetail;
}
+
+ /**
+ * Normalizes a <tt>String</tt> phone number by converting alpha characters
+ * to their respective digits on a keypad and then stripping non-digit
+ * characters.
+ *
+ * @param phoneNumber a <tt>String</tt> which represents a phone number to
+ * normalize
+ * @return a <tt>String</tt> which is a normalized form of the specified
+ * <tt>phoneNumber</tt>
+ */
+ protected String normalizePhoneNumber(String phoneNumber)
+ {
+ PhoneNumberI18nService phoneNumberI18nService
+ = AddrBookActivator.getPhoneNumberI18nService();
+
+ return
+ (phoneNumberI18nService == null)
+ ? phoneNumber
+ : phoneNumberI18nService.normalize(phoneNumber);
+ }
+
+ /**
+ * 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.
+ */
+
+ PhoneNumberI18nService phoneNumberI18nService
+ = AddrBookActivator.getPhoneNumberI18nService();
+ boolean phoneNumberMatches = false;
+
+ if (phoneNumberI18nService != null)
+ {
+ if (query
+ .matcher(phoneNumberI18nService.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
+ = phoneNumberI18nService.phoneNumbersMatch(
+ phoneNumberQuery,
+ phoneNumber);
+ }
+ catch (IllegalArgumentException iaex)
+ {
+ /*
+ * Ignore it, phoneNumberMatches will remain equal to
+ * false.
+ */
+ }
+ }
+ }
+ }
+ return phoneNumberMatches;
+ }
}
diff --git a/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactSourceService.java b/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactSourceService.java
index 46e54d2..bb06efe 100644
--- a/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactSourceService.java
+++ b/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactSourceService.java
@@ -8,7 +8,6 @@ package net.java.sip.communicator.plugin.addrbook.macosx;
import java.util.regex.*;
-import net.java.sip.communicator.plugin.addrbook.*;
import net.java.sip.communicator.service.contactsource.*;
/**
diff --git a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java
index 535e1a1..7ecb171 100644
--- a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java
+++ b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java
@@ -376,8 +376,8 @@ public class MsOutlookAddrBookContactQuery
}
}
- AddrBookSourceContact sourceContact
- = new AddrBookSourceContact(
+ GenericSourceContact sourceContact
+ = new GenericSourceContact(
getContactSource(),
(String) props[PR_DISPLAY_NAME],
contactDetails);
@@ -456,4 +456,95 @@ public class MsOutlookAddrBookContactQuery
getContactSource().stopped(this);
}
}
+
+ /**
+ * Normalizes a <tt>String</tt> phone number by converting alpha characters
+ * to their respective digits on a keypad and then stripping non-digit
+ * characters.
+ *
+ * @param phoneNumber a <tt>String</tt> which represents a phone number to
+ * normalize
+ * @return a <tt>String</tt> which is a normalized form of the specified
+ * <tt>phoneNumber</tt>
+ */
+ protected String normalizePhoneNumber(String phoneNumber)
+ {
+ PhoneNumberI18nService phoneNumberI18nService
+ = AddrBookActivator.getPhoneNumberI18nService();
+
+ return
+ (phoneNumberI18nService == null)
+ ? phoneNumber
+ : phoneNumberI18nService.normalize(phoneNumber);
+ }
+
+ /**
+ * 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.
+ */
+
+ PhoneNumberI18nService phoneNumberI18nService
+ = AddrBookActivator.getPhoneNumberI18nService();
+ boolean phoneNumberMatches = false;
+
+ if (phoneNumberI18nService != null)
+ {
+ if (query
+ .matcher(phoneNumberI18nService.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
+ = phoneNumberI18nService.phoneNumbersMatch(
+ phoneNumberQuery,
+ phoneNumber);
+ }
+ catch (IllegalArgumentException iaex)
+ {
+ /*
+ * Ignore it, phoneNumberMatches will remain equal to
+ * false.
+ */
+ }
+ }
+ }
+ }
+ return phoneNumberMatches;
+ }
}
diff --git a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.java b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.java
index 20c915a..ddb2a82 100644
--- a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.java
+++ b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactSourceService.java
@@ -9,7 +9,6 @@ package net.java.sip.communicator.plugin.addrbook.msoutlook;
import java.util.*;
import java.util.regex.*;
-import net.java.sip.communicator.plugin.addrbook.*;
import net.java.sip.communicator.service.contactsource.*;
/**