public static String getCountryName(String code) {
   try {
     return CountryCode.getByCode(code).getName();
   } catch (Exception e) {
     return "";
   }
 }
 /**
  * Parses a country code as string.
  *
  * @param countryCodeAsString the string representing a country code.
  * @return the country code represented in the string, or absent if it does not correspond to a
  *     valid country.
  */
 public static Optional<CountryCode> parseCode(String countryCodeAsString) {
   try {
     return Optional.of(CountryCode.valueOf(countryCodeAsString));
   } catch (IllegalArgumentException e) {
     LOGGER.debug("Invalid country " + countryCodeAsString);
     return Optional.empty();
   }
 }
Beispiel #3
0
 public Address getAddress() {
   Address address = null;
   if (response != null && hasNode(response, "Address")) {
     JsonNode node = response.get("Address");
     if (!hasNode(node, "Country")) return null;
     address = new Address(CountryCode.valueOf(node.get("Country").getTextValue()));
     if (hasNode(response, "FirstName"))
       address.setFirstName(response.get("FirstName").getTextValue());
     if (hasNode(response, "LastName"))
       address.setLastName(response.get("LastName").getTextValue());
     if (hasNode(node, "AddressLine1"))
       address.setStreetName(node.get("AddressLine1").getTextValue());
     if (hasNode(node, "AddressLine2"))
       address.setStreetNumber(node.get("AddressLine2").getTextValue());
     if (hasNode(node, "PostalCode")) address.setPostalCode(node.get("PostalCode").getTextValue());
     if (hasNode(node, "City")) address.setCity(node.get("City").getTextValue());
   }
   return address;
 }
 /**
  * Sets the country associated with the user.
  *
  * @param countryCode the desired country for the user.
  */
 private void changeCountry(CountryCode countryCode) {
   if (availableCountries().contains(countryCode)) {
     Http.Context.current().session().put(COUNTRY_SESSION_KEY, countryCode.getAlpha2());
   }
 }