1 | /* | |
2 | * $Id: IanaEncodings.java 3373 2008-05-12 16:21:24Z xlv $ | |
3 | * | |
4 | * Copyright 2003-2007 Paulo Soares and Bruno Lowagie. | |
5 | * | |
6 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
7 | * (the "License"); you may not use this file except in compliance with the License. | |
8 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
9 | * | |
10 | * Software distributed under the License is distributed on an "AS IS" basis, | |
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 | * for the specific language governing rights and limitations under the License. | |
13 | * | |
14 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
15 | * | |
16 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
17 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
18 | * All Rights Reserved. | |
19 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
20 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
21 | * | |
22 | * Contributor(s): all the names of the contributors are added in the source code | |
23 | * where applicable. | |
24 | * | |
25 | * Alternatively, the contents of this file may be used under the terms of the | |
26 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
27 | * provisions of LGPL are applicable instead of those above. If you wish to | |
28 | * allow use of your version of this file only under the terms of the LGPL | |
29 | * License and not to allow others to use your version of this file under | |
30 | * the MPL, indicate your decision by deleting the provisions above and | |
31 | * replace them with the notice and other provisions required by the LGPL. | |
32 | * If you do not delete the provisions above, a recipient may use your version | |
33 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
34 | * | |
35 | * This library is free software; you can redistribute it and/or modify it | |
36 | * under the terms of the MPL as stated above or under the terms of the GNU | |
37 | * Library General Public License as published by the Free Software Foundation; | |
38 | * either version 2 of the License, or any later version. | |
39 | * | |
40 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
41 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
42 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
43 | * details. | |
44 | * | |
45 | * If you didn't download this code from the following link, you should check if | |
46 | * you aren't using an obsolete version: | |
47 | * http://www.lowagie.com/iText/ | |
48 | * | |
49 | * The values used in this class are based on class org.apache.xercis.util.EncodingMap | |
50 | * http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/util/EncodingMap.java?view=markup | |
51 | * This class was originally published under the following license: | |
52 | * | |
53 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
54 | * contributor license agreements. See the NOTICE file distributed with | |
55 | * this work for additional information regarding copyright ownership. | |
56 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
57 | * (the "License"); you may not use this file except in compliance with | |
58 | * the License. You may obtain a copy of the License at | |
59 | * | |
60 | * http://www.apache.org/licenses/LICENSE-2.0 | |
61 | * | |
62 | * Unless required by applicable law or agreed to in writing, software | |
63 | * distributed under the License is distributed on an "AS IS" BASIS, | |
64 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
65 | * See the License for the specific language governing permissions and | |
66 | * limitations under the License. | |
67 | */ | |
68 | package com.lowagie.text.xml.simpleparser; | |
69 | ||
70 | import java.util.HashMap; | |
71 | ||
72 | /** | |
73 | * Translates a IANA encoding name to a Java encoding. | |
74 | */ | |
75 | ||
76 | public class IanaEncodings { | |
77 | ||
78 | /** The object that maps IANA to Java encodings. */ | |
79 | private static final HashMap map = new HashMap(); | |
80 | ||
81 | static { | |
82 | // add IANA to Java encoding mappings. | |
83 | map.put("BIG5", "Big5"); | |
84 | map.put("CSBIG5", "Big5"); | |
85 | map.put("CP037", "CP037"); | |
86 | map.put("IBM037", "CP037"); | |
87 | map.put("CSIBM037", "CP037"); | |
88 | map.put("EBCDIC-CP-US", "CP037"); | |
89 | map.put("EBCDIC-CP-CA", "CP037"); | |
90 | map.put("EBCDIC-CP-NL", "CP037"); | |
91 | map.put("EBCDIC-CP-WT", "CP037"); | |
92 | map.put("IBM277", "CP277"); | |
93 | map.put("CP277", "CP277"); | |
94 | map.put("CSIBM277", "CP277"); | |
95 | map.put("EBCDIC-CP-DK", "CP277"); | |
96 | map.put("EBCDIC-CP-NO", "CP277"); | |
97 | map.put("IBM278", "CP278"); | |
98 | map.put("CP278", "CP278"); | |
99 | map.put("CSIBM278", "CP278"); | |
100 | map.put("EBCDIC-CP-FI", "CP278"); | |
101 | map.put("EBCDIC-CP-SE", "CP278"); | |
102 | map.put("IBM280", "CP280"); | |
103 | map.put("CP280", "CP280"); | |
104 | map.put("CSIBM280", "CP280"); | |
105 | map.put("EBCDIC-CP-IT", "CP280"); | |
106 | map.put("IBM284", "CP284"); | |
107 | map.put("CP284", "CP284"); | |
108 | map.put("CSIBM284", "CP284"); | |
109 | map.put("EBCDIC-CP-ES", "CP284"); | |
110 | map.put("EBCDIC-CP-GB", "CP285"); | |
111 | map.put("IBM285", "CP285"); | |
112 | map.put("CP285", "CP285"); | |
113 | map.put("CSIBM285", "CP285"); | |
114 | map.put("EBCDIC-CP-FR", "CP297"); | |
115 | map.put("IBM297", "CP297"); | |
116 | map.put("CP297", "CP297"); | |
117 | map.put("CSIBM297", "CP297"); | |
118 | map.put("EBCDIC-CP-AR1", "CP420"); | |
119 | map.put("IBM420", "CP420"); | |
120 | map.put("CP420", "CP420"); | |
121 | map.put("CSIBM420", "CP420"); | |
122 | map.put("EBCDIC-CP-HE", "CP424"); | |
123 | map.put("IBM424", "CP424"); | |
124 | map.put("CP424", "CP424"); | |
125 | map.put("CSIBM424", "CP424"); | |
126 | map.put("EBCDIC-CP-CH", "CP500"); | |
127 | map.put("IBM500", "CP500"); | |
128 | map.put("CP500", "CP500"); | |
129 | map.put("CSIBM500", "CP500"); | |
130 | map.put("EBCDIC-CP-CH", "CP500"); | |
131 | map.put("EBCDIC-CP-BE", "CP500"); | |
132 | map.put("IBM868", "CP868"); | |
133 | map.put("CP868", "CP868"); | |
134 | map.put("CSIBM868", "CP868"); | |
135 | map.put("CP-AR", "CP868"); | |
136 | map.put("IBM869", "CP869"); | |
137 | map.put("CP869", "CP869"); | |
138 | map.put("CSIBM869", "CP869"); | |
139 | map.put("CP-GR", "CP869"); | |
140 | map.put("IBM870", "CP870"); | |
141 | map.put("CP870", "CP870"); | |
142 | map.put("CSIBM870", "CP870"); | |
143 | map.put("EBCDIC-CP-ROECE", "CP870"); | |
144 | map.put("EBCDIC-CP-YU", "CP870"); | |
145 | map.put("IBM871", "CP871"); | |
146 | map.put("CP871", "CP871"); | |
147 | map.put("CSIBM871", "CP871"); | |
148 | map.put("EBCDIC-CP-IS", "CP871"); | |
149 | map.put("IBM918", "CP918"); | |
150 | map.put("CP918", "CP918"); | |
151 | map.put("CSIBM918", "CP918"); | |
152 | map.put("EBCDIC-CP-AR2", "CP918"); | |
153 | map.put("EUC-JP", "EUCJIS"); | |
154 | map.put("CSEUCPkdFmtJapanese", "EUCJIS"); | |
155 | map.put("EUC-KR", "KSC5601"); | |
156 | map.put("GB2312", "GB2312"); | |
157 | map.put("CSGB2312", "GB2312"); | |
158 | map.put("ISO-2022-JP", "JIS"); | |
159 | map.put("CSISO2022JP", "JIS"); | |
160 | map.put("ISO-2022-KR", "ISO2022KR"); | |
161 | map.put("CSISO2022KR", "ISO2022KR"); | |
162 | map.put("ISO-2022-CN", "ISO2022CN"); | |
163 | | |
164 | map.put("X0201", "JIS0201"); | |
165 | map.put("CSISO13JISC6220JP", "JIS0201"); | |
166 | map.put("X0208", "JIS0208"); | |
167 | map.put("ISO-IR-87", "JIS0208"); | |
168 | map.put("X0208dbiJIS_X0208-1983", "JIS0208"); | |
169 | map.put("CSISO87JISX0208", "JIS0208"); | |
170 | map.put("X0212", "JIS0212"); | |
171 | map.put("ISO-IR-159", "JIS0212"); | |
172 | map.put("CSISO159JISX02121990", "JIS0212"); | |
173 | map.put("SHIFT_JIS", "SJIS"); | |
174 | map.put("CSSHIFT_JIS", "SJIS"); | |
175 | map.put("MS_Kanji", "SJIS"); | |
176 | | |
177 | // Add support for Cp1252 and its friends | |
178 | map.put("WINDOWS-1250", "Cp1250"); | |
179 | map.put("WINDOWS-1251", "Cp1251"); | |
180 | map.put("WINDOWS-1252", "Cp1252"); | |
181 | map.put("WINDOWS-1253", "Cp1253"); | |
182 | map.put("WINDOWS-1254", "Cp1254"); | |
183 | map.put("WINDOWS-1255", "Cp1255"); | |
184 | map.put("WINDOWS-1256", "Cp1256"); | |
185 | map.put("WINDOWS-1257", "Cp1257"); | |
186 | map.put("WINDOWS-1258", "Cp1258"); | |
187 | map.put("TIS-620", "TIS620"); | |
188 | | |
189 | map.put("ISO-8859-1", "ISO8859_1"); | |
190 | map.put("ISO-IR-100", "ISO8859_1"); | |
191 | map.put("ISO_8859-1", "ISO8859_1"); | |
192 | map.put("LATIN1", "ISO8859_1"); | |
193 | map.put("CSISOLATIN1", "ISO8859_1"); | |
194 | map.put("L1", "ISO8859_1"); | |
195 | map.put("IBM819", "ISO8859_1"); | |
196 | map.put("CP819", "ISO8859_1"); | |
197 | | |
198 | map.put("ISO-8859-2", "ISO8859_2"); | |
199 | map.put("ISO-IR-101", "ISO8859_2"); | |
200 | map.put("ISO_8859-2", "ISO8859_2"); | |
201 | map.put("LATIN2", "ISO8859_2"); | |
202 | map.put("CSISOLATIN2", "ISO8859_2"); | |
203 | map.put("L2", "ISO8859_2"); | |
204 | | |
205 | map.put("ISO-8859-3", "ISO8859_3"); | |
206 | map.put("ISO-IR-109", "ISO8859_3"); | |
207 | map.put("ISO_8859-3", "ISO8859_3"); | |
208 | map.put("LATIN3", "ISO8859_3"); | |
209 | map.put("CSISOLATIN3", "ISO8859_3"); | |
210 | map.put("L3", "ISO8859_3"); | |
211 | | |
212 | map.put("ISO-8859-4", "ISO8859_4"); | |
213 | map.put("ISO-IR-110", "ISO8859_4"); | |
214 | map.put("ISO_8859-4", "ISO8859_4"); | |
215 | map.put("LATIN4", "ISO8859_4"); | |
216 | map.put("CSISOLATIN4", "ISO8859_4"); | |
217 | map.put("L4", "ISO8859_4"); | |
218 | | |
219 | map.put("ISO-8859-5", "ISO8859_5"); | |
220 | map.put("ISO-IR-144", "ISO8859_5"); | |
221 | map.put("ISO_8859-5", "ISO8859_5"); | |
222 | map.put("CYRILLIC", "ISO8859_5"); | |
223 | map.put("CSISOLATINCYRILLIC", "ISO8859_5"); | |
224 | | |
225 | map.put("ISO-8859-6", "ISO8859_6"); | |
226 | map.put("ISO-IR-127", "ISO8859_6"); | |
227 | map.put("ISO_8859-6", "ISO8859_6"); | |
228 | map.put("ECMA-114", "ISO8859_6"); | |
229 | map.put("ASMO-708", "ISO8859_6"); | |
230 | map.put("ARABIC", "ISO8859_6"); | |
231 | map.put("CSISOLATINARABIC", "ISO8859_6"); | |
232 | | |
233 | map.put("ISO-8859-7", "ISO8859_7"); | |
234 | map.put("ISO-IR-126", "ISO8859_7"); | |
235 | map.put("ISO_8859-7", "ISO8859_7"); | |
236 | map.put("ELOT_928", "ISO8859_7"); | |
237 | map.put("ECMA-118", "ISO8859_7"); | |
238 | map.put("GREEK", "ISO8859_7"); | |
239 | map.put("CSISOLATINGREEK", "ISO8859_7"); | |
240 | map.put("GREEK8", "ISO8859_7"); | |
241 | | |
242 | map.put("ISO-8859-8", "ISO8859_8"); | |
243 | map.put("ISO-8859-8-I", "ISO8859_8"); // added since this encoding only differs w.r.t. presentation | |
244 | map.put("ISO-IR-138", "ISO8859_8"); | |
245 | map.put("ISO_8859-8", "ISO8859_8"); | |
246 | map.put("HEBREW", "ISO8859_8"); | |
247 | map.put("CSISOLATINHEBREW", "ISO8859_8"); | |
248 | | |
249 | map.put("ISO-8859-9", "ISO8859_9"); | |
250 | map.put("ISO-IR-148", "ISO8859_9"); | |
251 | map.put("ISO_8859-9", "ISO8859_9"); | |
252 | map.put("LATIN5", "ISO8859_9"); | |
253 | map.put("CSISOLATIN5", "ISO8859_9"); | |
254 | map.put("L5", "ISO8859_9"); | |
255 | | |
256 | map.put("KOI8-R", "KOI8_R"); | |
257 | map.put("CSKOI8-R", "KOI8_R"); | |
258 | map.put("US-ASCII", "ASCII"); | |
259 | map.put("ISO-IR-6", "ASCII"); | |
260 | map.put("ANSI_X3.4-1986", "ASCII"); | |
261 | map.put("ISO_646.IRV:1991", "ASCII"); | |
262 | map.put("ASCII", "ASCII"); | |
263 | map.put("CSASCII", "ASCII"); | |
264 | map.put("ISO646-US", "ASCII"); | |
265 | map.put("US", "ASCII"); | |
266 | map.put("IBM367", "ASCII"); | |
267 | map.put("CP367", "ASCII"); | |
268 | map.put("UTF-8", "UTF8"); | |
269 | map.put("UTF-16", "Unicode"); | |
270 | map.put("UTF-16BE", "UnicodeBig"); | |
271 | map.put("UTF-16LE", "UnicodeLittle"); | |
272 | } | |
273 | | |
274 | /** | |
275 | * Gets the java encoding from the IANA encoding. If the encoding cannot be found | |
276 | * it returns the input. | |
277 | * @param iana the IANA encoding | |
278 | * @return the java encoding | |
279 | */ | |
280 | public static String getJavaEncoding(String iana) { | |
281 | String IANA = iana.toUpperCase(); | |
282 | String jdec = (String)map.get(IANA); | |
283 |
1
1. getJavaEncoding : negated conditional → NO_COVERAGE |
if (jdec == null) |
284 | jdec = iana; | |
285 |
1
1. getJavaEncoding : mutated return of Object value for com/lowagie/text/xml/simpleparser/IanaEncodings::getJavaEncoding to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return jdec; |
286 | } | |
287 | } | |
Mutations | ||
283 |
1.1 |
|
285 |
1.1 |