Home » apache-tomcat-6.0.26-src » org.apache » tomcat » util » http » [javadoc | source]

    1   
    2   
    3   /*
    4    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    5    * 
    6    * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
    7    * 
    8    * Portions Copyright Apache Software Foundation.
    9    * 
   10    * The contents of this file are subject to the terms of either the GNU
   11    * General Public License Version 2 only ("GPL") or the Common Development
   12    * and Distribution License("CDDL") (collectively, the "License").  You
   13    * may not use this file except in compliance with the License. You can obtain
   14    * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
   15    * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
   16    * language governing permissions and limitations under the License.
   17    * 
   18    * When distributing the software, include this License Header Notice in each
   19    * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
   20    * Sun designates this particular file as subject to the "Classpath" exception
   21    * as provided by Sun in the GPL Version 2 section of the License file that
   22    * accompanied this code.  If applicable, add the following below the License
   23    * Header, with the fields enclosed by brackets [] replaced by your own
   24    * identifying information: "Portions Copyrighted [year]
   25    * [name of copyright owner]"
   26    * 
   27    * Contributor(s):
   28    * 
   29    * If you wish your version of this file to be governed by only the CDDL or
   30    * only the GPL Version 2, indicate your decision by adding "[Contributor]
   31    * elects to include this software in this distribution under the [CDDL or GPL
   32    * Version 2] license."  If you don't indicate a single choice of license, a
   33    * recipient has the option to distribute your version of this file under
   34    * either the CDDL, the GPL Version 2 or to extend the choice of license to
   35    * its licensees as provided above.  However, if you add GPL Version 2 code
   36    * and therefore, elected the GPL Version 2 license, then the option applies
   37    * only if the new code is made subject to such option by the copyright
   38    * holder.
   39    */
   40   
   41   /*
   42    *
   43    * This class was originally written by Jason Hunter <jhunter@acm.org>
   44    * as part of the book "Java Servlet Programming" (O'Reilly).  
   45    * See http://www.servlets.com/book for more information.
   46    * Used by Sun Microsystems with permission.
   47    *
   48    */
   49   
   50   package org.apache.tomcat.util.http;
   51   
   52   import java.util;
   53   
   54   /** 
   55    * A mapping to determine the (somewhat arbitrarily) preferred charset for 
   56    * a given locale.  Supports all locales recognized in JDK 1.1.
   57    * This class was originally written by Jason Hunter [jhunter@acm.org]
   58    * as part of the book "Java Servlet Programming" (O'Reilly).
   59    * See <a href="http://www.servlets.com/book">
   60    * http://www.servlets.com/book</a> for more information.
   61    * Used by Sun Microsystems with permission.
   62    */
   63   public class LocaleToCharsetMap {
   64   
   65     private static Hashtable map;
   66   
   67     static {
   68       map = new Hashtable();
   69   
   70       map.put("ar", "ISO-8859-6");
   71       map.put("be", "ISO-8859-5");
   72       map.put("bg", "ISO-8859-5");
   73       map.put("ca", "ISO-8859-1");
   74       map.put("cs", "ISO-8859-2");
   75       map.put("da", "ISO-8859-1");
   76       map.put("de", "ISO-8859-1");
   77       map.put("el", "ISO-8859-7");
   78       map.put("en", "ISO-8859-1");
   79       map.put("es", "ISO-8859-1");
   80       map.put("et", "ISO-8859-1");
   81       map.put("fi", "ISO-8859-1");
   82       map.put("fr", "ISO-8859-1");
   83       map.put("hr", "ISO-8859-2");
   84       map.put("hu", "ISO-8859-2");
   85       map.put("is", "ISO-8859-1");
   86       map.put("it", "ISO-8859-1");
   87       map.put("iw", "ISO-8859-8");
   88       map.put("ja", "Shift_JIS");
   89       map.put("ko", "EUC-KR");     // Requires JDK 1.1.6
   90       map.put("lt", "ISO-8859-2");
   91       map.put("lv", "ISO-8859-2");
   92       map.put("mk", "ISO-8859-5");
   93       map.put("nl", "ISO-8859-1");
   94       map.put("no", "ISO-8859-1");
   95       map.put("pl", "ISO-8859-2");
   96       map.put("pt", "ISO-8859-1");
   97       map.put("ro", "ISO-8859-2");
   98       map.put("ru", "ISO-8859-5");
   99       map.put("sh", "ISO-8859-5");
  100       map.put("sk", "ISO-8859-2");
  101       map.put("sl", "ISO-8859-2");
  102       map.put("sq", "ISO-8859-2");
  103       map.put("sr", "ISO-8859-5");
  104       map.put("sv", "ISO-8859-1");
  105       map.put("tr", "ISO-8859-9");
  106       map.put("uk", "ISO-8859-5");
  107       map.put("zh", "GB2312");
  108       map.put("zh_TW", "Big5");
  109   
  110     }
  111   
  112     /**
  113      * Gets the preferred charset for the given locale, or null if the locale
  114      * is not recognized.
  115      *
  116      * @param loc the locale
  117      * @return the preferred charset
  118      */
  119     public static String getCharset(Locale loc) {
  120       String charset;
  121   
  122       // Try for an full name match (may include country)
  123       charset = (String) map.get(loc.toString());
  124       if (charset != null) return charset;
  125   
  126       // If a full name didn't match, try just the language
  127       charset = (String) map.get(loc.getLanguage());
  128       return charset;  // may be null
  129     }
  130   }

Home » apache-tomcat-6.0.26-src » org.apache » tomcat » util » http » [javadoc | source]