Index: lams_common/src/java/org/lamsfoundation/lams/web/filter/LocaleFilter.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/web/filter/LocaleFilter.java,v diff -u -r1.4 -r1.5 --- lams_common/src/java/org/lamsfoundation/lams/web/filter/LocaleFilter.java 16 Feb 2006 00:44:01 -0000 1.4 +++ lams_common/src/java/org/lamsfoundation/lams/web/filter/LocaleFilter.java 1 Mar 2006 22:44:28 -0000 1.5 @@ -48,7 +48,7 @@ // private static final String DEFAULT_LANGUAGE = "en"; // private static final String DEFUALT_COUNTRY = "AU"; private static final String PREFERRED_LOCALE_KEY = "org.apache.struts.action.LOCALE"; - + private static final String CHARSET_KEY_KEY = "org.lamsfoundation.lams.web.filter.CHARSET.KEY"; public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { Locale preferredLocale = null; @@ -85,6 +85,7 @@ } else { session.setAttribute(PREFERRED_LOCALE_KEY, preferredLocale); Config.set(session, Config.FMT_LOCALE, preferredLocale); + session.setAttribute(CHARSET_KEY_KEY,LocaleToCharsetMap.getCharset(preferredLocale)); } } if (preferredLocale != null && !(request instanceof LocaleRequestWrapper)) { Index: lams_common/src/java/org/lamsfoundation/lams/web/filter/LocaleToCharsetMap.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/web/filter/Attic/LocaleToCharsetMap.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_common/src/java/org/lamsfoundation/lams/web/filter/LocaleToCharsetMap.java 1 Mar 2006 22:44:28 -0000 1.1 @@ -0,0 +1,103 @@ +/* + *Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + * + *You should have received a copy of the GNU General Public License + *along with this program; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + *USA + * + *http://www.gnu.org/licenses/gpl.txt + */ +package org.lamsfoundation.lams.web.filter; + +import java.util.Hashtable; +import java.util.Locale; + + +/** +* A mapping to determine the (somewhat arbitrarily) preferred charset for +* a given locale. Supports all locales recognized in JDK 1.1. +* This class was originally written by Jason Hunter [jhunter@acm.org] +* as part of the book "Java Servlet Programming" (O'Reilly). +* See +* http://www.servlets.com/book for more information. +* Used by Sun Microsystems with permission. +*/ + public class LocaleToCharsetMap { + + private static Hashtable map; + + static { + map = new Hashtable(); + + map.put("ar", "ISO-8859-6"); + map.put("be", "ISO-8859-5"); + map.put("bg", "ISO-8859-5"); + map.put("ca", "ISO-8859-1"); + map.put("cs", "ISO-8859-2"); + map.put("da", "ISO-8859-1"); + map.put("de", "ISO-8859-1"); + map.put("el", "ISO-8859-7"); + map.put("en", "ISO-8859-1"); + map.put("es", "ISO-8859-1"); + map.put("et", "ISO-8859-1"); + map.put("fi", "ISO-8859-1"); + map.put("fr", "ISO-8859-1"); + map.put("hr", "ISO-8859-2"); + map.put("hu", "ISO-8859-2"); + map.put("is", "ISO-8859-1"); + map.put("it", "ISO-8859-1"); + map.put("iw", "ISO-8859-8"); + map.put("ja", "Shift_JIS"); + map.put("ko", "EUC-KR"); // Requires JDK 1.1.6 + map.put("lt", "ISO-8859-2"); + map.put("lv", "ISO-8859-2"); + map.put("mk", "ISO-8859-5"); + map.put("nl", "ISO-8859-1"); + map.put("no", "ISO-8859-1"); + map.put("pl", "ISO-8859-2"); + map.put("pt", "ISO-8859-1"); + map.put("ro", "ISO-8859-2"); + map.put("ru", "ISO-8859-5"); + map.put("sh", "ISO-8859-5"); + map.put("sk", "ISO-8859-2"); + map.put("sl", "ISO-8859-2"); + map.put("sq", "ISO-8859-2"); + map.put("sr", "ISO-8859-5"); + map.put("sv", "ISO-8859-1"); + map.put("tr", "ISO-8859-9"); + map.put("uk", "ISO-8859-5"); + map.put("zh", "GB2312"); + map.put("zh_TW", "Big5"); + + } + + /** + * Gets the preferred charset for the given locale, or null if the locale + * is not recognized. + * + * @param loc the locale + * @return the preferred charset + */ + public static String getCharset(Locale loc) { + String charset; + + // Try for an full name match (may include country) + charset = (String) map.get(loc.toString()); + if (charset != null) return charset; + + // If a full name didn't match, try just the language + charset = (String) map.get(loc.getLanguage()); + return charset; // may be null + } +} \ No newline at end of file