use of com.google.i18n.phonenumbers.PhoneNumberUtil in project tdq-studio-se by Talend.
the class InvalidRegCodeCountIndicatorImpl method handle.
@Override
public boolean handle(Object data) {
super.handle(data);
if (data == null) {
this.invalidRegCount++;
setMustStoreRow();
return false;
}
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
boolean parseSuccess = true;
String regionCodeForNumber = null;
try {
// the parameter defualtRegion is null at here, it will get an region code when the data is guaranteed to
// start with a '+' followed by the country calling code. e.g. "+86 13521588311", "+8613521588311",
// "+86 1352 1588 311". or else, it will throw Exception as an invalid Region Code.
PhoneNumber phhoneNum = phoneUtil.parse(data.toString(), null);
regionCodeForNumber = phoneUtil.getRegionCodeForNumber(phhoneNum);
} catch (NumberParseException e) {
parseSuccess = false;
}
Set<String> supportedCountries = phoneUtil.getSupportedRegions();
if (!parseSuccess || (!supportedCountries.contains(regionCodeForNumber))) {
this.invalidRegCount++;
setMustStoreRow();
}
return true;
}
use of com.google.i18n.phonenumbers.PhoneNumberUtil in project tdq-studio-se by Talend.
the class PossiblePhoneCountIndicatorImpl method handle.
@Override
public boolean handle(Object data) {
super.handle(data);
if (data == null) {
return false;
}
try {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
IndicatorParameters indParameters = this.getParameters();
TextParameters textParameters = indParameters == null ? null : indParameters.getTextParameter();
String country = IndicatorHelper.getCountryCodeByParameter(textParameters);
PhoneNumber phoneNumeber = phoneUtil.parse(data.toString(), country);
// number.
if (phoneUtil.isPossibleNumber(phoneNumeber)) {
this.possiblePhoneCount++;
if (checkMustStoreCurrentRow() || this.checkMustStoreCurrentRow(drillDownValueCount)) {
this.mustStoreRow = true;
}
}
} catch (NumberParseException e) {
return false;
}
return true;
}
use of com.google.i18n.phonenumbers.PhoneNumberUtil in project tdq-studio-se by Talend.
the class WellFormE164PhoneCountIndicatorImpl method handle.
@Override
public boolean handle(Object data) {
super.handle(data);
if (data == null) {
return false;
}
try {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
IndicatorParameters indParameters = this.getParameters();
TextParameters textParameters = indParameters == null ? null : indParameters.getTextParameter();
String country = IndicatorHelper.getCountryCodeByParameter(textParameters);
PhoneNumber phoneNumeber = phoneUtil.parse(data.toString(), country);
String format = phoneUtil.format(phoneNumeber, PhoneNumberFormat.E164);
if (data.toString().equals(format)) {
wellFormE164PhoneCount++;
if (checkMustStoreCurrentRow() || checkMustStoreCurrentRow(drillDownValueCount)) {
this.mustStoreRow = true;
}
}
} catch (NumberParseException e) {
return false;
}
return true;
}
use of com.google.i18n.phonenumbers.PhoneNumberUtil in project ofbiz-framework by apache.
the class UtilMisc method splitPhoneNumber.
public static Map<String, String> splitPhoneNumber(String phoneNumber, Delegator delegator) {
Map<String, String> result = new HashMap<>();
try {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
String defaultCountry = EntityUtilProperties.getPropertyValue("general", "country.geo.id.default", delegator);
GenericValue defaultGeo = EntityQuery.use(delegator).from("Geo").where("geoId", defaultCountry).cache().queryOne();
String defaultGeoCode = defaultGeo != null ? defaultGeo.getString("geoCode") : "US";
PhoneNumber phNumber = phoneUtil.parse(phoneNumber, defaultGeoCode);
if (phoneUtil.isValidNumber(phNumber) || phoneUtil.isPossibleNumber(phNumber)) {
String nationalSignificantNumber = phoneUtil.getNationalSignificantNumber(phNumber);
int areaCodeLength = phoneUtil.getLengthOfGeographicalAreaCode(phNumber);
result.put("countryCode", Integer.toString(phNumber.getCountryCode()));
if (areaCodeLength > 0) {
result.put("areaCode", nationalSignificantNumber.substring(0, areaCodeLength));
result.put("contactNumber", nationalSignificantNumber.substring(areaCodeLength));
} else {
result.put("areaCode", "");
result.put("contactNumber", nationalSignificantNumber);
}
} else {
Debug.logError("Invalid phone number " + phoneNumber, module);
result.put(ModelService.ERROR_MESSAGE, "Invalid phone number");
}
} catch (GenericEntityException | NumberParseException ex) {
Debug.logError(ex, module);
result.put(ModelService.ERROR_MESSAGE, ex.getMessage());
}
return result;
}
use of com.google.i18n.phonenumbers.PhoneNumberUtil in project Signal-Android by WhisperSystems.
the class CurrencyUtil method getCurrencyByE164.
@Nullable
public static Currency getCurrencyByE164(@NonNull String e164) {
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber number;
try {
number = PhoneNumberUtil.getInstance().parse(e164, "");
} catch (NumberParseException e) {
return null;
}
String regionCodeForNumber = phoneNumberUtil.getRegionCodeForNumber(number);
for (Locale l : Locale.getAvailableLocales()) {
if (l.getCountry().equals(regionCodeForNumber)) {
return getCurrencyByLocale(l);
}
}
return null;
}
Aggregations