Example usage for java.util Locale equals

List of usage examples for java.util Locale equals

Introduction

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

Prototype

@Override
public boolean equals(Object obj) 

Source Link

Document

Returns true if this Locale is equal to another object.

Usage

From source file:com.processpuzzle.internalization.domain.ProcessPuzzleLocale.java

private boolean checkIfSupported(String language, String country) {
    Locale subjectLocale = null;/*from www.ja  v  a 2s.  c o m*/
    if (country != null)
        subjectLocale = new Locale(language, country);
    else if (language != null)
        subjectLocale = new Locale(language);
    else
        return false;

    Locale[] availableLocales = Locale.getAvailableLocales();
    for (int i = 0; i < availableLocales.length; i++) {
        Locale availableLocale = availableLocales[i];
        if (availableLocale.equals(subjectLocale))
            return true;
    }
    return false;
}

From source file:org.opencms.search.documents.CmsDocumentDependency.java

/**
 * Creates a dependency object from a String representation.<p>
 *
 * @param input the String representation
 * @param rootPath the root path of the base document of which the dependencies are encoded
 *
 * @return the dependency object created from a String representation
 *//*from ww w.  j ava 2s.c  o m*/
public static CmsDocumentDependency fromDependencyString(String input, String rootPath) {

    CmsDocumentDependency result = new CmsDocumentDependency(null, rootPath);
    if (input != null) {

        try {
            if (input.startsWith("{")) {
                JSONObject jsonDoc = new JSONObject(input);
                result.fromJSON(jsonDoc, rootPath);

                // main document
                if (jsonDoc.has(JSON_MAIN)) {

                    JSONObject jsonMain = jsonDoc.getJSONObject(JSON_MAIN);

                    CmsDocumentDependency main = new CmsDocumentDependency(null, jsonMain.getString(JSON_PATH));
                    main.fromJSON(jsonMain, rootPath);
                    result.setMainDocument(main);
                }
            } else {
                // special handling for news
                String[] docs = CmsStringUtil.splitAsArray(input, '|');
                for (int i = 0; i < docs.length; i++) {
                    String doc = docs[i];

                    String lang = doc.substring(0, 2);
                    Locale loc = new Locale(lang);

                    if (i == 0) {
                        result.setLocale(loc);
                    } else {
                        String rp = doc.substring(3);
                        CmsDocumentDependency dep = new CmsDocumentDependency(null, rp);
                        if (!loc.equals(result.getLocale())) {
                            dep.setLocale(new Locale(lang));
                            result.addVariant(dep);
                        }
                    }
                }
            }
        } catch (Exception ex) {
            if (LOG.isErrorEnabled()) {
                LOG.error(ex.getLocalizedMessage(), ex);
            }
        }
    }
    return result;
}

From source file:com.mfalaize.ant.LocalizeTask.java

/**
 * Get the list of available// w w  w .  jav  a  2s  .  c om
 * <code>ResourceBundle</code> in the project.
 *
 * @return The list of <code>ResourceBundle</code> available in the project
 * to build.
 * @throws BuildException when the <code>ResourceBundle</code> cannot be
 * find.
 */
private List<ResourceBundle> getAvailableResourceBundles() throws BuildException {
    List<ResourceBundle> list = new ArrayList<ResourceBundle>();

    for (Locale locale : Locale.getAvailableLocales()) {
        try {
            ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceBundleBaseName, locale);

            if (locale.equals(resourceBundle.getLocale())) {
                list.add(resourceBundle);
            } else {
                log(String.format("No resource bundle exists for the locale %s. Continue...",
                        locale.getLanguage()), Project.MSG_VERBOSE);
            }
        } catch (Throwable ex) {
            throw new BuildException(ex);
        }
    }

    return list;
}

From source file:org.sonar.core.i18n.DefaultI18n.java

public DefaultI18n(PluginRepository pluginRepository, System2 system2) {
    this.pluginRepository = pluginRepository;
    this.system2 = system2;
    // SONAR-2927
    this.control = new ResourceBundle.Control() {
        @Override//w ww  . ja v a  2 s. com
        public Locale getFallbackLocale(String baseName, Locale locale) {
            Preconditions.checkNotNull(baseName);
            Locale defaultLocale = Locale.ENGLISH;
            return locale.equals(defaultLocale) ? null : defaultLocale;
        }
    };
}

From source file:org.mili.core.resource.ResourceUtilImpl.java

private void loadDevResources(Locale locale, URL url, String realBaseName, String baseName) {
    if ((locale.equals(Locale.GERMAN) || locale.equals(Locale.GERMANY)) && url != null) {
        InputStream is = null;/*w ww.j  av  a 2s.  co  m*/
        try {
            is = FileUtil.getInputStream(url.getPath() + "/" + baseName + "_dev.properties");
            copyPropertiesInResMap(PropUtil.readProperties(is), realBaseName, locale);
        } catch (Exception e) {
            // eat it
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) { // eat it!
                }
            }
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectionDataGetter.java

private Map<String, Object> buildLocaleMap(Locale locale, Locale currentLocale) throws FileNotFoundException {
    Map<String, Object> map = new HashMap<>();
    map.put("code", locale.toString());
    map.put("label", locale.getDisplayName(currentLocale));
    map.put("imageUrl", LocaleSelectorUtilities.getImageUrl(vreq, locale));
    map.put("selected", currentLocale.equals(locale));
    return map;/* w w w . ja  va  2 s .  co  m*/
}

From source file:net.lunikon.rethul.data.FileDAO.java

/**
 * Assembles a {@link FileStatus} object for the given {@link File}.
 * /*w w w . ja v a  2 s  .  co m*/
 * @param file
 *            The file to generate the status for.
 * @return the status file.
 */
public FileStatus loadStatus(File file) {
    FileStatus status = new FileStatus(file);

    if (status.isMasterAvailable()) {
        // add all project languages by default
        List<LanguageStatus> stati = new ArrayList<LanguageStatus>();
        LanguageStatus master = new LanguageStatus(file, null);
        stati.add(master);
        List<ProjectLocale> locales = projectDao.getProjectLocales(file.getProject());
        for (ProjectLocale pl : locales)
            stati.add(new LanguageStatus(file, pl.getLocale()));

        // load counters for the languages
        @SuppressWarnings("unchecked")
        List<Object[]> raw = getSession() //
                .createQuery(
                        "select locale, pending, count(*) from LocalizedString where file = :file group by locale, pending") //
                .setParameter("file", file) //
                .list();

        for (Object[] row : raw) {
            LanguageStatus ls = null;

            Locale locale = (Locale) row[0];
            if (locale == null)
                ls = master;
            else {
                for (int i = 0; i < stati.size(); i++) {
                    if (locale.equals(stati.get(i).getLocale())) {
                        ls = stati.get(i);
                        break;
                    }
                }
                if (ls == null)
                    continue; // not an active language anymore
            }

            boolean pending = (Boolean) row[1];
            int count = ((Number) row[2]).intValue();
            if (pending)
                ls.setPending(count);
            else
                ls.setDone(count);
        }
        status.setLanguages(stati);

        // determine missing entries
        for (LanguageStatus ls : stati) {
            if (ls.getLocale() == null)
                continue;

            int missing = master.getDone() - ls.getPending() - ls.getDone();
            ls.setMissing(missing);
        }

        Collections.sort(stati);
    }

    return status;
}

From source file:Main.java

public String getSymbol(String currencyCode, Locale locale) {
    if (currencyCode == null || locale == null)
        throw new NullPointerException();

    if (currencyCode.length() != 3)
        throw new IllegalArgumentException("currency code length not 3");

    for (int i = 0; i < 3; i++)
        if (!Character.isUpperCase(currencyCode.charAt(i)))
            throw new IllegalArgumentException("bad currency code");

    if (!locale.equals(locales[0]))
        throw new IllegalArgumentException("unsupported locale");

    if (currencyCode.equals("ERN"))
        return "Nfk";
    else/*from  ww w. ja v  a  2s. co  m*/
        return null;
}

From source file:net.sourceforge.subsonic.controller.GeneralSettingsController.java

protected Object formBackingObject(HttpServletRequest request) throws Exception {
    GeneralSettingsCommand command = new GeneralSettingsCommand();
    command.setCoverArtFileTypes(settingsService.getCoverArtFileTypes());
    command.setIgnoredArticles(settingsService.getIgnoredArticles());
    command.setShortcuts(settingsService.getShortcuts());
    command.setIndex(settingsService.getIndexString());
    command.setPlaylistFolder(settingsService.getPlaylistFolder());
    command.setMusicFileTypes(settingsService.getMusicFileTypes());
    command.setVideoFileTypes(settingsService.getVideoFileTypes());
    command.setSortAlbumsByYear(settingsService.isSortAlbumsByYear());
    command.setGettingStartedEnabled(settingsService.isGettingStartedEnabled());
    command.setWelcomeTitle(settingsService.getWelcomeTitle());
    command.setWelcomeSubtitle(settingsService.getWelcomeSubtitle());
    command.setWelcomeMessage(settingsService.getWelcomeMessage());
    command.setLoginMessage(settingsService.getLoginMessage());

    Theme[] themes = settingsService.getAvailableThemes();
    command.setThemes(themes);/*from  ww w.  java2s  .  com*/
    String currentThemeId = settingsService.getThemeId();
    for (int i = 0; i < themes.length; i++) {
        if (currentThemeId.equals(themes[i].getId())) {
            command.setThemeIndex(String.valueOf(i));
            break;
        }
    }

    Locale currentLocale = settingsService.getLocale();
    Locale[] locales = settingsService.getAvailableLocales();
    String[] localeStrings = new String[locales.length];
    for (int i = 0; i < locales.length; i++) {
        localeStrings[i] = locales[i].getDisplayName(locales[i]);

        if (currentLocale.equals(locales[i])) {
            command.setLocaleIndex(String.valueOf(i));
        }
    }
    command.setLocales(localeStrings);

    return command;

}

From source file:com.android.managedprovisioning.DeviceOwnerProvisioningService.java

private void setLocale(Locale locale) {
    if (locale == null || locale.equals(Locale.getDefault())) {
        return;/*from  w  w w  .  j  av a2s .c o  m*/
    }
    try {
        if (DEBUG)
            ProvisionLogger.logd("Setting locale to " + locale);
        // If locale is different from current locale this results in a configuration change,
        // which will trigger the restarting of the activity.
        LocalePicker.updateLocale(locale);
    } catch (Exception e) {
        ProvisionLogger.loge("Failed to set the system locale.");
        // Do not stop provisioning process, but ignore this error.
    }
}