diff options
author | Vincent Lucas <chenzo@jitsi.org> | 2012-09-25 14:11:58 +0000 |
---|---|---|
committer | Vincent Lucas <chenzo@jitsi.org> | 2012-09-25 14:11:58 +0000 |
commit | b7acf89cd9da40c9c78f4564c1cd4c37304829ae (patch) | |
tree | 63d36c5cce2ac2e8933967e67c4647b8d8dd40c7 /src/net/java/sip/communicator/impl | |
parent | 09cd4c6414659d8488c94f89dd4347a0c9670e53 (diff) | |
download | jitsi-b7acf89cd9da40c9c78f4564c1cd4c37304829ae.zip jitsi-b7acf89cd9da40c9c78f4564c1cd4c37304829ae.tar.gz jitsi-b7acf89cd9da40c9c78f4564c1cd4c37304829ae.tar.bz2 |
Updates the PhoneNumberI18nServiceImpl, in order to remove the dependency to the libphonenumber.
Diffstat (limited to 'src/net/java/sip/communicator/impl')
7 files changed, 9 insertions, 307 deletions
diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java index 45afa50..e061cba 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java @@ -60,13 +60,6 @@ public class GoogleContactsActivator implements BundleActivator private static ResourceManagementService resourceService; /** - * The cached reference to the <tt>PhoneNumberI18nService</tt> instance used - * by the functionality of the Google Contacts plug-in and fetched from its - * <tt>BundleContext</tt>. - */ - private static PhoneNumberI18nService phoneNumberI18nService; - - /** * Google contacts service. */ private static GoogleContactsServiceImpl googleContactsService; @@ -78,25 +71,6 @@ public class GoogleContactsActivator implements BundleActivator = new HashMap<GoogleContactsSourceService, ServiceRegistration>(); /** - * Gets the <tt>PhoneNumberI18nService</tt> to be used by the functionality - * of the addrbook plug-in. - * - * @return the <tt>PhoneNumberI18nService</tt> to be used by the - * functionality of the addrbook plug-in - */ - public static PhoneNumberI18nService getPhoneNumberI18nService() - { - if (phoneNumberI18nService == null) - { - phoneNumberI18nService - = ServiceUtils.getService( - bundleContext, - PhoneNumberI18nService.class); - } - return phoneNumberI18nService; - } - - /** * Returns a reference to a ConfigurationService implementation currently * registered in the bundle context or null if no such implementation was * found. diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsQuery.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsQuery.java index ea319bb..5fa2b77 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsQuery.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsQuery.java @@ -55,98 +55,6 @@ public class GoogleContactsQuery } /** - * 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 - = GoogleContactsActivator.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 - = GoogleContactsActivator.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; - } - - - /** * Create a <tt>SourceContact</tt> from a <tt>GoogleContactsEntry</tt>. * * @param entry <tt>GoogleContactsEntry</tt> @@ -264,7 +172,7 @@ public class GoogleContactsQuery = new ArrayList<Class<? extends OperationSet>>(1); supportedOpSets.add(OperationSetBasicTelephony.class); - homePhone = normalizePhoneNumber(homePhone); + homePhone = PhoneNumberI18nService.normalize(homePhone); detail = new ContactDetail(homePhone, ContactDetail.CATEGORY_PHONE, new String[]{ContactDetail.LABEL_HOME}); @@ -278,7 +186,7 @@ public class GoogleContactsQuery = new ArrayList<Class<? extends OperationSet>>(1); supportedOpSets.add(OperationSetBasicTelephony.class); - workPhone = normalizePhoneNumber(workPhone); + workPhone = PhoneNumberI18nService.normalize(workPhone); detail = new ContactDetail(workPhone, ContactDetail.CATEGORY_PHONE, new String[]{ContactDetail.LABEL_WORK}); @@ -292,7 +200,7 @@ public class GoogleContactsQuery = new ArrayList<Class<? extends OperationSet>>(1); supportedOpSets.add(OperationSetBasicTelephony.class); - mobilePhone = normalizePhoneNumber(mobilePhone); + mobilePhone = PhoneNumberI18nService.normalize(mobilePhone); detail = new ContactDetail(mobilePhone, ContactDetail.CATEGORY_PHONE, new String[]{ContactDetail.LABEL_MOBILE}); diff --git a/src/net/java/sip/communicator/impl/gui/GuiActivator.java b/src/net/java/sip/communicator/impl/gui/GuiActivator.java index 1ec9479..3f46cef 100644 --- a/src/net/java/sip/communicator/impl/gui/GuiActivator.java +++ b/src/net/java/sip/communicator/impl/gui/GuiActivator.java @@ -82,8 +82,6 @@ public class GuiActivator implements BundleActivator private static SmiliesReplacementService smiliesService; - private static PhoneNumberI18nService phoneNumberService; - private static GlobalStatusService globalStatusService; private static AccountManager accountManager; @@ -775,24 +773,6 @@ public class GuiActivator implements BundleActivator } /** - * Returns the <tt>PhoneNumberI18nService</tt> obtained from the bundle - * context. - * - * @return the <tt>PhoneNumberI18nService</tt> implementation obtained - * from the bundle context - */ - public static PhoneNumberI18nService getPhoneNumberService() - { - if (phoneNumberService == null) - { - phoneNumberService - = ServiceUtils.getService(bundleContext, - PhoneNumberI18nService.class); - } - return phoneNumberService; - } - - /** * Returns the <tt>SecurityAuthority</tt> implementation registered to * handle security authority events. * diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java index f9d0260..402a4f2 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java @@ -779,7 +779,7 @@ public class CallManager // Removes special characters from phone numbers. if (ConfigurationManager.isNormalizePhoneNumber()) - callString = normalizePhoneNumber(callString); + callString = PhoneNumberI18nService.normalize(callString); List<ProtocolProviderService> telephonyProviders = CallManager.getTelephonyProviders(); @@ -1595,7 +1595,7 @@ public class CallManager contact = null; } - stringContact = normalizePhoneNumber(stringContact); + stringContact = PhoneNumberI18nService.normalize(stringContact); } try @@ -2255,44 +2255,6 @@ public class CallManager } /** - * Normalizes a <tt>String</tt> contact address or phone number for the - * purposes of establishing a <tt>Call</tt>. - * - * @param callee the <tt>String</tt> contact address or phone number to be - * normalized for the purposes of establishing a <tt>Call</tt> - * @return the normalized form of the specified <tt>callee</tt> appropriate - * for establishing a <tt>Call</tt> - */ - private static String normalizePhoneNumber(String callee) - { - return - normalizePhoneNumber(callee, GuiActivator.getPhoneNumberService()); - } - - /** - * Normalizes a <tt>String</tt> contact address or phone number for the - * purposes of establishing a <tt>Call</tt>. - * - * @param addr the <tt>String</tt> contact address or phone number to be - * normalized for the purposes of establishing a <tt>Call</tt> - * @param phoneNumberService the <tt>PhoneNumberI18nService</tt> to perform - * the normalization if the specified <tt>addr</tt> is recognized as a - * phone number - * @return the normalized form of the specified <tt>addr</tt> appropriate - * for establishing a <tt>Call</tt> - */ - private static String normalizePhoneNumber( - String addr, - PhoneNumberI18nService phoneNumberService) - { - addr = StringUtils.concatenateWords(addr); - if (!StringUtils.containsLetters(addr) - && phoneNumberService.isPhoneNumber(addr)) - addr = phoneNumberService.normalize(addr); - return addr; - } - - /** * Normalizes the phone numbers (if any) in a list of <tt>String</tt> * contact addresses or phone numbers. * @@ -2301,10 +2263,7 @@ public class CallManager */ private static void normalizePhoneNumbers(String callees[]) { - PhoneNumberI18nService phoneNumberService - = GuiActivator.getPhoneNumberService(); - for (int i = 0 ; i < callees.length ; i++) - callees[i] = normalizePhoneNumber(callees[i], phoneNumberService); + callees[i] = PhoneNumberI18nService.normalize(callees[i]); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/ProtocolContactSourceServiceImpl.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/ProtocolContactSourceServiceImpl.java index 228d1e5..50f71ed 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/ProtocolContactSourceServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/ProtocolContactSourceServiceImpl.java @@ -118,13 +118,11 @@ public class ProtocolContactSourceServiceImpl this.contactCount = contactCount; } - @Override protected String normalizePhoneNumber(String phoneNumber) { return phoneNumber; } - @Override protected boolean phoneNumberMatches(String phoneNumber) { return false; diff --git a/src/net/java/sip/communicator/impl/ldap/LdapActivator.java b/src/net/java/sip/communicator/impl/ldap/LdapActivator.java index d47f3e1..faf6227 100644 --- a/src/net/java/sip/communicator/impl/ldap/LdapActivator.java +++ b/src/net/java/sip/communicator/impl/ldap/LdapActivator.java @@ -56,13 +56,6 @@ public class LdapActivator } /** - * The cached reference to the <tt>PhoneNumberI18nService</tt> instance used - * by the functionality of the LDAP plug-in and fetched from its - * <tt>BundleContext</tt>. - */ - private static PhoneNumberI18nService phoneNumberI18nService; - - /** * List of contact source service registrations. */ private static Map<LdapContactSourceService, ServiceRegistration> cssList = @@ -168,25 +161,6 @@ public class LdapActivator } /** - * Gets the <tt>PhoneNumberI18nService</tt> to be used by the functionality - * of the addrbook plug-in. - * - * @return the <tt>PhoneNumberI18nService</tt> to be used by the - * functionality of the addrbook plug-in - */ - public static PhoneNumberI18nService getPhoneNumberI18nService() - { - if (phoneNumberI18nService == null) - { - phoneNumberI18nService - = ServiceUtils.getService( - bundleContext, - PhoneNumberI18nService.class); - } - return phoneNumberI18nService; - } - - /** * Enable contact source service with specified LDAP directory. * * @param ldapDir LDAP directory diff --git a/src/net/java/sip/communicator/impl/ldap/LdapContactQuery.java b/src/net/java/sip/communicator/impl/ldap/LdapContactQuery.java index 5fcc86b..3f325d5 100644 --- a/src/net/java/sip/communicator/impl/ldap/LdapContactQuery.java +++ b/src/net/java/sip/communicator/impl/ldap/LdapContactQuery.java @@ -68,97 +68,6 @@ public class LdapContactQuery } /** - * 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 - = LdapActivator.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 - = LdapActivator.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>AsyncContactQuery</tt> in a background <tt>Thread</tt>. * * @see AsyncContactQuery#run() @@ -242,7 +151,7 @@ public class LdapContactQuery = new ArrayList<Class<? extends OperationSet>>(1); supportedOpSets.add(OperationSetBasicTelephony.class); - homePhone = normalizePhoneNumber(homePhone); + homePhone = PhoneNumberI18nService.normalize(homePhone); detail = new ContactDetail(homePhone, ContactDetail.CATEGORY_PHONE, new String[]{ContactDetail.LABEL_HOME}); @@ -256,7 +165,7 @@ public class LdapContactQuery = new ArrayList<Class<? extends OperationSet>>(1); supportedOpSets.add(OperationSetBasicTelephony.class); - workPhone = normalizePhoneNumber(workPhone); + workPhone = PhoneNumberI18nService.normalize(workPhone); detail = new ContactDetail(workPhone, ContactDetail.CATEGORY_PHONE, new String[]{ContactDetail.LABEL_WORK}); @@ -270,7 +179,7 @@ public class LdapContactQuery = new ArrayList<Class<? extends OperationSet>>(1); supportedOpSets.add(OperationSetBasicTelephony.class); - mobilePhone = normalizePhoneNumber(mobilePhone); + mobilePhone = PhoneNumberI18nService.normalize(mobilePhone); detail = new ContactDetail(mobilePhone, ContactDetail.CATEGORY_PHONE, new String[]{ContactDetail.LABEL_MOBILE}); |