Package com.jalios.jcms.i18n
Class PhoneNumberUtil
java.lang.Object
com.jalios.jcms.i18n.PhoneNumberUtil
Utility class providing misc methods to deal with phone number.
- Since:
- jcms-9.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classGenerator of the HTML suitable to display the specified number (with additionnal optional parameters). -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetPhoneHtml(String number, String region) Retrieve the specified telephone number properly formated in an HTML tag.static PhoneNumberparseNumber(String number, String region) Parse a phone number string into a PhoneNumber instance.
-
Field Details
-
EXCLUSION_PATTERN_PROPERTY
Name of the JCMS property used to exclude number from parsing (value is a regular expression).If defined, all text that match the regular expression will be excluded from parsing into a valid PhoneNumber instance.
- See Also:
-
exclusionPattern
-
-
Constructor Details
-
PhoneNumberUtil
public PhoneNumberUtil()
-
-
Method Details
-
getPhoneHtml
Retrieve the specified telephone number properly formated in an HTML tag.Uses the RFC 3966 ("tel:" uri) as the anchor href, and the international format in the anchor body text, the original input is placed inside the title attribute.
Phone number is parsed with rule explained in
parseNumber(String, String). For example :assertEquals("<a href=\"tel:+33-4-46-68-18-00\" title=\"+33 44 66 8 180 0\" class=\"tel\">+33 4 46 68 18 00</a>", PhoneTag.getPhoneHtml("+33 44 66 8 180 0", null)); final String sourceNumber = "0446681800"; assertEquals("<a href=\"tel:+41-44-668-18-00\" title=\"0446681800\" class=\"tel\">+41 44 668 18 00</a>", PhoneTag.getPhoneHtml(sourceNumber, "CH")); assertEquals("<a href=\"tel:+33-4-46-68-18-00\" title=\"0446681800\" class=\"tel\">+33 4 46 68 18 00</a>", PhoneTag.getPhoneHtml(sourceNumber, "FR"));If number could not be parsed, it is returned encoded for HTML, inside a dedicated span with theinvalid-telCSS classassertEquals("<span class=\"invalid-tel\">do not call me!</span>", PhoneTag.getPhoneHtml("do not call me!", null));- Parameters:
number- the telephone number to parse and displayregion- the ISO 3166-1 two-letter region code that denotes the region that we are expecting the number to be from. This is only used if the number being parsed is not written in international format.- Returns:
- an HTML string suitable for displaying a phone number, an empty string if number was empty or could not be parsed
-
parseNumber
Parse a phone number string into a PhoneNumber instance.The following rules are applied regarding regionnal information :
- regionnal information contained in the number is used first if available
- otherwise the region paremeter is used, if specified and valid
- otherwise the default site country is used
- Parameters:
number- the telephone number to parseregion- the ISO 3166-1 two-letter region code that denotes the region that we are expecting the number to be from. This is only used if the number being parsed is not written in international format.- Returns:
- a PhoneNumber instance or null if number could not be parsed properly
-