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 2002/04/12 21:16:50 UTC
cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tlv JstlFmtTLV.java
luehe 02/04/12 12:16:50
Modified: standard/conf fmt-rt.tld fmt.tld
standard/examples/web/format FormatNumber.jsp
GermanLocale.jsp ItalianLocale.jsp
ParametricReplacement.jsp PrefixAttribute.jsp
UndefinedKey.jsp
standard/src/org/apache/taglibs/standard/tag/common/fmt
BundleSupport.java FormatDateSupport.java
FormatNumberSupport.java MessageSupport.java
ParseDateSupport.java ParseNumberSupport.java
standard/src/org/apache/taglibs/standard/tag/el/fmt
ParseDateTag.java ParseNumberTag.java
standard/src/org/apache/taglibs/standard/tag/rt/fmt
ParseDateTag.java ParseNumberTag.java
standard/src/org/apache/taglibs/standard/tlv JstlFmtTLV.java
Added: standard/src/org/apache/taglibs/standard/tag/common/fmt
SetLocaleSupport.java
standard/src/org/apache/taglibs/standard/tag/el/fmt
SetLocaleTag.java
standard/src/org/apache/taglibs/standard/tag/rt/fmt
SetLocaleTag.java
Removed: standard/src/org/apache/taglibs/standard/tag/common/fmt
LocaleSupport.java
standard/src/org/apache/taglibs/standard/tag/el/fmt
LocaleTag.java
standard/src/org/apache/taglibs/standard/tag/rt/fmt
LocaleTag.java
Log:
Renamed <fmt:locale> to <fmt:setLocale>
Revision Changes Path
1.19 +2 -2 jakarta-taglibs/standard/conf/fmt-rt.tld
Index: fmt-rt.tld
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/conf/fmt-rt.tld,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- fmt-rt.tld 12 Apr 2002 02:11:02 -0000 1.18
+++ fmt-rt.tld 12 Apr 2002 19:16:49 -0000 1.19
@@ -34,8 +34,8 @@
</tag>
<tag>
- <name>locale</name>
- <tag-class>org.apache.taglibs.standard.tag.rt.fmt.LocaleTag</tag-class>
+ <name>setLocale</name>
+ <tag-class>org.apache.taglibs.standard.tag.rt.fmt.SetLocaleTag</tag-class>
<body-content>EMPTY</body-content>
<description>
Establishes the locale to use for resource bundles and formatting
1.19 +4 -4 jakarta-taglibs/standard/conf/fmt.tld
Index: fmt.tld
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/conf/fmt.tld,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- fmt.tld 12 Apr 2002 02:11:02 -0000 1.18
+++ fmt.tld 12 Apr 2002 19:16:49 -0000 1.19
@@ -18,8 +18,8 @@
<param-name>expressionAttributes</param-name>
<param-value>
requestEncoding:value
- locale:value
- locale:variant
+ setLocale:value
+ setLocale:variant
timeZone:value
bundle:basename
bundle:prefix
@@ -75,8 +75,8 @@
</tag>
<tag>
- <name>locale</name>
- <tag-class>org.apache.taglibs.standard.tag.el.fmt.LocaleTag</tag-class>
+ <name>setLocale</name>
+ <tag-class>org.apache.taglibs.standard.tag.el.fmt.SetLocaleTag</tag-class>
<body-content>EMPTY</body-content>
<description>
Establishes the locale to use for resource bundles and formatting
1.9 +2 -2 jakarta-taglibs/standard/examples/web/format/FormatNumber.jsp
Index: FormatNumber.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/format/FormatNumber.jsp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FormatNumber.jsp 5 Mar 2002 21:17:44 -0000 1.8
+++ FormatNumber.jsp 12 Apr 2002 19:16:49 -0000 1.9
@@ -35,7 +35,7 @@
<fmt:parseNumber value="${cur}" type="currency"/>
<li> Format "12345.67" as US Dollar:<br>
- <fmt:locale value="en-US"/>
+ <fmt:setLocale value="en-US"/>
<fmt:formatNumber value="12345.67" type="currency"/><br>
then parse its integer portion only and output the result:<br>
<fmt:formatNumber value="12345.67" type="currency" var="cur"/>
@@ -43,7 +43,7 @@
<li> Format "12345.67" as German currency (given string is
parsed using "en" locale before it is formatted):<br>
- <fmt:locale value="de-DE"/>
+ <fmt:setLocale value="de-DE"/>
<fmt:formatNumber value="12345.67" type="currency"/>
</ul>
1.3 +1 -1 jakarta-taglibs/standard/examples/web/format/GermanLocale.jsp
Index: GermanLocale.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/format/GermanLocale.jsp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- GermanLocale.jsp 18 Dec 2001 01:53:15 -0000 1.2
+++ GermanLocale.jsp 12 Apr 2002 19:16:49 -0000 1.3
@@ -7,7 +7,7 @@
<body bgcolor="#FFFFFF">
<h3>German Locale</h3>
-<fmt:locale value="de"/>
+<fmt:setLocale value="de"/>
<fmt:bundle basename="org.apache.taglibs.standard.examples.i18n.Resources">
<fmt:message>
greetingMorning
1.4 +1 -1 jakarta-taglibs/standard/examples/web/format/ItalianLocale.jsp
Index: ItalianLocale.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/format/ItalianLocale.jsp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ItalianLocale.jsp 5 Mar 2002 21:17:44 -0000 1.3
+++ ItalianLocale.jsp 12 Apr 2002 19:16:49 -0000 1.4
@@ -7,7 +7,7 @@
<body bgcolor="#FFFFFF">
<h3>Italian Locale</h3>
-<fmt:locale value="it_IT"/>
+<fmt:setLocale value="it_IT"/>
<fmt:bundle basename="org.apache.taglibs.standard.examples.i18n.Resources" var="itBundle" scope="page"/>
<fmt:message key="greetingMorning" bundle="${itBundle}"/>
1.6 +1 -1 jakarta-taglibs/standard/examples/web/format/ParametricReplacement.jsp
Index: ParametricReplacement.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/format/ParametricReplacement.jsp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ParametricReplacement.jsp 5 Mar 2002 21:17:44 -0000 1.5
+++ ParametricReplacement.jsp 12 Apr 2002 19:16:49 -0000 1.6
@@ -8,7 +8,7 @@
<body bgcolor="#FFFFFF">
<h3>Parametric Replacement</h3>
-<fmt:locale value="de"/>
+<fmt:setLocale value="de"/>
<fmt:bundle basename="org.apache.taglibs.standard.examples.i18n.Resources" var="deBundle"/>
<fmt:formatDate type="both" var="currentDateString"/>
<fmt:parseDate value="${currentDateString}" type="both" var="currentDate"/>
1.2 +1 -1 jakarta-taglibs/standard/examples/web/format/PrefixAttribute.jsp
Index: PrefixAttribute.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/format/PrefixAttribute.jsp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PrefixAttribute.jsp 21 Nov 2001 07:34:35 -0000 1.1
+++ PrefixAttribute.jsp 12 Apr 2002 19:16:49 -0000 1.2
@@ -7,7 +7,7 @@
<body bgcolor="#FFFFFF">
<h3>Prefix Attribute</h3>
-<fmt:locale value="de"/>
+<fmt:setLocale value="de"/>
<fmt:bundle basename="org.apache.taglibs.standard.examples.i18n.Resources" prefix="com.acme.labels.">
<fmt:message key="cancel"/>
</fmt:bundle>
1.3 +1 -1 jakarta-taglibs/standard/examples/web/format/UndefinedKey.jsp
Index: UndefinedKey.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/examples/web/format/UndefinedKey.jsp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UndefinedKey.jsp 5 Mar 2002 21:17:44 -0000 1.2
+++ UndefinedKey.jsp 12 Apr 2002 19:16:49 -0000 1.3
@@ -7,7 +7,7 @@
<body bgcolor="#FFFFFF">
<h3>Undefined Key</h3>
-<fmt:locale value="it"/>
+<fmt:setLocale value="it"/>
<fmt:bundle basename="org.apache.taglibs.standard.examples.i18n.Resources" var="itBundle"/>
<fmt:message key="invalidKey" bundle="${itBundle}"/>
1.19 +5 -5 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- BundleSupport.java 12 Apr 2002 02:11:02 -0000 1.18
+++ BundleSupport.java 12 Apr 2002 19:16:49 -0000 1.19
@@ -177,8 +177,8 @@
String basename) {
ResourceBundle ret = null;
- Locale pref = LocaleSupport.getLocale(pageContext,
- Config.FMT_LOCALE);
+ Locale pref = SetLocaleSupport.getLocale(pageContext,
+ Config.FMT_LOCALE);
if (pref != null) {
// Preferred locale is application-based
ret = findMatch(basename, pref);
@@ -189,8 +189,8 @@
if (ret == null) {
// no match found, use fallback locale (if present)
- pref = LocaleSupport.getLocale(pageContext,
- Config.FMT_FALLBACKLOCALE);
+ pref = SetLocaleSupport.getLocale(pageContext,
+ Config.FMT_FALLBACKLOCALE);
if (pref != null) {
ret = findMatch(basename, pref);
}
@@ -198,7 +198,7 @@
if (ret != null) {
// set response locale
- LocaleSupport.setResponseLocale(pageContext, ret.getLocale());
+ SetLocaleSupport.setResponseLocale(pageContext, ret.getLocale());
}
return ret;
1.17 +1 -1 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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- FormatDateSupport.java 8 Apr 2002 22:39:44 -0000 1.16
+++ FormatDateSupport.java 12 Apr 2002 19:16:49 -0000 1.17
@@ -174,7 +174,7 @@
}
// Create formatter
- Locale locale = LocaleSupport.getFormattingLocale(
+ Locale locale = SetLocaleSupport.getFormattingLocale(
pageContext,
this,
true,
1.15 +1 -1 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- FormatNumberSupport.java 3 Apr 2002 21:14:06 -0000 1.14
+++ FormatNumberSupport.java 12 Apr 2002 19:16:49 -0000 1.15
@@ -183,7 +183,7 @@
}
// Create formatter
- Locale locale = LocaleSupport.getFormattingLocale(
+ Locale locale = SetLocaleSupport.getFormattingLocale(
pageContext,
this,
true,
1.14 +2 -1 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/MessageSupport.java
Index: MessageSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/MessageSupport.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- MessageSupport.java 12 Apr 2002 02:11:02 -0000 1.13
+++ MessageSupport.java 12 Apr 2002 19:16:49 -0000 1.14
@@ -175,7 +175,8 @@
Config.FMT_BUNDLE);
}
} else {
- LocaleSupport.setResponseLocale(pageContext, bundle.getLocale());
+ SetLocaleSupport.setResponseLocale(pageContext,
+ bundle.getLocale());
}
String message = null;
1.15 +1 -1 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ParseDateSupport.java 11 Apr 2002 22:38:12 -0000 1.14
+++ ParseDateSupport.java 12 Apr 2002 19:16:49 -0000 1.15
@@ -154,7 +154,7 @@
*/
Locale locale = parseLocale;
if (locale == null)
- locale = LocaleSupport.getFormattingLocale(
+ locale = SetLocaleSupport.getFormattingLocale(
pageContext,
this,
false,
1.11 +1 -1 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ParseNumberSupport.java 21 Mar 2002 18:44:00 -0000 1.10
+++ ParseNumberSupport.java 12 Apr 2002 19:16:49 -0000 1.11
@@ -152,7 +152,7 @@
*/
Locale locale = parseLocale;
if (locale == null)
- locale = LocaleSupport.getFormattingLocale(
+ locale = SetLocaleSupport.getFormattingLocale(
pageContext,
this,
false,
1.1 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/fmt/SetLocaleSupport.java
Index: SetLocaleSupport.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
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 javax.servlet.jsp.jstl.core.Config;
import org.apache.taglibs.standard.tag.common.core.Util;
import org.apache.taglibs.standard.resources.Resources;
/**
* Support for tag handlers for <setLocale>, the locale setting tag in
* JSTL 1.0.
*
* @author Jan Luehe
*/
public abstract class SetLocaleSupport extends TagSupport {
//*********************************************************************
// Private constants
private static final char HYPHEN = '-';
private static final char UNDERSCORE = '_';
//*********************************************************************
// Protected state
protected String value; // 'value' attribute
protected String variant; // 'variant' attribute
//*********************************************************************
// Private state
private String scope; // 'scope' attribute
//*********************************************************************
// Constructor and initialization
public SetLocaleSupport() {
super();
init();
}
private void init() {
value = variant = null;
scope = "page";
}
//*********************************************************************
// Tag attributes known at translation time
public void setScope(String scope) {
this.scope = scope;
}
//*********************************************************************
// Tag logic
public int doEndTag() throws JspException {
Locale locale = null;
if ((value == null) || "".equals(value)) {
locale = Locale.getDefault();
} else {
locale = parseLocale(value, variant);
}
Config.set(pageContext, Config.FMT_LOCALE, locale,
Util.getScope(scope));
setResponseLocale(pageContext, locale);
return EVAL_PAGE;
}
// Releases any resources we may have (or inherit)
public void release() {
init();
}
//*********************************************************************
// Public utility methods
/**
* See parseLocale(String, String) for details.
*/
public static Locale parseLocale(String locale) {
return parseLocale(locale, null);
}
/**
* Parses the given locale string into its language and (optionally)
* country components, and returns the corresponding
* <tt>java.util.Locale</tt> object.
*
* If the given locale string is null or empty, the runtime's default
* locale is returned.
*
* @param locale the locale string to parse
* @param variant the variant
*
* @return <tt>java.util.Locale</tt> object corresponding to the given
* locale string, or the runtime's default locale if the locale string is
* null or empty
*
* @throws IllegalArgumentException if the given locale does not have a
* language component or has an empty country component
*/
public static Locale parseLocale(String locale, String variant) {
Locale ret = null;
String language = locale;
String country = null;
int index = -1;
if (((index = locale.indexOf(HYPHEN)) > -1)
|| ((index = locale.indexOf(UNDERSCORE)) > -1)) {
language = locale.substring(0, index);
country = locale.substring(index+1);
}
if ((language == null) || (language.length() == 0)) {
throw new IllegalArgumentException(
Resources.getMessage("LOCALE_NO_LANGUAGE"));
}
if (country == null) {
if (variant != null)
ret = new Locale(language, "", variant);
else
ret = new Locale(language, "");
} else if (country.length() > 0) {
if (variant != null)
ret = new Locale(language, country, variant);
else
ret = new Locale(language, country);
} else {
throw new IllegalArgumentException(
Resources.getMessage("LOCALE_EMPTY_COUNTRY"));
}
return ret;
}
//*********************************************************************
// 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.fmt.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);
}
/*
* Returns the formatting locale to use with the given formatting action
* in the given page.
*
* @param pc The page context 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
* (if set to <tt>true</tt>, the formatting locale that is returned by
* this method is used to set the response locale).
*
* @param avail the array of available locales
*
* @return the formatting locale to use
*/
static Locale getFormattingLocale(PageContext pc,
Tag fromTag,
boolean format,
Locale[] avail) {
Locale match = null;
ResourceBundle bundle = null;
Tag parent = findAncestorWithClass(fromTag, BundleSupport.class);
if (parent != null) {
// use locale from parent <fmt:bundle> tag
match = ((BundleSupport) parent).getBundle().getLocale();
} else if ((bundle = (ResourceBundle)
Config.find(pc, Config.FMT_BUNDLE)) != null) {
// Use locale associated with default bundle base name.
match = bundle.getLocale();
} else {
/*
* Compare the preferred locales (in order of preference) against
* the available formatting locales, and determine the best
* matching locale.
*/
Locale pref = getLocale(pc, Config.FMT_LOCALE);
if (pref != null) {
// Preferred locale is application-based
match = findFormattingMatch(pref, avail);
} else {
// Preferred locales are browser-based
match = findFormattingMatch(pc, avail);
}
if (match == null) {
//Use fallback locale.
pref = getLocale(pc, Config.FMT_FALLBACKLOCALE);
if ((pref == null)
|| ((match = findFormattingMatch(pref,
avail)) == null)) {
// Use runtime's default locale.
match = Locale.getDefault();
}
}
}
if (format) {
setResponseLocale(pc, match);
}
return match;
}
/*
* Returns the locale specified by the named scoped attribute or context
* configuration parameter.
*
* <p> The named scoped attribute is searched in the page, request,
* session (if valid), and application scope(s) (in this order). If no such
* attribute exists in any of the scopes, the locale is taken from the
* named context configuration parameter.
*
* @param pageContext the page in which to search for the named scoped
* attribute or context configuration parameter
* @param name the name of the scoped attribute or context configuration
* parameter
*
* @return the locale specified by the named scoped attribute or context
* configuration parameter, or <tt>null</tt> if no scoped attribute or
* configuration parameter with the given name exists
*/
static Locale getLocale(PageContext pageContext, String name) {
Locale loc = null;
Object obj = Config.find(pageContext, name);
if (obj != null) {
if (obj instanceof Locale) {
loc = (Locale) obj;
} else {
loc = parseLocale((String) obj);
}
}
return loc;
}
//*********************************************************************
// Private utility methods
/*
* Determines the client's preferred locales from the request, and compares
* each of the locales (in order of preference) against the available
* locales in order to determine the best matching locale.
*
* @param pageContext Page containing the formatting action
* @param avail Available formatting locales
*
* @return Best matching locale, or <tt>null</tt> if no match was found
*/
private static Locale findFormattingMatch(PageContext pageContext,
Locale[] avail) {
Locale match = null;
for (Enumeration enum = pageContext.getRequest().getLocales();
enum.hasMoreElements(); ) {
/*
* If client request doesn't provide an Accept-Language header,
* the returned locale Enumeration contains the runtime's default
* locale, so it always contains at least one element.
*/
match = findFormattingMatch((Locale) enum.nextElement(), avail);
if (match != null) {
break;
}
}
return match;
}
/*
* Returns the best match between the given preferred locale and the
* given available locales.
*
* The best match is given as the first available locale that exactly
* matches the given preferred locale ("exact match"). If no exact match
* exists, the best match is given as the first available locale that
* matches the preferred locale's language component and does not have any
* country component ("language match").
*
* @param pref the preferred locale
* @param avail the available formatting locales
*
* @return Available locale that best matches the given preferred locale,
* or <tt>null</tt> if no match exists
*/
private static Locale findFormattingMatch(Locale pref, Locale[] avail) {
Locale match = null;
for (int i=0; i<avail.length; i++) {
if (pref.equals(avail[i])) {
// Exact match
match = avail[i];
break;
} else {
if (pref.getLanguage().equals(avail[i].getLanguage())
&& ("".equals(avail[i].getCountry()))) {
// Language match
if (match == null) {
match = avail[i];
}
}
}
}
return match;
}
}
1.10 +1 -1 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/fmt/ParseDateTag.java
Index: ParseDateTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/fmt/ParseDateTag.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ParseDateTag.java 3 Apr 2002 23:18:03 -0000 1.9
+++ ParseDateTag.java 12 Apr 2002 19:16:50 -0000 1.10
@@ -222,7 +222,7 @@
} else {
String localeStr = (String) obj;
if (!"".equals(localeStr)) {
- parseLocale = LocaleSupport.parseLocale(localeStr);
+ parseLocale = SetLocaleSupport.parseLocale(localeStr);
}
}
}
1.8 +1 -1 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/fmt/ParseNumberTag.java
Index: ParseNumberTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/fmt/ParseNumberTag.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ParseNumberTag.java 3 Apr 2002 23:18:03 -0000 1.7
+++ ParseNumberTag.java 12 Apr 2002 19:16:50 -0000 1.8
@@ -194,7 +194,7 @@
} else {
String localeStr = (String) obj;
if (!"".equals(localeStr)) {
- parseLocale = LocaleSupport.parseLocale(localeStr);
+ parseLocale = SetLocaleSupport.parseLocale(localeStr);
}
}
}
1.1 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/el/fmt/SetLocaleTag.java
Index: SetLocaleTag.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.taglibs.standard.tag.el.fmt;
import java.util.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import org.apache.taglibs.standard.lang.support.*;
import org.apache.taglibs.standard.tag.common.fmt.*;
/**
* <p>A handler for <setLocale> that accepts attributes as Strings
* and evaluates them as expressions at runtime.</p>
*
* @author Jan Luehe
*/
public class SetLocaleTag extends SetLocaleSupport {
//*********************************************************************
// 'Private' state (implementation details)
private String value_; // stores EL-based property
private String variant_; // stores EL-based property
//*********************************************************************
// Constructor
/**
* Constructs a new LocaleTag. As with TagSupport, subclasses
* should not provide other constructors and are expected to call
* the superclass constructor
*/
public SetLocaleTag() {
super();
init();
}
//*********************************************************************
// Tag logic
// evaluates expression and chains to parent
public int doStartTag() throws JspException {
// evaluate any expressions we were passed, once per invocation
evaluateExpressions();
// chain to the parent implementation
return super.doStartTag();
}
// Releases any resources we may have (or inherit)
public void release() {
super.release();
init();
}
//*********************************************************************
// Accessor methods
// for EL-based attribute
public void setValue(String value_) {
this.value_ = value_;
}
// for EL-based attribute
public void setVariant(String variant_) {
this.variant_ = variant_;
}
//*********************************************************************
// Private (utility) methods
// (re)initializes state (during release() or construction)
private void init() {
// null implies "no expression"
value_ = variant_ = null;
}
// Evaluates expressions as necessary
private void evaluateExpressions() throws JspException {
/*
* Note: we don't check for type mismatches here; we assume
* the expression evaluator will return the expected type
* (by virtue of knowledge we give it about what that type is).
* A ClassCastException here is truly unexpected, so we let it
* propagate up.
*/
// 'value' attribute (mandatory)
value = (String) ExpressionEvaluatorManager.evaluate(
"value", value_, String.class, this, pageContext);
if (variant_ != null) {
variant = (String) ExpressionEvaluatorManager.evaluate(
"variant", variant_, String.class, this, pageContext);
}
}
}
1.9 +2 -1 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt/ParseDateTag.java
Index: ParseDateTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt/ParseDateTag.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ParseDateTag.java 3 Apr 2002 23:18:04 -0000 1.8
+++ ParseDateTag.java 12 Apr 2002 19:16:50 -0000 1.9
@@ -109,7 +109,8 @@
this.parseLocale = (Locale) loc;
} else {
if (!"".equals((String) loc)) {
- this.parseLocale = LocaleSupport.parseLocale((String) loc);
+ this.parseLocale = SetLocaleSupport.parseLocale((String)
+ loc);
}
}
}
1.7 +1 -1 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt/ParseNumberTag.java
Index: ParseNumberTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt/ParseNumberTag.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ParseNumberTag.java 3 Apr 2002 23:18:04 -0000 1.6
+++ ParseNumberTag.java 12 Apr 2002 19:16:50 -0000 1.7
@@ -93,7 +93,7 @@
this.parseLocale = (Locale) loc;
} else {
if (!"".equals((String) loc)) {
- this.parseLocale = LocaleSupport.parseLocale((String) loc);
+ this.parseLocale = SetLocaleSupport.parseLocale((String) loc);
}
}
}
1.1 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/rt/fmt/SetLocaleTag.java
Index: SetLocaleTag.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.taglibs.standard.tag.rt.fmt;
import java.util.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import org.apache.taglibs.standard.tag.common.fmt.*;
/**
* <p>A handler for <setLocale> that supports rtexprvalue-based
* attributes.</p>
*
* @author Jan Luehe
*/
public class SetLocaleTag extends SetLocaleSupport {
//*********************************************************************
// Accessor methods
// for tag attribute
public void setValue(String value) throws JspTagException {
this.value = value;
}
// for tag attribute
public void setVariant(String variant) throws JspTagException {
this.variant = variant;
}
}
1.14 +2 -2 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tlv/JstlFmtTLV.java
Index: JstlFmtTLV.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tlv/JstlFmtTLV.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- JstlFmtTLV.java 8 Apr 2002 19:15:17 -0000 1.13
+++ JstlFmtTLV.java 12 Apr 2002 19:16:50 -0000 1.14
@@ -109,7 +109,7 @@
// Constants
// tag names
- private final String LOCALE = "locale";
+ private final String SETLOCALE = "setLocale";
private final String BUNDLE = "bundle";
private final String TIMEZONE = "timeZone";
private final String MESSAGE = "message";
@@ -187,7 +187,7 @@
fail(Resources.getMessage("TLV_INVALID_ATTRIBUTE",
SCOPE, qn, a.getValue(SCOPE)));
if (qn.startsWith(prefix + ":")
- && !isTag(qn, LOCALE)
+ && !isTag(qn, SETLOCALE)
&& !isTag(qn, BUNDLE)
&& !isTag(qn, TIMEZONE)
&& hasDanglingScope(a))
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>