001: /*
002: * $Id: IanaEncodings.java 2696 2007-04-19 11:57:29Z blowagie $
003: * $Name$
004: *
005: * Copyright 2003-2007 Paulo Soares and Bruno Lowagie.
006: *
007: * The contents of this file are subject to the Mozilla Public License Version 1.1
008: * (the "License"); you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the License.
014: *
015: * The Original Code is 'iText, a free JAVA-PDF library'.
016: *
017: * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
018: * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
019: * All Rights Reserved.
020: * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
021: * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
022: *
023: * Contributor(s): all the names of the contributors are added in the source code
024: * where applicable.
025: *
026: * Alternatively, the contents of this file may be used under the terms of the
027: * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
028: * provisions of LGPL are applicable instead of those above. If you wish to
029: * allow use of your version of this file only under the terms of the LGPL
030: * License and not to allow others to use your version of this file under
031: * the MPL, indicate your decision by deleting the provisions above and
032: * replace them with the notice and other provisions required by the LGPL.
033: * If you do not delete the provisions above, a recipient may use your version
034: * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
035: *
036: * This library is free software; you can redistribute it and/or modify it
037: * under the terms of the MPL as stated above or under the terms of the GNU
038: * Library General Public License as published by the Free Software Foundation;
039: * either version 2 of the License, or any later version.
040: *
041: * This library is distributed in the hope that it will be useful, but WITHOUT
042: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
043: * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
044: * details.
045: *
046: * If you didn't download this code from the following link, you should check if
047: * you aren't using an obsolete version:
048: * http://www.lowagie.com/iText/
049: *
050: * The values used in this class are based on class org.apache.xercis.util.EncodingMap
051: * http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/util/EncodingMap.java?view=markup
052: * This class was originally published under the following license:
053: *
054: * Licensed to the Apache Software Foundation (ASF) under one or more
055: * contributor license agreements. See the NOTICE file distributed with
056: * this work for additional information regarding copyright ownership.
057: * The ASF licenses this file to You under the Apache License, Version 2.0
058: * (the "License"); you may not use this file except in compliance with
059: * the License. You may obtain a copy of the License at
060: *
061: * http://www.apache.org/licenses/LICENSE-2.0
062: *
063: * Unless required by applicable law or agreed to in writing, software
064: * distributed under the License is distributed on an "AS IS" BASIS,
065: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
066: * See the License for the specific language governing permissions and
067: * limitations under the License.
068: */
069: package com.lowagie.text.xml.simpleparser;
070:
071: import java.util.HashMap;
072:
073: /**
074: * Translates a IANA encoding name to a Java encoding.
075: */
076:
077: public class IanaEncodings {
078:
079: /** The object that maps IANA to Java encodings. */
080: private static final HashMap map = new HashMap();
081:
082: static {
083: // add IANA to Java encoding mappings.
084: map.put("BIG5", "Big5");
085: map.put("CSBIG5", "Big5");
086: map.put("CP037", "CP037");
087: map.put("IBM037", "CP037");
088: map.put("CSIBM037", "CP037");
089: map.put("EBCDIC-CP-US", "CP037");
090: map.put("EBCDIC-CP-CA", "CP037");
091: map.put("EBCDIC-CP-NL", "CP037");
092: map.put("EBCDIC-CP-WT", "CP037");
093: map.put("IBM277", "CP277");
094: map.put("CP277", "CP277");
095: map.put("CSIBM277", "CP277");
096: map.put("EBCDIC-CP-DK", "CP277");
097: map.put("EBCDIC-CP-NO", "CP277");
098: map.put("IBM278", "CP278");
099: map.put("CP278", "CP278");
100: map.put("CSIBM278", "CP278");
101: map.put("EBCDIC-CP-FI", "CP278");
102: map.put("EBCDIC-CP-SE", "CP278");
103: map.put("IBM280", "CP280");
104: map.put("CP280", "CP280");
105: map.put("CSIBM280", "CP280");
106: map.put("EBCDIC-CP-IT", "CP280");
107: map.put("IBM284", "CP284");
108: map.put("CP284", "CP284");
109: map.put("CSIBM284", "CP284");
110: map.put("EBCDIC-CP-ES", "CP284");
111: map.put("EBCDIC-CP-GB", "CP285");
112: map.put("IBM285", "CP285");
113: map.put("CP285", "CP285");
114: map.put("CSIBM285", "CP285");
115: map.put("EBCDIC-CP-FR", "CP297");
116: map.put("IBM297", "CP297");
117: map.put("CP297", "CP297");
118: map.put("CSIBM297", "CP297");
119: map.put("EBCDIC-CP-AR1", "CP420");
120: map.put("IBM420", "CP420");
121: map.put("CP420", "CP420");
122: map.put("CSIBM420", "CP420");
123: map.put("EBCDIC-CP-HE", "CP424");
124: map.put("IBM424", "CP424");
125: map.put("CP424", "CP424");
126: map.put("CSIBM424", "CP424");
127: map.put("EBCDIC-CP-CH", "CP500");
128: map.put("IBM500", "CP500");
129: map.put("CP500", "CP500");
130: map.put("CSIBM500", "CP500");
131: map.put("EBCDIC-CP-CH", "CP500");
132: map.put("EBCDIC-CP-BE", "CP500");
133: map.put("IBM868", "CP868");
134: map.put("CP868", "CP868");
135: map.put("CSIBM868", "CP868");
136: map.put("CP-AR", "CP868");
137: map.put("IBM869", "CP869");
138: map.put("CP869", "CP869");
139: map.put("CSIBM869", "CP869");
140: map.put("CP-GR", "CP869");
141: map.put("IBM870", "CP870");
142: map.put("CP870", "CP870");
143: map.put("CSIBM870", "CP870");
144: map.put("EBCDIC-CP-ROECE", "CP870");
145: map.put("EBCDIC-CP-YU", "CP870");
146: map.put("IBM871", "CP871");
147: map.put("CP871", "CP871");
148: map.put("CSIBM871", "CP871");
149: map.put("EBCDIC-CP-IS", "CP871");
150: map.put("IBM918", "CP918");
151: map.put("CP918", "CP918");
152: map.put("CSIBM918", "CP918");
153: map.put("EBCDIC-CP-AR2", "CP918");
154: map.put("EUC-JP", "EUCJIS");
155: map.put("CSEUCPkdFmtJapanese", "EUCJIS");
156: map.put("EUC-KR", "KSC5601");
157: map.put("GB2312", "GB2312");
158: map.put("CSGB2312", "GB2312");
159: map.put("ISO-2022-JP", "JIS");
160: map.put("CSISO2022JP", "JIS");
161: map.put("ISO-2022-KR", "ISO2022KR");
162: map.put("CSISO2022KR", "ISO2022KR");
163: map.put("ISO-2022-CN", "ISO2022CN");
164:
165: map.put("X0201", "JIS0201");
166: map.put("CSISO13JISC6220JP", "JIS0201");
167: map.put("X0208", "JIS0208");
168: map.put("ISO-IR-87", "JIS0208");
169: map.put("X0208dbiJIS_X0208-1983", "JIS0208");
170: map.put("CSISO87JISX0208", "JIS0208");
171: map.put("X0212", "JIS0212");
172: map.put("ISO-IR-159", "JIS0212");
173: map.put("CSISO159JISX02121990", "JIS0212");
174: map.put("SHIFT_JIS", "SJIS");
175: map.put("CSSHIFT_JIS", "SJIS");
176: map.put("MS_Kanji", "SJIS");
177:
178: // Add support for Cp1252 and its friends
179: map.put("WINDOWS-1250", "Cp1250");
180: map.put("WINDOWS-1251", "Cp1251");
181: map.put("WINDOWS-1252", "Cp1252");
182: map.put("WINDOWS-1253", "Cp1253");
183: map.put("WINDOWS-1254", "Cp1254");
184: map.put("WINDOWS-1255", "Cp1255");
185: map.put("WINDOWS-1256", "Cp1256");
186: map.put("WINDOWS-1257", "Cp1257");
187: map.put("WINDOWS-1258", "Cp1258");
188: map.put("TIS-620", "TIS620");
189:
190: map.put("ISO-8859-1", "ISO8859_1");
191: map.put("ISO-IR-100", "ISO8859_1");
192: map.put("ISO_8859-1", "ISO8859_1");
193: map.put("LATIN1", "ISO8859_1");
194: map.put("CSISOLATIN1", "ISO8859_1");
195: map.put("L1", "ISO8859_1");
196: map.put("IBM819", "ISO8859_1");
197: map.put("CP819", "ISO8859_1");
198:
199: map.put("ISO-8859-2", "ISO8859_2");
200: map.put("ISO-IR-101", "ISO8859_2");
201: map.put("ISO_8859-2", "ISO8859_2");
202: map.put("LATIN2", "ISO8859_2");
203: map.put("CSISOLATIN2", "ISO8859_2");
204: map.put("L2", "ISO8859_2");
205:
206: map.put("ISO-8859-3", "ISO8859_3");
207: map.put("ISO-IR-109", "ISO8859_3");
208: map.put("ISO_8859-3", "ISO8859_3");
209: map.put("LATIN3", "ISO8859_3");
210: map.put("CSISOLATIN3", "ISO8859_3");
211: map.put("L3", "ISO8859_3");
212:
213: map.put("ISO-8859-4", "ISO8859_4");
214: map.put("ISO-IR-110", "ISO8859_4");
215: map.put("ISO_8859-4", "ISO8859_4");
216: map.put("LATIN4", "ISO8859_4");
217: map.put("CSISOLATIN4", "ISO8859_4");
218: map.put("L4", "ISO8859_4");
219:
220: map.put("ISO-8859-5", "ISO8859_5");
221: map.put("ISO-IR-144", "ISO8859_5");
222: map.put("ISO_8859-5", "ISO8859_5");
223: map.put("CYRILLIC", "ISO8859_5");
224: map.put("CSISOLATINCYRILLIC", "ISO8859_5");
225:
226: map.put("ISO-8859-6", "ISO8859_6");
227: map.put("ISO-IR-127", "ISO8859_6");
228: map.put("ISO_8859-6", "ISO8859_6");
229: map.put("ECMA-114", "ISO8859_6");
230: map.put("ASMO-708", "ISO8859_6");
231: map.put("ARABIC", "ISO8859_6");
232: map.put("CSISOLATINARABIC", "ISO8859_6");
233:
234: map.put("ISO-8859-7", "ISO8859_7");
235: map.put("ISO-IR-126", "ISO8859_7");
236: map.put("ISO_8859-7", "ISO8859_7");
237: map.put("ELOT_928", "ISO8859_7");
238: map.put("ECMA-118", "ISO8859_7");
239: map.put("GREEK", "ISO8859_7");
240: map.put("CSISOLATINGREEK", "ISO8859_7");
241: map.put("GREEK8", "ISO8859_7");
242:
243: map.put("ISO-8859-8", "ISO8859_8");
244: map.put("ISO-8859-8-I", "ISO8859_8"); // added since this encoding only differs w.r.t. presentation
245: map.put("ISO-IR-138", "ISO8859_8");
246: map.put("ISO_8859-8", "ISO8859_8");
247: map.put("HEBREW", "ISO8859_8");
248: map.put("CSISOLATINHEBREW", "ISO8859_8");
249:
250: map.put("ISO-8859-9", "ISO8859_9");
251: map.put("ISO-IR-148", "ISO8859_9");
252: map.put("ISO_8859-9", "ISO8859_9");
253: map.put("LATIN5", "ISO8859_9");
254: map.put("CSISOLATIN5", "ISO8859_9");
255: map.put("L5", "ISO8859_9");
256:
257: map.put("KOI8-R", "KOI8_R");
258: map.put("CSKOI8-R", "KOI8_R");
259: map.put("US-ASCII", "ASCII");
260: map.put("ISO-IR-6", "ASCII");
261: map.put("ANSI_X3.4-1986", "ASCII");
262: map.put("ISO_646.IRV:1991", "ASCII");
263: map.put("ASCII", "ASCII");
264: map.put("CSASCII", "ASCII");
265: map.put("ISO646-US", "ASCII");
266: map.put("US", "ASCII");
267: map.put("IBM367", "ASCII");
268: map.put("CP367", "ASCII");
269: map.put("UTF-8", "UTF8");
270: map.put("UTF-16", "Unicode");
271: map.put("UTF-16BE", "UnicodeBig");
272: map.put("UTF-16LE", "UnicodeLittle");
273: }
274:
275: /**
276: * Gets the java encoding from the IANA encoding. If the encoding cannot be found
277: * it returns the input.
278: * @param iana the IANA encoding
279: * @return the java encoding
280: */
281: public static String getJavaEncoding(String iana) {
282: String IANA = iana.toUpperCase();
283: String jdec = (String) map.get(IANA);
284: if (jdec == null)
285: jdec = iana;
286: return jdec;
287: }
288: }
|