/** * Determine whether the country code is valid. The code is valid if it is * null or empty. The code is valid if it is in iso3166.properties. If a * locale is used for the iso3166Code, it will use the part after the '_'. * Thus, this code does not support dialects. * * @param iso3166Code the country code * @return true if the country is valid. */ public static boolean isValidCountry(String iso3166Code) { String lookup = iso3166Code; if (lookup == null || lookup.length() == 0) { return true; } if (lookup.indexOf('_') != -1) { String[] locale = StringUtil.split(lookup, '_'); return isValidCountry(locale[1]); } if (lookup.length() > 2) { return false; } try { getLocalisedCountries().getString(lookup); return true; } catch (MissingResourceException e) { return false; } }