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:info.magnolia.cms.i18n.AbstractI18nContentSupport.java

/**
 * Returns the closest locale for which {@link #isLocaleSupported(Locale)} is true.
 * <ul>//from w ww  .ja  v a2  s .  c  o  m
 * <li>If the locale has a country specified (fr_CH) the locale without country (fr) will be returned.</li>
 * <li>If the locale has no country specified (fr) the first locale with the same language but specific country (fr_CH) will be returned.</li>
 * <li>If this fails the fall-back locale is returned</li>
 * </ul>
 * Warning: if you have configured both (fr and fr_CH) this method will jiter between this two values.
 */
protected Locale getNextLocale(Locale locale) {
    // if this locale defines a country
    if (StringUtils.isNotEmpty(locale.getCountry())) {
        // try to use the language only
        Locale langOnlyLocale = new Locale(locale.getLanguage());
        if (isLocaleSupported(langOnlyLocale)) {
            return langOnlyLocale;
        }
    }
    // try to find a locale with the same language (ignore the country)
    for (Iterator<Locale> iter = getLocales().iterator(); iter.hasNext();) {
        Locale otherCountryLocale = iter.next();
        // same lang, but not the same country as well or we end up in the loop
        if (locale.getLanguage().equals(otherCountryLocale.getLanguage())
                && !locale.equals(otherCountryLocale)) {
            return otherCountryLocale;
        }
    }
    return getFallbackLocale();
}

From source file:com.flexive.faces.beans.MessageBean.java

/**
 * Returns the resource translation in the given locale.
 *
 * @param key       resource key/*w w  w. jav  a  2s. c  o m*/
 * @param locale    the requested locale
 * @return the resource translation
 * @since 3.2.0
 */
public String getResource(String key, Locale locale) {
    if (!initialized) {
        initialize();
    }
    final FxSharedUtils.MessageKey messageKey = new FxSharedUtils.MessageKey(locale, key);
    String cachedMessage = cachedMessages.get(messageKey);
    if (cachedMessage != null) {
        return cachedMessage;
    }
    for (FxSharedUtils.BundleReference bundleReference : resourceBundles) {
        try {
            final ResourceBundle bundle = getResources(bundleReference, locale);
            String message = bundle.getString(key);
            cachedMessage = cachedMessages.putIfAbsent(messageKey, message);
            return cachedMessage != null ? cachedMessage : message;
        } catch (MissingResourceException e) {
            // continue with next bundle
        }
    }
    if (!locale.equals(Locale.ENGLISH)) {
        //try to find the locale in english as last resort
        //this is a fix for using PropertyResourceBundles which can only handle one locale (have to use them thanks to JBoss 5...)
        for (FxSharedUtils.BundleReference bundleReference : resourceBundles) {
            try {
                final ResourceBundle bundle = getResources(bundleReference, Locale.ENGLISH);
                String message = bundle.getString(key);
                cachedMessage = cachedMessages.putIfAbsent(messageKey, message);
                return cachedMessage != null ? cachedMessage : message;
            } catch (MissingResourceException e) {
                // continue with next bundle
            }
        }
    }
    throw new MissingResourceException("Resource not found", "MessageBean", key);
}

From source file:com.customdatepicker.date.MonthView.java

/**
 * Return a 1 or 2 letter String for use as a weekday label
 *
 * @param day The day for which to generate a label
 * @return The weekday label/*www.  j a va2  s.  co m*/
 */
private String getWeekDayLabel(Calendar day) {
    Locale locale = Locale.getDefault();

    // Localised short version of the string is not available on API < 18
    if (Build.VERSION.SDK_INT < 18) {
        String dayName = new SimpleDateFormat("E", locale).format(day.getTime());
        String dayLabel = dayName.toUpperCase(locale).substring(0, 1);

        // Chinese labels should be fetched right to left
        if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE)
                || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) {
            int len = dayName.length();
            dayLabel = dayName.substring(len - 1, len);
        }

        // Most hebrew labels should select the second to last character
        if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) {
            if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
                int len = dayName.length();
                dayLabel = dayName.substring(len - 2, len - 1);
            } else {
                // I know this is duplication, but it makes the code easier to grok by
                // having all hebrew code in the same block
                dayLabel = dayName.toUpperCase(locale).substring(0, 1);
            }
        }

        // Catalan labels should be two digits in lowercase
        if (locale.getLanguage().equals("ca"))
            dayLabel = dayName.toLowerCase().substring(0, 2);

        // Correct single character label in Spanish is X
        if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)
            dayLabel = "X";

        return dayLabel;
    }
    // Getting the short label is a one liner on API >= 18
    if (weekDayLabelFormatter == null) {
        weekDayLabelFormatter = new SimpleDateFormat("EEEEE", locale);
    }
    return weekDayLabelFormatter.format(day.getTime());
}

From source file:jp.terasoluna.fw.message.DataSourceMessageSource.java

/**
 * ???? ??/*from ww w .ja v  a2s . c  o m*/
 * ????????
 * locale??????
 * locale??????
 * ???????
 * ?????
 * ????
 * 
 * @param locale
 *            
 * 
 * @return ???
 */
protected List<Locale> getAlternativeLocales(Locale locale) {
    List<Locale> locales = new ArrayList<Locale>();
    // ?????
    if (locale.getVariant().length() > 0) {
        // Locale(language,country,"")
        locales.add(new Locale(locale.getLanguage(), locale.getCountry()));
    }
    // ????
    if (locale.getCountry().length() > 0) {
        // Locale(language,"","")
        locales.add(new Locale(locale.getLanguage()));
    }
    // ?????
    if (defaultLocale != null && !locale.equals(defaultLocale)) {
        if (defaultLocale.getVariant().length() > 0) {
            // Locale(language,country,"")
            locales.add(defaultLocale);
        }
        if (defaultLocale.getCountry().length() > 0) {
            // Locale(language,country,"")
            locales.add(new Locale(defaultLocale.getLanguage(), defaultLocale.getCountry()));
        }
        // ????
        if (defaultLocale.getLanguage().length() > 0) {
            // Locale(language,"","")
            locales.add(new Locale(defaultLocale.getLanguage()));
        }
    }
    return locales;
}

From source file:com.borax12.materialdaterangepicker.date.MonthView.java

protected void drawMonthDayLabels(Canvas canvas) {
    int y = getMonthHeaderSize() - (MONTH_DAY_LABEL_TEXT_SIZE / 2);
    int dayWidthHalf = (mWidth - mEdgePadding * 2) / (mNumDays * 2);

    for (int i = 0; i < mNumDays; i++) {
        int x = (2 * i + 1) * dayWidthHalf + mEdgePadding;

        int calendarDay = (i + mWeekStart) % mNumDays;
        mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay);
        Locale locale = Locale.getDefault();
        String localWeekDisplayName = mDayLabelCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT,
                locale);//from w  ww.j a v  a2  s.com
        String weekString = localWeekDisplayName.toUpperCase(locale).substring(0, 1);

        if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE)
                || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) {
            int len = localWeekDisplayName.length();
            weekString = localWeekDisplayName.substring(len - 1, len);
        }

        if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) {
            if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
                int len = localWeekDisplayName.length();
                weekString = localWeekDisplayName.substring(len - 2, len - 1);
            } else {
                // I know this is duplication, but it makes the code easier to grok by
                // having all hebrew code in the same block
                weekString = localWeekDisplayName.toUpperCase(locale).substring(0, 1);
            }
        }
        canvas.drawText(weekString, x, y, mMonthDayLabelPaint);
    }
}

From source file:edu.ku.brc.specify.prefs.SystemPrefs.java

/**
 * Constructor.//  w  w w  .ja  v a  2 s .  c om
 */
public SystemPrefs() {
    createForm("Preferences", "System");

    JButton clearCache = form.getCompById("clearcache");

    clearCache.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            clearCache();
        }
    });

    ValBrowseBtnPanel browse = form.getCompById("7");
    if (browse != null) {
        oldSplashPath = localPrefs.get(SPECIFY_BG_IMG_PATH, null);
        browse.setValue(oldSplashPath, null);
    }

    final ValComboBox localeCBX = form.getCompById("5");
    localeCBX.getComboBox().setRenderer(new LocaleRenderer());
    localeCBX.setEnabled(false);

    SwingWorker workerThread = new SwingWorker() {
        protected int inx = -1;

        @Override
        public Object construct() {

            Vector<Locale> locales = new Vector<Locale>();
            Collections.addAll(locales, Locale.getAvailableLocales());
            Collections.sort(locales, new Comparator<Locale>() {
                public int compare(Locale o1, Locale o2) {
                    return o1.getDisplayName().compareTo(o2.getDisplayName());
                }
            });

            int i = 0;
            String language = AppPreferences.getLocalPrefs().get("locale.lang",
                    Locale.getDefault().getLanguage());
            String country = AppPreferences.getLocalPrefs().get("locale.country",
                    Locale.getDefault().getCountry());
            String variant = AppPreferences.getLocalPrefs().get("locale.var", Locale.getDefault().getVariant());

            Locale prefLocale = new Locale(language, country, variant);

            int justLangIndex = -1;
            Locale cachedLocale = Locale.getDefault();
            for (Locale l : locales) {
                try {
                    Locale.setDefault(l);
                    ResourceBundle rb = ResourceBundle.getBundle("resources", l);

                    boolean isOK = (l.getLanguage().equals("en") && StringUtils.isEmpty(l.getCountry()))
                            || (l.getLanguage().equals("pt") && l.getCountry().equals("PT"));

                    if (isOK && rb.getKeys().hasMoreElements()) {
                        if (l.getLanguage().equals(prefLocale.getLanguage())) {
                            justLangIndex = i;
                        }
                        if (l.equals(prefLocale)) {
                            inx = i;
                        }
                        localeCBX.getComboBox().addItem(l);
                        i++;
                    }

                } catch (MissingResourceException ex) {
                }
            }

            if (inx == -1 && justLangIndex > -1) {
                inx = justLangIndex;
            }
            Locale.setDefault(cachedLocale);

            return null;
        }

        @Override
        public void finished() {
            UIValidator.setIgnoreAllValidation("SystemPrefs", true);
            localeCBX.setEnabled(true);
            localeCBX.getComboBox().setSelectedIndex(inx);
            JTextField loadingLabel = form.getCompById("6");
            if (loadingLabel != null) {
                loadingLabel.setText(UIRegistry.getResourceString("LOCALE_RESTART_REQUIRED"));
            }
            UIValidator.setIgnoreAllValidation("SystemPrefs", false);
        }
    };

    // start the background task
    workerThread.start();

    ValCheckBox chk = form.getCompById("2");
    chk.setValue(localPrefs.getBoolean(VERSION_CHECK, true), "true");

    chk = form.getCompById("3");
    chk.setValue(remotePrefs.getBoolean(SEND_STATS, true), "true");

    chk = form.getCompById("9");
    chk.setValue(remotePrefs.getBoolean(SEND_ISA_STATS, true), "true");
    chk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class);
            if (collection != null) {
                String isaNumber = collection.getIsaNumber();
                if (StringUtils.isNotEmpty(isaNumber) && !((JCheckBox) e.getSource()).isSelected()) {
                    UIRegistry.showLocalizedMsg("ISA_STATS_WARNING");
                }
            }
        }
    });

    // Not sure why the form isn't picking up the pref automatically
    /* remove if worldwind is broken*/ValCheckBox useWWChk = form.getCompById(USE_WORLDWIND);
    /* remove if worldwind is broken*/ValCheckBox hasOGLChk = form.getCompById(SYSTEM_HasOpenGL);

    /* remove if worldwind is broken*/useWWChk.setValue(localPrefs.getBoolean(USE_WORLDWIND, false), null);
    /* remove if worldwind is broken*/hasOGLChk.setValue(localPrefs.getBoolean(SYSTEM_HasOpenGL, false), null);
    /* remove if worldwind is broken*/hasOGLChk.setEnabled(false);

    //ValCheckBox askCollChk = form.getCompById(ALWAYS_ASK_COLL);
    //askCollChk.setValue(localPrefs.getBoolean(ALWAYS_ASK_COLL, false), null);
}

From source file:com.aurel.track.admin.customize.category.filter.execute.SavedFilterExecuteAction.java

/**
 * Executes an encoded query//from   w w  w.j ava  2  s  . co  m
 * @return
 */
public String executeEncodedQuery() {
    try {
        EncodedQueryCtx encodedQueryCtx = SavedFilterExecuteBL.executeEncodedQuery(query, session);
        if (encodedQueryCtx != null) {
            TPersonBean loggedPerson = encodedQueryCtx.getPersonBean();
            Locale loggedLocale = encodedQueryCtx.getLocale();
            QueryContext queryContext = encodedQueryCtx.getQueryContext();
            boolean keepMeLogged = encodedQueryCtx.isKeepMeLogged();
            if (keepMeLogged) {
                LastExecutedBL.storeLastExecutedQuery(loggedPerson.getObjectID(), queryContext);
                session.put(Constants.USER_KEY, loggedPerson);
                session.put(Constants.LOCALE_KEY, loggedLocale);
                if (loggedLocale != null && !loggedLocale.equals(locale)) {
                    LocaleHandler.exportLocaleToSession(session, loggedLocale);
                }
                return "itemNavigator";
            } else {
                hasInitData = true;
                initData = ItemNavigatorBL.prepareInitData(ApplicationBean.getInstance(), loggedPerson,
                        loggedLocale, queryContext, session, true, null, null, forceAllItems, false);
                session.remove(Constants.USER_KEY);
                session.put(Constants.USER_KEY + "-permLink", loggedPerson);
                session.put(Constants.LOCALE_KEY + "-permLink", loggedLocale);
                session.put("localizationJSON", LocalizeJSON.encodeLocalization(loggedLocale));
                layoutCls = "com.trackplus.layout.ItemNavigatorLiteLayout";
                return "itemNavigatorLite";
            }
        } else {
            return LOGON;
        }
    } catch (HasParametersException e) {
        return FILTER_PARAMETERS;
    } catch (NotLoggedException e) {
        String uri = ServletActionContext.getRequest().getRequestURI();
        String queryEncoded = null;
        try {
            queryEncoded = URLEncoder.encode(query, "UTF-8");
        } catch (UnsupportedEncodingException e1) {
            LOGGER.error(ExceptionUtils.getStackTrace(e1)); //To change body of catch statement use File | Settings | File Templates.
        }
        String forwardURL = uri + "?query=" + queryEncoded;
        session.put(Constants.POSTLOGINFORWARD, forwardURL);
        return LOGON;
    }
}

From source file:com.jarklee.materialdatetimepicker.date.MonthView.java

/**
 * Return a 1 or 2 letter String for use as a weekday label
 *
 * @param day The day for which to generate a label
 * @return The weekday label//from  ww  w .j  a  v  a2  s  .  co m
 */
private String getWeekDayLabel(Calendar day) {
    Locale locale = getLocale();
    // Localised short version of the string is not available on API < 18
    if (Build.VERSION.SDK_INT < 18) {
        String dayName = new SimpleDateFormat("E", locale).format(day.getTime());
        String dayLabel = dayName.toUpperCase(locale).substring(0, 1);

        // Chinese labels should be fetched right to left
        if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE)
                || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) {
            int len = dayName.length();
            dayLabel = dayName.substring(len - 1, len);
        }

        // Most hebrew labels should select the second to last character
        if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) {
            if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
                int len = dayName.length();
                dayLabel = dayName.substring(len - 2, len - 1);
            } else {
                // I know this is duplication, but it makes the code easier to grok by
                // having all hebrew code in the same block
                dayLabel = dayName.toUpperCase(locale).substring(0, 1);
            }
        }

        // Catalan labels should be two digits in lowercase
        if (locale.getLanguage().equals("ca"))
            dayLabel = dayName.toLowerCase().substring(0, 2);

        // Correct single character label in Spanish is X
        if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)
            dayLabel = "X";

        return dayLabel;
    }
    // Getting the short label is a one liner on API >= 18
    return new SimpleDateFormat("EEEEE", locale).format(day.getTime());
}

From source file:com.icesoft.faces.application.D2DViewHandler.java

public Locale calculateLocale(FacesContext context) {
    Application application = context.getApplication();
    Iterator acceptedLocales = context.getExternalContext().getRequestLocales();
    while (acceptedLocales.hasNext()) {
        Locale acceptedLocale = (Locale) acceptedLocales.next();
        Iterator supportedLocales = application.getSupportedLocales();
        while (supportedLocales.hasNext()) {
            Locale supportedLocale = (Locale) supportedLocales.next();
            if (acceptedLocale.equals(supportedLocale)) {
                return supportedLocale;
            }//from www  .  j a  va2s.  c om
        }
        supportedLocales = application.getSupportedLocales();
        while (supportedLocales.hasNext()) {
            Locale supportedLocale = (Locale) supportedLocales.next();
            if (acceptedLocale.getLanguage().equals(supportedLocale.getLanguage())
                    && supportedLocale.getCountry().length() == 0) {
                return supportedLocale;
            }
        }
    }
    // no match is found.
    Locale defaultLocale = application.getDefaultLocale();
    return defaultLocale == null ? Locale.getDefault() : defaultLocale;
}

From source file:com.borax12.materialdaterangepicker.single.date.MonthView.java

/**
 * Return a 1 or 2 letter String for use as a weekday label
 * @param day The day for which to generate a label
 * @return The weekday label/*from  w  w  w. ja v a  2  s.c  om*/
 */
private String getWeekDayLabel(Calendar day) {
    Locale locale = Locale.getDefault();

    // Localised short version of the string is not available on API < 18
    if (Build.VERSION.SDK_INT < 18) {
        String dayName = new SimpleDateFormat("E", locale).format(day.getTime());
        String dayLabel = dayName.toUpperCase(locale).substring(0, 1);

        // Chinese labels should be fetched right to left
        if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE)
                || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) {
            int len = dayName.length();
            dayLabel = dayName.substring(len - 1, len);
        }

        // Most hebrew labels should select the second to last character
        if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) {
            if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
                int len = dayName.length();
                dayLabel = dayName.substring(len - 2, len - 1);
            } else {
                // I know this is duplication, but it makes the code easier to grok by
                // having all hebrew code in the same block
                dayLabel = dayName.toUpperCase(locale).substring(0, 1);
            }
        }

        // Catalan labels should be two digits in lowercase
        if (locale.getLanguage().equals("ca"))
            dayLabel = dayName.toLowerCase().substring(0, 2);

        // Correct single character label in Spanish is X
        if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)
            dayLabel = "X";

        return dayLabel;
    }
    // Getting the short label is a one liner on API >= 18
    return new SimpleDateFormat("EEEEE", locale).format(day.getTime());
}