diff options
18 files changed, 289 insertions, 688 deletions
@@ -67,7 +67,6 @@ </attributes> </classpathentry> <classpathentry kind="lib" path="lib/installer-exclude/libjitsi.jar"/> - <classpathentry kind="lib" path="lib/installer-exclude/libphonenumber-2.4.jar"/> <classpathentry kind="lib" path="lib/installer-exclude/log4j-1.2.8.jar"/> <classpathentry kind="lib" path="lib/installer-exclude/mac_widgets-0.9.5.jar"/> <classpathentry kind="lib" path="lib/installer-exclude/objenesis-1.2.jar"/> @@ -2658,7 +2658,6 @@ javax.swing.event, javax.swing.border"/> manifest="${src}/net/java/sip/communicator/plugin/addrbook/addrbook.manifest.mf"> <zipfileset dir="${dest}/net/java/sip/communicator/plugin/addrbook" prefix="net/java/sip/communicator/plugin/addrbook" /> - <zipfileset src="${lib.noinst}/libphonenumber-2.4.jar" prefix="" /> </jar> </target> diff --git a/lib/installer-exclude/libphonenumber-2.4.jar b/lib/installer-exclude/libphonenumber-2.4.jar Binary files differdeleted file mode 100644 index dd9af49..0000000 --- a/lib/installer-exclude/libphonenumber-2.4.jar +++ /dev/null diff --git a/nbproject/project.xml b/nbproject/project.xml index 78ca0b6..6ca8ab1 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -116,7 +116,7 @@ <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/2"> <compilation-unit> <package-root>src</package-root> - <classpath mode="compile">lib/felix.jar:lib/jdic-all.jar:lib/bundle/commons-logging.jar:lib/bundle/junit.jar:lib/bundle/log4j.jar:lib/installer-exclude/aclibico-2.1.jar:lib/installer-exclude/apache-ant-1.7.0.jar:lib/installer-exclude/concurrent.jar:lib/installer-exclude/dhcp4java-1.00.jar:lib/installer-exclude/dict4j.jar:lib/installer-exclude/dnsjava.jar:lib/installer-exclude/fmj.jar:lib/installer-exclude/forms-1.2.1.jar:lib/installer-exclude/gdata-client-1.0.jar:lib/installer-exclude/gdata-client-meta-1.0.jar:lib/installer-exclude/gdata-contacts-3.0.jar:lib/installer-exclude/gdata-contacts-meta-3.0.jar:lib/installer-exclude/gdata-core-1.0.jar:lib/installer-exclude/google-collect-1.0-rc1.jar:lib/installer-exclude/hexdump-0.2.jar:lib/installer-exclude/httpclient-4.1.2.jar:lib/installer-exclude/httpcore-4.1.2.jar:lib/installer-exclude/httpmime-4.1.2.jar:lib/installer-exclude/ice4j.jar:lib/installer-exclude/jain-sdp.jar:lib/installer-exclude/jain-sip-api.jar:lib/installer-exclude/jain-sip-ri.jar:lib/installer-exclude/jcalendar-1.3.2.jar:lib/installer-exclude/jdic_misc.jar:lib/installer-exclude/jdom.jar:lib/installer-exclude/jfontchooser-1.0.5.jar:lib/installer-exclude/jmdns.jar:lib/installer-exclude/jml-1.0b5.jar:lib/installer-exclude/jmyspell-core.jar:lib/installer-exclude/jna.jar:lib/installer-exclude/jnsapi.jar:lib/installer-exclude/joscar-client.jar:lib/installer-exclude/joscar-common.jar:lib/installer-exclude/joscar-protocol.jar:lib/installer-exclude/jsch-0.1.36.jar:lib/installer-exclude/jsocks-klea.jar:lib/installer-exclude/json-20090723.jar:lib/installer-exclude/jspeex.jar:lib/installer-exclude/junit.jar:lib/installer-exclude/laf-widget.jar:lib/installer-exclude/lcrypto-jdk16-143.jar:lib/installer-exclude/libdbus-java-2.7.jar:lib/installer-exclude/libjitsi.jar:lib/installer-exclude/libphonenumber-2.4.jar:lib/installer-exclude/log4j-1.2.8.jar:lib/installer-exclude/lti-civil-no_s_w_t.jar:lib/installer-exclude/mac_widgets-0.9.5.jar:lib/installer-exclude/nist-sdp-1.0.jar:lib/installer-exclude/otr4j.jar:lib/installer-exclude/pircbot.jar:lib/installer-exclude/profiler4j-1.0-beta3-SC.jar:lib/installer-exclude/rome-0.9.jar:lib/installer-exclude/sdes4j.jar:lib/installer-exclude/smack.jar:lib/installer-exclude/smackx.jar:lib/installer-exclude/swing-worker-1.2.jar:lib/installer-exclude/transparency.jar:lib/installer-exclude/unix-0.5.jar:lib/installer-exclude/weupnp-0.1.2-SNAPSHOT.jar:lib/installer-exclude/ymsg_network_v0_67.jar:lib/installer-exclude/zrtp4j-light.jar:lib/os-specific/linux/jdic_stub.jar:lib/os-specific/mac/growl4j.jar:lib/os-specific/mac/jdic_stub.jar:lib/os-specific/mac/OrangeExtensions.jar:lib/os-specific/mac/installer-exclude/dock.jar:lib/os-specific/solaris/jdic_stub.jar:lib/os-specific/windows/jdic_stub.jar:lib/os-specific/windows/installer-exclude/jna-platform-win32.jar</classpath> + <classpath mode="compile">lib/felix.jar:lib/jdic-all.jar:lib/bundle/commons-logging.jar:lib/bundle/junit.jar:lib/bundle/log4j.jar:lib/installer-exclude/aclibico-2.1.jar:lib/installer-exclude/apache-ant-1.7.0.jar:lib/installer-exclude/concurrent.jar:lib/installer-exclude/dhcp4java-1.00.jar:lib/installer-exclude/dict4j.jar:lib/installer-exclude/dnsjava.jar:lib/installer-exclude/fmj.jar:lib/installer-exclude/forms-1.2.1.jar:lib/installer-exclude/gdata-client-1.0.jar:lib/installer-exclude/gdata-client-meta-1.0.jar:lib/installer-exclude/gdata-contacts-3.0.jar:lib/installer-exclude/gdata-contacts-meta-3.0.jar:lib/installer-exclude/gdata-core-1.0.jar:lib/installer-exclude/google-collect-1.0-rc1.jar:lib/installer-exclude/hexdump-0.2.jar:lib/installer-exclude/httpclient-4.1.2.jar:lib/installer-exclude/httpcore-4.1.2.jar:lib/installer-exclude/httpmime-4.1.2.jar:lib/installer-exclude/ice4j.jar:lib/installer-exclude/jain-sdp.jar:lib/installer-exclude/jain-sip-api.jar:lib/installer-exclude/jain-sip-ri.jar:lib/installer-exclude/jcalendar-1.3.2.jar:lib/installer-exclude/jdic_misc.jar:lib/installer-exclude/jdom.jar:lib/installer-exclude/jfontchooser-1.0.5.jar:lib/installer-exclude/jmdns.jar:lib/installer-exclude/jml-1.0b5.jar:lib/installer-exclude/jmyspell-core.jar:lib/installer-exclude/jna.jar:lib/installer-exclude/jnsapi.jar:lib/installer-exclude/joscar-client.jar:lib/installer-exclude/joscar-common.jar:lib/installer-exclude/joscar-protocol.jar:lib/installer-exclude/jsch-0.1.36.jar:lib/installer-exclude/jsocks-klea.jar:lib/installer-exclude/json-20090723.jar:lib/installer-exclude/jspeex.jar:lib/installer-exclude/junit.jar:lib/installer-exclude/laf-widget.jar:lib/installer-exclude/lcrypto-jdk16-143.jar:lib/installer-exclude/libdbus-java-2.7.jar:lib/installer-exclude/libjitsi.jar:lib/installer-exclude/log4j-1.2.8.jar:lib/installer-exclude/lti-civil-no_s_w_t.jar:lib/installer-exclude/mac_widgets-0.9.5.jar:lib/installer-exclude/nist-sdp-1.0.jar:lib/installer-exclude/otr4j.jar:lib/installer-exclude/pircbot.jar:lib/installer-exclude/profiler4j-1.0-beta3-SC.jar:lib/installer-exclude/rome-0.9.jar:lib/installer-exclude/sdes4j.jar:lib/installer-exclude/smack.jar:lib/installer-exclude/smackx.jar:lib/installer-exclude/swing-worker-1.2.jar:lib/installer-exclude/transparency.jar:lib/installer-exclude/unix-0.5.jar:lib/installer-exclude/weupnp-0.1.2-SNAPSHOT.jar:lib/installer-exclude/ymsg_network_v0_67.jar:lib/installer-exclude/zrtp4j-light.jar:lib/os-specific/linux/jdic_stub.jar:lib/os-specific/mac/growl4j.jar:lib/os-specific/mac/jdic_stub.jar:lib/os-specific/mac/OrangeExtensions.jar:lib/os-specific/mac/installer-exclude/dock.jar:lib/os-specific/solaris/jdic_stub.jar:lib/os-specific/windows/jdic_stub.jar:lib/os-specific/windows/installer-exclude/jna-platform-win32.jar</classpath> <built-to>classes</built-to> <source-level>1.5</source-level> </compilation-unit> 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}); diff --git a/src/net/java/sip/communicator/plugin/addrbook/AddrBookActivator.java b/src/net/java/sip/communicator/plugin/addrbook/AddrBookActivator.java index 7c3dafa..74c1215 100644 --- a/src/net/java/sip/communicator/plugin/addrbook/AddrBookActivator.java +++ b/src/net/java/sip/communicator/plugin/addrbook/AddrBookActivator.java @@ -67,13 +67,6 @@ public class AddrBookActivator private static ServiceRegistration cssServiceRegistration;
/**
- * The cached reference to the <tt>PhoneNumberI18nService</tt> instance used
- * by the functionality of the addrbook plug-in and fetched from its
- * <tt>BundleContext</tt>.
- */
- private static PhoneNumberI18nService phoneNumberI18nService;
-
- /**
* The <tt>ResourceManagementService</tt> through which we access resources.
*/
private static ResourceManagementService resourceService;
@@ -85,25 +78,6 @@ public class AddrBookActivator private static ConfigurationService configService;
/**
- * 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;
- }
-
- /**
* Gets the <tt>ResourceManagementService</tt> to be used by the
* functionality of the addrbook plug-in.
*
@@ -155,11 +129,6 @@ public class AddrBookActivator {
AddrBookActivator.bundleContext = bundleContext;
- bundleContext.registerService(
- PhoneNumberI18nService.class.getName(),
- new PhoneNumberI18nServiceImpl(),
- null);
-
Dictionary<String, String> properties = new Hashtable<String, String>();
// Registers the sip config panel as advanced configuration form.
diff --git a/src/net/java/sip/communicator/plugin/addrbook/PhoneNumberI18nServiceImpl.java b/src/net/java/sip/communicator/plugin/addrbook/PhoneNumberI18nServiceImpl.java deleted file mode 100644 index 660333d..0000000 --- a/src/net/java/sip/communicator/plugin/addrbook/PhoneNumberI18nServiceImpl.java +++ /dev/null @@ -1,126 +0,0 @@ -/*
- * Jitsi, 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.protocol.*;
-
-import com.google.i18n.phonenumbers.*;
-import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
-
-/**
- * Implements <tt>PhoneNumberI18nService</tt> which aids the parsing, formatting
- * and validating of international phone numbers using the libphonenumber
- * library.
- *
- * @author Lyubomir Marinov
- */
-public class PhoneNumberI18nServiceImpl
- implements PhoneNumberI18nService
-{
-
- /**
- * 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>
- * @see PhoneNumberI18nService#normalize(String)
- */
- public String normalize(String phoneNumber)
- {
- String plusSign = "+";
- boolean plusSignFound = false;
- if (phoneNumber.startsWith(plusSign))
- plusSignFound = true;
-
- String normalizedNumber
- = PhoneNumberUtil.normalizeDigitsOnly(
- PhoneNumberUtil.convertAlphaCharactersInNumber(
- phoneNumber));
-
- if (plusSignFound && !normalizedNumber.startsWith(plusSign))
- return plusSign + normalizedNumber;
-
- return normalizedNumber;
- }
-
- /**
- * Determines whether two <tt>String</tt> phone numbers match.
- *
- * @param aPhoneNumber a <tt>String</tt> which represents a phone number to
- * match to <tt>bPhoneNumber</tt>
- * @param bPhoneNumber a <tt>String</tt> which represents a phone number to
- * match to <tt>aPhoneNumber</tt>
- * @return <tt>true</tt> if the specified <tt>String</tt>s match as phone
- * numbers; otherwise, <tt>false</tt>
- */
- public boolean phoneNumbersMatch(String aPhoneNumber, String bPhoneNumber)
- {
- PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
-
- try
- {
- String defaultCountry = Locale.getDefault().getCountry();
-
- if ((defaultCountry != null) && (defaultCountry.length() != 0))
- {
- PhoneNumber a
- = phoneNumberUtil.parse(aPhoneNumber, defaultCountry);
- PhoneNumber b
- = phoneNumberUtil.parse(bPhoneNumber, defaultCountry);
-
- if (PhoneNumberUtil.MatchType.NO_MATCH
- != phoneNumberUtil.isNumberMatch(a, b))
- return true;
- }
- }
- catch (NumberParseException npex)
- {
- /* Ignore it, we'll try without the defaultCountry. */
- }
- try
- {
- return
- PhoneNumberUtil.MatchType.NO_MATCH
- != phoneNumberUtil.isNumberMatch(aPhoneNumber, bPhoneNumber);
- }
- catch (NumberParseException npex)
- {
- throw new IllegalArgumentException(npex);
- }
- }
-
- /**
- * Indicates if the given string is possibly a phone number.
- *
- * @param possibleNumber the string to be verified
- * @return <tt>true</tt> if the possibleNumber is a phone number,
- * <tt>false</tt> - otherwise
- */
- public boolean isPhoneNumber(String possibleNumber)
- {
- PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance();
- try
- {
- if (numberUtil.isPossibleNumber(possibleNumber, null))
- return true;
- else
- return numberUtil.isPossibleNumber(
- numberUtil.parse( possibleNumber,
- Locale.getDefault().getCountry()));
- }
- catch (NumberParseException e)
- {
- return false;
- }
- }
-}
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 e15684f..ad4ebea 100644 --- a/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java +++ b/src/net/java/sip/communicator/plugin/addrbook/macosx/MacOSXAddrBookContactQuery.java @@ -322,7 +322,8 @@ public class MacOSXAddrBookContactQuery if (stringValue.length() != 0)
{
if (kABPhoneProperty == property)
- stringValue = normalizePhoneNumber(stringValue);
+ stringValue
+ = PhoneNumberI18nService.normalize(stringValue);
contactDetails.add(
setCapabilities(
@@ -351,8 +352,8 @@ public class MacOSXAddrBookContactQuery {
if (kABPhoneProperty == property)
{
- stringSubValue
- = normalizePhoneNumber(stringSubValue);
+ stringSubValue = PhoneNumberI18nService
+ .normalize(stringSubValue);
}
contactDetails.add(
@@ -787,95 +788,4 @@ 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/msoutlook/MsOutlookAddrBookContactQuery.java b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java index 2291378..2c45d59 100644 --- a/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java +++ b/src/net/java/sip/communicator/plugin/addrbook/msoutlook/MsOutlookAddrBookContactQuery.java @@ -374,7 +374,8 @@ public class MsOutlookAddrBookContactQuery if (stringProp.length() != 0)
{
if (isPhoneNumber(propIndex))
- stringProp = normalizePhoneNumber(stringProp);
+ stringProp =
+ PhoneNumberI18nService.normalize(stringProp);
ContactDetail contactDetail
= new ContactDetail(
@@ -491,95 +492,4 @@ 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/phonenumbercontactsource/PhoneNumberContactQuery.java b/src/net/java/sip/communicator/plugin/phonenumbercontactsource/PhoneNumberContactQuery.java index e65ba51..2ac2717 100644 --- a/src/net/java/sip/communicator/plugin/phonenumbercontactsource/PhoneNumberContactQuery.java +++ b/src/net/java/sip/communicator/plugin/phonenumbercontactsource/PhoneNumberContactQuery.java @@ -214,15 +214,13 @@ public class PhoneNumberContactQuery } } - @Override protected String normalizePhoneNumber(String phoneNumber) { return null; } - @Override protected boolean phoneNumberMatches(String phoneNumber) { return false; } -}
\ No newline at end of file +} diff --git a/src/net/java/sip/communicator/service/contactsource/AsyncContactQuery.java b/src/net/java/sip/communicator/service/contactsource/AsyncContactQuery.java index aed89b3..4ec2cde 100644 --- a/src/net/java/sip/communicator/service/contactsource/AsyncContactQuery.java +++ b/src/net/java/sip/communicator/service/contactsource/AsyncContactQuery.java @@ -9,6 +9,8 @@ package net.java.sip.communicator.service.contactsource; import java.util.*;
import java.util.regex.*;
+import net.java.sip.communicator.service.protocol.*;
+
/**
* Provides an abstract implementation of a <tt>ContactQuery</tt> which runs in
* a separate <tt>Thread</tt>.
@@ -175,30 +177,6 @@ public abstract class AsyncContactQuery<T extends ContactSourceService> }
/**
- * 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 abstract String normalizePhoneNumber(String 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 abstract boolean phoneNumberMatches(String phoneNumber);
-
- /**
* Performs this <tt>ContactQuery</tt> in a background <tt>Thread</tt>.
*/
protected abstract void run();
@@ -253,4 +231,69 @@ public abstract class AsyncContactQuery<T extends ContactSourceService> 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(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/service/protocol/PhoneNumberI18nService.java b/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java index cbe43f9..91e50e5 100644 --- a/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java +++ b/src/net/java/sip/communicator/service/protocol/PhoneNumberI18nService.java @@ -6,25 +6,156 @@ */
package net.java.sip.communicator.service.protocol;
+import java.util.*;
+import java.util.regex.*;
+
+import net.java.sip.communicator.impl.gui.*;
+
+import org.jitsi.service.configuration.*;
+
/**
- * Represents an OSGi service which aids the parsing, formatting and validating
- * of international phone numbers.
+ * Implements <tt>PhoneNumberI18nService</tt> which aids the parsing, formatting
+ * and validating of international phone numbers.
*
* @author Lyubomir Marinov
+ * @author Vincent Lucas
*/
-public interface PhoneNumberI18nService
+public abstract class PhoneNumberI18nService
{
/**
+ * The configuration service.
+ */
+ private static ConfigurationService configService
+ = ProtocolProviderActivator.getConfigurationService();
+
+ /**
+ * String identifier of a boolean propery telling if a phone number can
+ * contain alphabetical characters.
+ */
+ private static final String DISABLED_PROP
+ = "net.java.sip.communicator.plugin.addrbook.phonenumbercharacterstonumbers.DISABLED";
+ /**
+ * Characters which have to be removed from a phone number in order to
+ * normalized it.
+ */
+ private static final Pattern removedCharactersToNormalizedPhoneNumber
+ = Pattern.compile("[-\\(\\)\\. ]");
+
+ /**
+ * Characters which have to be removed from a number (which is not a phone
+ * number, such as a sip id, a jabber id, etc.) in order to normalized it.
+ */
+ private static final Pattern removedCharactersToNormalizedIdentifier
+ = Pattern.compile("[\\(\\) ]");
+
+ /**
+ * The list of characters corresponding to the number 2 in a phone dial pad.
+ */
+ private static final Pattern charactersFordialPadNumber2
+ = Pattern.compile("[abc]", Pattern.CASE_INSENSITIVE);
+ /**
+ * The list of characters corresponding to the number 3 in a phone dial pad.
+ */
+ private static final Pattern charactersFordialPadNumber3
+ = Pattern.compile("[def]", Pattern.CASE_INSENSITIVE);
+
+ /**
+ * The list of characters corresponding to the number 4 in a phone dial pad.
+ */
+ private static final Pattern charactersFordialPadNumber4
+ = Pattern.compile("[ghi]", Pattern.CASE_INSENSITIVE);
+
+ /**
+ * The list of characters corresponding to the number 5 in a phone dial pad.
+ */
+ private static final Pattern charactersFordialPadNumber5
+ = Pattern.compile("[jkl]", Pattern.CASE_INSENSITIVE);
+
+ /**
+ * The list of characters corresponding to the number 6 in a phone dial pad.
+ */
+ private static final Pattern charactersFordialPadNumber6
+ = Pattern.compile("[mno]", Pattern.CASE_INSENSITIVE);
+
+ /**
+ * The list of characters corresponding to the number 7 in a phone dial pad.
+ */
+ private static final Pattern charactersFordialPadNumber7
+ = Pattern.compile("[pqrs]", Pattern.CASE_INSENSITIVE);
+
+ /**
+ * The list of characters corresponding to the number 8 in a phone dial pad.
+ */
+ private static final Pattern charactersFordialPadNumber8
+ = Pattern.compile("[tuv]", Pattern.CASE_INSENSITIVE);
+
+ /**
+ * The list of characters corresponding to the number 9 in a phone dial pad.
+ */
+ private static final Pattern charactersFordialPadNumber9
+ = Pattern.compile("[wxyz]", Pattern.CASE_INSENSITIVE);
+
+ /**
+ * Normalizes a <tt>String</tt> which may be a phone number or a identifier
+ * by removing useless characters and, if necessary, replacing the alpahe
+ * characters in corresponding dial pad numbers.
+ *
+ * @param possibleNumber a <tt>String</tt> which may represents a phone
+ * number or an identifier to normalize.
+ *
+ * @return a <tt>String</tt> which is a normalized form of the specified
+ * <tt>possibleNumber</tt>.
+ */
+ public static String normalize(String possibleNumber)
+ {
+ String normalizedNumber;
+ if(isPhoneNumber(possibleNumber))
+ {
+ normalizedNumber = normalizePhoneNumber(possibleNumber);
+ }
+ else
+ {
+ normalizedNumber = normalizeIdentifier(possibleNumber);
+ }
+
+ return normalizedNumber;
+ }
+
+
+ /**
* 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>
+ *
+ * @see PhoneNumberI18nService#normalize(String)
+ */
+ private static String normalizePhoneNumber(String phoneNumber)
+ {
+ phoneNumber = convertAlphaCharactersInNumber(phoneNumber);
+ return removedCharactersToNormalizedPhoneNumber
+ .matcher(phoneNumber).replaceAll("");
+ }
+
+ /**
+ * Removes useless characters from a identifier (which is not a phone
+ * number) in order to normalized it.
+ *
+ * @param id The identifier string with some useless characters like: " ",
+ * "(", ")".
+ *
+ * @return The normalized identifier.
*/
- public String normalize(String phoneNumber);
+ private static String normalizeIdentifier(String id)
+ {
+ return removedCharactersToNormalizedIdentifier
+ .matcher(id).replaceAll("");
+ }
/**
* Determines whether two <tt>String</tt> phone numbers match.
@@ -36,13 +167,79 @@ public interface PhoneNumberI18nService * @return <tt>true</tt> if the specified <tt>String</tt>s match as phone
* numbers; otherwise, <tt>false</tt>
*/
- public boolean phoneNumbersMatch(String aPhoneNumber, String bPhoneNumber);
+ public static boolean phoneNumbersMatch(
+ String aPhoneNumber,
+ String bPhoneNumber)
+ {
+ String aPhoneNumberNormalized = normalize(aPhoneNumber);
+ String bPhoneNumberNormalized = normalize(bPhoneNumber);
+
+ return aPhoneNumberNormalized.equals(bPhoneNumberNormalized);
+ }
/**
* Indicates if the given string is possibly a phone number.
*
* @param possibleNumber the string to be verified
- * @return true if the given string is a phone number, false otherwise
+ * @return <tt>true</tt> if the possibleNumber is a phone number,
+ * <tt>false</tt> - otherwise
+ */
+ public static boolean isPhoneNumber(String possibleNumber)
+ {
+ // If the string does not contains an "@", this may be a phone number.
+ if(possibleNumber.indexOf('@') == -1)
+ {
+ // If the string does not contain any alphabetical characters, then
+ // this is a phone number.
+ if(!possibleNumber.matches(".*[a-zA-Z].*"))
+ {
+ return true;
+ }
+ else
+ {
+ // Removes the " ", "(" and ")" in order to search the "+"
+ // character at the beginning at the string.
+ String tmpPossibleNumber
+ = possibleNumber.replaceAll(" \\(\\)", "");
+ // If the property is enabled and the string starts with a "+",
+ // then we consider that this is a phone number.
+ if(!configService.getBoolean(DISABLED_PROP, false)
+ && tmpPossibleNumber.startsWith("+"))
+ {
+ return true;
+ }
+ }
+ }
+ // Else the string is not a phone number.
+ return false;
+ }
+
+ /**
+ * Changes all alphabetical characters into numbers, following phone dial
+ * pad disposition.
+ *
+ * @param phoneNumber The phone number string with some alphabetical
+ * characters.
+ *
+ * @return The phone number with all alphabetical caracters replaced with
+ * the corresponding dial pad number.
*/
- public boolean isPhoneNumber(String possibleNumber);
+ private static String convertAlphaCharactersInNumber(String phoneNumber)
+ {
+ phoneNumber
+ = charactersFordialPadNumber2.matcher(phoneNumber).replaceAll("2");
+ phoneNumber
+ = charactersFordialPadNumber3.matcher(phoneNumber).replaceAll("3");
+ phoneNumber
+ = charactersFordialPadNumber4.matcher(phoneNumber).replaceAll("4");
+ phoneNumber
+ = charactersFordialPadNumber5.matcher(phoneNumber).replaceAll("5");
+ phoneNumber
+ = charactersFordialPadNumber6.matcher(phoneNumber).replaceAll("6");
+ phoneNumber
+ = charactersFordialPadNumber7.matcher(phoneNumber).replaceAll("7");
+ phoneNumber
+ = charactersFordialPadNumber8.matcher(phoneNumber).replaceAll("8");
+ return charactersFordialPadNumber9.matcher(phoneNumber).replaceAll("9");
+ }
}
|