001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.format;
016    
017    import com.liferay.registry.Registry;
018    import com.liferay.registry.RegistryUtil;
019    import com.liferay.registry.ServiceTracker;
020    
021    /**
022     * @author Brian Wing Shun Chan
023     * @author Manuel de la Pe??a
024     * @author Peter Fellwock
025     */
026    public class PhoneNumberFormatUtil {
027    
028            public static String format(String phoneNumber) {
029                    return getPhoneNumberFormat().format(phoneNumber);
030            }
031    
032            public static PhoneNumberFormat getPhoneNumberFormat() {
033                    return _instance._serviceTracker.getService();
034            }
035    
036            public static String strip(String phoneNumber) {
037                    return getPhoneNumberFormat().strip(phoneNumber);
038            }
039    
040            public static boolean validate(String phoneNumber) {
041                    return getPhoneNumberFormat().validate(phoneNumber);
042            }
043    
044            private PhoneNumberFormatUtil() {
045                    Registry registry = RegistryUtil.getRegistry();
046    
047                    _serviceTracker = registry.trackServices(PhoneNumberFormat.class);
048    
049                    _serviceTracker.open();
050            }
051    
052            private static final PhoneNumberFormatUtil _instance =
053                    new PhoneNumberFormatUtil();
054    
055            private final ServiceTracker<PhoneNumberFormat, PhoneNumberFormat>
056                    _serviceTracker;
057    
058    }