kpiroumian 2002/07/10 08:41:52
Modified: src/java/org/apache/cocoon/acting LocaleAction.java
src/java/org/apache/cocoon/i18n I18nUtils.java
Log:
Minor addition to allow user defined locales with 'variant' part to be
recognised correctly.
PR: 10559
Revision Changes Path
1.11 +8 -8 xml-cocoon2/src/java/org/apache/cocoon/acting/LocaleAction.java
Index: LocaleAction.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/LocaleAction.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- LocaleAction.java 9 Jul 2002 21:12:58 -0000 1.10
+++ LocaleAction.java 10 Jul 2002 15:41:51 -0000 1.11
@@ -273,8 +273,8 @@
) throws Exception {
// obtain locale information from params, session or cookies
- Locale locale = getLocaleAttribute(objectModel, localeAttr);
- String lc = locale.toString();
+ String lc = getLocaleAttribute(objectModel, localeAttr);
+ Locale locale = I18nUtils.parseLocale(lc);
if (getLogger().isDebugEnabled()) {
debug("obtained locale information, locale = " + lc);
@@ -324,7 +324,7 @@
* @param objectModel requesting object's environment
* @return locale value or <code>null</null> if no locale was found
*/
- public static Locale getLocaleAttribute(Map objectModel,
+ public static String getLocaleAttribute(Map objectModel,
String localeAttrName) {
String ret_val;
@@ -333,13 +333,13 @@
// 1. Request CGI parameter 'locale'
if ((ret_val = request.getParameter(localeAttrName)) != null)
- return I18nUtils.parseLocale(ret_val);
+ return ret_val;
// 2. Session attribute 'locale'
Session session = request.getSession(false);
if (session != null &&
((ret_val = (String) session.getAttribute(localeAttrName)) != null))
- return I18nUtils.parseLocale(ret_val);
+ return ret_val;
// 3. First matching cookie parameter 'locale' within each cookie sent
Cookie[] cookies = request.getCookies();
@@ -347,12 +347,12 @@
for (int i = 0; i < cookies.length; ++i) {
Cookie cookie = cookies[i];
if (cookie.getName().equals(localeAttrName))
- return I18nUtils.parseLocale(cookie.getValue());
+ return cookie.getValue();
}
}
// 4. Locale setting of the requesting object/server
- return request.getLocale();
+ return request.getLocale().toString();
}
/**
1.5 +8 -2 xml-cocoon2/src/java/org/apache/cocoon/i18n/I18nUtils.java
Index: I18nUtils.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/i18n/I18nUtils.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- I18nUtils.java 22 Feb 2002 07:03:52 -0000 1.4
+++ I18nUtils.java 10 Jul 2002 15:41:52 -0000 1.5
@@ -63,11 +63,17 @@
public class I18nUtils {
// Locale string delimiter
- private static final String LOCALE_DELIMITER = "_";
+ private static final String LOCALE_DELIMITER = "_-@.";
/**
* Parses given locale string to Locale object. If the string is null
* then the given locale is returned.
+ * Locale string is concidered to be of the form lang_country_variant,
+ * where '_' delimiter can be one of the '_', '-', '@' or '.'. Some
+ * servlet containers does not parse correctly user defined locales
+ * (e.g. 'de-at-euro' or 'de-at@EURO'), so this function performs additional
parsing to
+ * handle those cases correctly.
+ *
*
* @param localeString a string containing locale in
* <code>language_country_variant</code> format.
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]