Example usage for java.util Locale toString

List of usage examples for java.util Locale toString

Introduction

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

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string representation of this Locale object, consisting of language, country, variant, script, and extensions as below:
language + "_" + country + "_" + (variant + "_#" | "#") + script + "_" + extensions
Language is always lower case, country is always upper case, script is always title case, and extensions are always lower case.

Usage

From source file:org.olat.core.commons.contextHelp.ContextHelpMainController.java

/**
 * Constructor for the context help display.
 * // ww  w.  j a  v a2  s. c  o  m
 * @param ureq
 * @param control
 */
public ContextHelpMainController(UserRequest ureq, WindowControl control) {
    super(ureq, control);
    String[] uriParts = ureq.getNonParsedUri().split("/");
    String lang = null;
    // get lang and set locale for help page accordingly
    lang = uriParts[0];
    Locale newLocale = I18nManager.getInstance().getLocaleOrNull(lang);
    if (newLocale == null || !I18nModule.getEnabledLanguageKeys().contains(newLocale.toString())) {
        newLocale = I18nModule.getDefaultLocale();
    }
    if (!getLocale().toString().equals(newLocale.toString())) {
        setLocale(newLocale, true);
    }
    // Create bread crumb navigation
    breadCrumbLayoutCtr = new BreadCrumbController(ureq, control);
    listenTo(breadCrumbLayoutCtr);
    // Add translation tool start controller to bread crumb
    startCtr = new ContextHelpTOCCrumbController(ureq, control, newLocale);
    listenTo(startCtr);
    breadCrumbLayoutCtr.activateFirstCrumbController(startCtr);
    // Our view is generated by the main and the bread crumb layouer
    mainLayoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), null, null,
            breadCrumbLayoutCtr.getInitialComponent(), null);
    listenTo(mainLayoutCtr);
    putInitialPanel(mainLayoutCtr.getInitialComponent());

    activatePageFromURL(uriParts, ureq, startCtr);

    // Register for events on this user session. Identity is set to null, but
    // event bus is still user-session only
    eventBus = ureq.getUserSession().getSingleUserEventCenter();
    eventBus.registerFor(this, ureq.getIdentity(), ContextHelpTopNavController.CHANGE_LANG_RESOURCE);

    // do logging
    if (ureq.getUserSession().getSessionInfo() != null) {
        // context help can be called in dmz zone as well - in that case don't call log() - only call log() for logged-in users
        ThreadLocalUserActivityLogger.log(OlatLoggingAction.CS_HELP, getClass(), CoreLoggingResourceable
                .wrapNonOlatResource(StringResourceableType.csHelp, "-1", ArrayUtils.toString(uriParts)));
    }
}

From source file:org.eclipse.jubula.client.core.model.TestDataPO.java

/**
 * get the value for a given locale//w ww  .ja v  a  2s.c  om
 * @param lang language, for which to get the value
 * @return value
 */
public String getValue(Locale lang) {
    Validate.notNull(lang);
    return getMap().get(lang.toString());
}

From source file:org.lockss.util.TestMetadataUtil.java

String findClosestLocale(String str) {
    Locale l = MetadataUtil.findClosestLocale(LocaleUtils.toLocale(str), testLocales);
    return l != null ? l.toString() : null;
}

From source file:nz.co.senanque.localemanagement.XMLMessageSource.java

@SuppressWarnings("unchecked")
@Override/*  w  w w. j  av  a2s. c o m*/
public void afterPropertiesSet() throws Exception {
    m_resource.getInputStream();
    Document doc = null;
    try {
        InputStream in = getResource().getInputStream();
        SAXBuilder sax = new SAXBuilder();
        doc = sax.build(in);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Locale defaultLocale = Locale.getDefault();
    for (Element e : (List<Element>) doc.getRootElement().getChildren("locale")) {
        String l = e.getAttributeValue("name");
        if (l == null) {
            l = defaultLocale.toString();
        }
        for (Locale locale : Locale.getAvailableLocales()) {
            if (locale.toString().equals(l)) {
                Map<String, String> values = new HashMap<String, String>();
                m_map.put(locale, values);
                for (Element e1 : (List<Element>) e.getChildren("entry")) {
                    values.put(e1.getAttributeValue("name"), e1.getAttributeValue("value"));
                }
            }
        }
    }
}

From source file:cn.vlabs.umt.common.mail.MessageFormatter.java

private String readTemplate(Locale locale, String templateName) throws TemplateNotFound {
    StringBuffer content = new StringBuffer();
    Reader reader = null;/* w ww . j  ava2  s  .c  om*/
    String templateFileDir = path;
    try {
        templateFileDir = path + "/" + locale.toString();
        File f = new File(templateFileDir);
        if (!f.exists()) {
            templateFileDir = path + "/en_US";
        }
        templateFileDir = templateFileDir + "/" + templateName;
        reader = new InputStreamReader(new FileInputStream(templateFileDir), "UTF-8");

        int num = 0;
        while ((num = reader.read(buff)) != -1) {
            content.append(buff, 0, num);
        }
    } catch (FileNotFoundException e) {
        throw new TemplateNotFound(templateFileDir);
    } catch (UnsupportedEncodingException e) {
        log.error("????");
        log.debug("?", e);
    } catch (IOException e) {
        log.error("????");
        log.debug("?", e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                log.debug("??");
            }
        }
    }
    return content.toString();
}

From source file:com.progress.singapore.datadirect.jdbc.demo.saleskit.common.StaticMessageSource.java

/**
 * Associate the given message with the given code.
 * @param code the lookup code/*from   w  ww .  ja  v  a2  s.  c  om*/
 * @param locale the locale that the message should be found within
 * @param msg the message associated with this lookup code
 */
public void addMessage(String code, Locale locale, String msg) {
    Assert.notNull(code, "Code must not be null");
    Assert.notNull(msg, "Message must not be null");
    if (locale == null) {
        locale = Locale.getDefault();
    }
    String key = code + "_" + locale.toString();
    this.messages.put(key, msg);
    this.cachedMessageFormats.remove(key);
    if (logger.isDebugEnabled()) {
        logger.debug("Added message for code [" + code + "] and Locale [" + locale + "]");
    }
}

From source file:com.jaspersoft.studio.swt.widgets.WLocale.java

public void setSelection(Locale locale) {
    int index;/*from   www .  j  av a  2  s . com*/
    if (locale == null)
        index = getIndexFromLocale(Locale.getDefault());
    else
        index = getIndexFromLocale(locale);
    combo.select(index);
    if (index < 0 && locale != null)
        combo.setText(locale.toString());
}

From source file:com.haulmont.cuba.gui.ScreensHelper.java

protected String getCaptionCacheKey(String src, Locale locale) {
    return src + locale.toString();
}

From source file:edu.cornell.mannlib.vitro.webapp.filters.CachingResponseFilter.java

/**
 * The ETAG from the search index is not specific enough, since we may have
 * different versions for different languages. Add the Locales from the
 * request to make it unique.//from   w ww .ja  va  2 s.com
 */
private String produceLanguageSpecificEtag(HttpServletRequest req, String rawEtag) {
    if (rawEtag == null) {
        return null;
    }

    @SuppressWarnings("unchecked")
    List<Locale> locales = EnumerationUtils.toList(req.getLocales());

    StringBuilder buffer = new StringBuilder("\"").append(rawEtag);
    for (Locale locale : locales) {
        buffer.append(locale.toString());
    }
    buffer.append("\"");

    String etag = buffer.toString().replaceAll("\\s", "");
    log.debug("Language-specific ETAG = " + etag);
    return etag;
}

From source file:dk.teachus.backend.bean.impl.SpringVelocityBean.java

public String mergeTemplate(String template, Map<String, Object> model, Locale locale)
        throws VelocityException {
    StringBuilder templateLocation = new StringBuilder(template);

    if (locale != null) {
        StringBuilder localeTemplateLocation = new StringBuilder(templateLocation);
        localeTemplateLocation.append(UNDERSCORE);
        localeTemplateLocation.append(locale.toString());
        localeTemplateLocation.append(VM);

        ClassPathResource classPathResource = new ClassPathResource(localeTemplateLocation.toString());
        if (classPathResource.exists()) {
            templateLocation = localeTemplateLocation;
        } else {//w ww.ja  v a2  s  . c  om
            templateLocation.append(VM);
        }
    } else {
        templateLocation.append(VM);
    }

    return mergeTemplate(templateLocation.toString(), model);
}