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:marytts.datatypes.MaryDataType.java

/**
 * Get an example text for the given type and the given locale.
 * /*from   w  ww. j a  va2 s. c  om*/
 * @param type
 *            type
 * @param locale
 *            locale
 * @return an example text suitable for type and locale, or null if none is available.
 */
public static String getExampleText(MaryDataType type, Locale locale) {
    // Convention:
    // - example texts for locale null are Resources in same package as type;
    // - example texts for a given locale are in marytts.language.<locale>.datatypes.
    // - example texts are always encoded as UTF-8.
    InputStream exampleStream;
    if (locale == null) {
        exampleStream = type.getClass().getResourceAsStream(type.name() + ".example");
    } else {
        exampleStream = type.getClass().getResourceAsStream("/marytts/language/" + locale.toString()
                + "/datatypes/" + type.name() + "." + locale.toString() + ".example");
    }
    if (exampleStream == null)
        return null;
    try {
        return IOUtils.toString(exampleStream, "UTF-8");
    } catch (IOException e) {
        logger.debug("Could not get example text for " + type.name() + " / locale " + locale);
        return null;
    }
}

From source file:org.ajax4jsf.renderkit.AjaxRendererUtils.java

/**
 * Encode declaration for AJAX response. Render &lt;html&gt;&lt;body&gt;
 * /*from   ww  w. j a  v a2 s .  co m*/
 * @param context
 * @param component
 * @throws IOException
 */
public static void encodeAjaxBegin(FacesContext context, UIComponent component) throws IOException {
    // AjaxContainer ajax = (AjaxContainer) component;
    ResponseWriter out = context.getResponseWriter();
    // DebugUtils.traceView("ViewRoot in AJAX Page encode begin");
    out.startElement("html", component);
    Locale locale = context.getViewRoot().getLocale();
    out.writeAttribute(HTML.lang_ATTRIBUTE, locale.toString(), "lang");
    out.startElement("body", component);
}

From source file:org.kepler.configuration.CommonsConfigurationReader.java

/**
 * return true if this is the only configuration file with its stem name
 * or if this configuration file is for en_US and there are no other
 * configuration files with the same base name with a matching locale.
 *///from  w  ww .j a va 2 s  .co m
private static boolean noOtherConfigurationMatch(File f, Locale l) {
    File dir = f.getParentFile();
    String[] list = dir.list();
    String fBasename = getBaseName(f);

    // NOTE: if this file is en_US and l is not en_US, return true
    // since we should use this file. this method is only called
    // after we have checked all other possibilities.
    String localeStr = getLocaleDesignator(f);
    if (localeStr != null && localeStr.equals("en_US") && !l.toString().equals("en_US")) {
        return true;
    }

    for (int i = 0; i < list.length; i++) {
        File dirF = new File(dir, list[i]);
        if (dirF.getAbsolutePath().equals(f.getAbsolutePath())) { //don't look at the actual file, just its siblings
            continue;
        }
        String basename = getBaseName(dirF);
        if (basename.equals(fBasename)) {
            return false;
        }
    }

    return true;
}

From source file:dk.i2m.jsf.converters.LocaleConverter.java

public String getAsString(FacesContext ctx, UIComponent comp, Object obj) throws ConverterException {
    System.out.println("GEtting Locale as String: " + obj);
    Locale locale = (Locale) obj;
    return locale.toString();
}

From source file:org.echocat.jomon.runtime.jaxb.LocaleAdapter.java

@Override
public String marshal(Locale v) throws Exception {
    return v != null ? v.toString() : null;
}

From source file:debop4k.data.orm.jpa.converters.LocaleAsString.java

/**
 * ? {@link Locale} ?? Database String  .
 *
 * @param attribute ? {@link Locale} ?//  ww w .  jav  a 2s  .  com
 * @return Database String 
 */
@Override
public String convertToDatabaseColumn(Locale attribute) {
    return (attribute != null) ? attribute.toString() : null;
}

From source file:org.bremersee.common.model.LocaleXmlAdapter.java

/**
 * Returns the string representation of the locale.
 *
 * @param locale the locale/*from   w  w w .  j a  v a 2s . c o m*/
 * @return the string representation
 * @throws Exception when parsing failed
 */
@Override
public String marshal(Locale locale) throws Exception {
    String s = locale != null ? locale.toString() : null;
    return StringUtils.isBlank(s) ? null : s;
}

From source file:com.rsmart.certification.impl.LocaleHandlerInterceptor.java

public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        Object object) throws Exception {
    ResourceLoader rb = new ResourceLoader();
    Locale locale = rb.getLocale();
    httpServletRequest.setAttribute("locale", locale.toString());
    httpServletRequest.setAttribute("localeRef", locale);
    httpServletRequest.setAttribute("messageSource", messageSource);
    return true;/*from   ww  w. j  a  v a  2 s.  c o m*/
}

From source file:org.openinfinity.web.controller.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *///from w  ww  . ja v  a2s .  co  m
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
    LOGGER.info("Welcome home! the client locale is " + locale.toString());
    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    String formattedDate = dateFormat.format(date);
    model.addAttribute("serverTime", formattedDate);
    return "home";
}

From source file:com.gelecekonline.web.HomeController.java

/**
 * Simply selects the home view to render by returning its name.
 *///from  w  ww.java 2s.  c  om
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
    logger.info("Welcome home! the client locale is " + locale.toString());

    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    model.addAttribute("serverTime", formattedDate);

    return "home";
}