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.tinymediamanager.ui.settings.GeneralSettingsPanel.java

/**
 * Check changes./*w w  w .  ja  v a 2s  .c  o  m*/
 */
private void checkChanges() {
    LocaleComboBox loc = (LocaleComboBox) cbLanguage.getSelectedItem();
    Locale locale = loc.loc;
    Locale actualLocale = Utils.getLocaleFromLanguage(Globals.settings.getLanguage());
    if (!locale.equals(actualLocale)) {
        Globals.settings.setLanguage(locale.toString());
        lblLanguageHint.setText(BUNDLE.getString("Settings.languagehint")); //$NON-NLS-1$
    }

    // fonts
    Integer fontSize = (Integer) cbFontSize.getSelectedItem();
    if (fontSize != Globals.settings.getFontSize()) {
        Globals.settings.setFontSize(fontSize);
        lblFontChangeHint.setText(BUNDLE.getString("Settings.fontchangehint")); //$NON-NLS-1$
    }

    String fontFamily = (String) cbFontFamily.getSelectedItem();
    if (!fontFamily.equals(Globals.settings.getFontFamily())) {
        Globals.settings.setFontFamily(fontFamily);
        lblFontChangeHint.setText(BUNDLE.getString("Settings.fontchangehint")); //$NON-NLS-1$
    }
}

From source file:org.openmrs.ConceptName.java

/**
 * Convenience method for determining whether this is a synonym in a given locale.
 *
 * @param locale The locale in which this synonym should belong
 * @return true if the concept name is marked as a synonym in the given locale, otherwise false
 *///from w  ww. j ava  2s .c om
public Boolean isSynonymInLocale(Locale locale) {
    return getConceptNameType() == null && locale.equals(getLocale());
}

From source file:org.kitodo.production.forms.LanguageForm.java

/**
 * The function getSupportedLocales() returns a list of maps, each
 * representing one locale configured in the faces-config.xml file. Each of
 * the maps will contain the fields. id  the locales ID String, e.g. fr?
 * or en_GB? displayLanguageSelf  the name of the language in the language
 * itself, e.g. English?, Deutsch?, franais?, espaol?, ???,
 * ?, /*from   w w  w.  ja  va  2 s  . c om*/
 *
 * <p>
 * Its a good practice to identify a language in its own spelling, since
 * this will be most likely what a speaker of that language will recognize.
 * See also: http://www.cs.tut.fi/~jkorpela/flags.html Note that
 * capitalisation is subject to the respective language. If the language is
 * unknown, the id will be returned. displayLanguageTranslated  the name of
 * the language in the currently selected language, e.g., if the current
 * language is English: English?, German?, French?, 
 * </p>
 *
 * <p>
 * This is just a nice feature because the language names are provided by
 * Java; and its used in the mouse-over titles, so you can find out what
 * e.g. ? means, even if you dont have a clue of the glyphs used. If
 * no translations are available, this will fall back to English. selected 
 * whether this is the current language
 * </p>
 *
 * <p>
 * This can be used for a sophisticated layout.
 * </p>
 *
 * @return a list of maps, each with the fields id?, displayName? and
 *         selected?
 */
public List<Map<String, Object>> getSupportedLocales() {
    List<Map<String, Object>> result = new ArrayList<>();
    Locale currentDisplayLanguage = FacesContext.getCurrentInstance().getViewRoot().getLocale();
    // It seems we have an old Faces API, Faces 2.1s getSupportedLocales()
    // returns Iterator<Locale>
    // TODO: Update JSF API
    Iterator<Locale> localesIterator = FacesContext.getCurrentInstance().getApplication().getSupportedLocales();
    while (localesIterator.hasNext()) {
        Locale supportedLocale = localesIterator.next();
        if (supportedLocale.getLanguage().length() > 0) {
            Map<String, Object> translation = new HashMap<>();
            translation.put("id", supportedLocale.toString());
            translation.put("displayLanguageSelf", supportedLocale.getDisplayLanguage(supportedLocale));
            translation.put("displayLanguageTranslated",
                    supportedLocale.getDisplayLanguage(currentDisplayLanguage));
            translation.put("selected", supportedLocale.equals(currentDisplayLanguage));
            translation.put("flag", "javax.faces.resource/images/" + supportedLocale.toString() + ".svg.jsf");
            result.add(translation);
        }
    }
    return result;
}

From source file:org.apache.myfaces.application.jsp.JspViewHandlerImpl.java

public Locale calculateLocale(FacesContext facesContext) {
    Iterator locales = facesContext.getExternalContext().getRequestLocales();
    while (locales.hasNext()) {
        Locale locale = (Locale) locales.next();
        for (Iterator it = facesContext.getApplication().getSupportedLocales(); it.hasNext();) {
            Locale supportLocale = (Locale) it.next();
            // higher priority to a language match over an exact match
            // that occures further down (see Jstl Reference 1.0 8.3.1)
            if (locale.getLanguage().equals(supportLocale.getLanguage())
                    && (supportLocale.getCountry() == null || supportLocale.getCountry().length() == 0)) {
                return supportLocale;
            } else if (supportLocale.equals(locale)) {
                return supportLocale;
            }//from   w ww . ja v a 2s. co  m
        }
    }

    Locale defaultLocale = facesContext.getApplication().getDefaultLocale();
    return defaultLocale != null ? defaultLocale : Locale.getDefault();
}

From source file:org.opencms.i18n.CmsLocaleGroupService.java

/**
 * Checks if the two resources are linkable as locale variants and returns an appropriate status<p>
 *
 *  This is the case if exactly one of the resources represents a locale group, the locale of the other resource
 *  is not already present in the locale group, and if some other permission / validity checks are passed.
 *
 * @param firstResource a resource// www  . j a v  a 2s.co m
 * @param secondResource a resource
 *
 * @return the result of the linkability check
 */
public Status checkLinkable(CmsResource firstResource, CmsResource secondResource) {

    String debugPrefix = "checkLinkable [" + Thread.currentThread().getName() + "]: ";
    LOG.debug(debugPrefix + (firstResource != null ? firstResource.getRootPath() : null) + " -- "
            + (secondResource != null ? secondResource.getRootPath() : null));
    try {
        CmsResource firstResourceCorrected = getDefaultFileOrSelf(firstResource);
        CmsResource secondResourceCorrected = getDefaultFileOrSelf(secondResource);
        if ((firstResourceCorrected == null) || (secondResourceCorrected == null)) {
            LOG.debug(debugPrefix + " rejected - no resource");
            return Status.other;
        }
        Locale locale1 = OpenCms.getLocaleManager().getDefaultLocale(m_cms, firstResourceCorrected);
        Locale locale2 = OpenCms.getLocaleManager().getDefaultLocale(m_cms, secondResourceCorrected);
        if (locale1.equals(locale2)) {
            LOG.debug(debugPrefix + "  rejected - same locale " + locale1);
            return Status.other;
        }

        Locale mainLocale1 = getMainLocale(firstResourceCorrected.getRootPath());
        Locale mainLocale2 = getMainLocale(secondResourceCorrected.getRootPath());
        if ((mainLocale1 == null) || !(mainLocale1.equals(mainLocale2))) {
            LOG.debug(debugPrefix + " rejected - incompatible main locale " + mainLocale1 + "/" + mainLocale2);
            return Status.other;
        }

        CmsLocaleGroup group1 = readLocaleGroup(firstResourceCorrected);
        Set<Locale> locales1 = group1.getLocales();
        CmsLocaleGroup group2 = readLocaleGroup(secondResourceCorrected);
        Set<Locale> locales2 = group2.getLocales();
        if (!(Sets.intersection(locales1, locales2).isEmpty())) {
            LOG.debug(debugPrefix + "  rejected - already linked (case 1)");
            return Status.alreadyLinked;
        }

        if (group1.isMarkedNoTranslation(group2.getLocales())
                || group2.isMarkedNoTranslation(group1.getLocales())) {
            LOG.debug(debugPrefix + "  rejected - marked 'no translation'");
            return Status.notranslation;
        }

        if (group1.isRealGroupOrPotentialGroupHead() == group2.isRealGroupOrPotentialGroupHead()) {
            LOG.debug(debugPrefix + "  rejected - incompatible locale group states");
            return Status.other;
        }

        CmsResource permCheckResource = null;
        if (group1.isRealGroupOrPotentialGroupHead()) {
            permCheckResource = group2.getPrimaryResource();
        } else {
            permCheckResource = group1.getPrimaryResource();
        }
        if (!m_cms.hasPermissions(permCheckResource, CmsPermissionSet.ACCESS_WRITE, false,
                CmsResourceFilter.IGNORE_EXPIRATION)) {
            LOG.debug(debugPrefix + " no write permissions: " + permCheckResource.getRootPath());
            return Status.other;
        }

        if (!checkLock(permCheckResource)) {
            LOG.debug(debugPrefix + " lock state: " + permCheckResource.getRootPath());
            return Status.other;
        }

        if (group2.getPrimaryResource().getStructureId().equals(group1.getPrimaryResource().getStructureId())) {
            LOG.debug(debugPrefix + "  rejected - already linked (case 2)");
            return Status.alreadyLinked;
        }
    } catch (Exception e) {
        LOG.error(debugPrefix + e.getLocalizedMessage(), e);
        LOG.debug(debugPrefix + "  rejected - exception (see previous)");
        return Status.other;
    }
    LOG.debug(debugPrefix + " OK");
    return Status.linkable;
}

From source file:com.jecelyin.editor.v2.core.text.TextUtils.java

/**
 * Return the layout direction for a given Locale
 *
 * @param locale the Locale for which we want the layout direction. Can be null.
 * @return the layout direction. This may be one of:
 * {@link android.view.View#LAYOUT_DIRECTION_LTR} or
 * {@link android.view.View#LAYOUT_DIRECTION_RTL}.
 *
 * Be careful: this code will need to be updated when vertical scripts will be supported
 *///from  w  w w  .  j  a  v a2s.  c om
public static int getLayoutDirectionFromLocale(Locale locale) {
    if (locale != null && !locale.equals(Locale.ROOT)) {
        //            final String scriptSubtag = ICU.addLikelySubtags(locale).getScript();
        final String scriptSubtag = ICUCompat.maximizeAndGetScript(locale);
        if (scriptSubtag == null)
            return getLayoutDirectionFromFirstChar(locale);

        if (scriptSubtag.equalsIgnoreCase(ARAB_SCRIPT_SUBTAG)
                || scriptSubtag.equalsIgnoreCase(HEBR_SCRIPT_SUBTAG)) {
            return View.LAYOUT_DIRECTION_RTL;
        }
    }
    // If forcing into RTL layout mode, return RTL as default, else LTR
    //        return SystemProperties.getBoolean(Settings.Global.DEVELOPMENT_FORCE_RTL, false)
    //                ? View.LAYOUT_DIRECTION_RTL
    //                : View.LAYOUT_DIRECTION_LTR;
    return View.LAYOUT_DIRECTION_LTR; //jec: ?
}

From source file:org.openmrs.ConceptName.java

/**
 * Convenience method for determining whether this is an index Term for a given locale.
 *
 * @param locale The locale in which this concept name should belong as an index term
 * @return true if the name is marked as an index term, otherwise false
 *//*w ww.  j  a v a 2  s . c  om*/
public Boolean isIndexTermInLocale(Locale locale) {
    return getConceptNameType() != null && getConceptNameType().equals(ConceptNameType.INDEX_TERM)
            && locale.equals(getLocale());
}

From source file:org.sakaiproject.portal.charon.handlers.BasePortalHandler.java

protected void addLocale(PortalRenderContext rcontext, Site site, String userId) {
    Locale prevLocale = null;
    ResourceLoader rl = new ResourceLoader();
    if (userId != null) {
        prevLocale = rl.getLocale();//from w w  w.  j a  v  a 2 s. c om
    }

    Locale locale = setSiteLanguage(site);
    if (log.isDebugEnabled()) {
        log.debug("Locale for site " + site.getId() + " = " + locale.toString());
    }
    String localeString = locale.getLanguage();
    String country = locale.getCountry();
    if (country.length() > 0)
        localeString += "-" + country;
    rcontext.put("locale", localeString);
    rcontext.put("dir", rl.getOrientation(locale));

    if (prevLocale != null && !prevLocale.equals(locale)) {
        // if the locale was changed, clear the date/time format which was cached in the previous locale
        timeService.clearLocalTimeZone(userId);
    }
}

From source file:com.sun.faces.application.ViewHandlerImpl.java

/**
 * Attempts to find a matching locale based on <code>perf</code> and
 * list of supported locales, using the matching algorithm
 * as described in JSTL 8.3.2.//w w w .j  a va2s .c  o  m
 */
protected Locale findMatch(FacesContext context, Locale perf) {
    Locale result = null;
    Iterator it = context.getApplication().getSupportedLocales();
    while (it.hasNext()) {
        Locale supportedLocale = (Locale) it.next();

        if (perf.equals(supportedLocale)) {
            // exact match
            result = supportedLocale;
            break;
        } else {
            // Make sure the preferred locale doesn't have country
            // set, when doing a language match, For ex., if the
            // preferred locale is "en-US", if one of supported
            // locales is "en-UK", even though its language matches
            // that of the preferred locale, we must ignore it.
            if (perf.getLanguage().equals(supportedLocale.getLanguage())
                    && supportedLocale.getCountry().equals("")) {
                result = supportedLocale;
            }
        }
    }
    // if it's not in the supported locales,
    if (null == result) {
        Locale defaultLocale = context.getApplication().getDefaultLocale();
        if (defaultLocale != null) {
            if (perf.equals(defaultLocale)) {
                // exact match
                result = defaultLocale;
            } else {
                // Make sure the preferred locale doesn't have country
                // set, when doing a language match, For ex., if the
                // preferred locale is "en-US", if one of supported
                // locales is "en-UK", even though its language matches
                // that of the preferred locale, we must ignore it.
                if (perf.getLanguage().equals(defaultLocale.getLanguage())
                        && defaultLocale.getCountry().equals("")) {
                    result = defaultLocale;
                }
            }
        }
    }

    return result;
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

private void testLocales(final String format, final boolean eraBC) throws Exception {

    final Calendar cal = Calendar.getInstance(GMT);
    cal.clear();//from w w w  . j a  va  2 s. c  o  m
    cal.set(2003, Calendar.FEBRUARY, 10);
    if (eraBC) {
        cal.set(Calendar.ERA, GregorianCalendar.BC);
    }

    for (final Locale locale : Locale.getAvailableLocales()) {
        // ja_JP_JP cannot handle dates before 1868 properly
        if (eraBC && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
            continue;
        }
        final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
        final DateParser fdf = getInstance(format, locale);

        try {
            checkParse(locale, cal, sdf, fdf);
        } catch (final ParseException ex) {
            Assert.fail("Locale " + locale + " failed with " + format + " era " + (eraBC ? "BC" : "AD") + "\n"
                    + trimMessage(ex.toString()));
        }
    }
}