Package gov.nasa.arc.pds.tools.util
Class LocaleUtils
- java.lang.Object
-
- gov.nasa.arc.pds.tools.util.LocaleUtils
-
public class LocaleUtils extends java.lang.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 java.util.ResourceBundle
bundle
static java.util.Map<java.util.Set<java.lang.Object>,java.util.ResourceBundle>
BUNDLE_CACHE
static java.lang.String
DEFAULT_BUNDLE_ROOT
static boolean
DEFAULT_DEV_MODE
static java.lang.String
DEFAULT_LANGUAGE
static java.util.Locale
DEFAULT_LOCALE
static java.lang.String
DEFAULT_LOCALE_KEY
static java.util.regex.Pattern
LOCALE_PATTERN
static java.lang.String
NUMERIC_FORMAT
-
Constructor Summary
Constructors Constructor Description LocaleUtils()
LocaleUtils(java.lang.Boolean devMode)
LocaleUtils(java.lang.String bundleRoot)
LocaleUtils(java.util.Locale locale)
LocaleUtils(java.util.Locale locale, java.lang.Boolean devMode)
LocaleUtils(java.util.Locale locale, java.lang.Boolean devMode, java.lang.String bundleRoot)
LocaleUtils(java.util.Locale locale, java.lang.Boolean devMode, java.util.ResourceBundle bundle)
LocaleUtils(java.util.Locale locale, java.lang.String bundleRoot)
LocaleUtils(java.util.Locale locale, java.util.ResourceBundle bundle)
LocaleUtils(java.util.ResourceBundle bundle)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
formatBytes(double memory)
java.lang.String
formatBytes(double memory, java.util.Locale override)
Format bytes to human readable textjava.lang.String
formatText(java.lang.String message, java.lang.Object... arguments)
java.util.ResourceBundle
getBundle()
java.util.Locale
getLocale()
java.lang.String
getNumber(java.lang.Number number)
java.lang.String
getText(java.lang.String key, java.lang.Object... arguments)
This retrieves a message from the appropriate properties file for your given Locale.boolean
isDevMode()
static boolean
isValidLocale(java.util.Locale locale)
static java.lang.String
localeToString(java.util.Locale locale)
protected void
setBundle(java.util.ResourceBundle bundle)
protected void
setBundleName(java.lang.String bundleName)
protected void
setDevMode(java.lang.Boolean devMode)
protected void
setLocale(java.util.Locale locale)
static java.util.Locale
stringToLocale(java.lang.String localeName)
-
-
-
Field Detail
-
DEFAULT_LOCALE_KEY
public static final java.lang.String DEFAULT_LOCALE_KEY
- See Also:
- Constant Field Values
-
DEFAULT_LANGUAGE
public static final java.lang.String DEFAULT_LANGUAGE
- See Also:
- Constant Field Values
-
DEFAULT_LOCALE
public static final java.util.Locale DEFAULT_LOCALE
-
DEFAULT_BUNDLE_ROOT
public static final java.lang.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 java.util.ResourceBundle bundle
-
LOCALE_PATTERN
public static final java.util.regex.Pattern LOCALE_PATTERN
-
NUMERIC_FORMAT
public static final java.lang.String NUMERIC_FORMAT
- See Also:
- Constant Field Values
-
BUNDLE_CACHE
public static final java.util.Map<java.util.Set<java.lang.Object>,java.util.ResourceBundle> BUNDLE_CACHE
-
-
Constructor Detail
-
LocaleUtils
public LocaleUtils()
-
LocaleUtils
public LocaleUtils(java.util.Locale locale)
-
LocaleUtils
public LocaleUtils(java.lang.Boolean devMode)
-
LocaleUtils
public LocaleUtils(java.lang.String bundleRoot)
-
LocaleUtils
public LocaleUtils(java.util.ResourceBundle bundle)
-
LocaleUtils
public LocaleUtils(java.util.Locale locale, java.lang.Boolean devMode)
-
LocaleUtils
public LocaleUtils(java.util.Locale locale, java.lang.String bundleRoot)
-
LocaleUtils
public LocaleUtils(java.util.Locale locale, java.util.ResourceBundle bundle)
-
LocaleUtils
public LocaleUtils(java.util.Locale locale, java.lang.Boolean devMode, java.lang.String bundleRoot)
-
LocaleUtils
public LocaleUtils(java.util.Locale locale, java.lang.Boolean devMode, java.util.ResourceBundle bundle)
-
-
Method Detail
-
setLocale
protected void setLocale(java.util.Locale locale)
-
getLocale
public java.util.Locale getLocale()
-
setDevMode
protected void setDevMode(java.lang.Boolean devMode)
-
isDevMode
public boolean isDevMode()
-
setBundle
protected void setBundle(java.util.ResourceBundle bundle)
-
getBundle
public java.util.ResourceBundle getBundle()
-
setBundleName
protected void setBundleName(java.lang.String bundleName)
-
isValidLocale
public static boolean isValidLocale(java.util.Locale locale)
-
stringToLocale
public static java.util.Locale stringToLocale(java.lang.String localeName)
-
localeToString
public static java.lang.String localeToString(java.util.Locale locale)
-
getText
public java.lang.String getText(java.lang.String key, java.lang.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
-
formatText
public java.lang.String formatText(java.lang.String message, java.lang.Object... arguments)
-
getNumber
public java.lang.String getNumber(java.lang.Number number)
-
formatBytes
public java.lang.String formatBytes(double memory)
-
formatBytes
public java.lang.String formatBytes(double memory, java.util.Locale override)
Format bytes to human readable text- Parameters:
memory
- The memory value to format.override
- The locale to be used (determines decimal and grouping separators).- Returns:
- The formatted number string.
-
-