Package gov.nasa.arc.pds.tools.util
Class LocaleUtils
- java.lang.Object
-
- gov.nasa.arc.pds.tools.util.LocaleUtils
-
public class LocaleUtils extends Object
A helper class for Locale functionality and locale specific functionality. This includes message retrieval and formatting from message bundles.- Version:
- $Revision: $
- Author:
- jagander
-
-
Field Summary
Fields Modifier and Type Field Description ResourceBundle
bundle
static Map<Set<Object>,ResourceBundle>
BUNDLE_CACHE
static String
DEFAULT_BUNDLE_ROOT
static boolean
DEFAULT_DEV_MODE
static String
DEFAULT_LANGUAGE
static Locale
DEFAULT_LOCALE
static String
DEFAULT_LOCALE_KEY
static Pattern
LOCALE_PATTERN
static String
NUMERIC_FORMAT
-
Constructor Summary
Constructors Constructor Description LocaleUtils()
LocaleUtils(Boolean devMode)
LocaleUtils(String bundleRoot)
LocaleUtils(Locale locale)
LocaleUtils(Locale locale, Boolean devMode)
LocaleUtils(Locale locale, Boolean devMode, String bundleRoot)
LocaleUtils(Locale locale, Boolean devMode, ResourceBundle bundle)
LocaleUtils(Locale locale, String bundleRoot)
LocaleUtils(Locale locale, ResourceBundle bundle)
LocaleUtils(ResourceBundle bundle)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
formatBytes(double memory)
String
formatBytes(double memory, Locale override)
Format bytes to human readable textString
formatText(String message, Object... arguments)
ResourceBundle
getBundle()
Locale
getLocale()
String
getNumber(Number number)
String
getText(String key, Object... arguments)
This retrieves a message from the appropriate properties file for your given Locale.boolean
isDevMode()
static boolean
isValidLocale(Locale locale)
static String
localeToString(Locale locale)
protected void
setBundle(ResourceBundle bundle)
protected void
setBundleName(String bundleName)
protected void
setDevMode(Boolean devMode)
protected void
setLocale(Locale locale)
static Locale
stringToLocale(String localeName)
-
-
-
Field Detail
-
DEFAULT_LOCALE_KEY
public static final String DEFAULT_LOCALE_KEY
- See Also:
- Constant Field Values
-
DEFAULT_LANGUAGE
public static final String DEFAULT_LANGUAGE
- See Also:
- Constant Field Values
-
DEFAULT_LOCALE
public static final Locale DEFAULT_LOCALE
-
DEFAULT_BUNDLE_ROOT
public static final String DEFAULT_BUNDLE_ROOT
- See Also:
- Constant Field Values
-
DEFAULT_DEV_MODE
public static final boolean DEFAULT_DEV_MODE
- See Also:
- Constant Field Values
-
bundle
public ResourceBundle bundle
-
LOCALE_PATTERN
public static final Pattern LOCALE_PATTERN
-
NUMERIC_FORMAT
public static final String NUMERIC_FORMAT
- See Also:
- Constant Field Values
-
BUNDLE_CACHE
public static final Map<Set<Object>,ResourceBundle> BUNDLE_CACHE
-
-
Constructor Detail
-
LocaleUtils
public LocaleUtils()
-
LocaleUtils
public LocaleUtils(Locale locale)
-
LocaleUtils
public LocaleUtils(Boolean devMode)
-
LocaleUtils
public LocaleUtils(String bundleRoot)
-
LocaleUtils
public LocaleUtils(ResourceBundle bundle)
-
LocaleUtils
public LocaleUtils(Locale locale, ResourceBundle bundle)
-
LocaleUtils
public LocaleUtils(Locale locale, Boolean devMode, ResourceBundle bundle)
-
-
Method Detail
-
setLocale
protected void setLocale(Locale locale)
-
getLocale
public Locale getLocale()
-
setDevMode
protected void setDevMode(Boolean devMode)
-
isDevMode
public boolean isDevMode()
-
setBundle
protected void setBundle(ResourceBundle bundle)
-
getBundle
public ResourceBundle getBundle()
-
setBundleName
protected void setBundleName(String bundleName)
-
isValidLocale
public static boolean isValidLocale(Locale locale)
-
getText
public String getText(String key, Object... arguments)
This retrieves a message from the appropriate properties file for your given Locale. It also uses any provided arguments to make substitutions and formatting changes to the found message. Note that this uses the OGNL expression language syntax for formatting.- Parameters:
key
- - properties key used to look up messagearguments
- - an array of arguments to be used in the message, uses OGNL syntax- Returns:
- found and formatted message
- Throws:
KeyNotFoundException
-
formatBytes
public String formatBytes(double memory)
-
-