com.oreilly.servlet.LocaleToCharsetMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cos Show documentation
Show all versions of cos Show documentation
Cos.
The version 2024.5.0.0 is for Servlet 5.0.0.
The newest version!
// Copyright (C) 1998-2001 by Jason Hunter .
// All rights reserved. Use of this class is limited.
// Please see the LICENSE for more information.
package com.oreilly.servlet;
import java.util.*;
/**
* A mapping to determine the (somewhat arbitrarily) preferred charset for
* a given locale. Supports all locales recognized in JDK 1.1. This
* class is used by the LocaleNegotiator.
*
* @see com.oreilly.servlet.LocaleNegotiator
*
* @author Jason Hunter, Copyright © 1998
* @version 1.0, 98/09/18
*/
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
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy