net.sf.doolin.util
Class LocaleUtils

java.lang.Object
  extended by net.sf.doolin.util.LocaleUtils

public class LocaleUtils
extends Object

Utility methods for Locales

Author:
Damien Coraboeuf

Method Summary
static URL getResource(String path, Locale locale)
          Get a resource using a locale.
static InputStream getResourceAsStream(String path, Locale locale)
          Get a resource using a locale.
static String getResourceName(String name, Locale locale)
          Get a resource name according to the locale.
static String getResourceName(String name, Locale locale, ELocaleMode localeMode)
          Get a resource name according to the locale and a given mode.
static boolean isMoreSpecific(Locale localeA, Locale localeB)
          Tests if localeA is more specific than localeB.
static Locale parseLocale(String value)
          Parse a Locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseLocale

public static Locale parseLocale(String value)
Parse a Locale. Expected text is the one that is obtained by the method Locale.toString(). For example, fr_FR for French (France).

Parameters:
value - Text to parse
Returns:
Resulting locale or null if the value is null or empty.
See Also:
Locale.toString()

getResourceAsStream

public static InputStream getResourceAsStream(String path,
                                              Locale locale)
Get a resource using a locale.

Parameters:
path - Path to look for
locale - Locale to look for
Returns:
Associated stream or null is not found.
See Also:
getResourceName(String, Locale)

getResource

public static URL getResource(String path,
                              Locale locale)
Get a resource using a locale.

Parameters:
path - Path to look for
locale - Locale to look for
Returns:
Associated URL or null is not found.
See Also:
getResourceName(String, Locale)

getResourceName

public static String getResourceName(String name,
                                     Locale locale)
Get a resource name according to the locale. Given a resource name like prefix.ext, this name is updated regarding to the locale. For example, for french (fr), it becomes prefix_fr.ext and for french (France), i.e. fr_FR, it becomes prefix_fr_FR.ext.

Parameters:
name - Name of the resource
locale - Locale to be used
Returns:
Updated resource name

getResourceName

public static String getResourceName(String name,
                                     Locale locale,
                                     ELocaleMode localeMode)
Get a resource name according to the locale and a given mode.

Parameters:
name - Name of the resource
locale - Locale to be used
localeMode - Indicates how the locale parameters must be used or not
Returns:
Updated resource name
See Also:
getResourceName(String, Locale)

isMoreSpecific

public static boolean isMoreSpecific(Locale localeA,
                                     Locale localeB)
Tests if localeA is more specific than localeB. A locale is more specific if it defines supplementary elements (country) while the language is the same.

Parameters:
localeA - First locale
localeB - Second locale
Returns:
true if the localeA is more specific than localeB


Copyright © 2011. All Rights Reserved.