List of usage examples for java.util Locale getISO3Country
public String getISO3Country() throws MissingResourceException
From source file:DisplayCountryOutput.java
public static void main(String[] argv) { Locale defaultLocale = Locale.getDefault(); System.out.println(defaultLocale.getISO3Country()); System.out.println(defaultLocale.getDisplayCountry()); System.out.println(defaultLocale.getDisplayCountry(Locale.GERMAN)); }
From source file:Main.java
public static void main(String[] args) { Locale locale = new Locale("ENGLISH", "US", "WIN"); System.out.println("Locale:" + locale); // print ISO3 country name for locale System.out.println("Name:" + locale.getISO3Country()); }
From source file:org.openestate.io.core.LocaleUtils.java
/** * Create an ISO-3 country code from an ISO-2 country code. * * @param iso2Code/*w w w. j a v a 2 s .c o m*/ * ISO-2 country code * * @return * ISO-3 country code or null, if no code was found */ public static String getCountryISO3FromISO2(String iso2Code) { iso2Code = StringUtils.trimToNull(iso2Code); if (iso2Code == null) return null; if (iso2Code.length() == 2) { Locale countryLocale = new Locale(iso2Code, iso2Code); String iso3Code = StringUtils.trimToNull(countryLocale.getISO3Country()); if (iso3Code != null) return iso3Code; } return null; }
From source file:org.openmrs.util.LocaleUtility.java
/** * Checks if specified locale object is valid * * @param locale/*from ww w .j a v a2 s . co m*/ * object for validation * @return true if locale is available */ public static boolean isValid(Locale locale) { try { return locale.getISO3Language() != null && locale.getISO3Country() != null; } catch (MissingResourceException e) { return false; } }
From source file:org.openestate.io.core.LocaleUtils.java
/** * Create an ISO-2 country code from an ISO-3 country code. * * @param iso3Code//from ww w . j a v a 2s. co m * ISO-3 country code * * @return * ISO-2 country code or null, if no code was found */ public static String getCountryISO2FromISO3(String iso3Code) { iso3Code = StringUtils.trimToNull(iso3Code); if (iso3Code == null) return null; if (iso3Code.length() == 3) { for (String iso2Code : Locale.getISOCountries()) { Locale countryLocale = new Locale(iso2Code, iso2Code); String countryISO3 = StringUtils.trimToNull(countryLocale.getISO3Country()); if (countryISO3 != null && countryISO3.equalsIgnoreCase(iso3Code)) { return iso2Code; } } } return null; }
From source file:org.openestate.io.core.LocaleUtils.java
/** * Return an ISO-3 country code from a country name. * * @param country//from ww w . j a v a 2 s. c om * country name * * @return * ISO-3 country code or null, if no code was found */ public static String getCountryISO3(String country) { country = StringUtils.trimToNull(country); if (country == null) return null; if (country.length() == 3) return country; String[] iso2Codes = Locale.getISOCountries(); if (country.length() == 2) { String iso3code = LocaleUtils.getCountryISO3FromISO2(country); if (iso3code != null) return iso3code; } for (String iso2Code : iso2Codes) { Locale countryLocale = new Locale(iso2Code, iso2Code); String iso3Code = StringUtils.trimToNull(countryLocale.getISO3Country()); if (iso3Code == null) continue; for (Locale translationLocale : LocaleUtils.availableLocaleList()) { String name = StringUtils.trimToNull(countryLocale.getDisplayCountry(translationLocale)); if (name != null && name.equalsIgnoreCase(country)) return iso3Code; } } return null; }
From source file:eu.eidas.auth.commons.CountryCodes.java
/** * Returns the CountryCode (3166-1 alpha3 format) based on the given alpha2 country code or null if it does not * exist.// w w w . j a v a 2 s .c o m * * @param alpha2CountryCode The alpha2 Country code to search. * @return the CountryCode (3166-1 alpha3 format) or null if it does not exist * @throws MissingResourceException Throws MissingResourceException if the three-letter country abbreviation is not * available for this countryCode. * @since 1.1 */ public static String getCountryCodeAlpha3(final String alpha2CountryCode) throws MissingResourceException { try { Locale countryLocale = getCountryLocale(alpha2CountryCode); if (null == countryLocale) { return null; } String alpha3Country = countryLocale.getISO3Country(); if (alpha3Country.trim().length() != 0) { return alpha3Country; } } catch (MissingResourceException ignored) { } return null; }
From source file:org.encuestame.core.security.util.WidgetUtil.java
public static boolean isValid(Locale locale) { try {// w ww. java 2s . com return locale.getISO3Language() != null && locale.getISO3Country() != null; } catch (Exception e) { return false; } }
From source file:im.delight.faceless.Server.java
public static void saveMessage(final Context context, final String colorHex, final int patternID, final String text, final String topic, final Callback.MessageEvent callback) { WebRequest request = new APIRequest(context).post().to("/messages/new"); request.auth(Global.Setup.getUsername(), Global.Setup.getPassword()); request.addParam("colorHex", colorHex); request.addParam("patternID", patternID); request.addParam("text", text); request.addParam("topic", topic); try {/*from w w w .j a va2 s .c o m*/ request.addParam("languageISO3", Locale.getDefault().getISO3Language().toUpperCase(Locale.US)); } catch (Exception e) { } String countryIso3 = null; try { // get the user's country from the preferences countryIso3 = PreferenceManager.getDefaultSharedPreferences(context) .getString(ActivitySettings.PREF_COUNTRY, null); // if the country is not set in the preferences yet if (countryIso3 == null || countryIso3.length() != 3) { // use the Locale's country property as the default countryIso3 = Locale.getDefault().getISO3Country().toUpperCase(Locale.US); if (countryIso3 == null || countryIso3.length() != 3) { Locale originalLocale = CustomLanguage.getOriginalLocale(); if (originalLocale != null) { countryIso3 = originalLocale.getISO3Country().toUpperCase(Locale.US); } } } request.addParam("countryISO3", countryIso3); } catch (Exception e) { } final String messageCountryIso3 = countryIso3; request.addParam("random", UUID.randomUUID().toString()); request.executeAsync(new WebRequest.Callback() { @Override public void onSuccess(String responseText) { try { final JSONObject responseData = new JSONObject(responseText); final String messageID = responseData.getString("messageID"); final long messageTime = responseData.getInt("messageTime") * 1000L; if (callback != null) { callback.onSentMessage(parseStatus(responseText), text, topic, messageID, messageTime, colorHex, patternID, messageCountryIso3); } } catch (Exception e) { if (callback != null) { callback.onSentMessage(STATUS_BAD_REQUEST, null, null, null, 0, null, 0, null); } } } @Override public void onError() { if (callback != null) { callback.onSentMessage(STATUS_NO_CONNECTION, null, null, null, 0, null, 0, null); } } }); }
From source file:com.commerce4j.storefront.controllers.ProfileController.java
@SuppressWarnings("unchecked") public ModelAndView register(HttpServletRequest request, HttpServletResponse response) { ModelAndView mav = new ModelAndView("register"); // user localization java.util.Locale locale = request.getLocale(); String iso3country = locale.getISO3Country(); if (StringUtils.isNotEmpty(iso3country)) { if (logger.isDebugEnabled()) logger.debug(iso3country);//from w ww . j a v a2 s .co m mav.addObject("iso3country", iso3country); } String sql = "Select * From c4j_countries Order By country_name"; List countries = getJdbcTemplate().queryForList(sql); mav.addObject("countries", countries); return mav; }