Package com.ibm.icu.util

Examples of com.ibm.icu.util.ULocale$JDKLocaleHelper


        columnDescriptions.add(new ColumnDescription("B", ValueType.TIMEOFDAY, "B"));
        TimeOfDayValue hindiTimeOfDayValue = new TimeOfDayValue(1, 12, 1);
        String hindiTimeOfDayString = "\u0966\u0967\u003a\u0967\u0968\u003a\u0966\u0967";
        Reader reader = new StringReader("1," + hindiTimeOfDayString);
        DataTable dataTable = CsvDataSourceHelper.read(reader, columnDescriptions, false,
                new ULocale("hi_IN"));
        assertEquals(1, dataTable.getNumberOfRows());
        assertEquals(2, dataTable.getNumberOfColumns());
        assertEquals(new NumberValue(1), dataTable.getRow(0).getCell(0).getValue());
        assertEquals(hindiTimeOfDayValue, dataTable.getRow(0).getCell(1).getValue());
    }
View Full Code Here


        assertNotNull(ValueFormatter.createDefault(ValueType.DATE, null));
        assertNotNull(ValueFormatter.createDefault(ValueType.DATETIME, null));
        assertNotNull(ValueFormatter.createDefault(ValueType.TIMEOFDAY, null));
        assertNotNull(ValueFormatter.createDefault(ValueType.TEXT, null));

        ULocale ulocale = ULocale.ENGLISH;
        ULocale ulocale1 = ULocale.CANADA_FRENCH;

        assertEquals(ulocale,
                ValueFormatter.createFromPattern(ValueType.NUMBER, "", ulocale).getLocale());
        assertEquals(ulocale1,
                ValueFormatter.createDefault(ValueType.NUMBER, ulocale1).getLocale());
View Full Code Here

        assertEquals(ulocale1,
                ValueFormatter.createDefault(ValueType.NUMBER, ulocale1).getLocale());
    }

    public void testAFewMoreCases() {
        ULocale ulocale = ULocale.ENGLISH;

        // Create a ValueFormatter for each type
        ValueFormatter booleanFormatter = ValueFormatter.createFromPattern(
                ValueType.BOOLEAN, null, ulocale);
        assertNotNull(booleanFormatter);
View Full Code Here

    // Some locales use localized digits and so even a simple pattern will be formatted
    // differently than in English.
    // The following is a simple example for Hindi.
    public void testHindiLocale() {
        ValueFormatter dateFormatter = ValueFormatter.createFromPattern(
                ValueType.DATE, "MM | dd | yyyy", new ULocale("hi_IN"));
        DateValue dateValue = new DateValue(2009, 1, 2);
        String dateString =
                "\u0966\u0968\u0020\u007c\u0020\u0966\u0968\u0020\u007c\u0020\u0968\u0966\u0966\u096f";
        assertEquals(dateString, dateFormatter.format(dateValue));
        assertEquals(dateValue, dateFormatter.parse(dateString));
View Full Code Here

     * @throws InvalidQueryException Thrown if the column is invalid.
     */
    @Override
    public void validateColumn(DataTable dataTable) throws InvalidQueryException {
        ValueType valueType = dataTable.getColumnDescription(aggregatedColumn.getId()).getType();
        ULocale userLocale = dataTable.getLocaleForUserMessages();
        switch(aggregationType) {
            case COUNT:
            case MAX:
            case MIN:
                break;
View Full Code Here

   
    ArrayList<ULocale> ulocales = new ArrayList<ULocale>();
    for (String locale:locales){
      if (locale != null){
        try {
          ULocale ulocale = ULocale.forLanguageTag(locale);
          if (!ulocale.getLanguage().equals(""))
            ulocales.add(ulocale);
        } catch (Exception e) {
          // There can be intermittent problems with the internal
          // functioning of the ULocale class with some
          // language tags; best to just log these and continue
View Full Code Here

   * @return true if a valid language tag, otherwise false
   */
  public static boolean isValidLanguageTag(String tag){
    try {
      if (tag.equals("x-w3c-test")) return true; // hack for testing :(
      ULocale locale = ULocale.forLanguageTag(tag);
      if (locale.toLanguageTag() == null) return false;
      // We don't accept "x" extensions (private use tags)
      if(locale.getExtension("x".charAt(0))!=null) return false;
      if (!locale.toLanguageTag().equalsIgnoreCase(tag)) return false;
      return true;
    } catch (Exception e) {
      return false;
    }
  }
View Full Code Here

            languageCode = "";
            countryCode = "";
            variantCode = variant;
            return;
        }
        this.uLocale = new ULocale(language, country, variant);
        languageCode = uLocale.getLanguage();
        // Map new language codes to the obsolete language
        // codes so the correct resource bundles will be used.
        if (languageCode.equals("he")) {//$NON-NLS-1$
            languageCode = "iw"; //$NON-NLS-1$
View Full Code Here

        // setLocales(ULocale[])
        logln("Call setLocales(ULocale[]) after frozen");
        bSet = true;
        try {
            gp.setLocales(new ULocale[] {new ULocale("fr_FR")});
        } catch (UnsupportedOperationException uoe) {
            bSet = false;
        }
        if (bSet) {
            errln("FAIL: setLocales(ULocale[]) must be blocked after frozen");
        }

        // setLocales(ULocale[])
        logln("Call setLocales(List) after frozen");
        bSet = true;
        ArrayList list = new ArrayList(1);
        list.add(new ULocale("fr_FR"));
        try {
            gp.setLocales(list);
        } catch (UnsupportedOperationException uoe) {
            bSet = false;
        }
        if (bSet) {
            errln("FAIL: setLocales(List) must be blocked after frozen");
        }

        // setLocales(String)
        logln("Call setLocales(String) after frozen");
        bSet = true;
        try {
            gp.setLocales("pt-BR,es;q=0.7");
        } catch (UnsupportedOperationException uoe) {
            bSet = false;
        }
        if (bSet) {
            errln("FAIL: setLocales(String) must be blocked after frozen");
        }

        // setLocale(ULocale)
        logln("Call setLocale(ULocale) after frozen");
        bSet = true;
        try {
            gp.setLocale(new ULocale("fi_FI"));
        } catch (UnsupportedOperationException uoe) {
            bSet = false;
        }
        if (bSet) {
            errln("FAIL: setLocale(ULocale) must be blocked after frozen");
        }
       
        // setTerritory(String)
        logln("Call setTerritory(String) after frozen");
        bSet = true;
        try {
            gp.setTerritory("AU");
        } catch (UnsupportedOperationException uoe) {
            bSet = false;
        }
        if (bSet) {
            errln("FAIL: setTerritory(String) must be blocked after frozen");
        }

        // Modifiable clone
        logln("Create a modifiable clone");
        GlobalizationPreferences gp1 = (GlobalizationPreferences)gp.cloneAsThawed();

        if (gp1.isFrozen()) {
            errln("FAIL: The object returned by cloneAsThawed() must not be frozen yet");
        }       

        // setLocale(ULocale)
        logln("Call setLocale(ULocale) of the modifiable clone");
        bSet = true;
        try {
            gp1.setLocale(new ULocale("fr_FR"));
        } catch (UnsupportedOperationException uoe) {
            bSet = false;
        }
        if (!bSet) {
            errln("FAIL: setLocales(ULocale) must not throw an exception before frozen");
View Full Code Here

        for (int i = 0; i < INPUT_LOCALEIDS.length; i++) {
            String[] localeStrings = INPUT_LOCALEIDS[i];
            ArrayList locales = new ArrayList();
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < localeStrings.length; j++) {
                locales.add(new ULocale(localeStrings[j]));
                if (j != 0) {
                    sb.append(", ");
                }
                sb.append(localeStrings[j]);
            }
            logln("Input locales: " + sb.toString());
           
            gp.reset();
            gp.setLocales(locales);

            List resultLocales = gp.getLocales();
            if (resultLocales.size() != RESULTS_LOCALEIDS[i].length) {
                errln("FAIL: Number of locales mismatch - GP:" + resultLocales.size()
                        + " Expected:" + RESULTS_LOCALEIDS[i].length);
            } else {
               
                for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
                    ULocale loc = gp.getLocale(j);
                    logln("Locale[" + j + "]: " + loc.toString());
                    if (!gp.getLocale(j).toString().equals(RESULTS_LOCALEIDS[i][j])) {
                        errln("FAIL: Locale index(" + j + ") does not match - GP:" + loc.toString()
                                + " Expected:" + RESULTS_LOCALEIDS[i][j]);
                    }
                }   
            }
        }
       
        // setLocales(ULocale[])
        for (int i = 0; i < INPUT_LOCALEIDS.length; i++) {
            String[] localeStrings = INPUT_LOCALEIDS[i];
            ULocale[] localeArray = new ULocale[INPUT_LOCALEIDS[i].length];
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < localeStrings.length; j++) {
                localeArray[j] = new ULocale(localeStrings[j]);
                if (j != 0) {
                    sb.append(", ");
                }
                sb.append(localeStrings[j]);
            }
            logln("Input locales: " + sb.toString());
           
            gp.reset();
            gp.setLocales(localeArray);

            List resultLocales = gp.getLocales();
            if (resultLocales.size() != RESULTS_LOCALEIDS[i].length) {
                errln("FAIL: Number of locales mismatch - GP:" + resultLocales.size()
                        + " Expected:" + RESULTS_LOCALEIDS[i].length);
            } else {
               
                for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
                    ULocale loc = gp.getLocale(j);
                    logln("Locale[" + j + "]: " + loc.toString());
                    if (!gp.getLocale(j).toString().equals(RESULTS_LOCALEIDS[i][j])) {
                        errln("FAIL: Locale index(" + j + ") does not match - GP:" + loc.toString()
                                + " Expected:" + RESULTS_LOCALEIDS[i][j]);
                    }
                }   
            }
        }

        // setLocales(String)
        for (int i = 0; i < ACCEPT_LANGUAGES.length; i++) {
            String acceptLanguage = ACCEPT_LANGUAGES[i];
            logln("Accept language: " + acceptLanguage);
           
            gp.reset();
            gp.setLocales(acceptLanguage);

            List resultLocales = gp.getLocales();
            if (resultLocales.size() != RESULTS_LOCALEIDS[i].length) {
                errln("FAIL: Number of locales mismatch - GP:" + resultLocales.size()
                        + " Expected:" + RESULTS_LOCALEIDS[i].length);
            } else {
               
                for (int j = 0; j < RESULTS_LOCALEIDS[i].length; j++) {
                    ULocale loc = gp.getLocale(j);
                    logln("Locale[" + j + "]: " + loc.toString());
                    if (!gp.getLocale(j).toString().equals(RESULTS_LOCALEIDS[i][j])) {
                        errln("FAIL: Locale index(" + j + ") does not match - GP:" + loc.toString()
                                + " Expected:" + RESULTS_LOCALEIDS[i][j]);
                    }
                }   
            }
        }


        // accept-language without q-value
        logln("Set accept-language - de,de-AT");
        gp.setLocales("de,de-AT");
        if (!gp.getLocale(0).toString().equals("de_AT")) {
            errln("FAIL: getLocale(0) returns " + gp.getLocale(0).toString() + " Expected: de_AT");
        }
       
        // Invalid accept-language
        logln("Set locale - ko_KR");
        gp.setLocale(new ULocale("ko_KR"));
        boolean bException = false;
        try {
            logln("Set invlaid accept-language - ko=100");
            gp.setLocales("ko=100");
        } catch (IllegalArgumentException iae) {
View Full Code Here

TOP

Related Classes of com.ibm.icu.util.ULocale$JDKLocaleHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.