Exemplo n.º 1
0
        /**
         * Processes a phone number description element from the XML file and returns it as a
         * PhoneNumberDesc. If the description element is a fixed line or mobile number, the general
         * description will be used to fill in the whole element if necessary, or any components that are
         * missing. For all other types, the general description will only be used to fill in missing
         * components if the type has a partial definition. For example, if no "tollFree" element exists,
         * we assume there are no toll free numbers for that locale, and return a phone number description
         * with "NA" for both the national and possible number patterns.
         *
         * @param generalDesc  a generic phone number description that will be used to fill in missing
         *                     parts of the description
         * @param countryXmlElement  the XML element representing all the country information
         * @param numberType  the name of the number type, corresponding to the appropriate tag in the XML
         *                    file with information about that type
         * @return  complete description of that phone number type
         */
        // @VisibleForTesting
        internal static PhoneNumberDesc.Builder processPhoneNumberDescElement(PhoneNumberDesc.Builder generalDesc,
                                                                              XmlElement countryXmlElement,
                                                                              String numberType,
                                                                              bool liteBuild)
        {
            var phoneNumberDescList = countryXmlElement.GetElementsByTagName(numberType);

            PhoneNumberDesc.Builder numberDesc = PhoneNumberDesc.newBuilder();
            if (phoneNumberDescList.Count == 0 && !isValidNumberType(numberType))
            {
                numberDesc.setNationalNumberPattern("NA");
                numberDesc.setPossibleNumberPattern("NA");
                return(numberDesc);
            }
            numberDesc.mergeFrom(generalDesc.build());
            if (phoneNumberDescList.Count > 0)
            {
                XmlElement element         = (XmlElement)phoneNumberDescList.Item(0);
                var        possiblePattern = element.GetElementsByTagName(POSSIBLE_NUMBER_PATTERN);
                if (possiblePattern.Count > 0)
                {
                    numberDesc.setPossibleNumberPattern(
                        validateRE(possiblePattern.Item(0).FirstChild.Value, true));
                }

                var validPattern = element.GetElementsByTagName(NATIONAL_NUMBER_PATTERN);
                if (validPattern.Count > 0)
                {
                    numberDesc.setNationalNumberPattern(
                        validateRE(validPattern.Item(0).FirstChild.Value, true));
                }

                if (!liteBuild)
                {
                    var exampleNumber = element.GetElementsByTagName(EXAMPLE_NUMBER);
                    if (exampleNumber.Count > 0)
                    {
                        numberDesc.setExampleNumber(exampleNumber.Item(0).FirstChild.Value);
                    }
                }
            }
            return(numberDesc);
        }