Include date symbols in the properties exposed via the core/messages module
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/51325958 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/51325958 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/51325958 Branch: refs/heads/5.4-js-rewrite Commit: 513259585083895ccab3543a319027b7daf80620 Parents: dc1d936 Author: Howard M. Lewis Ship <[email protected]> Authored: Thu Nov 8 10:35:22 2012 -0800 Committer: Howard M. Lewis Ship <[email protected]> Committed: Thu Nov 8 10:35:22 2012 -0800 ---------------------------------------------------------------------- .../ClientLocalizationMessageResource.java | 45 ++++++++++++--- tapestry-core/src/test/app1/WEB-INF/app.properties | 2 +- 2 files changed, 38 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/51325958/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/ClientLocalizationMessageResource.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/ClientLocalizationMessageResource.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/ClientLocalizationMessageResource.java index 3ba57fa..7f8c34b 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/ClientLocalizationMessageResource.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/messages/ClientLocalizationMessageResource.java @@ -16,12 +16,15 @@ package org.apache.tapestry5.internal.services.messages; import org.apache.tapestry5.internal.util.VirtualResource; import org.apache.tapestry5.ioc.Resource; +import org.apache.tapestry5.ioc.internal.util.CollectionFactory; +import org.apache.tapestry5.ioc.internal.util.InternalUtils; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.text.DateFormatSymbols; import java.text.DecimalFormatSymbols; -import java.util.Locale; +import java.util.*; /** * Provides a number of symbols related to client-side localization; by exposing these in the global message catalog, @@ -76,19 +79,45 @@ public class ClientLocalizationMessageResource extends VirtualResource @Override public InputStream openStream() throws IOException { - DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale); + DecimalFormatSymbols decimalSymbols = DecimalFormatSymbols.getInstance(locale); - StringBuilder builder = new StringBuilder(200); + Map<String, Object> symbols = CollectionFactory.newMap(); - write(builder, "group", symbols.getGroupingSeparator()); - write(builder, "minus", symbols.getMinusSign()); - write(builder, "decimal", symbols.getDecimalSeparator()); + symbols.put("decimal-symbols.group", decimalSymbols.getGroupingSeparator()); + symbols.put("decimal-symbols.minus", decimalSymbols.getMinusSign()); + symbols.put("decimal-symbols.decimal", decimalSymbols.getDecimalSeparator()); + + DateFormatSymbols dateSymbols = new DateFormatSymbols(locale); + + List<String> months = Arrays.asList(dateSymbols.getMonths()).subList(0, 12); + + // Comma-separated list, starting with January + symbols.put("date-symbols.months", InternalUtils.join(months)); + + List<String> days = Arrays.asList(dateSymbols.getWeekdays()).subList(1, 8); + + // Comma-separated list, starting with Sunday + symbols.put("date-symbols.days", InternalUtils.join(days)); + + Calendar c = Calendar.getInstance(locale); + + // First day of the week, usually 0 for Sunday (e.g., in the US) or 1 for Monday + // (e.g., France). + symbols.put("date-symbols.first-day", c.getFirstDayOfWeek() - 1); + + + StringBuilder builder = new StringBuilder(); + + for (Map.Entry<String, Object> entry : symbols.entrySet()) + { + write(builder, entry.getKey(), entry.getValue()); + } return toInputStream(builder.toString()); } - private void write(StringBuilder builder, String name, char value) + private void write(StringBuilder builder, String name, Object value) { - builder.append("decimal-symbols.").append(name).append("=").append(value).append("\n"); + builder.append(name).append("=").append(value).append("\n"); } } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/51325958/tapestry-core/src/test/app1/WEB-INF/app.properties ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/app1/WEB-INF/app.properties b/tapestry-core/src/test/app1/WEB-INF/app.properties index 5551efe..50a7f3b 100644 --- a/tapestry-core/src/test/app1/WEB-INF/app.properties +++ b/tapestry-core/src/test/app1/WEB-INF/app.properties @@ -1,4 +1,4 @@ -# Copyright 2007, 2008 The Apache Software Foundation +# Copyright 2007, 2008, 2012 The Apache Software Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.
