public final class CalendarText extends Object
Source for localized calendrical informations on enum basis like month or weekday names.
This class is a facade for an underlying implementation of
CalendarText.Provider which will be loaded as SPI-interface
by help of a ServiceLoader. If no such SPI-interface can be
found then this class will resort to the sources of JDK (usually
as wrapper around java.text.DateFormatSymbols).
Furthermore, an instance of CalendarText can also access
the UTF-8 text resources in the folder "data" relative to
the class path which are not based on JDK-defaults. In all ISO-systems
the "iso8601_{locale}.properties"-files will override the
JDK-defaults unless it is the ROOT-locale. Example:
If you wish to use the name "Sonnabend" instead of the standard word "Samstag" in german locale (english: Saturday) then you can copy the existing file "data/iso8601_de.properties" from the content of "time4j-core-v{version}.jar"-file into a new directory with the same path. Then you can insert these lines extra (all seven entries must be inserted, not just the sixth line):
DAY_OF_WEEK(WIDE)_1=Montag DAY_OF_WEEK(WIDE)_2=Dienstag DAY_OF_WEEK(WIDE)_3=Mittwoch DAY_OF_WEEK(WIDE)_4=Donnerstag DAY_OF_WEEK(WIDE)_5=Freitag DAY_OF_WEEK(WIDE)_6=Sonnabend DAY_OF_WEEK(WIDE)_7=Sonntag
The general format of these lines is:
{element-name}({text-width}[|STANDALONE])_{one-based-integer}={text}
STANDALONE is optional. As element name in the context of ISO-8601 following names are supported:
| Modifier and Type | Class and Description |
|---|---|
static class |
CalendarText.Accessor
Supplies an access to the internal name list of an enum-based
element value.
|
static interface |
CalendarText.Provider
This SPI-interface enables the access to calendrical
standard text informations and will be instantiated by a
ServiceLoader-mechanism. |
| Modifier and Type | Field and Description |
|---|---|
static String |
ISO_CALENDAR_TYPE
Default calendar type for all ISO systems.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
clearCache()
Clears the internal cache.
|
CalendarText.Accessor |
getEras(TextWidth textWidth)
Yields an
Accessor for all era names. |
static String |
getGMTPrefix(Locale locale)
Yields the localized GMT-prefix which is used in the
localized GMT format of CLDR.
|
static CalendarText |
getInstance(Chronology<?> chronology,
Locale locale)
Returns an instance of
CalendarText for given chronology
and language. |
static CalendarText |
getInstance(String calendarType,
Locale locale)
Returns an instance of
CalendarText for given calendar type
and language. |
CalendarText.Accessor |
getLeapMonths(TextWidth textWidth,
OutputContext outputContext)
Yields an
Accessor for all months if a leap month
is relevant. |
CalendarText.Accessor |
getMeridiems(TextWidth textWidth)
Yields an
Accessor for all am/pm-names. |
CalendarText.Accessor |
getQuarters(TextWidth textWidth,
OutputContext outputContext)
Yields an
Accessor for all quarter years. |
CalendarText.Accessor |
getStdMonths(TextWidth textWidth,
OutputContext outputContext)
Yields an
Accessor for all standard months. |
<V extends Enum<V>> |
getTextForms(ChronoElement<V> element,
String... variants)
Yields an
Accessor for all text forms of given
chronological element. |
CalendarText.Accessor |
getWeekdays(TextWidth textWidth,
OutputContext outputContext)
Yields an
Accessor for all weekday names. |
String |
toString()
Yields the name of the internal
CalendarText.Provider. |
public static final String ISO_CALENDAR_TYPE
Default calendar type for all ISO systems.
public static CalendarText getInstance(Chronology<?> chronology, Locale locale)
Returns an instance of CalendarText for given chronology
and language.
chronology - chronology (with calendar system)locale - languageCalendarText object maybe cachedpublic static CalendarText getInstance(String calendarType, Locale locale)
Returns an instance of CalendarText for given calendar type
and language.
calendarType - name of calendar systemlocale - languageCalendarText object maybe cachedCalendarTypepublic CalendarText.Accessor getStdMonths(TextWidth textWidth, OutputContext outputContext)
Yields an Accessor for all standard months.
The underlying list is sorted such that it will obey to the typical order of months in given calendar system. ISO-systems define January as first month and at whole 12 months. Other calendar systems can also define for example 13 months. The order of element value enums must be in agreement with the order of the text forms contained here.
The default implementation handles SHORT as synonym for ABBREVIATION in the context of ISO-8601.
textWidth - text width of displayed month nameoutputContext - output context (stand-alone?)Monthpublic CalendarText.Accessor getLeapMonths(TextWidth textWidth, OutputContext outputContext)
Yields an Accessor for all months if a leap month
is relevant.
Note: Leap months are defined in some calendar systems like the hebrew calendar ("Adar II") else there is no difference between standard and leap months escpecially not in ISO-8601.
textWidth - text width of displayed month nameoutputContext - output context (stand-alone?)Month,
getStdMonths(TextWidth, OutputContext)public CalendarText.Accessor getQuarters(TextWidth textWidth, OutputContext outputContext)
Yields an Accessor for all quarter years.
The underlying list of text forms is sorted in the same order
as the enum Quarter and uses its ordinal index as list
index. ISO systems define the range January-March as first quarter
etc. and at whole four quarters per calendar year.
The default implementation handles SHORT as synonym for ABBREVIATION in the context of ISO-8601.
textWidth - text width of displayed quarter nameoutputContext - output context (stand-alone?)Quarterpublic CalendarText.Accessor getWeekdays(TextWidth textWidth, OutputContext outputContext)
Yields an Accessor for all weekday names.
The underlying list of text forms is sorted such that the typical order of weekdays is used in given calendar system. ISO systems define Monday as first day of week and at whole 7 weekdays. This order is also valid for US in the context of this class although in US Sunday is considered as start of a week. The order element value enums must be in agreement with the order of text forms contained here.
textWidth - text width of displayed weekday nameoutputContext - output context (stand-alone?)Weekdaypublic CalendarText.Accessor getEras(TextWidth textWidth)
Yields an Accessor for all era names.
The underlying list of text forms is sorted such that the
typical order of eras is used in given calendar system. ISO systems
define era names based on their historical extensions (eras of
gregorian/historic calendar) because they themselves have no internal
concept of eras. The order of element value enums must be in agreement
with the text forms contained here. If an era is not defined on enum
basis then the format API will not evaluate this class but the
CalendarSystem to get the right text forms.
textWidth - text width of displayed era nameCalendarSystem.getEras()public CalendarText.Accessor getMeridiems(TextWidth textWidth)
Yields an Accessor for all am/pm-names.
The underlying list of text forms is sorted in AM-PM-order. The order of element value enums must be the same.
textWidth - text width of displayed AM/PM nameMeridiempublic <V extends Enum<V>> CalendarText.Accessor getTextForms(ChronoElement<V> element, String... variants)
Yields an Accessor for all text forms of given
chronological element.
Text forms might exist in different variations. In case of
enum-based variants the name of the enum (example "WIDE" in
the variant TextWidth) is to be used, in case of boolean-based
variants the literals "true" and "false" are to be
used.
While the methods getStdMonths(), getWeekdays()
etc.are mainly based on JDK-defaults, this method is escpecially
designed for querying chronological texts which are not contained in
JDK. Text forms will be stored internally in the resource folder
"data" relative to class path in properties-files using
UTF-8 encoding. The basic name of these resources is the calendar type.
The combination of element name and optionally variants in the form
"(variant1|variant2|...|variantN)" and the underscore and
finally a numerical suffix with base 1 serves as resource text key.
If there is no entry for given key in the resources then this method
will simply yield the name of enum value associated with given element
value.
V - generic type of element values based on enumselement - element text forms are searched forvariants - text form variants (optional)MissingResourceException - if for given calendar type there are
no text resource filespublic static String getGMTPrefix(Locale locale)
Yields the localized GMT-prefix which is used in the localized GMT format of CLDR.
locale - language and country configurationpublic String toString()
Yields the name of the internal CalendarText.Provider.
public static void clearCache()
Clears the internal cache.
This method should be called if the internal text resources have
changed and must be reloaded with a suitable ClassLoader.
Copyright © 2014. All rights reserved.