/** * Extracts the pattern for international format. If there is no intlFormat, default to using the * national format. If the intlFormat is set to "NA" the intlFormat should be ignored. * * @throws RuntimeException if multiple intlFormats have been encountered. * @return whether an international number format is defined. */ // @VisibleForTesting internal static bool loadInternationalFormat(PhoneMetadata.Builder metadata, XmlElement numberFormatXmlElement, NumberFormat nationalFormat) { NumberFormat.Builder intlFormat = NumberFormat.newBuilder(); var intlFormatPattern = numberFormatXmlElement.GetElementsByTagName(INTL_FORMAT); var hasExplicitIntlFormatDefined = false; if (intlFormatPattern.Count > 1) { // LOGGER.log(Level.SEVERE, // "A maximum of one intlFormat pattern for a numberFormat element should be " + // "defined."); String countryId = metadata.getId().Length > 0 ? metadata.getId() : metadata.getCountryCode().ToString(); throw new Exception("Invalid number of intlFormat patterns for country: " + countryId); } else if (intlFormatPattern.Count == 0) { // Default to use the same as the national pattern if none is defined. intlFormat.mergeFrom(nationalFormat); } else { intlFormat.setPattern(numberFormatXmlElement.GetAttribute(PATTERN)); setLeadingDigitsPatterns(numberFormatXmlElement, intlFormat); String intlFormatPatternValue = intlFormatPattern.Item(0).FirstChild.Value; if (!intlFormatPatternValue.Equals("NA")) { intlFormat.setFormat(intlFormatPatternValue); } hasExplicitIntlFormatDefined = true; } if (intlFormat.HasFormat()) { metadata.addIntlNumberFormat(intlFormat); } return(hasExplicitIntlFormatDefined); }