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 ResourceBundlebundlestatic Map<Set<Object>,ResourceBundle>BUNDLE_CACHEstatic StringDEFAULT_BUNDLE_ROOTstatic booleanDEFAULT_DEV_MODEstatic StringDEFAULT_LANGUAGEstatic LocaleDEFAULT_LOCALEstatic StringDEFAULT_LOCALE_KEYstatic PatternLOCALE_PATTERNstatic StringNUMERIC_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 StringformatBytes(double memory)StringformatBytes(double memory, Locale override)Format bytes to human readable textStringformatText(String message, Object... arguments)ResourceBundlegetBundle()LocalegetLocale()StringgetNumber(Number number)StringgetText(String key, Object... arguments)This retrieves a message from the appropriate properties file for your given Locale.booleanisDevMode()static booleanisValidLocale(Locale locale)static StringlocaleToString(Locale locale)protected voidsetBundle(ResourceBundle bundle)protected voidsetBundleName(String bundleName)protected voidsetDevMode(Boolean devMode)protected voidsetLocale(Locale locale)static LocalestringToLocale(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)
-
-