|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectkiwi.util.LocaleManager
The Kiwi locale manager. This class
retrieves resource bundles from one or more ResourceManager
s,
and provides convenience methods for formatting various types of data
according to the rules of the current locale.
In the case of decimal-based values such as percentages and currency amounts, if the corresponding parse fails, this class will resort to parsing the string as a generic decimal value, throwing an exception if that also fails. This allows for the parsing of values that are formatted specifically or generically. For example, the currency value $49.55 will parse to the decimal value 49.55 whether the source string is "$49.55" or "49.55".
Field Summary | |
private static java.text.Collator |
collator
|
private java.text.NumberFormat |
currencyFormat
|
private java.text.DateFormat[] |
dateFormat
|
private java.text.DateFormatSymbols |
dateFormatSymbols
|
private java.text.DateFormat[] |
dateTimeFormat
|
private java.text.NumberFormat |
decimalFormat
|
static int |
DEFAULT_CURRENCY_DECIMALS
The default number of decimal digits to retain when formatting currency values. |
static int |
DEFAULT_NUMBER_DECIMALS
The default number of decimal digits to retain when formatting numeric values. |
static int |
DEFAULT_PERCENTAGE_DECIMALS
The default number of decimal digits to retain when formatting percentage values. |
private static LocaleManager |
defaultLocaleManager
|
private java.text.NumberFormat |
integerFormat
|
private int[] |
lengthTypes
|
private java.text.NumberFormat |
percentFormat
|
private static java.text.ParsePosition |
pos
|
private java.util.Vector |
resourceManagers
|
private java.text.DateFormat[] |
timeFormat
|
Constructor Summary | |
LocaleManager()
Construct a new LocaleManager . |
|
LocaleManager(ResourceManager resourceManager)
Construct a new LocaleManager . |
Method Summary | |
void |
addResourceManager(ResourceManager manager)
Register a ResourceManager with the locale manager. |
java.lang.String |
formatCurrency(double value)
Format a currency value according to the rules of the current locale, with DEFAULT_CURRENCY_DECIMALS decimal places retained, and
grouping turned off. |
java.lang.String |
formatCurrency(double value,
int decimals)
Format a currency value according to the rules of the current locale, with the specified number of decimal places retained, and grouping turned off. |
java.lang.String |
formatCurrency(double value,
int decimals,
boolean grouping)
Format a currency value according to the rules of the current locale, with the specified number of decimal places retained, and the specified grouping policy. |
java.lang.String |
formatCurrency(float value)
Format a currency value according to the rules of the current locale, with DEFAULT_CURRENCY_DECIMALS decimal places retained, and
grouping turned off. |
java.lang.String |
formatCurrency(float value,
int decimals)
Format a currency value according to the rules of the current locale, with the specified number of decimal places retained, and grouping turned off. |
java.lang.String |
formatCurrency(float value,
int decimals,
boolean grouping)
Format a currency value according to the rules of the current locale, with the specified number of decimal places retained, and the specified grouping policy. |
java.lang.String |
formatDate(java.util.Calendar date)
Format a date according to the rules of the current locale, with the default (medium) format length. |
java.lang.String |
formatDate(java.util.Date date)
Format a date according to the rules of the current locale, with the default (medium) format length. |
java.lang.String |
formatDate(java.util.Date date,
int type)
Format a date according to the rules of the current locale, with the specified format length. |
java.lang.String |
formatDateTime(java.util.Calendar date)
Format a date and time according to the rules of the current locale, with the default (medium) format length. |
java.lang.String |
formatDateTime(java.util.Date date)
Format a date and time according to the rules of the current locale, with the default (medium) format length. |
java.lang.String |
formatDateTime(java.util.Date date,
int type)
Format a date and time according to the rules of the current locale, with the specified format length. |
java.lang.String |
formatDecimal(double value)
Format a floating point value according to the rules of the current locale, with DEFAULT_NUMBER_DECIMALS decimal places
retained, and grouping turned off. |
java.lang.String |
formatDecimal(double value,
int decimals)
Format a floating point value according to the rules of the current locale, with the specified number of decimal places retained, and grouping turned off. |
java.lang.String |
formatDecimal(double value,
int decimals,
boolean grouping)
Format a floating point value according to the rules of the current locale, with the specified number of decimal places retained, and the specified grouping policy. |
java.lang.String |
formatDecimal(float value)
Format a floating point value according to the rules of the current locale, with DEFAULT_NUMBER_DECIMALS decimal places
retained, and grouping turned off. |
java.lang.String |
formatDecimal(float value,
int decimals)
Format a floating point value according to the rules of the current locale, with the specified number of decimal places retained, and grouping turned off. |
java.lang.String |
formatDecimal(float value,
int decimals,
boolean grouping)
Format a floating point value according to the rules of the current locale, with the specified number of decimal places retained, and the specified grouping policy. |
java.lang.String |
formatInteger(int value)
Format an integer value according to the rules of the current locale, with grouping turned off. |
java.lang.String |
formatInteger(int value,
boolean grouping)
Format an integer value according to the rules of the current locale, and the specified grouping policy. |
java.lang.String |
formatInteger(long value)
Format an integer value according to the rules of the current locale, with grouping turned off. |
java.lang.String |
formatInteger(long value,
boolean grouping)
Format an integer value according to the rules of the current locale, and the specified grouping policy. |
java.lang.String |
formatPercentage(double value)
Format a percentage value according to the rules of the current locale, with DEFAULT_PERCENTAGE_DECIMALS decimal places retained, and
grouping turned off. |
java.lang.String |
formatPercentage(double value,
int decimals)
Format a percentage value according to the rules of the current locale, with the specified number of decimal places retained, and grouping turned off. |
java.lang.String |
formatPercentage(double value,
int decimals,
boolean grouping)
Format a percentage value according to the rules of the current locale, with the specified number of decimal places retained, and the specified grouping policy. |
java.lang.String |
formatPercentage(float value)
Format a percentage value according to the rules of the current locale, with DEFAULT_PERCENTAGE_DECIMALS decimal places retained, and
grouping turned off. |
java.lang.String |
formatPercentage(float value,
int decimals)
Format a percentage value according to the rules of the current locale, with the specified number of decimal places retained, and grouping turned off. |
java.lang.String |
formatPercentage(float value,
int decimals,
boolean grouping)
Format a percentage value according to the rules of the current locale, with the specified number of decimal places retained, and the specified grouping policy. |
java.lang.String |
formatTime(java.util.Calendar date)
Format a time according to the rules of the current locale, with the default (medium) format length. |
java.lang.String |
formatTime(java.util.Date date)
Format a time according to the rules of the current locale, with the default (medium) format length. |
java.lang.String |
formatTime(java.util.Date date,
int type)
Format a time according to the rules of the current locale, with the specified format length. |
java.text.Collator |
getCollator()
Get an instance of the Collator object for the current
locale. |
java.text.DateFormatSymbols |
getDateFormatSymbols()
Get an instance of the DateFormatSymbols object for the
current locale. |
static LocaleManager |
getDefaultLocaleManager()
Get a reference to the default LocaleManager . |
java.util.Locale |
getLocale()
Get the default locale. |
LocaleData |
getLocaleData(java.lang.String name)
Retrieve the named resource bundle. |
static LocaleManager |
getLocaleManager()
Deprecated. Use getDefaultLocaleManager() instead. |
double |
parseCurrency(java.lang.String s)
Parse a currency value from a string using the rules of the current locale. |
java.util.Date |
parseDate(java.lang.String s)
Parse a date value from a string using the rules of the current locale, with the default (medium) format length. |
java.util.Date |
parseDate(java.lang.String s,
int type)
Parse a date value from a string using the rules of the current locale, with the specified format length. |
java.util.Date |
parseDateTime(java.lang.String s)
Parse a date and time value from a string using the rules of the current locale, with the default (medium) format length. |
java.util.Date |
parseDateTime(java.lang.String s,
int type)
Parse a date and time value from a string using the rules of the current locale, with the specified format length. |
double |
parseDecimal(java.lang.String s)
Parse a numeric value from a string using the rules of the current locale. |
long |
parseInteger(java.lang.String s)
Parse an integer value from a string using the rules of the current locale. |
double |
parsePercentage(java.lang.String s)
Parse a currency value from a string using the rules of the current locale. |
java.util.Date |
parseTime(java.lang.String s)
Parse a time value from a string using the rules of the current locale, with the default (medium) format length. |
java.util.Date |
parseTime(java.lang.String s,
int type)
Parse a time value from a string using the rules of the current locale, with the specified format length. |
void |
removeResourceManager(ResourceManager manager)
Unregister a ResourceManager from the locale manager. |
void |
setLocale(java.util.Locale locale)
Set the default locale. |
private void |
trapGarbage(java.lang.String s)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static LocaleManager defaultLocaleManager
private static java.text.Collator collator
private java.text.NumberFormat currencyFormat
private java.text.NumberFormat percentFormat
private java.text.NumberFormat decimalFormat
private java.text.NumberFormat integerFormat
private java.util.Vector resourceManagers
private static java.text.ParsePosition pos
private java.text.DateFormat[] dateFormat
private java.text.DateFormat[] timeFormat
private java.text.DateFormat[] dateTimeFormat
private int[] lengthTypes
private java.text.DateFormatSymbols dateFormatSymbols
public static final int DEFAULT_CURRENCY_DECIMALS
public static final int DEFAULT_PERCENTAGE_DECIMALS
public static final int DEFAULT_NUMBER_DECIMALS
Constructor Detail |
public LocaleManager(ResourceManager resourceManager)
LocaleManager
.
resourceManager
- The ResourceManager
that will be
used to load resource bundles.public LocaleManager()
LocaleManager
.
Method Detail |
public java.util.Locale getLocale()
LocaleManager
.public void setLocale(java.util.Locale locale)
Locale.setDefault()
(though it does call this method itself).
locale
- The new locale.public static LocaleManager getLocaleManager()
LocaleManager
.
public static LocaleManager getDefaultLocaleManager()
LocaleManager
.
LocaleManager
.public void addResourceManager(ResourceManager manager)
ResourceManager
with the locale manager. The
locale manager searches through all registered resource managers when
searching for a resource bundle. The Kiwi internal resource manager is
always registered.
manager
- The ResourceManager
to register.public void removeResourceManager(ResourceManager manager)
ResourceManager
from the locale manager. The
Kiwi internal resource manager is always registered and cannot be removed.
manager
- The ResourceManager
to unregister.public LocaleData getLocaleData(java.lang.String name) throws ResourceNotFoundException
LocaleData
object representing the specified
resource bundle.
java.util.ResourceNotFoundException
- If the specified bundle
could not be located by any of the registered resource managers.
ResourceNotFoundException
public java.lang.String formatDate(java.util.Calendar date)
date
- The date to format.
public java.lang.String formatDate(java.util.Date date)
date
- The date to format.
public java.lang.String formatDate(java.util.Date date, int type)
date
- The date to format.type
- The format length; one of the symbolic constants
SHORT
, MEDIUM
, or LONG
.
public java.lang.String formatTime(java.util.Calendar date)
date
- The date to format.
public java.lang.String formatTime(java.util.Date date)
date
- The date to format.
public java.lang.String formatTime(java.util.Date date, int type)
date
- The date to format.type
- The format length; one of the symbolic constants
SHORT
, MEDIUM
, or LONG
.
public java.lang.String formatDateTime(java.util.Calendar date)
date
- The date to format.
public java.lang.String formatDateTime(java.util.Date date)
date
- The date to format.
public java.lang.String formatDateTime(java.util.Date date, int type)
date
- The date to format.type
- The format length; one of the symbolic constants
SHORT
, MEDIUM
, or LONG
.
public java.util.Date parseDate(java.lang.String s) throws java.text.ParseException
s
- The string to parse.
Date
object.
java.text.ParseException
- If the value could not be parsed.public java.util.Date parseDate(java.lang.String s, int type) throws java.text.ParseException
s
- The string to parse.type
- The format length; one of the symbolic constants
SHORT
, MEDIUM
, or LONG
.
Date
object.
java.text.ParseException
- If the value could not be parsed.public java.util.Date parseTime(java.lang.String s) throws java.text.ParseException
s
- The string to parse.
Date
object.
java.text.ParseException
- If the value could not be parsed.public java.util.Date parseTime(java.lang.String s, int type) throws java.text.ParseException
s
- The string to parse.type
- The format length; one of the symbolic constants
SHORT
, MEDIUM
, or LONG
.
Date
object.
java.text.ParseException
- If the value could not be parsed.public java.util.Date parseDateTime(java.lang.String s) throws java.text.ParseException
s
- The string to parse.
Date
object.
java.text.ParseException
- If the value could not be parsed.public java.util.Date parseDateTime(java.lang.String s, int type) throws java.text.ParseException
s
- The string to parse.type
- The format length; one of the symbolic constants
SHORT
, MEDIUM
, or LONG
.
Date
object.
java.text.ParseException
- If the value could not be parsed.public java.lang.String formatCurrency(double value)
DEFAULT_CURRENCY_DECIMALS
decimal places retained, and
grouping turned off.
value
- The currency value to format.
public java.lang.String formatCurrency(double value, int decimals)
value
- The currency value to format.decimals
- The number of decimal places to retain.
public java.lang.String formatCurrency(double value, int decimals, boolean grouping)
value
- The currency value to format.decimals
- The number of decimal places to retain.grouping
- A flag specifying whether grouping should be used.
public java.lang.String formatCurrency(float value)
DEFAULT_CURRENCY_DECIMALS
decimal places retained, and
grouping turned off.
value
- The currency value to format.
public java.lang.String formatCurrency(float value, int decimals)
value
- The currency value to format.decimals
- The number of decimal places to retain.
public java.lang.String formatCurrency(float value, int decimals, boolean grouping)
value
- The currency value to format.decimals
- The number of decimal places to retain.grouping
- A flag specifying whether grouping should be used.
public double parseCurrency(java.lang.String s) throws java.text.ParseException
s
- The string to parse.
java.text.ParseException
- If the value could not be parsed.public java.lang.String formatPercentage(double value)
DEFAULT_PERCENTAGE_DECIMALS
decimal places retained, and
grouping turned off.
value
- The percentage value to format.
public java.lang.String formatPercentage(double value, int decimals)
value
- The percentage value to format.decimals
- The number of decimal places to retain.
public java.lang.String formatPercentage(double value, int decimals, boolean grouping)
value
- The percentage value to format.decimals
- The number of decimal places to retain.grouping
- A flag specifying whether grouping should be used.
public java.lang.String formatPercentage(float value)
DEFAULT_PERCENTAGE_DECIMALS
decimal places retained, and
grouping turned off.
value
- The percentage value to format.
public java.lang.String formatPercentage(float value, int decimals)
value
- The percentage value to format.decimals
- The number of decimal places to retain.
public java.lang.String formatPercentage(float value, int decimals, boolean grouping)
value
- The percentage value to format.decimals
- The number of decimal places to retain.grouping
- A flag specifying whether grouping should be used.
public double parsePercentage(java.lang.String s) throws java.text.ParseException
s
- The string to parse.
java.text.ParseException
- If the value could not be parsed.public java.lang.String formatInteger(int value)
value
- The integer value to format.
public java.lang.String formatInteger(long value)
value
- The integer value to format.
public java.lang.String formatInteger(int value, boolean grouping)
value
- The integer value to format.
public java.lang.String formatInteger(long value, boolean grouping)
value
- The integer value to format.
public long parseInteger(java.lang.String s) throws java.text.ParseException
s
- The string to parse.
java.text.ParseException
- If the value could not be parsed.public java.lang.String formatDecimal(double value)
DEFAULT_NUMBER_DECIMALS
decimal places
retained, and grouping turned off.
value
- The floating point value to format.
public java.lang.String formatDecimal(double value, int decimals)
value
- The floating point value to format.decimals
- The number of decimal places to retain.
public java.lang.String formatDecimal(double value, int decimals, boolean grouping)
value
- The floating point value to format.decimals
- The number of decimal places to retain.grouping
- A flag specifying whether grouping should be used.
public java.lang.String formatDecimal(float value)
DEFAULT_NUMBER_DECIMALS
decimal places
retained, and grouping turned off.
value
- The floating point value to format.
public java.lang.String formatDecimal(float value, int decimals)
value
- The floating point value to format.decimals
- The number of decimal places to retain.
public java.lang.String formatDecimal(float value, int decimals, boolean grouping)
value
- The floating point value to format.decimals
- The number of decimal places to retain.grouping
- A flag specifying whether grouping should be used.
public double parseDecimal(java.lang.String s) throws java.text.ParseException
s
- The string to parse.
java.text.ParseException
- If the value could not be parsed.public java.text.DateFormatSymbols getDateFormatSymbols()
DateFormatSymbols
object for the
current locale.
DateFormatSymbols
object.public java.text.Collator getCollator()
Collator
object for the current
locale.
Collator
object.private void trapGarbage(java.lang.String s) throws java.text.ParseException
java.text.ParseException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |