You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by lu...@apache.org on 2001/12/12 02:24:19 UTC
cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt BundleSupport.java FormatDateSupport.java FormatNumberSupport.java LocaleSupport.java ParseDateSupport.java ParseNumberSupport.java RequestEncodingSupport.java
luehe 01/12/11 17:24:19
Modified: standard/src/org/apache/taglibs/standard/tag/common/fmt
BundleSupport.java FormatDateSupport.java
FormatNumberSupport.java LocaleSupport.java
ParseDateSupport.java ParseNumberSupport.java
RequestEncodingSupport.java
Log:
Added support for dynamic response locales
Revision Changes Path
1.5 +9 -3 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/BundleSupport.java
Index: BundleSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/BundleSupport.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BundleSupport.java 2001/12/06 20:19:50 1.4
+++ BundleSupport.java 2001/12/12 01:24:19 1.5
@@ -230,29 +230,35 @@
ResourceBundle ret = null;
try {
+
loc = (Locale)
pageContext.findAttribute(LocaleSupport.LOCALE_ATTRIBUTE);
if (loc != null) {
+ // use resource bundle with specified locale
ret = ResourceBundle.getBundle(basename, loc);
} else {
- // use best matching client locale
+ // use resource bundle with best matching locale
ret = getBestMatch(pageContext, basename);
if (ret == null) {
- // use fallback locale
+ // no match available, check if fallback locale exists
String fallback = (String)
pageContext.findAttribute(FALLBACK_LOCALE);
if (fallback == null)
fallback = pageContext.getServletContext().
getInitParameter(FALLBACK_LOCALE);
if (fallback != null) {
+ // use resource bundle with fallback locale
loc = LocaleSupport.parseLocale(fallback, null);
ret = ResourceBundle.getBundle(basename, loc);
} else {
- // use runtime's default locale
+ // use resource bundle with runtime's default locale
ret = ResourceBundle.getBundle(basename);
}
}
}
+
+ LocaleSupport.setResponseLocale(pageContext, ret.getLocale());
+
} catch (MissingResourceException mre) {
ServletContext sc = pageContext.getServletContext();
sc.log(Resources.getMessage("MISSING_RESOURCE_BUNDLE", basename));
1.5 +1 -0 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatDateSupport.java
Index: FormatDateSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatDateSupport.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FormatDateSupport.java 2001/12/11 20:15:59 1.4
+++ FormatDateSupport.java 2001/12/12 01:24:19 1.5
@@ -196,6 +196,7 @@
Locale locale = LocaleSupport.getFormattingLocale(
pageContext,
this,
+ true,
DateFormat.getAvailableLocales());
switch (type) {
case DATE_TYPE:
1.4 +1 -0 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatNumberSupport.java
Index: FormatNumberSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/FormatNumberSupport.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- FormatNumberSupport.java 2001/12/11 20:15:59 1.3
+++ FormatNumberSupport.java 2001/12/12 01:24:19 1.4
@@ -169,6 +169,7 @@
Locale locale = LocaleSupport.getFormattingLocale(
pageContext,
this,
+ true,
NumberFormat.getAvailableLocales());
switch (type) {
case NUMBER_TYPE:
1.5 +44 -5 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/LocaleSupport.java
Index: LocaleSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/LocaleSupport.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LocaleSupport.java 2001/12/03 22:43:50 1.4
+++ LocaleSupport.java 2001/12/12 01:24:19 1.5
@@ -56,6 +56,7 @@
package org.apache.taglibs.standard.tag.common.fmt;
import java.util.*;
+import javax.servlet.ServletResponse;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import org.apache.taglibs.standard.tag.common.core.Util;
@@ -76,7 +77,7 @@
static final String LOCALE_ATTRIBUTE =
"javax.servlet.jsp.jstl.i18n.locale";
-
+
//*********************************************************************
// Private constants
@@ -123,8 +124,10 @@
// Tag logic
public int doEndTag() throws JspException {
- pageContext.setAttribute(LOCALE_ATTRIBUTE, parseLocale(value, variant),
- scope);
+ Locale locale = parseLocale(value, variant);
+ pageContext.setAttribute(LOCALE_ATTRIBUTE, locale, scope);
+ setResponseLocale(pageContext, locale);
+
return EVAL_PAGE;
}
@@ -189,6 +192,31 @@
// Package-scoped utility methods
/*
+ * Stores the given locale in the response object of the given page
+ * context, and stores the locale's associated charset in the
+ * javax.servlet.jsp.jstl.i18n.request.charset session attribute, which
+ * may be used by the <requestEncoding> action in a page invoked by a
+ * form included in the response to set the request charset to the same as
+ * the response charset (this makes it possible for the container to
+ * decode the form parameter values properly, since browsers typically
+ * encode form field values using the response's charset).
+ *
+ * @param pageContext the page context whose response object is assigned
+ * the given locale
+ * @param locale the response locale
+ */
+ static void setResponseLocale(PageContext pageContext, Locale locale) {
+ // set response locale
+ ServletResponse response = pageContext.getResponse();
+ response.setLocale(locale);
+
+ // get response character encoding and store it in session attribute
+ pageContext.setAttribute(RequestEncodingSupport.REQUEST_CHAR_SET,
+ response.getCharacterEncoding(),
+ PageContext.SESSION_SCOPE);
+ }
+
+ /*
* Determines the formatting locale to use with the given formatting
* action in the given page.
*
@@ -214,14 +242,16 @@
*
* @param pageContext the page containing the formatting action
* @param fromTag the formatting action
+ * @param format <tt>true</tt> if the formatting action is of type
+ * <formatXXX> (as opposed to <parseXXX>), and <tt>false</tt> otherwise
* @param avail the array of available locales
*
* @return the formatting locale to use
*/
static Locale getFormattingLocale(PageContext pageContext,
Tag fromTag,
+ boolean format,
Locale[] avail) {
-
Locale ret = (Locale) pageContext.findAttribute(LOCALE_ATTRIBUTE);
if (ret == null) {
Tag t = findAncestorWithClass(fromTag, BundleSupport.class);
@@ -233,17 +263,26 @@
ResourceBundle bundle = BundleSupport.getDefaultBundle(
pageContext, BundleSupport.DEFAULT_BASENAME);
if (bundle != null) {
+ // use locale from bundle with default base name
ret = bundle.getLocale();
} else {
+ // get best matching formatting locale
ret = getBestMatch(pageContext, avail);
if (ret == null) {
- // no match, use runtime's default locale
+ // no match available, use runtime's default locale
ret = Locale.getDefault();
}
}
}
}
+ /*
+ * If this is a <formatXXX> (as opposed to a <parseXXX>) action,
+ * set the response locale
+ */
+ if (format)
+ LocaleSupport.setResponseLocale(pageContext, ret);
+
return ret;
}
1.4 +1 -0 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/ParseDateSupport.java
Index: ParseDateSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/ParseDateSupport.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ParseDateSupport.java 2001/12/03 22:43:50 1.3
+++ ParseDateSupport.java 2001/12/12 01:24:19 1.4
@@ -151,6 +151,7 @@
locale = LocaleSupport.getFormattingLocale(
pageContext,
this,
+ false,
DateFormat.getAvailableLocales());
switch (type) {
1.3 +1 -0 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/ParseNumberSupport.java
Index: ParseNumberSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/ParseNumberSupport.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ParseNumberSupport.java 2001/12/03 22:43:50 1.2
+++ ParseNumberSupport.java 2001/12/12 01:24:19 1.3
@@ -138,6 +138,7 @@
locale = LocaleSupport.getFormattingLocale(
pageContext,
this,
+ false,
NumberFormat.getAvailableLocales());
switch (type) {
1.2 +2 -2 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/RequestEncodingSupport.java
Index: RequestEncodingSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/RequestEncodingSupport.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RequestEncodingSupport.java 2001/12/11 23:46:55 1.1
+++ RequestEncodingSupport.java 2001/12/12 01:24:19 1.2
@@ -72,9 +72,9 @@
public abstract class RequestEncodingSupport extends TagSupport {
//*********************************************************************
- // Private constants
+ // Package-scoped constants
- private static final String REQUEST_CHAR_SET =
+ static final String REQUEST_CHAR_SET =
"javax.servlet.jsp.jstl.i18n.request.charset";
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>