| java.lang.Object com.ibm.icu.util.GlobalizationPreferences
GlobalizationPreferences | public class GlobalizationPreferences implements Freezable(Code) | | This convenience class provides a mechanism for bundling together different
globalization preferences. It includes:
- A list of locales/languages in preference order
- A territory
- A currency
- A timezone
- A calendar
- A collator (for language-sensitive sorting, searching, and matching).
- Explicit overrides for date/time formats, etc.
The class will heuristically compute implicit, heuristic values for the above
based on available data if explicit values are not supplied. These implicit
values can be presented to users for confirmation, or replacement if the
values are incorrect.
To reset any explicit field so that it will get heuristic values, pass in
null. For example, myPreferences.setLocale(null);
All of the heuristics can be customized by subclasses, by overriding
getTerritory(), guessCollator(), etc.
The class also supplies display names for languages, scripts, territories,
currencies, timezones, etc. These are computed according to the
locale/language preference list. Thus, if the preference is Breton; French;
English, then the display name for a language will be returned in Breton if
available, otherwise in French if available, otherwise in English.
The codes used to reference territory, currency, etc. are as defined elsewhere
in ICU, and are taken from CLDR (which reflects RFC 3066bis usage, ISO 4217,
and the TZ Timezone database identifiers).
This is at a prototype stage, and has not incorporated all the design
changes that we would like yet; further feedback is welcome.
TODO:
- Add Holidays
- Add convenience to get/take Locale as well as ULocale.
- Add Lenient datetime formatting when that is available.
- Should this be serializable?
- Other utilities?
Note:
- to get the display name for the first day of the week, use the calendar +
display names.
- to get the work days, ask the calendar (when that is available).
- to get papersize / measurement system/bidi-orientation, ask the locale
(when that is available there)
- to get the field order in a date, and whether a time is 24hour or not,
ask the DateFormat (when that is available there)
- it will support HOST locale when it becomes available (it is a special
locale that will ask the services to use the host platform's values).
|
Method Summary | |
public Object | cloneAsThawed() | public Object | freeze() | public BreakIterator | getBreakIterator(int type) Get a copy of the break iterator for the specified type according to the
settings. | public Calendar | getCalendar() Get a copy of the calendar according to the settings. | public Collator | getCollator() Get a copy of the collator according to the settings. | public Currency | getCurrency() Get a copy of the currency computed according to the settings. | public DateFormat | getDateFormat(int dateStyle, int timeStyle) Gets a date format according to the current settings. | public String | getDisplayName(String id, int type) Get the display name for an ID: language, script, territory, currency, timezone...
Uses the language priority list to do so.
Parameters: id - language code, script code, ... Parameters: type - specifies the type of the ID: ID_LANGUAGE, etc. | public ULocale | getLocale(int index) Convenience function for getting the locales in priority order
Parameters: index - The index (0..n) of the desired item. | public List | getLocales() | public NumberFormat | getNumberFormat(int style) Gets a number format according to the current settings. | public ResourceBundle | getResourceBundle(String baseName) Convenience function to get a ResourceBundle instance using
the specified base name based on the language/locale priority list
stored in this object. | public ResourceBundle | getResourceBundle(String baseName, ClassLoader loader) Convenience function to get a ResourceBundle instance using
the specified base name and class loader based on the language/locale
priority list stored in this object. | public String | getTerritory() Gets the territory setting. | public TimeZone | getTimeZone() Get the timezone. | protected BreakIterator | guessBreakIterator(int type) This function can be overridden by subclasses to use different heuristics. | protected Calendar | guessCalendar() This function can be overridden by subclasses to use different heuristics. | protected Collator | guessCollator() This function can be overridden by subclasses to use different heuristics. | protected Currency | guessCurrency() | protected DateFormat | guessDateFormat(int dateStyle, int timeStyle) This function can be overridden by subclasses to use different heuristics. | protected List | guessLocales() | protected NumberFormat | guessNumberFormat(int style) This function can be overridden by subclasses to use different heuristics. | protected String | guessTerritory() This function can be overridden by subclasses to use different heuristics. | protected TimeZone | guessTimeZone() This function can be overridden by subclasses to use different heuristics. | public boolean | isFrozen() | protected List | processLocales(List inputLocales) Process a language/locale priority list specified via setLocales .
The input locale list may be expanded or re-ordered to represent the prioritized
language/locale order actually used by this object by the algorithm exaplained
below.
Step 1: Move later occurence of more specific locale before ealier occurence of less
specific locale.
Before: en, fr_FR, en_US, en_GB
After: en_US, en_GB, en, fr_FR
Step 2: Append a fallback locale to each locale.
Before: en_US, en_GB, en, fr_FR
After: en_US, en, en_GB, en, en, fr_FR, fr
Step 3: Remove ealier occurence of duplicated locale entries.
Before: en_US, en, en_GB, en, en, fr_FR, fr
After: en_US, en_GB, en, fr_FR, fr
The final locale list is used to produce a default value for the appropriate territory,
currency, timezone, etc. | public GlobalizationPreferences | reset() Restore the object to the initial state. | public GlobalizationPreferences | setBreakIterator(int type, BreakIterator iterator) Explicitly set the break iterator for this object. | public GlobalizationPreferences | setCalendar(Calendar calendar) Sets the calendar. | public GlobalizationPreferences | setCollator(Collator collator) Explicitly set the collator for this object. | public GlobalizationPreferences | setCurrency(Currency currency) Sets the currency code. | public GlobalizationPreferences | setDateFormat(int dateStyle, int timeStyle, DateFormat format) Set an explicit date format. | public GlobalizationPreferences | setLocale(ULocale uLocale) Convenience routine for setting the language/locale priority
list from a single locale/language. | public GlobalizationPreferences | setLocales(List inputLocales) Sets the language/locale priority list. | public GlobalizationPreferences | setLocales(ULocale[] uLocales) Convenience routine for setting the language/locale priority
list from an array. | public GlobalizationPreferences | setLocales(String acceptLanguageString) Convenience routine for setting the locale priority list from
an Accept-Language string. | public GlobalizationPreferences | setNumberFormat(int style, NumberFormat format) Sets a number format explicitly. | public GlobalizationPreferences | setTerritory(String territory) Sets the territory, which is a valid territory according to for
RFC 3066 (or successor). | public GlobalizationPreferences | setTimeZone(TimeZone timezone) Sets the timezone ID. |
BI_CHARACTERBI_WORDBI_LINEBI_SENTENCEBI_TITLE | final public static int BI_CHARACTERBI_WORDBI_LINEBI_SENTENCEBI_TITLE(Code) | | Break iterator types
|
DF_FULLDF_LONGDF_MEDIUMDF_SHORTDF_NONE | final public static int DF_FULLDF_LONGDF_MEDIUMDF_SHORTDF_NONE(Code) | | Date Format types
|
ID_LOCALEID_LANGUAGEID_SCRIPTID_TERRITORYID_VARIANTID_KEYWORDID_KEYWORD_VALUEID_CURRENCYID_CURRENCY_SYMBOLID_TIMEZONE | final public static int ID_LOCALEID_LANGUAGEID_SCRIPTID_TERRITORYID_VARIANTID_KEYWORDID_KEYWORD_VALUEID_CURRENCYID_CURRENCY_SYMBOLID_TIMEZONE(Code) | | For selecting a choice of display names
|
NF_NUMBERNF_CURRENCYNF_PERCENTNF_SCIENTIFICNF_INTEGER | final public static int NF_NUMBERNF_CURRENCYNF_PERCENTNF_SCIENTIFICNF_INTEGER(Code) | | Number Format types
|
territory_tzid_hack | final static String[][] territory_tzid_hack(Code) | | |
territory_tzid_hack_map | final static Map territory_tzid_hack_map(Code) | | |
GlobalizationPreferences | public GlobalizationPreferences()(Code) | | Default constructor
|
getBreakIterator | public BreakIterator getBreakIterator(int type)(Code) | | Get a copy of the break iterator for the specified type according to the
settings.
Parameters: type - break type - BI_CHARACTER or BI_WORD, BI_LINE, BI_SENTENCE, BI_TITLE break iterator explicit or implicit |
getCalendar | public Calendar getCalendar()(Code) | | Get a copy of the calendar according to the settings.
calendar explicit or implicit. |
getCollator | public Collator getCollator()(Code) | | Get a copy of the collator according to the settings.
collator explicit or implicit. |
getCurrency | public Currency getCurrency()(Code) | | Get a copy of the currency computed according to the settings.
currency code, explicit or implicit. |
getDateFormat | public DateFormat getDateFormat(int dateStyle, int timeStyle)(Code) | | Gets a date format according to the current settings. If there
is an explicit (non-null) date/time format set, a copy of that
is returned. Otherwise, the language priority list is used.
DF_NONE should be used for the style, where only the date or
time format individually is being gotten.
Parameters: dateStyle - DF_FULL, DF_LONG, DF_MEDIUM, DF_SHORT or DF_NONE Parameters: timeStyle - DF_FULL, DF_LONG, DF_MEDIUM, DF_SHORT or DF_NONE a DateFormat, according to the above description |
getDisplayName | public String getDisplayName(String id, int type)(Code) | | Get the display name for an ID: language, script, territory, currency, timezone...
Uses the language priority list to do so.
Parameters: id - language code, script code, ... Parameters: type - specifies the type of the ID: ID_LANGUAGE, etc. the display name |
getLocale | public ULocale getLocale(int index)(Code) | | Convenience function for getting the locales in priority order
Parameters: index - The index (0..n) of the desired item. desired item. null if index is out of range |
getLocales | public List getLocales()(Code) | | Get a copy of the language/locale priority list
a copy of the language/locale priority list. |
getNumberFormat | public NumberFormat getNumberFormat(int style)(Code) | | Gets a number format according to the current settings. If
there is an explicit (non-null) number format set, a copy of
that is returned. Otherwise, the language priority list is
used.
Parameters: style - NF_NUMBER, NF_CURRENCY, NF_PERCENT, NF_SCIENTIFIC, NF_INTEGER |
getResourceBundle | public ResourceBundle getResourceBundle(String baseName)(Code) | | Convenience function to get a ResourceBundle instance using
the specified base name based on the language/locale priority list
stored in this object.
Parameters: baseName - the base name of the resource bundle, a fully qualifiedclass name a resource bundle for the given base name and locale based on thelanguage/locale priority list stored in this object |
getResourceBundle | public ResourceBundle getResourceBundle(String baseName, ClassLoader loader)(Code) | | Convenience function to get a ResourceBundle instance using
the specified base name and class loader based on the language/locale
priority list stored in this object.
Parameters: baseName - the base name of the resource bundle, a fully qualifiedclass name Parameters: loader - the class object from which to load the resource bundle a resource bundle for the given base name and locale based on thelanguage/locale priority list stored in this object |
getTerritory | public String getTerritory()(Code) | | Gets the territory setting. If it wasn't explicitly set, it is
computed from the general locale setting.
territory code, explicit or implicit. |
getTimeZone | public TimeZone getTimeZone()(Code) | | Get the timezone. It was either explicitly set, or is
heuristically computed from other settings.
timezone, either implicitly or explicitly set |
guessBreakIterator | protected BreakIterator guessBreakIterator(int type)(Code) | | This function can be overridden by subclasses to use different heuristics.
It MUST return a 'safe' value,
one whose modification will not affect this object.
Parameters: type - |
guessCalendar | protected Calendar guessCalendar()(Code) | | This function can be overridden by subclasses to use different heuristics.
It MUST return a 'safe' value,
one whose modification will not affect this object.
|
guessCollator | protected Collator guessCollator()(Code) | | This function can be overridden by subclasses to use different heuristics.
It MUST return a 'safe' value,
one whose modification will not affect this object.
|
guessCurrency | protected Currency guessCurrency()(Code) | | This function can be overridden by subclasses to use different heuristics
|
guessDateFormat | protected DateFormat guessDateFormat(int dateStyle, int timeStyle)(Code) | | This function can be overridden by subclasses to use different heuristics.
It MUST return a 'safe' value,
one whose modification will not affect this object.
Parameters: dateStyle - Parameters: timeStyle - |
guessLocales | protected List guessLocales()(Code) | | This function can be overridden by subclasses to use different heuristics
It MUST return a 'safe' value,
one whose modification will not affect this object.
|
guessNumberFormat | protected NumberFormat guessNumberFormat(int style)(Code) | | This function can be overridden by subclasses to use different heuristics.
It MUST return a 'safe' value,
one whose modification will not affect this object.
Parameters: style - |
guessTerritory | protected String guessTerritory()(Code) | | This function can be overridden by subclasses to use different heuristics.
|
guessTimeZone | protected TimeZone guessTimeZone()(Code) | | This function can be overridden by subclasses to use different heuristics.
It MUST return a 'safe' value,
one whose modification will not affect this object.
|
isFrozen | public boolean isFrozen()(Code) | | |
processLocales | protected List processLocales(List inputLocales)(Code) | | Process a language/locale priority list specified via setLocales .
The input locale list may be expanded or re-ordered to represent the prioritized
language/locale order actually used by this object by the algorithm exaplained
below.
Step 1: Move later occurence of more specific locale before ealier occurence of less
specific locale.
Before: en, fr_FR, en_US, en_GB
After: en_US, en_GB, en, fr_FR
Step 2: Append a fallback locale to each locale.
Before: en_US, en_GB, en, fr_FR
After: en_US, en, en_GB, en, en, fr_FR, fr
Step 3: Remove ealier occurence of duplicated locale entries.
Before: en_US, en, en_GB, en, en, fr_FR, fr
After: en_US, en_GB, en, fr_FR, fr
The final locale list is used to produce a default value for the appropriate territory,
currency, timezone, etc. The list also represents the lookup order used in
getResourceBundle for this object. A subclass may override this method
to customize the algorithm used for populating the locale list.
Parameters: inputLocales - The list of input locales |
setBreakIterator | public GlobalizationPreferences setBreakIterator(int type, BreakIterator iterator)(Code) | | Explicitly set the break iterator for this object.
Parameters: type - break type - BI_CHARACTER or BI_WORD, BI_LINE, BI_SENTENCE, BI_TITLE Parameters: iterator - a break iterator this, for chaining |
setCalendar | public GlobalizationPreferences setCalendar(Calendar calendar)(Code) | | Sets the calendar. If this has not been set, uses default for territory.
Parameters: calendar - arbitrary calendar this, for chaining |
setCurrency | public GlobalizationPreferences setCurrency(Currency currency)(Code) | | Sets the currency code. If this has not been set, uses default for territory.
Parameters: currency - Valid ISO 4217 currency code. this, for chaining |
setDateFormat | public GlobalizationPreferences setDateFormat(int dateStyle, int timeStyle, DateFormat format)(Code) | | Set an explicit date format. Overrides the locale priority list for
a particular combination of dateStyle and timeStyle. DF_NONE should
be used if for the style, where only the date or time format individually
is being set.
Parameters: dateStyle - DF_FULL, DF_LONG, DF_MEDIUM, DF_SHORT or DF_NONE Parameters: timeStyle - DF_FULL, DF_LONG, DF_MEDIUM, DF_SHORT or DF_NONE Parameters: format - The date format this, for chaining |
setLocales | public GlobalizationPreferences setLocales(List inputLocales)(Code) | | Sets the language/locale priority list. If other information is
not (yet) available, this is used to to produce a default value
for the appropriate territory, currency, timezone, etc. The
user should be given the opportunity to correct those defaults
in case they are incorrect.
Parameters: inputLocales - list of locales in priority order, eg {"be", "fr"} for Breton first, then French if that fails. this, for chaining |
setNumberFormat | public GlobalizationPreferences setNumberFormat(int style, NumberFormat format)(Code) | | Sets a number format explicitly. Overrides the general locale settings.
Parameters: style - NF_NUMBER, NF_CURRENCY, NF_PERCENT, NF_SCIENTIFIC, NF_INTEGER Parameters: format - The number format this, for chaining |
setTerritory | public GlobalizationPreferences setTerritory(String territory)(Code) | | Sets the territory, which is a valid territory according to for
RFC 3066 (or successor). If not otherwise set, default
currency and timezone values will be set from this. The user
should be given the opportunity to correct those defaults in
case they are incorrect.
Parameters: territory - code this, for chaining |
setTimeZone | public GlobalizationPreferences setTimeZone(TimeZone timezone)(Code) | | Sets the timezone ID. If this has not been set, uses default for territory.
Parameters: timezone - a valid TZID (see UTS#35). this, for chaining |
|
|