Example usage for java.util Locale getAvailableLocales

List of usage examples for java.util Locale getAvailableLocales

Introduction

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

Prototype

public static Locale[] getAvailableLocales() 

Source Link

Document

Returns an array of all installed locales.

Usage

From source file:org.obiba.mica.search.csvexport.SpecificStudyReportGenerator.java

private Map<String, Locale> getCountries() {
    return Arrays.stream(Locale.getAvailableLocales()).collect(Collectors.toMap(locale -> {
        try {//from w  w  w . j a  v  a2  s.  co  m
            return locale.getISO3Country();
        } catch (RuntimeException e) {
            return locale.getCountry();
        }
    }, Function.identity(), (a, b) -> a));
}

From source file:richtercloud.document.scanner.gui.OCRPanel.java

/**
 * Creates new form OCRResultPanel/*from   w w  w . j  av  a2s.c  o  m*/
 * @param reflectionFormPanelMap A map with references to the
 * {@link ReflectionFormPanel} for each entity class which is manipulated by
 * the context menu items
 */
public OCRPanel(Set<Class<?>> entityClasses, Map<Class<?>, ReflectionFormPanel<?>> reflectionFormPanelMap,
        Map<Class<? extends JComponent>, ValueSetter<?, ?>> valueSetterMapping, EntityManager entityManager,
        MessageHandler messageHandler, ReflectionFormBuilder reflectionFormBuilder,
        DocumentScannerConf documentScannerConf) {
    this.initComponents();
    if (messageHandler == null) {
        throw new IllegalArgumentException("messageHandler mustn't be null");
    }
    this.messageHandler = messageHandler;
    if (documentScannerConf == null) {
        throw new IllegalArgumentException("documentScannerConf mustn't be " + "null");
    }
    this.documentScannerConf = documentScannerConf;
    List<Class<?>> entityClassesSort = EntityPanel.sortEntityClasses(entityClasses);
    for (Class<?> entityClass : entityClassesSort) {
        ReflectionFormPanel<?> reflectionFormPanel = reflectionFormPanelMap.get(entityClass);
        if (reflectionFormPanel == null) {
            throw new IllegalArgumentException(
                    String.format("entityClass %s has no %s mapped in reflectionFormPanelMap", entityClass,
                            ReflectionFormPanel.class));
        }
        String className;
        ClassInfo classInfo = entityClass.getAnnotation(ClassInfo.class);
        if (classInfo != null) {
            className = classInfo.name();
        } else {
            className = entityClass.getSimpleName();
        }
        JMenu entityClassMenu = new JMenu(className);
        List<Field> relevantFields = reflectionFormBuilder.getFieldRetriever()
                .retrieveRelevantFields(entityClass);
        for (Field relevantField : relevantFields) {
            String fieldName;
            FieldInfo fieldInfo = relevantField.getAnnotation(FieldInfo.class);
            if (fieldInfo != null) {
                fieldName = fieldInfo.name();
            } else {
                fieldName = relevantField.getName();
            }
            JMenuItem relevantFieldMenuItem = new JMenuItem(fieldName);
            relevantFieldMenuItem.addActionListener(
                    new FieldActionListener(reflectionFormPanel, relevantField, valueSetterMapping));
            entityClassMenu.add(relevantFieldMenuItem);
        }
        this.oCRResultPopupPasteIntoMenu.add(entityClassMenu);
    }
    Map<String, Pair<NumberFormat, Set<Locale>>> numberFormats = new HashMap<>();
    Map<String, Pair<NumberFormat, Set<Locale>>> percentFormats = new HashMap<>();
    Map<String, Pair<NumberFormat, Set<Locale>>> currencyFormats = new HashMap<>();
    Iterator<Locale> localeIterator = new ArrayList<>(Arrays.asList(Locale.getAvailableLocales())).iterator();
    Locale firstLocale = localeIterator.next();
    String numberString = NumberFormat.getNumberInstance(firstLocale).format(FORMAT_VALUE);
    String percentString = NumberFormat.getPercentInstance(firstLocale).format(FORMAT_VALUE);
    String currencyString = NumberFormat.getCurrencyInstance(firstLocale).format(FORMAT_VALUE);
    numberFormats.put(numberString, new ImmutablePair<NumberFormat, Set<Locale>>(
            NumberFormat.getNumberInstance(firstLocale), new HashSet<>(Arrays.asList(firstLocale))));
    percentFormats.put(percentString, new ImmutablePair<NumberFormat, Set<Locale>>(
            NumberFormat.getPercentInstance(firstLocale), new HashSet<>(Arrays.asList(firstLocale))));
    currencyFormats.put(currencyString, new ImmutablePair<NumberFormat, Set<Locale>>(
            NumberFormat.getCurrencyInstance(firstLocale), new HashSet<>(Arrays.asList(firstLocale))));
    while (localeIterator.hasNext()) {
        Locale locale = localeIterator.next();
        numberString = NumberFormat.getNumberInstance(locale).format(FORMAT_VALUE);
        percentString = NumberFormat.getPercentInstance(locale).format(FORMAT_VALUE);
        currencyString = NumberFormat.getCurrencyInstance(locale).format(FORMAT_VALUE);
        Pair<NumberFormat, Set<Locale>> numberFormatsPair = numberFormats.get(numberString);
        if (numberFormatsPair == null) {
            numberFormatsPair = new ImmutablePair<NumberFormat, Set<Locale>>(
                    NumberFormat.getNumberInstance(locale), new HashSet<Locale>());
            numberFormats.put(numberString, numberFormatsPair);
        }
        Set<Locale> numberFormatsLocales = numberFormatsPair.getValue();
        numberFormatsLocales.add(locale);
        Pair<NumberFormat, Set<Locale>> percentFormatsPair = percentFormats.get(percentString);
        if (percentFormatsPair == null) {
            percentFormatsPair = new ImmutablePair<NumberFormat, Set<Locale>>(
                    NumberFormat.getPercentInstance(locale), new HashSet<Locale>());
            percentFormats.put(percentString, percentFormatsPair);
        }
        Set<Locale> percentFormatsLocales = percentFormatsPair.getValue();
        percentFormatsLocales.add(locale);
        Pair<NumberFormat, Set<Locale>> currencyFormatsPair = currencyFormats.get(currencyString);
        if (currencyFormatsPair == null) {
            currencyFormatsPair = new ImmutablePair<NumberFormat, Set<Locale>>(
                    NumberFormat.getCurrencyInstance(locale), new HashSet<Locale>());
            currencyFormats.put(currencyString, currencyFormatsPair);
        }
        Set<Locale> currencyFormatsLocales = currencyFormatsPair.getValue();
        currencyFormatsLocales.add(locale);
    }
    for (Map.Entry<String, Pair<NumberFormat, Set<Locale>>> numberFormat : numberFormats.entrySet()) {
        JRadioButtonMenuItem menuItem = new NumberFormatMenuItem(numberFormat.getValue().getKey());
        numberFormatPopup.add(menuItem);
        numberFormatPopupButtonGroup.add(menuItem);
        if (numberFormat.getValue().getValue().contains(this.documentScannerConf.getLocale())) {
            menuItem.setSelected(true);
        }
    }
    for (Map.Entry<String, Pair<NumberFormat, Set<Locale>>> percentFormat : percentFormats.entrySet()) {
        JRadioButtonMenuItem menuItem = new NumberFormatMenuItem(percentFormat.getValue().getKey());
        percentFormatPopup.add(menuItem);
        percentFormatPopupButtonGroup.add(menuItem);
        if (percentFormat.getValue().getValue().contains(this.documentScannerConf.getLocale())) {
            menuItem.setSelected(true);
        }
    }
    for (Map.Entry<String, Pair<NumberFormat, Set<Locale>>> currencyFormat : currencyFormats.entrySet()) {
        JRadioButtonMenuItem menuItem = new NumberFormatMenuItem(currencyFormat.getValue().getKey());
        currencyFormatPopup.add(menuItem);
        currencyFormatPopupButtonGroup.add(menuItem);
        if (currencyFormat.getValue().getValue().contains(this.documentScannerConf.getLocale())) {
            menuItem.setSelected(true);
        }
    }
}

From source file:it.cnr.icar.eric.client.ui.thin.UserPreferencesBean.java

/** Returns a Collection of all locales as SelectItems. */
public Collection<SelectItem> getAllLocalesSelectItems() {
    if (allLocalesSelectItems == null) {
        TreeMap<String, SelectItem> selectItemsMap = new TreeMap<String, SelectItem>();
        Locale loc[] = Locale.getAvailableLocales();
        for (int i = 0; i < loc.length; i++) {
            String name = loc[i].getDisplayName(loc[i]);
            SelectItem item = new SelectItem(loc[i].toString(), name);
            selectItemsMap.put(name.toLowerCase(), item);
        }/*from   ww w.  j  a  va2s . c o  m*/
        Collection<SelectItem> all = new ArrayList<SelectItem>();
        all.addAll(selectItemsMap.values());
        allLocalesSelectItems = all;
    }
    return allLocalesSelectItems;
}

From source file:org.pentaho.platform.plugin.services.importer.LocaleImportHandler.java

/**
 * returns default of the name of the locale e.g. JA, FR, EN, ... or DEFAULT for root
 *
 * @param localeBundle/*from ww w  . j av a 2  s .c  o m*/
 * @return
 */
private String extractLocaleCode(RepositoryFileImportBundle localeBundle) {
    String localeCode = "default";
    String localeFileName = localeBundle.getName();
    if (localeBundle.getFile() != null) {
        localeFileName = localeBundle.getFile().getName();
    }
    for (Locale locale : Locale.getAvailableLocales()) {
        if (localeFileName.endsWith("_" + locale + LOCALE_EXT)
                || localeFileName.endsWith("_" + locale + OLD_LOCALE_EXT)) {
            localeCode = locale.toString();
            break;
        }
    }
    return localeCode;
}

From source file:org.webguitoolkit.ui.controls.util.TextService.java

public void loadLocalesInt(ISelect lcSelect) {
    Locale[] locs = Locale.getAvailableLocales();
    Map<String, String> loclist = new TreeMap<String, String>();

    for (int i = 0; i < locs.length; i++) {
        Locale l = locs[i];//w  w w .j av a2s .  c o  m
        String displayName = l.getDisplayName(getLocale());
        if (StringUtils.isNotBlank(displayName) && !loclist.containsValue(displayName)) {
            loclist.put(l.toString(), displayName);
        }
    }
    lcSelect.setModel(new SelectKVModel().loadList(loclist));
    lcSelect.loadList();
    lcSelect.setValue(getLocale().toString());
}

From source file:de.jfachwert.rechnung.Rechnungsmonat.java

private static LocalDate guessLocalDate(String monat, DateTimeParseException ex) {
    String[] datePatterns = { "d-MMM-yyyy", "d-MM-yyyy", "yyyy-MMM-d", "yyyy-MM-d", "MMM-d-yyyy" };
    for (String pattern : datePatterns) {
        for (Locale locale : Locale.getAvailableLocales()) {
            try {
                return LocalDate.parse(monat, DateTimeFormatter.ofPattern(pattern, locale));
            } catch (DateTimeParseException ignored) {
                ex.addSuppressed(new IllegalArgumentException(
                        ignored.getMessage() + " / '" + monat + "' does not match '" + pattern + "'"));
            }//from  w  w w .j  av a 2  s.  c om
        }
    }
    throw new InvalidValueException(monat, MONTH, ex);
}

From source file:org.webguitoolkit.ui.controls.util.TextService.java

public void setLocaleInt(String strLocale) {
    Locale[] locs = Locale.getAvailableLocales();
    for (int i = 0; i < locs.length; i++) {
        if (locs[i].toString().equals(strLocale)) {
            setLocale(locs[i]);//from  w  w  w . j  ava  2  s.  c  o m
            return;
        }
    }
}

From source file:org.solenopsis.checkstyle.checks.TranslationCheck.java

/**
 * Checks whether user specified language code is correct (is contained in available locales).
 * @param userSpecifiedLanguageCode user specified language code.
 * @return true if user specified language code is correct.
 *//*w ww . j av  a  2  s  .c o m*/
private static boolean isValidLanguageCode(final String userSpecifiedLanguageCode) {
    boolean valid = false;
    final Locale[] locales = Locale.getAvailableLocales();
    for (Locale locale : locales) {
        if (userSpecifiedLanguageCode.equals(locale.toString())) {
            valid = true;
            break;
        }
    }
    return valid;
}

From source file:de.undercouch.citeproc.bibtex.DateParser.java

/**
 * Parses the given month string/*from w w  w  . j  av a  2  s.  c  o m*/
 * @param month the month to parse. May be a number (<code>1-12</code>),
 * a short month name (<code>Jan</code> to <code>Dec</code>), or a
 * long month name (<code>January</code> to </code>December</code>). This
 * method is also able to recognize month names in several locales.
 * @return the month's number (<code>1-12</code>) or <code>-1</code> if
 * the string could not be parsed
 */
public static int toMonth(String month) {
    int m = -1;
    if (month != null && !month.isEmpty()) {
        if (StringUtils.isNumeric(month)) {
            m = Integer.parseInt(month);
        } else {
            m = tryParseMonth(month, Locale.ENGLISH);
            if (m <= 0) {
                m = tryParseMonth(month, Locale.getDefault());
                if (m <= 0) {
                    for (Locale l : Locale.getAvailableLocales()) {
                        m = tryParseMonth(month, l);
                        if (m > 0) {
                            break;
                        }
                    }
                }
            }
        }
    }
    return m;
}

From source file:org.tolven.restful.AccountResourcesV0.java

/**
 * Create a new Tolven account//from   w w  w  . j  av  a  2s .  co  m
 * Parameters include attributes of account object.
 * Parameters can also include account properties.
 * The initialUser must be specified. This user will have the account adminitrator permission
 * and will be the user capable of "inviting" other users to the account.
 * The response status code will be "created" if the account was created.
 * The location url will contain the account id.
 */
@Path("create")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Deprecated
public Response createAccount(@FormParam("accountType") String accountTypeName,
        @FormParam("initialUser") String initialUserString, @FormParam("title") String title,
        @FormParam("timezone") String timezone, @FormParam("locale") String localeName,
        @DefaultValue("html") @FormParam("emailFormat") String emailFormat,
        @DefaultValue("true") @FormParam("enableBackButton") String enableBackButton,
        @DefaultValue("false") @FormParam("disableAutoRefresh") String disableAutoRefresh,
        @DefaultValue("false") @FormParam("manualMetadataUpdate") String manualMetadataUpdate,
        @FormParam("property") String property, @Context SecurityContext sc,
        MultivaluedMap<String, String> formParams) {
    AccountType accountType = accountBean.findAccountTypebyKnownType(accountTypeName);
    if (accountType == null) {
        return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN)
                .entity("Account Type not provided").build();
    }
    if (!accountType.isCreatable()) {
        return Response.status(Status.FORBIDDEN).type(MediaType.TEXT_PLAIN)
                .entity("Account Type is not creatable").build();
    }
    if (initialUserString == null) {
        return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("Missing Initial User")
                .build();
    }
    TolvenUser initialUser = activationBean.findUser(initialUserString);
    if (initialUser == null) {
        return Response.status(Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("Invalid Initial User")
                .build();
    }
    Account account = null;
    try {
        account = accountBean.createAccount2(title, timezone, accountType);
    } catch (Exception e) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.TEXT_PLAIN)
                .entity(ExceptionFormatter.toSimpleString(e, "\\n")).build();
    }
    account.setAccountType(accountType);
    account.setEmailFormat(emailFormat);
    if (localeName != null) {
        Locale[] availableLocales = Locale.getAvailableLocales();
        Locale foundLocale = null;
        for (Locale locale : availableLocales) {
            if (localeName.equalsIgnoreCase(locale.getDisplayName())) {
                foundLocale = locale;
                break;
            }
        }
        account.setLocale(foundLocale.getDisplayName());
    }
    account.setEnableBackButton(enableBackButton.equalsIgnoreCase("true"));
    account.setDisableAutoRefresh(disableAutoRefresh.equalsIgnoreCase("true"));
    account.setManualMetadataUpdate(manualMetadataUpdate.equalsIgnoreCase("true"));
    // Add the initial user to the account
    TolvenSessionWrapper sessionWrapper = TolvenSessionWrapperFactory.getInstance();
    PublicKey userPublicKey = sessionWrapper.getUserPublicKey();
    accountBean.addAccountUser(account, initialUser, new Date(), true, userPublicKey);
    menuBean.updateMenuStructure(account);
    URI uri = null;
    try {
        uri = new URI(URLEncoder.encode(Long.toString(account.getId()), "UTF-8"));
    } catch (Exception e) {
        return Response.status(Status.INTERNAL_SERVER_ERROR).type(MediaType.TEXT_PLAIN)
                .entity(ExceptionFormatter.toSimpleString(e, "\\n")).build();
    }
    return Response.created(uri).type(MediaType.TEXT_PLAIN).entity(String.valueOf(account.getId())).build();
}