Java Code Examples for java.util.Locale.ROOT

The following are Jave code examples for showing how to use ROOT of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: Level.java   View Source Code Vote up 6 votes
private String computeLocalizedLevelName(Locale newLocale) {
    ResourceBundle rb = ResourceBundle.getBundle(resourceBundleName, newLocale);
    final String localizedName = rb.getString(name);

    final boolean isDefaultBundle = defaultBundle.equals(resourceBundleName);
    if (!isDefaultBundle) return localizedName;

    // This is a trick to determine whether the name has been translated
    // or not. If it has not been translated, we need to use Locale.ROOT
    // when calling toUpperCase().
    final Locale rbLocale = rb.getLocale();
    final Locale locale =
            Locale.ROOT.equals(rbLocale)
            || name.equals(localizedName.toUpperCase(Locale.ROOT))
            ? Locale.ROOT : rbLocale;

    // ALL CAPS in a resource bundle's message indicates no translation
    // needed per Oracle translation guideline.  To workaround this
    // in Oracle JDK implementation, convert the localized level name
    // to uppercase for compatibility reason.
    return Locale.ROOT.equals(locale) ? name : localizedName.toUpperCase(locale);
}
 
Example 2
Project: jdk8u-jdk   File: LocaleProviderAdapter.java   View Source Code Vote up 6 votes
public static Locale[] toLocaleArray(Set<String> tags) {
    Locale[] locs = new Locale[tags.size() + 1];
    int index = 0;
    locs[index++] = Locale.ROOT;
    for (String tag : tags) {
        switch (tag) {
        case "ja-JP-JP":
            locs[index++] = JRELocaleConstants.JA_JP_JP;
            break;
        case "th-TH-TH":
            locs[index++] = JRELocaleConstants.TH_TH_TH;
            break;
        default:
            locs[index++] = Locale.forLanguageTag(tag);
            break;
        }
    }
    return locs;
}
 
Example 3
Project: elasticsearch_my   File: LocaleUtils.java   View Source Code Vote up 6 votes
/**
 * Parse the string describing a locale into a {@link Locale} object
 */
public static Locale parse(String localeStr) {
    final String[] parts = localeStr.split("_", -1);
    switch (parts.length) {
        case 3:
            // lang_country_variant
            return new Locale(parts[0], parts[1], parts[2]);
        case 2:
            // lang_country
            return new Locale(parts[0], parts[1]);
        case 1:
            if ("ROOT".equalsIgnoreCase(parts[0])) {
                return Locale.ROOT;
            }
            // lang
            return new Locale(parts[0]);
        default:
            throw new IllegalArgumentException("Can't parse locale: [" + localeStr + "]");
    }
}
 
Example 4
Project: ChessMaster   File: UTF8Control.java   View Source Code Vote up 6 votes
@Override
public String toBundleName(String baseName, Locale locale) {
	if (locale == Locale.ROOT) return baseName;

	String language = locale.getLanguage();
	String script = locale.getScript();
	String country = locale.getCountry();
	String variant = locale.getVariant();

	if (Objects.equals(language, "") && Objects.equals(country, "") && Objects.equals(variant, "")) return baseName;

	StringBuilder sb = new StringBuilder(baseName);
	if (!baseName.endsWith("/"))
		sb.append('_');
	if (!Objects.equals(script, "")) if (!Objects.equals(variant, ""))
		sb.append(language).append('_').append(script).append('_').append(country).append('_').append(variant);
	else if (!Objects.equals(country, ""))
		sb.append(language).append('_').append(script).append('_').append(country);
	else sb.append(language).append('_').append(script);
	else if (!Objects.equals(variant, ""))
		sb.append(language).append('_').append(country).append('_').append(variant);
	else if (!Objects.equals(country, "")) sb.append(language).append('_').append(country);
	else sb.append(language);
	return sb.toString();

}
 
Example 5
Project: wulkanowy   File: Timetable.java   View Source Code Vote up 6 votes
private List<Day> getDays(Elements tableHeaderCells) throws ParseException {
    List<Day> days = new ArrayList<>();

    for (int i = 2; i < 7; i++) {
        String[] dayHeaderCell = tableHeaderCells.get(i).html().split("<br>");

        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
        Date d = sdf.parse(dayHeaderCell[1].trim());
        sdf.applyPattern("yyyy-MM-dd");

        Day day = new Day();
        day.setDayName(dayHeaderCell[0]);
        day.setDate(sdf.format(d));

        if (tableHeaderCells.get(i).hasClass("free-day")) {
            day.setFreeDay(true);
            day.setFreeDayName(dayHeaderCell[2]);
        }

        days.add(day);
    }

    return days;
}
 
Example 6
Project: Elasticsearch   File: Joda.java   View Source Code Vote up 5 votes
public static FormatDateTimeFormatter getStrictStandardDateFormatter() {
    // 2014/10/10
    DateTimeFormatter shortFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
            .toFormatter()
            .withZoneUTC();

    // 2014/10/10 12:12:12
    DateTimeFormatter longFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
            .appendLiteral(' ')
            .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2)
            .appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2)
            .appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2)
            .toFormatter()
            .withZoneUTC();

    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)});

    return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
}
 
Example 7
Project: wulkanowy   File: TimeUtilsTest.java   View Source Code Vote up 5 votes
@Test
public void getDateTest() throws Exception {
    DateFormat format = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = format.parse("31.07.2017");

    Assert.assertEquals(date, TimeUtils.getDate(636370560000000000L));
}
 
Example 8
Project: jdk8u-jdk   File: DecimalFormatSymbols.java   View Source Code Vote up 5 votes
/**
 * Reads the default serializable fields, provides default values for objects
 * in older serial versions, and initializes non-serializable fields.
 * If <code>serialVersionOnStream</code>
 * is less than 1, initializes <code>monetarySeparator</code> to be
 * the same as <code>decimalSeparator</code> and <code>exponential</code>
 * to be 'E'.
 * If <code>serialVersionOnStream</code> is less than 2,
 * initializes <code>locale</code>to the root locale, and initializes
 * If <code>serialVersionOnStream</code> is less than 3, it initializes
 * <code>exponentialSeparator</code> using <code>exponential</code>.
 * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that
 * default serialization will work properly if this object is streamed out again.
 * Initializes the currency from the intlCurrencySymbol field.
 *
 * @since JDK 1.1.6
 */
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (serialVersionOnStream < 1) {
        // Didn't have monetarySeparator or exponential field;
        // use defaults.
        monetarySeparator = decimalSeparator;
        exponential       = 'E';
    }
    if (serialVersionOnStream < 2) {
        // didn't have locale; use root locale
        locale = Locale.ROOT;
    }
    if (serialVersionOnStream < 3) {
        // didn't have exponentialSeparator. Create one using exponential
        exponentialSeparator = Character.toString(exponential);
    }
    serialVersionOnStream = currentSerialVersion;

    if (intlCurrencySymbol != null) {
        try {
             currency = Currency.getInstance(intlCurrencySymbol);
        } catch (IllegalArgumentException e) {
        }
    }
}
 
Example 9
Project: Elasticsearch   File: DateFieldMapper.java   View Source Code Vote up 5 votes
@Override
protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException {
    super.doXContentBody(builder, includeDefaults, params);

    if (includeDefaults || fieldType().numericPrecisionStep() != Defaults.PRECISION_STEP_64_BIT) {
        builder.field("precision_step", fieldType().numericPrecisionStep());
    }
    builder.field("format", fieldType().dateTimeFormatter().format());
    if (includeDefaults || fieldType().nullValueAsString() != null) {
        builder.field("null_value", fieldType().nullValueAsString());
    }
    if (includeInAll != null) {
        builder.field("include_in_all", includeInAll);
    } else if (includeDefaults) {
        builder.field("include_in_all", false);
    }

    if (includeDefaults || fieldType().timeUnit() != Defaults.TIME_UNIT) {
        builder.field("numeric_resolution", fieldType().timeUnit().name().toLowerCase(Locale.ROOT));
    }
    // only serialize locale if needed, ROOT is the default, so no need to serialize that case as well...
    if (fieldType().dateTimeFormatter().locale() != null && fieldType().dateTimeFormatter().locale() != Locale.ROOT) {
        builder.field("locale", fieldType().dateTimeFormatter().locale());
    } else if (includeDefaults) {
        if (fieldType().dateTimeFormatter().locale() == null) {
            builder.field("locale", Locale.ROOT);
        } else {
            builder.field("locale", fieldType().dateTimeFormatter().locale());
        }
    }
}
 
Example 10
Project: elasticsearch_my   File: Joda.java   View Source Code Vote up 5 votes
public static FormatDateTimeFormatter getStrictStandardDateFormatter() {
    // 2014/10/10
    DateTimeFormatter shortFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
            .toFormatter()
            .withZoneUTC();

    // 2014/10/10 12:12:12
    DateTimeFormatter longFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
            .appendLiteral(' ')
            .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2)
            .appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2)
            .appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2)
            .toFormatter()
            .withZoneUTC();

    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)});

    return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
}
 
Example 11
Project: elasticsearch_my   File: Errors.java   View Source Code Vote up 5 votes
/**
 * Returns the formatted message for an exception with the specified messages.
 */
public static String format(String heading, Collection<Message> errorMessages) {
    try (Formatter fmt = new Formatter(Locale.ROOT)) {
        fmt.format(heading).format(":%n%n");
        int index = 1;
        boolean displayCauses = getOnlyCause(errorMessages) == null;

        for (Message errorMessage : errorMessages) {
            fmt.format("%s) %s%n", index++, errorMessage.getMessage());

            List<Object> dependencies = errorMessage.getSources();
            for (int i = dependencies.size() - 1; i >= 0; i--) {
                Object source = dependencies.get(i);
                formatSource(fmt, source);
            }

            Throwable cause = errorMessage.getCause();
            if (displayCauses && cause != null) {
                StringWriter writer = new StringWriter();
                cause.printStackTrace(new PrintWriter(writer));
                fmt.format("Caused by: %s", writer.getBuffer());
            }

            fmt.format("%n");
        }

        if (errorMessages.size() == 1) {
            fmt.format("1 error");
        } else {
            fmt.format("%s errors", errorMessages.size());
        }

        return fmt.toString();
    }
}
 
Example 12
Project: openjdk-jdk10   File: TestChronoField.java   View Source Code Vote up 5 votes
@DataProvider(name = "localeList")
Locale[] data_localeList() {
    return new Locale[] {
            Locale.US,
            Locale.GERMAN,
            Locale.JAPAN,
            Locale.ROOT,
    };
}
 
Example 13
Project: directory-ldap-api   File: FilterEncoder.java   View Source Code Vote up 5 votes
/**
 * Formats a filter and handles encoding of special characters in the value arguments using the
 * &lt;valueencoding&gt; rule as described in <a href="http://www.ietf.org/rfc/rfc4515.txt">RFC 4515</a>.
 * <p>
 * Example of filter template format: <code>(&amp;(cn={0})(uid={1}))</code>
 * 
 * @param filterTemplate the filter with placeholders
 * @param values the values to encode and substitute
 * @return the formatted filter with escaped values
 * @throws IllegalArgumentException if the number of values does not match the number of placeholders in the template
 */
public static String format( String filterTemplate, String... values )
{
    if ( values == null )
    {
        values = EMPTY;
    }

    MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT );

    // check element count and argument count
    Format[] formats = mf.getFormatsByArgumentIndex();
    if ( formats.length != values.length )
    {
        // TODO: I18n
        String msg = "Filter template {0} has {1} placeholders but {2} arguments provided.";
        throw new IllegalArgumentException( I18n.format( msg, filterTemplate, formats.length, values.length ) );
    }

    // encode arguments
    for ( int i = 0; i < values.length; i++ )
    {
        values[i] = encodeFilterValue( values[i] );
    }

    // format the filter
    return mf.format( values );
}
 
Example 14
Project: AOSP-Kayboard-7.1.2   File: SubtypeLocaleUtils.java   View Source Code Vote up 5 votes
@Nonnull
public static Locale getDisplayLocaleOfSubtypeLocale(@Nonnull final String localeString) {
    if (NO_LANGUAGE.equals(localeString)) {
        return sResources.getConfiguration().locale;
    }
    if (sExceptionalLocaleDisplayedInRootLocale.containsKey(localeString)) {
        return Locale.ROOT;
    }
    return LocaleUtils.constructLocaleFromString(localeString);
}
 
Example 15
Project: openjdk-jdk10   File: DecimalFormatSymbols.java   View Source Code Vote up 5 votes
/**
 * Reads the default serializable fields, provides default values for objects
 * in older serial versions, and initializes non-serializable fields.
 * If <code>serialVersionOnStream</code>
 * is less than 1, initializes <code>monetarySeparator</code> to be
 * the same as <code>decimalSeparator</code> and <code>exponential</code>
 * to be 'E'.
 * If <code>serialVersionOnStream</code> is less than 2,
 * initializes <code>locale</code>to the root locale, and initializes
 * If <code>serialVersionOnStream</code> is less than 3, it initializes
 * <code>exponentialSeparator</code> using <code>exponential</code>.
 * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that
 * default serialization will work properly if this object is streamed out again.
 * Initializes the currency from the intlCurrencySymbol field.
 *
 * @since  1.1.6
 */
private void readObject(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    if (serialVersionOnStream < 1) {
        // Didn't have monetarySeparator or exponential field;
        // use defaults.
        monetarySeparator = decimalSeparator;
        exponential       = 'E';
    }
    if (serialVersionOnStream < 2) {
        // didn't have locale; use root locale
        locale = Locale.ROOT;
    }
    if (serialVersionOnStream < 3) {
        // didn't have exponentialSeparator. Create one using exponential
        exponentialSeparator = Character.toString(exponential);
    }
    serialVersionOnStream = currentSerialVersion;

    if (intlCurrencySymbol != null) {
        try {
             currency = Currency.getInstance(intlCurrencySymbol);
        } catch (IllegalArgumentException e) {
        }
        currencyInitialized = true;
    }
}
 
Example 16
Project: q-mail   File: SettingsExporter.java   View Source Code Vote up 4 votes
public static String generateDatedExportFileName() {
    Calendar now = Calendar.getInstance();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ROOT);

    return String.format("%s_%s.%s", EXPORT_FILENAME_PREFIX, dateFormat.format(now.getTime()), EXPORT_FILENAME_SUFFIX);
}
 
Example 17
Project: wulkanowy   File: GradesList.java   View Source Code Vote up 4 votes
public List<Grade> getAll(String semester) throws IOException, ParseException {
    Document gradesPage = snp.getSnPPageDocument(getGradesPageUrl() + semester);
    Elements gradesRows = gradesPage.select(".ocenySzczegoly-table > tbody > tr");
    Semester currentSemester = snp.getCurrentSemester(snp.getSemesters(gradesPage));

    for (Element row : gradesRows) {
        if ("Brak ocen".equals(row.select("td:nth-child(2)").text())) {
            continue;
        }

        String descriptions = row.select("td:nth-child(3)").text();
        String symbol = descriptions.split(", ")[0];
        String description = descriptions.replaceFirst(symbol, "").replaceFirst(", ", "");

        Pattern pattern = Pattern.compile("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})");
        Matcher matcher = pattern.matcher(row.select("td:nth-child(2) span.ocenaCzastkowa")
                .attr("style"));

        String color = "";
        while (matcher.find()) {
            color = matcher.group(1);
        }

        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
        Date d = sdf.parse(row.select("td:nth-child(5)").text());
        sdf.applyPattern("yyyy-MM-dd");

        grades.add(new Grade()
                .setSubject(row.select("td:nth-child(1)").text())
                .setValue(row.select("td:nth-child(2)").text())
                .setColor(color)
                .setSymbol(symbol)
                .setDescription(description)
                .setWeight(row.select("td:nth-child(4)").text())
                .setDate(sdf.format(d))
                .setTeacher(row.select("td:nth-child(6)").text())
                .setSemester(currentSemester.getNumber())
        );
    }

    return grades;
}
 
Example 18
Project: elasticsearch_my   File: RangeFieldMapper.java   View Source Code Vote up 4 votes
public Builder(String name, RangeType type) {
    super(name, new RangeFieldType(type), new RangeFieldType(type));
    builder = this;
    locale = Locale.ROOT;
}
 
Example 19
Project: syndesis   File: SqlExtensionFileStore.java   View Source Code Vote up 4 votes
private String newRandomTempFilePath() {
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd-HH-mm", Locale.ROOT);
    return "/tmp/" + fmt.format(new Date()) + "_" + UUID.randomUUID();
}
 
Example 20
Project: calcite-avatica   File: DateTimeUtils.java   View Source Code Vote up 2 votes
/**
 * Checks if the date/time format is valid
 *
 * @param pattern {@link SimpleDateFormat}  pattern
 * @throws IllegalArgumentException if the given pattern is invalid
 */
public static void checkDateFormat(String pattern) {
  new SimpleDateFormat(pattern, Locale.ROOT);
}