Example usage for java.util Locale getDisplayName

List of usage examples for java.util Locale getDisplayName

Introduction

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

Prototype

public final String getDisplayName() 

Source Link

Document

Returns a name for the locale that is appropriate for display to the user.

Usage

From source file:org.dspace.app.xmlui.aspect.eperson.EditProfile.java

private void add_language(List identity, String defaultLanguage) throws WingException {
    if (!ConfigurationManager.getBooleanProperty("lr", "lr.xmlui.user.showlanguage", true)) {
        identity.addItem().addHidden("language")
                .setValue((defaultLanguage == null || defaultLanguage.equals(""))
                        ? I18nUtil.DEFAULTLOCALE.toString()
                        : defaultLanguage);
    } else {/*from  w  ww . j av a 2s.  c  o m*/
        Select lang = identity.addItem().addSelect("language");
        lang.setLabel(T_language);
        if (supportedLocales.length > 0) {
            for (Locale lc : supportedLocales) {
                lang.addOption(lc.toString(), lc.getDisplayName());
            }
        } else {
            lang.addOption(I18nUtil.DEFAULTLOCALE.toString(), I18nUtil.DEFAULTLOCALE.getDisplayName());
        }
        lang.setOptionSelected(
                (defaultLanguage == null || defaultLanguage.equals("")) ? I18nUtil.DEFAULTLOCALE.toString()
                        : defaultLanguage);
        if (!registering && !ConfigurationManager.getBooleanProperty("xmlui.user.editmetadata", true)) {
            lang.setDisabled();
        }
    }
}

From source file:org.dspace.app.xmlui.aspect.administrative.eperson.EditEPersonForm.java

private void add_config_info(Request request, EPerson edited_eperson, List identity,
        java.util.List<String> errors) throws SQLException, WingException {
    String languageValue = edited_eperson.getLanguage();
    String phoneValue = edited_eperson.getMetadata("phone");
    boolean canLogInValue = edited_eperson.canLogIn();
    boolean certificatValue = edited_eperson.getRequireCertificate();

    if (request.getParameter("phone") != null)
        phoneValue = request.getParameter("phone");
    if (request.getParameter("language") != null)
        languageValue = request.getParameter("language");

    if (!ConfigurationManager.getBooleanProperty("lr", "lr.xmlui.user.showlanguage", true)) {
        identity.addItem().addHidden("language").setValue(
                (languageValue == null || languageValue.equals("")) ? I18nUtil.DEFAULTLOCALE.toString()
                        : languageValue);
    } else {/*ww  w  . j a  v a  2 s  . co m*/
        if (isAdmin()) {
            Select language = identity.addItem(null, "admin-field").addSelect("language");
            language.setLabel(T_language);
            //language.setValue(languageValue);

            if (supportedLocales.length > 0) {
                for (Locale lc : supportedLocales) {
                    language.addOption(lc.toString(), lc.getDisplayName());
                }

            } else {
                language.addOption(I18nUtil.DEFAULTLOCALE.toString(), I18nUtil.DEFAULTLOCALE.getDisplayName());
            }
            language.setOptionSelected(
                    (languageValue == null || languageValue.equals("")) ? I18nUtil.DEFAULTLOCALE.toString()
                            : languageValue);

        } else {
            identity.addLabel(T_language);
            //identity.addItem(languageValue);
            identity.addItem(
                    (languageValue == null || languageValue.equals("")) ? I18nUtil.DEFAULTLOCALE.toString()
                            : languageValue);
        }
    }

    add_key_pair(isAdmin(), false, "phone", T_telephone, phoneValue, identity, null);

    if (isAdmin()) {
        // Administrative options:
        CheckBox canLogInField = identity.addItem(null, "admin-field").addCheckBox("can_log_in");
        canLogInField.setLabel(T_can_log_in);
        canLogInField.addOption(canLogInValue, "true");

        CheckBox certificateField = identity.addItem(null, "admin-field").addCheckBox("certificate");
        certificateField.setLabel(T_req_certs);
        certificateField.addOption(certificatValue, "true");

        CheckBox editsMetadata = identity.addItem(null, "admin-field").addCheckBox("can_edit_metadata");
        editsMetadata.setLabel("Can edit own item's metadata");
        editsMetadata.addOption(edited_eperson.canEditSubmissionMetadata(), "true");
    }

}

From source file:icom.jpa.bdk.dao.SimpleContentDAO.java

private void updateNonIdentifiableObjectState(ManagedObjectProxy obj, DAOContext context) {
    StreamedSimpleContentUpdater updater = (StreamedSimpleContentUpdater) context.getUpdater();
    Persistent pojoObject = obj.getPojoObject();

    String characterEncoding = (String) getAttributeValue(pojoObject,
            SimpleContentInfo.Attributes.characterEncoding.name());
    if ((obj.isNew() && characterEncoding != null)
            || isChanged(obj, SimpleContentInfo.Attributes.characterEncoding.name())) {
        updater.setCharacterEncoding(characterEncoding);
    }//from   w w  w .  java  2s.  c  o m
    Locale contentLanguage = (Locale) getAttributeValue(pojoObject,
            SimpleContentInfo.Attributes.contentLanguage.name());
    if ((obj.isNew() && contentLanguage != null)
            || isChanged(obj, SimpleContentInfo.Attributes.contentLanguage.name())) {
        updater.setContentLanguage(contentLanguage.getDisplayName());
    }
    String contentEncoding = (String) getAttributeValue(pojoObject,
            SimpleContentInfo.Attributes.contentEncoding.name());
    if ((obj.isNew() && contentEncoding != null)
            || isChanged(obj, SimpleContentInfo.Attributes.contentEncoding.name())) {
        updater.setContentEncoding(ContentEncodingType.OTHER); //TODO
    }
    if (obj.isNew() || isChanged(obj, SimpleContentInfo.Attributes.contentBody.name())) {
        uploadContentBody(obj, context);
        updater.setContentStreamId(context.getUploadContentStreamId());
    }
}

From source file:icom.jpa.bdk.dao.SimpleContentDAO.java

private void updateIdentifiableObjectState(ManagedObjectProxy obj, DAOContext context) {
    IdentifiableSimpleContentUpdater updater = (IdentifiableSimpleContentUpdater) context.getUpdater();
    Persistent pojoIdentifiable = obj.getPojoObject();

    String characterEncoding = (String) getAttributeValue(pojoIdentifiable,
            SimpleContentInfo.Attributes.characterEncoding.name());
    if ((obj.isNew() && characterEncoding != null)
            || isChanged(obj, SimpleContentInfo.Attributes.characterEncoding.name())) {
        updater.setCharacterEncoding(characterEncoding);
    }/*from  w w w  .ja va 2  s. com*/
    Locale contentLanguage = (Locale) getAttributeValue(pojoIdentifiable,
            SimpleContentInfo.Attributes.contentLanguage.name());
    if ((obj.isNew() && contentLanguage != null)
            || isChanged(obj, SimpleContentInfo.Attributes.contentLanguage.name())) {
        updater.setContentLanguage(contentLanguage.getDisplayName());
    }
    String contentEncoding = (String) getAttributeValue(pojoIdentifiable,
            SimpleContentInfo.Attributes.contentEncoding.name());
    if ((obj.isNew() && contentEncoding != null)
            || isChanged(obj, SimpleContentInfo.Attributes.contentEncoding.name())) {
        updater.setContentEncoding(ContentEncodingType.OTHER); //TODO
    }
    if (obj.isNew() || isChanged(obj, SimpleContentInfo.Attributes.contentBody.name())) {
        uploadContentBody(obj, context);
    }
}

From source file:icom.jpa.bdk.dao.SimpleContentDAO.java

void updateObjectStateForDiscussionMessage(ManagedObjectProxy obj, DAOContext context) {
    SimpleContentUpdater updater = (SimpleContentUpdater) context.getUpdater();
    Persistent pojoIdentifiable = obj.getPojoObject();

    String characterEncoding = (String) getAttributeValue(pojoIdentifiable,
            SimpleContentInfo.Attributes.characterEncoding.name());
    if ((obj.isNew() && characterEncoding != null)
            || isChanged(obj, SimpleContentInfo.Attributes.characterEncoding.name())) {
        updater.setCharacterEncoding(characterEncoding);
    }/*from w w  w . ja  v a2  s  .  c  o m*/
    Locale contentLanguage = (Locale) getAttributeValue(pojoIdentifiable,
            SimpleContentInfo.Attributes.contentLanguage.name());
    if ((obj.isNew() && contentLanguage != null)
            || isChanged(obj, SimpleContentInfo.Attributes.contentLanguage.name())) {
        updater.setContentLanguage(contentLanguage.getDisplayName());
    }
    String contentEncoding = (String) getAttributeValue(pojoIdentifiable,
            SimpleContentInfo.Attributes.contentEncoding.name());
    if ((obj.isNew() && contentEncoding != null)
            || isChanged(obj, SimpleContentInfo.Attributes.contentEncoding.name())) {
        //updater.setContentEncoding(ContentEncodingType.EIGHT_BIT);  //TODO
    }
    if (obj.isNew() || isChanged(obj, SimpleContentInfo.Attributes.contentBody.name())) {
        updater.setPiecewiseUpdate(false);
        try {
            ContentStreamTrait cos = (ContentStreamTrait) getAttributeValue(pojoIdentifiable,
                    SimpleContentInfo.Attributes.contentBody.name());
            InputStream fis = null;
            if (cos != null) {
                fis = cos.getFileInputStream();
            }
            if (fis != null) {
                try {
                    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                    byte[] data = new byte[ContentStreamTrait.dataSize];
                    int num = 0;
                    do {
                        num = fis.read(data);
                        if (num != -1) {
                            buffer.write(data, 0, num);
                        }
                    } while (num != -1);
                    byte[] alldata = buffer.toByteArray();
                    updater.setContentBytes(alldata);
                } finally {
                    fis.close();
                }
            }
        } catch (IOException ex) {
            throw new PersistenceException(ex);
        }
    }
}

From source file:com.ichi2.anki.PreferenceContext.java

private void initializeLanguageDialog(PreferenceScreen screen) {
    ListPreference languageSelection = (ListPreference) screen.findPreference(LANGUAGE);
    if (languageSelection != null) {
        Map<String, String> items = new TreeMap<>();
        for (String localeCode : LanguageUtil.APP_LANGUAGES) {
            Locale loc = LanguageUtil.getLocale(localeCode);
            items.put(loc.getDisplayName(), loc.toString());
        }/*w ww .j  av a2s  . c  om*/
        CharSequence[] languageDialogLabels = new CharSequence[items.size() + 1];
        CharSequence[] languageDialogValues = new CharSequence[items.size() + 1];
        languageDialogLabels[0] = getResources().getString(R.string.language_system);
        languageDialogValues[0] = "";
        int i = 1;
        for (Map.Entry<String, String> e : items.entrySet()) {
            languageDialogLabels[i] = e.getKey();
            languageDialogValues[i] = e.getValue();
            i++;
        }

        languageSelection.setEntries(languageDialogLabels);
        languageSelection.setEntryValues(languageDialogValues);
    }
}

From source file:org.sakaiproject.component.section.SectionAwarenessHibernateImpl.java

/**
 * @inheritDoc//  w  w w.ja va2 s  .  c  om
 */
public String getCategoryName(String categoryId, Locale locale) {
    ResourceBundle bundle = ResourceBundle.getBundle(SectionManagerHibernateImpl.CATEGORY_BUNDLE, locale);
    String name;
    try {
        name = bundle.getString(categoryId);
    } catch (MissingResourceException mre) {
        if (log.isInfoEnabled())
            log.info("Could not find the name for category id = " + categoryId + " in locale "
                    + locale.getDisplayName());
        name = null;
    }
    return name;
}

From source file:info.jtrac.JtracImpl.java

public void setLocaleList(String[] array) {
    locales = new LinkedHashMap<String, String>();
    for (String localeString : array) {
        Locale locale = StringUtils.parseLocaleString(localeString);
        locales.put(localeString, localeString + " - " + locale.getDisplayName());
    }/*ww  w  .ja va2  s.  c  o  m*/
    logger.info("available locales configured " + locales);
}

From source file:no.abmu.common.locale.LocaleUtil.java

/**
 * Method for logging of locale. Used under test and development.
 * /*from w  w w  . j a v a2 s .  com*/
 * @param request current HTTP request
 */

public void logLocale(HttpServletRequest request) {
    HttpSession session = request.getSession(false);

    String parameterSiteLocale = request.getParameter("siteLocale");
    String parameterStartLocale = request.getParameter("startLocale");
    String rcSiteLocale = (String) request.getAttribute("siteLocale");
    //        String seSiteLocale = (String) session.getAttribute("siteLocale");

    Locale locale = RequestContextUtils.getLocale(request);

    logger.info("request siteLocale: " + rcSiteLocale);
    logger.info("request parameter siteLocale: " + parameterSiteLocale);
    logger.info("request parameter startLocale: " + parameterStartLocale);
    //        logger.info("session siteLocale: " + seSiteLocale);

    logger.info("Locale getDisplayCountry: " + locale.getDisplayCountry());
    logger.info("Locale getDisplayLanguage: " + locale.getDisplayLanguage());
    logger.info("Locale getDisplayVariant: " + locale.getDisplayVariant());
    logger.info("Locale getDisplayName: " + locale.getDisplayName());
    logger.info("Locale getISO3Country: " + locale.getISO3Country());
    logger.info("Locale getLanguage: " + locale.getLanguage());
    logger.info("Locale getVariant: " + locale.getVariant());
    logger.info("Locale toString: " + locale.toString());

}

From source file:org.openmrs.web.controller.ConceptFormValidator.java

/**
 * Checks the form object for any inconsistencies/errors
 *
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 *///from w ww. j a  v  a 2  s .  c om
public void validate(Object obj, Errors errors) {
    ConceptFormBackingObject backingObject = (ConceptFormBackingObject) obj;
    Set<String> localesWithErrors = new HashSet<String>();
    if (backingObject.getConcept() == null) {
        errors.rejectValue("concept", "error.general");
    } else {
        // validate the concept term mappings
        for (int x = 0; x < backingObject.getConceptMappings().size(); x++) {
            ConceptMap map = backingObject.getConceptMappings().get(x);
            //this mapping has been removed or is new with no term selected, so ignore it
            if (map.getConceptReferenceTerm().getConceptReferenceTermId() == null) {
                continue;
            }
            if (map.getConceptMapType() == null) {
                errors.rejectValue("conceptMappings[" + x + "].conceptMapType", "Concept.map.typeRequired");
            }
        }

        boolean foundAtLeastOneFullySpecifiedName = false;

        for (Locale locale : backingObject.getLocales()) {

            for (int x = 0; x < backingObject.getSynonymsByLocale().get(locale).size(); x++) {
                ConceptName synonym = backingObject.getSynonymsByLocale().get(locale).get(x);
                // validate that synonym names are non-empty (null name means it was invalid and then removed)
                if (!synonym.isVoided() && synonym.getName() != null && synonym.getName().length() == 0) {
                    errors.rejectValue("synonymsByLocale[" + locale + "][" + x + "].name",
                            "Concept.synonyms.textRequired");
                    localesWithErrors.add(locale.getDisplayName());
                }
            }

            for (int x = 0; x < backingObject.getIndexTermsByLocale().get(locale).size(); x++) {
                ConceptName indexTerm = backingObject.getIndexTermsByLocale().get(locale).get(x);
                // validate that indexTerm names are non-empty (null name means it was invalid and then removed)
                if (!indexTerm.isVoided() && indexTerm.getName() != null && indexTerm.getName().length() == 0) {
                    errors.rejectValue("indexTermsByLocale[" + locale + "][" + x + "].name",
                            "Concept.indexTerms.textRequired");
                    localesWithErrors.add(locale.getDisplayName());
                }
            }

            // validate that at least one name in a locale is non-empty
            if (StringUtils.isNotEmpty(backingObject.getNamesByLocale().get(locale).getName())) {
                foundAtLeastOneFullySpecifiedName = true;

            } // if this is a new name and user has changed it into an empty string, reject it
            else if (backingObject.getNamesByLocale().get(locale).getConceptNameId() != null) {
                errors.rejectValue("namesByLocale[" + locale + "].name", "Concept.fullySpecified.textRequired");
                localesWithErrors.add(locale.getDisplayName());
            }
        }

        if (!foundAtLeastOneFullySpecifiedName) {
            errors.reject("Concept.name.atLeastOneRequired");
        }

    }

    if (errors.hasErrors() && localesWithErrors.size() > 0) {
        StringBuilder sb = new StringBuilder(
                Context.getMessageSourceService().getMessage("Concept.localesWithErrors"));
        sb.append(StringUtils.join(localesWithErrors, ", "));
        errors.rejectValue("concept", sb.toString());
    }
}