Class LcData


  • public class LcData
    extends java.lang.Object
    LcData defines locale data objects in support of localization. The source of the localized data was originally Java's JDK 1.4. However this has long since been converted to use Unicode's CLDR 1.3 data. CLDR data has been slightly modified to conform to XFA standards.

    The C++ implementation stores locale data in a static store. Alas, the Java compiler's 64K data limit precludes us from doing the same. Instead, the Java implementation stores locale data in properties files -- one for each supported locale.

    Here's a snippet of code illustrating the use of LcData to retrieve abbreviated month names, and retrieve a date format.

    
     
      
       import com.adobe.xfa.ut.LcData;
                    ...
       LcData data = new lcData("es_ES");
       String s = data.getAbbrMonthName(LcData.FEB);
       System.out.println(s);
       data = new lcData("pt_BR");
       s = data.getDateFormat(LcData.SHORT);
       System.out.println(s);
       
      
     

    Besides the static store, this class also maintains a more dynamic thread-local store. The application can provide its own locale data definitions to be stored in the runtime store. In general, when locale information is requested, the runtime store is searched first, then the static store. This happens on every single request, so if the runtime store changes between two calls on an LcData data instance, the two calls may return different results. In practice, LcData object have such limited lifespans that this doesn't become an issue.

    To populate the runtime store, the application calls method LcData.update() with an instance of the nested class LcDada.LcRunTimeData. This class contains several arrays of strings that hold locale information. A number of public static final int constants provided may be used as indexes into these arrays.

    • Constructor Detail

      • LcData

        public LcData​(java.lang.String locale)
        Instantiates an LcData object for the given locale.
        Parameters:
        locale - the locale name.
    • Method Detail

      • withWidth

        public static final int withWidth​(int width)
      • withPrecision

        public static final int withPrecision​(int prec)
      • getLocale

        public java.lang.String getLocale()
        Gets this LcData object's locale.
        Returns:
        Locale name (e.g., "ar_SA").
      • validate

        public static boolean validate​(LcData.LcRunTimeData oLcData)
        Validates the given runtime locale data. Applications should validate() the data before calling update().
        Parameters:
        oLcData - the some runtime locale data.
        Returns:
        Boolean true if valid and false otherwise.
      • reset

        public static void reset()
        Reset this class's runtime store of locale data to its internal defaults.
      • update

        public static void update​(LcData.LcRunTimeData oLcData)
        Updates (replaces) this class's runtime store of data for the given locale with the given locale data.
        Parameters:
        oLcData - the runtime locale data.
      • get

        public static LcData.LcRunTimeData get​(java.lang.String sLocale)
        Gets the locale data for the given locale from this class's runtime store.
        Parameters:
        sLocale - the locale name to search for.
        Returns:
        The runtime locale data if found and null otherwise.
      • getWeekDayName

        public java.lang.String getWeekDayName​(int weekday)
        Gets the name of the given day of the week.
        Parameters:
        weekday - the day of the week in the range of values 0-6, where (0 = Sunday).
        Returns:
        The weekday name, or the empty string upon error.
      • getAbbrWeekdayName

        public java.lang.String getAbbrWeekdayName​(int weekday)
        Gets the abbreviated name of the given day of the week.
        Parameters:
        weekday - the day of the week in the range of values 0-6, where (0 = Sunday).
        Returns:
        The abbreviated weekday name, or the empty string upon error.
      • getMonthName

        public java.lang.String getMonthName​(int month)
        Gets the name of the given month of the year.
        Parameters:
        month - the month of the year in the range of values 0-11, where (0 = January).
        Returns:
        The month name, or the empty string upon error.
      • getAbbrMonthName

        public java.lang.String getAbbrMonthName​(int month)
        Gets the abbreviated name of the given month of the year.
        Parameters:
        month - the month of the year in the range of values 0-11, where (0 = January).
        Returns:
        The abbreviated month name, or the empty string upon error.
      • getMeridiemName

        public java.lang.String getMeridiemName​(int aspect)
        Gets the name of the given aspect of the meridiem.
        Parameters:
        aspect - an aspect of the meridiem in the range of values 0-1, where (0 = AM, 1 = PM).
        Returns:
        The meridiem name, or the empty string upon error.
      • getEraName

        public java.lang.String getEraName​(int era)
        Gets the name of the given era.
        Parameters:
        era - an era of the calendar in the range of values 0-1, where (0 = BC, 1 = AD).
        Returns:
        The era name, or the empty string upon error.
      • getDateFormat

        public java.lang.String getDateFormat​(int style)
        Gets the date format in the given style.
        Parameters:
        style - the style of the format in the range of values 0-4, where (0 = default, 1 = short, 2 = medium, 3 = long, 4 = full).
        Returns:
        The date format.
      • getTimeFormat

        public java.lang.String getTimeFormat​(int style)
        Gets the time format in the given style.
        Parameters:
        style - the style of the format in the range of values 0-4, where (0 = default, 1 = short, 2 = medium, 3 = long, 4 = full).
        Returns:
        The time format.
      • getDateTimePattern

        public java.lang.String getDateTimePattern()
        Gets the date time pattern.
        Returns:
        The date time pattern.
      • getDateTimeFormat

        public java.lang.String getDateTimeFormat​(int style,
                                                  int type)
        Gets the datetime format in the given style.
        Parameters:
        style - the style of the format in the range of values 0-4, where (0 = default, 1 = short, 2 = medium, 3 = long, 4 = full).
        type - the type of the format in the range of values 0-1, where (0 = w/o picture categories, 1 = w picture categories).
        Returns:
        The date time format.
      • getLocalDateFormat

        public java.lang.String getLocalDateFormat​(int style)
        Gets the local date format in the given style.
        Parameters:
        style - the style of the format in the range of values 0-4, where (0 = default, 1 = short, 2 = medium, 3 = long, 4 = full).
        Returns:
        The date format.
      • getLocalTimeFormat

        public java.lang.String getLocalTimeFormat​(int style)
        Gets the local time format in the given style.
        Parameters:
        style - the style of the format in the range of values 0-4, where (0 = default, 1 = short, 2 = medium, 3 = long, 4 = full).
        Returns:
        The time format.
      • getLocalDateTimeFormat

        public java.lang.String getLocalDateTimeFormat()
        Gets the local datetime format.

        This method is not functional yet.

        Returns:
        The date time format.
      • getNumericFormat

        public java.lang.String getNumericFormat​(int style)
        Gets the numeric format in the given style.
        Parameters:
        style - the style of the format in the range of values 0-2, where (0 = number, 1 = currency, 2 = percentage).
        Returns:
        The numeric format.
      • getNumberFormat

        public java.lang.String getNumberFormat​(int style,
                                                int option)
        Gets the number format in the given style.
        Parameters:
        style - in the range of values 0-2, where (0 = integral, 1 = decimal, 2 = currency).
        option - in the set of format options:
      • bit 1: reset => w/o commas; set => w/ commas.
      • bit 2: reset => w/ fractional z's; set => w/ fractional 8's.
      • bit 4: reset => w/o radix; set => w/ radix.
      • bit 8-15: the precision.
      • bit 16: reset => keep precision; set => trim precision.
      • bit 17-24: the width.
      • getNumberPrecision

        public int getNumberPrecision​(java.lang.String sVal)
        Gets the decimal precision of the given numeric string.
        Returns:
        The decimal precision or 0 for integral values.
      • getCurrencyName

        public java.lang.String getCurrencyName()
        Gets the name of the currency.
        Returns:
        The currency name or the empty string upon error.
      • getCurrencySymbol

        public java.lang.String getCurrencySymbol()
        Gets the symbol of the currency.
        Returns:
        The currency symbol or the empty string upon error.
      • getCurrencyRadix

        public java.lang.String getCurrencyRadix()
        Gets the radix of the currency.
        Returns:
        The currency radix or the empty string upon error.
      • getRadixSymbol

        public java.lang.String getRadixSymbol()
        Gets the radix symbol.
        Returns:
        The radix symbol or the empty string upon error.
      • getGroupingSymbol

        public java.lang.String getGroupingSymbol()
        Gets the grouping symbol.
        Returns:
        The grouping symbol or the empty string upon error.
      • getPercentSymbol

        public java.lang.String getPercentSymbol()
        Gets the percent symbol.
        Returns:
        The percent symbol or the empty string upon error.
      • getTypefaces

        public java.util.List<java.lang.String> getTypefaces()
        Gets the list of typefaces.
        Returns:
        The list of typefaces which is possibly empty upon error.
      • getNegativeSymbol

        public java.lang.String getNegativeSymbol()
        Gets the negative symbol.
        Returns:
        The negative symbol or the empty string upon error.
      • getZeroSymbol

        public java.lang.String getZeroSymbol()
        Gets the native zero digit symbol.
        Returns:
        The zero symbol or the empty string upon error.
      • getPositiveSymbol

        public java.lang.String getPositiveSymbol()
        Gets the positive symbol.
        Returns:
        The positive symbol or the empty string upon error.
      • getLocaleNames

        public static void getLocaleNames​(java.util.List<java.lang.String> oLocales)
        Gets all the supported locale names.
        Parameters:
        oLocales - the List object to be populated with the name of all the locales for which we have data.
      • findMatchingLocale

        public static java.lang.String findMatchingLocale​(java.lang.String sCurrencySymbol,
                                                          java.lang.String sRadixSymbol,
                                                          java.lang.String sGroupingSymbol)
        Finds a locale who's currency, radix and grouping symbols match all of the given symbols.
        Parameters:
        sCurrencySymbol - the currency symbol to match.
        sRadixSymbol - the decimal radix symbol to match.
        sGroupingSymbol - the grouping separator symbol to match.
        Returns:
        The matching locale name or the empty string upon failure.