Commits

Anonymous committed 534bbff

Port changes for alternate formats.
Review URL: https://codereview.appspot.com/6350083

Comments (0)

Files changed (4)

tools/java/common/src/com/google/i18n/phonenumbers/BuildMetadataFromXml.java

     int numOfTerritories = territory.getLength();
     for (int i = 0; i < numOfTerritories; i++) {
       Element territoryElement = (Element) territory.item(i);
-      String id = territoryElement.getAttribute("id");
-      try {
-        PhoneMetadata metadata = loadCountryMetadata(id, territoryElement);
-        metadataCollection.addMetadata(metadata);
-      } catch (IllegalArgumentException e) {
-        LOGGER.log(Level.WARNING, "Found data for region '" + id + "' but no valid region code " +
-                   "can be found to match this. Data will be ignored.");
+      String regionCode = "";
+      // For the main metadata file this should always be set, but for other supplementary data
+      // files the country calling code may be all that is needed.
+      if (territoryElement.hasAttribute("id")) {
+        regionCode = territoryElement.getAttribute("id");
       }
+      PhoneMetadata metadata = loadCountryMetadata(regionCode, territoryElement);
+      metadataCollection.addMetadata(metadata);
     }
     return metadataCollection.build();
   }
 
   // @VisibleForTesting
   static PhoneMetadata.Builder loadTerritoryTagMetadata(String regionCode, Element element,
-                                                        String nationalPrefix,
-                                                        String nationalPrefixFormattingRule) {
+                                                        String nationalPrefix) {
     PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder();
     metadata.setId(regionCode);
     metadata.setCountryCode(Integer.parseInt(element.getAttribute(COUNTRY_CODE)));
    *  the parent (territory) element.
    */
   // @VisibleForTesting
-  static void loadAvailableFormats(PhoneMetadata.Builder metadata, String regionCode,
+  static void loadAvailableFormats(PhoneMetadata.Builder metadata,
                                    Element element, String nationalPrefix,
                                    String nationalPrefixFormattingRule,
                                    boolean nationalPrefixOptionalWhenFormatting) {
 
   public static PhoneMetadata loadCountryMetadata(String regionCode, Element element) {
     String nationalPrefix = getNationalPrefix(element);
+    PhoneMetadata.Builder metadata =
+        loadTerritoryTagMetadata(regionCode, element, nationalPrefix);
     String nationalPrefixFormattingRule =
         getNationalPrefixFormattingRuleFromElement(element, nationalPrefix);
-    PhoneMetadata.Builder metadata =
-        loadTerritoryTagMetadata(regionCode, element, nationalPrefix, nationalPrefixFormattingRule);
-
-    loadAvailableFormats(metadata, regionCode, element, nationalPrefix.toString(),
+    loadAvailableFormats(metadata, element, nationalPrefix.toString(),
                          nationalPrefixFormattingRule.toString(),
                          element.hasAttribute(NATIONAL_PREFIX_OPTIONAL_WHEN_FORMATTING));
     loadGeneralDesc(metadata, element);

tools/java/common/test/com/google/i18n/phonenumbers/BuildMetadataFromXmlTest.java

         "</territory>";
     Element territoryElement = parseXmlString(xmlInput);
     PhoneMetadata.Builder phoneMetadata =
-        BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "0", "");
+        BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "0");
     assertEquals(33, phoneMetadata.getCountryCode());
     assertEquals("2", phoneMetadata.getLeadingDigits());
     assertEquals("00", phoneMetadata.getInternationalPrefix());
     String xmlInput = "<territory countryCode='33'/>";
     Element territoryElement = parseXmlString(xmlInput);
     PhoneMetadata.Builder phoneMetadata =
-        BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "", "");
+        BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "");
     assertFalse(phoneMetadata.getMainCountryForCode());
     assertFalse(phoneMetadata.isLeadingZeroPossible());
   }
     String xmlInput = "<territory countryCode='33'/>";
     Element territoryElement = parseXmlString(xmlInput);
     PhoneMetadata.Builder phoneMetadata =
-        BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "00", "");
+        BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "00");
     // When unspecified, nationalPrefixForParsing defaults to nationalPrefix.
     assertEquals("00", phoneMetadata.getNationalPrefix());
     assertEquals(phoneMetadata.getNationalPrefix(), phoneMetadata.getNationalPrefixForParsing());
     String xmlInput = "<territory countryCode='33' internationalPrefix='00'/>";
     Element territoryElement = parseXmlString(xmlInput);
     // Should not throw any exception.
-    BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "", "");
+    BuildMetadataFromXml.loadTerritoryTagMetadata("33", territoryElement, "");
   }
 
   // Tests loadInternationalFormat().
     Element element = parseXmlString(xmlInput);
     PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder();
     BuildMetadataFromXml.loadAvailableFormats(
-        metadata, "AE", element, "0", "", false /* NP not optional */);
+        metadata, element, "0", "", false /* NP not optional */);
     assertEquals("($1)", metadata.getNumberFormat(0).getNationalPrefixFormattingRule());
     assertEquals("0 $CC ($1)", metadata.getNumberFormat(0).getDomesticCarrierCodeFormattingRule());
     assertEquals("$1 $2 $3", metadata.getNumberFormat(0).getFormat());
     Element element = parseXmlString(xmlInput);
     PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder();
     BuildMetadataFromXml.loadAvailableFormats(
-        metadata, "AE", element, "0", "", false /* NP not optional */);
+        metadata, element, "0", "", false /* NP not optional */);
     assertEquals("($1)", metadata.getNumberFormat(0).getNationalPrefixFormattingRule());
     assertEquals("0 $CC ($1)", metadata.getNumberFormat(0).getDomesticCarrierCodeFormattingRule());
     assertEquals("$1 $2 $3", metadata.getNumberFormat(0).getFormat());
     Element element = parseXmlString(xmlInput);
     PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder();
     BuildMetadataFromXml.loadAvailableFormats(
-        metadata, "AE", element, "", "($1)", false /* NP not optional */);
+        metadata, element, "", "($1)", false /* NP not optional */);
     assertEquals("($1)", metadata.getNumberFormat(0).getNationalPrefixFormattingRule());
   }
 
     Element element = parseXmlString(xmlInput);
     PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder();
     BuildMetadataFromXml.loadAvailableFormats(
-        metadata, "AE", element, "0", "($1)", false /* NP not optional */);
+        metadata, element, "0", "($1)", false /* NP not optional */);
     assertEquals(0, metadata.intlNumberFormatSize());
   }
 
     Element element = parseXmlString(xmlInput);
     PhoneMetadata.Builder metadata = PhoneMetadata.newBuilder();
     BuildMetadataFromXml.loadAvailableFormats(
-        metadata, "AE", element, "0", "($1)", false /* NP not optional */);
+        metadata, element, "0", "($1)", false /* NP not optional */);
     assertEquals("$1 $2 $3", metadata.getNumberFormat(0).getFormat());
     assertEquals("$1-$2", metadata.getNumberFormat(1).getFormat());
   }

tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar

Binary file modified.

tools/java/java-build/target/java-build-1.0-SNAPSHOT-jar-with-dependencies.jar

Binary file modified.