Example usage for java.util Locale getISOCountries

List of usage examples for java.util Locale getISOCountries

Introduction

In this page you can find the example usage for java.util Locale getISOCountries.

Prototype

public static String[] getISOCountries() 

Source Link

Document

Returns a list of all 2-letter country codes defined in ISO 3166.

Usage

From source file:mo.iguideu.ui.initGuideProfile.FragmentInitGuideDataStep2.java

public void refreshSupportLocales() {

    String[] countries = Locale.getISOCountries();
    Locale[] locales = Locale.getAvailableLocales();

    Map<String, String> languagesMap = new TreeMap<String, String>();

    for (Locale obj : locales) {
        if ((obj.getDisplayCountry() != null) && (!"".equals(obj.getDisplayCountry()))) {
            languagesMap.put(obj.getCountry(), obj.getLanguage());
        }//from w w  w. j  av  a 2s. c  om
    }

    for (String countryCode : countries) {
        Locale obj = new Locale("", countryCode);
        if (languagesMap.get(countryCode) != null) {
            obj = new Locale(languagesMap.get(countryCode), countryCode);
            if (!obj.getCountry().equals("TW") && !obj.getCountry().equals("JP")
                    && !obj.getCountry().equals("CN"))
                supportLocale.add(obj);
        }
    }
}

From source file:org.openestate.io.core.LocaleUtils.java

/**
 * Translate a country name into another language.
 *
 * @param country//from ww  w  . java  2  s.c  om
 * country name
 *
 * @param language
 * language to translate
 *
 * @return
 * translated country name or null, if no translation was found
 */
public static String translateCountryName(String country, Locale language) {
    country = StringUtils.trimToNull(country);
    if (country == null)
        return null;
    for (String iso2Code : Locale.getISOCountries()) {
        Locale countryLocale = new Locale(iso2Code, iso2Code);
        for (Locale translationLocale : LocaleUtils.availableLocaleList()) {
            String name = StringUtils.trimToNull(countryLocale.getDisplayCountry(translationLocale));
            if (name != null && name.equalsIgnoreCase(country)) {
                name = StringUtils.trimToNull(countryLocale.getDisplayCountry(language));
                if (name != null)
                    return name;
            }
        }
    }
    return null;
}

From source file:org.apache.click.extras.control.CountrySelect.java

/**
 * Load the Country Select options if not defined, using all the available
 * countries. The option value will be the two letter uppercase ISO name of
 * the country as the value and the localized country name as the label.
 *//*  w  ww  .j av  a  2s  . c  o m*/
protected void loadOptionList() {
    List optionList = getOptionList();

    // Determine whether option list should be loaded
    if (optionList.size() == 1) {
        Option option = (Option) optionList.get(0);
        if (option.getValue().equals(Option.EMPTY_OPTION.getValue())) {
            // Continue and load option list

        } else {
            // Don't load list
            return;
        }

    } else if (optionList.size() > 1) {
        // Don't load list
        return;
    }

    Set<Option> countryList = new TreeSet<Option>(new OptionLabelComparator(getLocale()));

    String[] isoCountries = Locale.getISOCountries();

    Locale userLocale = getLocale();

    for (int i = 0; i < isoCountries.length; i++) {
        Locale tmpLocale = new Locale("en", isoCountries[i]);
        final String iso = tmpLocale.getCountry();
        final String country = tmpLocale.getDisplayCountry(userLocale);

        if (StringUtils.isNotEmpty(iso) && StringUtils.isNotEmpty(country)) {
            countryList.add(new Option(iso, country));
        }
    }

    if (isRequired() && optionList.isEmpty()) {
        add(Option.EMPTY_OPTION);
    }

    addAll(countryList);
}

From source file:com.ethercamp.harmony.service.PeersService.java

/**
 * Create MaxMind lookup service to find country by IP.
 * IPv6 is not used./*from   w ww. j  a v  a 2  s  .c  o  m*/
 */
private void createGeoDatabase() {
    final String[] countries = Locale.getISOCountries();
    final Optional<String> dbFilePath = Optional.ofNullable(env.getProperty("maxmind.file"));

    for (String country : countries) {
        Locale locale = new Locale("", country);
        localeMap.put(locale.getISO3Country().toUpperCase(), locale);
    }
    lookupService = dbFilePath.flatMap(path -> {
        try {
            return Optional.ofNullable(new LookupService(path,
                    LookupService.GEOIP_MEMORY_CACHE | LookupService.GEOIP_CHECK_CACHE));
        } catch (IOException e) {
            log.error("Problem finding maxmind database at " + path + ". " + e.getMessage());
            log.error(
                    "Wasn't able to create maxmind location service. Country information will not be available.");
            return Optional.empty();
        }
    });
}

From source file:alfio.controller.api.support.TicketHelper.java

public static List<Pair<String, String>> getLocalizedCountries(Locale locale) {
    return mapISOCountries(Stream.of(Locale.getISOCountries()), locale);
}

From source file:alfio.controller.api.support.TicketHelper.java

public static List<Pair<String, String>> getLocalizedEUCountries(Locale locale, String euCountries) {
    return mapISOCountries(
            Stream.of(Locale.getISOCountries()).filter(isoCode -> StringUtils.contains(euCountries, isoCode)),
            locale);/*from ww w  . j  a  v a  2s . c o m*/
}

From source file:com.activecq.samples.workflow.impl.LocalizedTagTitleExtractorProcessWorkflow.java

/**
 * Derive the locale from the parent path segments (/content/us/en/..)
 *
 * @param resource/*w  w  w . j  av a 2  s .c  o m*/
 * @return
 */
private Locale getLocaleFromPath(final Resource resource) {
    final String[] segments = StringUtils.split(resource.getPath(), PATH_DELIMITER);

    String country = "";
    String language = "";

    for (final String segment : segments) {
        if (ArrayUtils.contains(Locale.getISOCountries(), segment)) {
            country = segment;
        } else if (ArrayUtils.contains(Locale.getISOLanguages(), segment)) {
            language = segment;
        }
    }

    if (StringUtils.isNotBlank(country) && StringUtils.isNotBlank(language)) {
        return LocaleUtils.toLocale(country + "-" + language);
    } else if (StringUtils.isNotBlank(country)) {
        return LocaleUtils.toLocale(country);
    } else if (StringUtils.isNotBlank(language)) {
        return LocaleUtils.toLocale(language);
    }

    return null;
}

From source file:SecurityGiver.java

public void processDictionary() throws JSONException, IOException {
    //ArrayList<String> keys = new ArrayList<String>();
    //ArrayList<Integer> values = new ArrayList<Integer>();
    HashMap<String, Integer> processedDictionary = new HashMap<String, Integer>();
    ArrayList<String> locales = new ArrayList<String>(Arrays.asList(Locale.getISOCountries()));
    ArrayList<String> queries = new ArrayList<String>(Arrays.asList(d_queryString));

    for (String line : allDescriptions) {
        String[] words = line.split(" ");
        for (String word : words)
            if (!queries.contains(word) && (!locales.contains(word))) {
                if (processedDictionary.get(word) == null)
                    processedDictionary.put(word, 1);
                else
                    processedDictionary.put(word, processedDictionary.get(word) + 1);
            }/*  w w w  .  j  av  a  2s  .com*/

    }
    //JSONObject obj = new JSONObject();
    //for (String s : processedDictionary.keySet()) {
    //    int val = processedDictionary.get(s);
    //if (!d_ignore[0].toLowerCase().contains(s.toLowerCase()) && (val > 5)) obj.put(s, val);

    //}
    FileWriter file = new FileWriter("dataForCloud.json");

    //file.write(obj.toString(3));

    try {
        file.write("{");
        //quick and dirty fix
        int i = processedDictionary.size();
        //JSONObject obj = new JSONObject();
        for (String s : processedDictionary.keySet()) {
            i--;
            Integer val = processedDictionary.get(s);
            if ((val > 1 || i == 1) && (!search.toLowerCase().contains(s.toLowerCase()))) {
                //file.write("{text: \""+s+"\", weight: "+val.toString()+"}");
                file.write("\"" + s + "\"" + ":" + "\"" + val.toString() + "\"");
                if (i > 1)
                    file.write(",\n");
            }
            //"{text: "+s, " weight: "+val.toString()+"}");
        }
        file.write("}");
        System.out.println("Successfully printed");

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        file.flush();
        file.close();
    }

}

From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java

public static Map<String, Locale> getCountries() {
    List<String> countries = Arrays.asList(Locale.getISOCountries());
    HashMap<String, Locale> mapCountries = new HashMap<>();
    countries.parallelStream().forEach((country) -> {
        List<Locale> locales = LocaleUtils.languagesByCountry(country);
        if (!locales.isEmpty()) {
            mapCountries.put(country, new Locale(locales.get(0).getLanguage(), country));
        }/*from  w  ww. j  ava 2  s . co m*/
    });
    return mapCountries;
}

From source file:net.maritimecloud.identityregistry.utils.CertificateUtil.java

/**
 * Generates a signed certificate for an entity.
 * /*from   ww w.  j a  v a 2  s.  co m*/
 * @param country The country of org/entity
 * @param orgName The name of the organization the entity belongs to
 * @param type The type of the  entity
 * @param callName The name of the entity
 * @param email The email of the entity
 * @param publickey The public key of the entity
 * @return Returns a signed X509Certificate
 */
public X509Certificate generateCertForEntity(BigInteger serialNumber, String country, String orgName,
        String type, String callName, String email, String uid, PublicKey publickey,
        Map<String, String> customAttr) {
    PrivateKeyEntry signingCertEntry = getSigningCertEntry();
    java.security.cert.Certificate signingCert = signingCertEntry.getCertificate();
    X509Certificate signingX509Cert = (X509Certificate) signingCert;
    // Try to find the correct country code, else we just use the country name as code
    String orgCountryCode = country;
    String[] locales = Locale.getISOCountries();
    for (String countryCode : locales) {
        Locale loc = new Locale("", countryCode);
        if (loc.getDisplayCountry(Locale.ENGLISH).equals(orgCountryCode)) {
            orgCountryCode = loc.getCountry();
            break;
        }
    }
    String orgSubjectDn = "C=" + orgCountryCode + ", " + "O=" + orgName + ", " + "OU=" + type + ", " + "CN="
            + callName + ", " + "UID=" + uid;
    if (email != null && !email.isEmpty()) {
        orgSubjectDn += ", " + "E=" + email;
    }
    X509Certificate orgCert = null;
    try {
        orgCert = buildAndSignCert(serialNumber, signingCertEntry.getPrivateKey(),
                signingX509Cert.getPublicKey(), publickey,
                new JcaX509CertificateHolder(signingX509Cert).getSubject(), new X500Name(orgSubjectDn),
                customAttr, "ENTITY");
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return orgCert;
}