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:org.xwiki.localization.jar.internal.RootClassLoaderTranslationBundle.java

/**
 * @param locale the locale to search for
 * @return the content of all the resources files associated to the provided locale
 */// w w w  .  j  a va  2 s.  c om
private Properties getResourceProperties(Locale locale) {
    String resourceName = "ApplicationResources";
    if (!locale.equals(Locale.ROOT)) {
        resourceName += "_" + locale;
    }
    resourceName += ".properties";

    Enumeration<URL> urls;
    try {
        urls = getClass().getClassLoader().getResources(resourceName);
    } catch (IOException e) {
        this.logger.error("Failed to get resource URLs from class loader for name [{}]", resourceName, e);

        return null;
    }

    if (!urls.hasMoreElements()) {
        return null;
    }

    List<URL> urlList = EnumerationUtils.toList(urls);

    Properties properties = new Properties();

    // Load resources in reverse order to give priority to first found resources (follow ClassLoader#getResource
    // behavior)
    for (ListIterator<URL> it = urlList.listIterator(urlList.size()); it.hasPrevious();) {
        URL url = it.previous();

        try {
            InputStream componentListStream = url.openStream();

            try {
                properties.load(componentListStream);
            } finally {
                componentListStream.close();
            }
        } catch (IOException e) {
            this.logger.error("Failed to parse resource [{}] as translation budle", url, e);
        }
    }

    return properties;
}

From source file:com.haulmont.cuba.desktop.LoginDialog.java

protected Locale resolveLocale() {
    Locale appLocale;// w  w w . j a  v a2 s  .c o  m
    String lastLocale = this.loginProperties.loadLastLocale();
    if (StringUtils.isNotEmpty(lastLocale)) {
        appLocale = LocaleUtils.toLocale(lastLocale);
    } else {
        appLocale = Locale.getDefault();
    }

    for (Locale locale : locales.values()) {
        if (locale.equals(appLocale)) {
            return locale;
        }
    }

    // if not found and application locale contains country, try to match by language only
    if (StringUtils.isNotEmpty(appLocale.getCountry())) {
        Locale languageTagLocale = Locale.forLanguageTag(appLocale.getLanguage());
        for (Locale locale : locales.values()) {
            if (Locale.forLanguageTag(locale.getLanguage()).equals(languageTagLocale)) {
                return locale;
            }
        }
    }

    // return first locale set in the cuba.availableLocales app property
    return locales.values().iterator().next();
}

From source file:de.xaniox.heavyspleef.core.i18n.YMLControl.java

@Override
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
    List<Locale> candidates = Lists.newArrayList();
    candidates.add(locale);//from w ww.j a va2 s.c  o m

    if (!locale.equals(Locale.US)) {
        candidates.add(Locale.US);
    }

    return candidates;
}

From source file:org.mozilla.focus.locale.LocaleAwareFragment.java

@Override
public void onResume() {
    super.onResume();

    if (cachedLocale == null) {
        cachedLocale = Locale.getDefault();
    } else {//  w w w  .j a v  a  2  s . c om
        Locale newLocale = LocaleManager.getInstance().getCurrentLocale(getActivity().getApplicationContext());

        if (newLocale == null) {
            // Using system locale:
            newLocale = Locale.getDefault();
        }
        if (!newLocale.equals(cachedLocale)) {
            cachedLocale = newLocale;
            applyLocale();
        }
    }
}

From source file:cn.vlabs.duckling.vwb.ui.servlet.AbstractLoginServlet.java

private void redirectToUmt(HttpServletRequest request, HttpServletResponse response, String viewUrl)
        throws IOException, ServletException {
    Oauth oauth = new Oauth(properties);
    int siteId = getVwbcontext(request).getSiteId();
    VWBContainer container = VWBContainerImpl.findContainer();
    Locale locale = request.getLocale();
    String language = locale.getLanguage() + "_" + locale.getCountry();
    if (!locale.equals(Locale.CHINA)) {
        language = Locale.US.getLanguage() + "_" + Locale.US.getCountry();
    }/*from  ww  w.  j  av  a 2s .  co m*/
    if (StringUtils.isEmpty(language)) {
        language = container.getSiteConfig().getProperty(siteId, KeyConstants.SITE_LANGUAGE);
    }

    try {
        String redirectUrl = oauth.getAuthorizeURL(request) + "&state=" + URLEncoder.encode(viewUrl, "UTF-8")
                + "&locale=" + language;
        response.sendRedirect(redirectUrl);
    } catch (UMTOauthConnectException e) {
        throw new ServletException(e);
    }
}

From source file:it.simoneloru.ctmdroid.activities.TimetableActivity.java

private String callCtmSite() throws Exception {
    HttpResponse execute = null;/*  ww w .  java2 s . com*/
    HttpClient defaultHttpClient = new DefaultHttpClient();
    HttpPost request = new HttpPost();
    request.setURI(new URI(URI));
    request.addHeader("Referer", URI);

    Cursor codeCursor = ctmDb.getRoad(
            Long.toString(getIntent().getLongExtra(getPackageName() + ".busStopCodeId", -1)),
            new String[] { CTMDroidDatabase.KEY_CODE });
    String code = codeCursor.getString(0);
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("mode", "1"));
    nameValuePairs.add(new BasicNameValuePair("stopcode", "-1"));
    nameValuePairs.add(new BasicNameValuePair("stopdescr", code));
    nameValuePairs.add(new BasicNameValuePair("linenames", "-1"));
    nameValuePairs.add(new BasicNameValuePair("ptsearch", "Ricerca"));
    Calendar now = Calendar.getInstance();
    nameValuePairs.add(new BasicNameValuePair("pt_day", Integer.toString(now.get(Calendar.DAY_OF_MONTH))));
    nameValuePairs.add(new BasicNameValuePair("pt_month", Integer.toString(now.get(Calendar.MONTH) + 1)));
    nameValuePairs.add(new BasicNameValuePair("pt_year", Integer.toString(now.get(Calendar.YEAR))));

    nameValuePairs.add(new BasicNameValuePair("PT_HH_FROM", Integer.toString(now.get(Calendar.HOUR_OF_DAY))));
    Calendar later = new GregorianCalendar();
    later.setTime(now.getTime());
    later.add(Calendar.HOUR_OF_DAY, 1);
    nameValuePairs.add(new BasicNameValuePair("PT_HH_TO", Integer.toString(later.get(Calendar.HOUR_OF_DAY))));
    nameValuePairs.add(new BasicNameValuePair("PT_MM_FROM", Integer.toString(now.get(Calendar.MINUTE))));
    nameValuePairs.add(new BasicNameValuePair("PT_MM_TO", Integer.toString(later.get(Calendar.MINUTE))));
    UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(nameValuePairs);
    request.setEntity(urlEncodedFormEntity);
    execute = defaultHttpClient.execute(request);
    resultWebView = (WebView) findViewById(R.id.webview);
    BasicResponseHandler basicResponseHandler = new BasicResponseHandler();
    String handleResponse = basicResponseHandler.handleResponse(execute);
    if (handleResponse.contains("Dati non disponibili")) {
        return NODATA;
    } else {
        String body = handleResponse.substring(handleResponse.indexOf("<body"),
                handleResponse.lastIndexOf("</body>"));
        String homehtm = CTMDroidUtil.LoadFile("home.htm", getResources());
        Locale locale = this.getResources().getConfiguration().locale;
        if (!locale.equals(Locale.ITALY)) {
            body = CTMDroidUtil.bodyInEnglish(body);
        }
        homehtm = homehtm.replace("$placeholder$", body);
        Log.i("CTM", homehtm);
        resultWebView.loadDataWithBaseURL("file:///android-asset/", homehtm, "text/html", "utf-8", null);
        resultWebView.setTag(homehtm);
        return null;
    }
}

From source file:com.github.peholmst.springsecuritydemo.ui.SpringSecurityDemoApp.java

@Override
public String getLocaleDisplayName(Locale locale) {
    for (int i = 0; i < SUPPORTED_LOCALES.length; i++) {
        if (locale.equals(SUPPORTED_LOCALES[i])) {
            return LOCALE_NAMES[i];
        }//from ww w  . j a  v a2  s .  c  o  m
    }
    return "Unsupported Locale";
}

From source file:org.mypsycho.text.EnumMessage.java

@Override
public void setLocale(Locale locale) {
    if (locale.equals(getLocale())) {
        return; // uselesss
    }//from   w  ww. jav  a  2s  .co  m
    applyPattern(getPattern(id, locale));
    mapArgs();
    super.setLocale(locale);
}

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

public boolean equals(ProcessPuzzleLocale other) {
    Locale javaLocale = getJavaLocale();
    return javaLocale.equals(other.getJavaLocale());
}

From source file:de.kaiserpfalzEdv.commons.HandleI18NImpl.java

@Override
public void setLocale(@NotNull final Locale locale) {
    checkArgument(locale != null, "locale must be not null");

    //noinspection ConstantConditions
    if (!locale.equals(this.locale)) {
        LOG.trace("Setting locale to '{}'.", locale.getDisplayName());

        this.locale = locale;

        resetMessageBundle();/*from w  w w.  java 2  s .  c o m*/
    }
}