PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/xml.core/src/org/netbeans/modules/xml/core/lib/EncodingHelper.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 511 lines | 326 code | 80 blank | 105 comment | 68 complexity | e61db24fe1935b0fc680f61620115779 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.netbeans.modules.xml.core.lib;
  45. import java.io.*;
  46. import java.util.Iterator;
  47. import java.util.Map;
  48. import java.util.TreeMap;
  49. import java.util.logging.Level;
  50. import java.util.logging.Logger;
  51. import javax.swing.text.*;
  52. import org.openide.util.NbBundle;
  53. /**
  54. * XML uses inband encoding detection - this class obtains it.
  55. *
  56. * @author Petr Kuzel
  57. * @version 1.0
  58. */
  59. public class EncodingHelper extends Object {
  60. // heuristic constant guessing max prolog length
  61. private static final int EXPECTED_PROLOG_LENGTH = 1000;
  62. private static final Logger logger = Logger.getLogger(EncodingHelper.class.getName());
  63. /**
  64. * Returns the Java encoding name for the specified IANA encoding name.
  65. *
  66. * @param ianaEncoding
  67. * @return
  68. */
  69. public static String getIANA2JavaMapping(String ianaEncoding) {
  70. String java = (String) encodingIANA2JavaMap.get (ianaEncoding.toUpperCase ());
  71. return java == null ? ianaEncoding : java;
  72. }
  73. /**
  74. * Returns the IANA encoding name for the specified Java encoding name.
  75. *
  76. * @param ianaEncoding
  77. * @return
  78. */
  79. public static String getJava2IANAMapping(String javaEncoding) {
  80. String iana = (String) encodingJava2IANAMap.get (javaEncoding);
  81. return iana == null ? javaEncoding : iana;
  82. }
  83. /** Detect input stream encoding.
  84. * The stream stays intact.
  85. * @return java encoding names ("UTF8", "ASCII", etc.) or null
  86. * if the stream is not markable or enoding cannot be detected.
  87. */
  88. public static String detectEncoding(InputStream in) throws IOException {
  89. if (! in.markSupported()) {
  90. logger.log(Level.WARNING, "EncodingHelper got unmarkable stream: " + in.getClass()); // NOI18N
  91. return null;
  92. }
  93. try {
  94. in.mark(EXPECTED_PROLOG_LENGTH);
  95. byte[] bytes = new byte[EXPECTED_PROLOG_LENGTH];
  96. for (int i = 0; i<bytes.length; i++) {
  97. try {
  98. int datum = in.read();
  99. if (datum == -1) break;
  100. bytes[i] = (byte) datum;
  101. } catch (EOFException ex) {
  102. }
  103. }
  104. String enc = autoDetectEncoding(bytes);
  105. if (enc == null) return null;
  106. enc = detectDeclaredEncoding(bytes, enc);
  107. if (enc == null) return null;
  108. return getIANA2JavaMapping(enc);
  109. } finally {
  110. in.reset();
  111. }
  112. }
  113. /**
  114. * @return Java encoding family identifier or <tt>null</tt> for unrecognized
  115. */
  116. public static String autoDetectEncoding(byte[] buf) throws IOException {
  117. if (buf.length >= 4) {
  118. switch (buf[0]) {
  119. case 0:
  120. // byte order mark of (1234-big endian) or (2143) USC-4
  121. // or '<' encoded as UCS-4 (1234, 2143, 3412) or UTF-16BE
  122. if (buf[1] == (byte)0x3c && buf[2] == (byte)0x00 && buf[3] == (byte)0x3f) {
  123. return "UnicodeBigUnmarked";
  124. }
  125. // else it's probably UCS-4
  126. break;
  127. case 0x3c:
  128. switch (buf[1]) {
  129. // First character is '<'; could be XML without
  130. // an XML directive such as "<hello>", "<!-- ...", // NOI18N
  131. // and so on.
  132. // 3c 00 3f 00 UTF-16 little endian
  133. case 0x00:
  134. if (buf [2] == (byte)0x3f && buf [3] == (byte)0x00) {
  135. return "UnicodeLittleUnmarked";
  136. }
  137. break;
  138. // 3c 3f 78 6d == ASCII and supersets '<?xm'
  139. case '?':
  140. if (buf [2] == 'x' && buf [3] == 'm') {
  141. return "UTF8"; // NOI18N
  142. }
  143. break;
  144. }
  145. break;
  146. // 4c 6f a7 94 ... some EBCDIC code page
  147. case 0x4c:
  148. if (buf[1] == (byte)0x6f && buf[2] == (byte)0xa7 && buf[3] == (byte)0x94) {
  149. return "Cp037"; // NOI18N
  150. }
  151. break;
  152. // UTF-16 big-endian marked
  153. case (byte)0xfe:
  154. if (buf[1] == (byte)0xff && (buf[2] != 0 || buf[3] != 0)) {
  155. return "UnicodeBig"; // NOI18N
  156. }
  157. break;
  158. // UTF-16 little-endian marked
  159. case (byte)0xff:
  160. if (buf[1] == (byte)0xfe && (buf[2] != 0 || buf[3] != 0)) {
  161. return "UnicodeLittle"; // NOI18N
  162. }
  163. break;
  164. // UTF-8 byte order mark
  165. case (byte)0xef:
  166. if (buf[1] == (byte)0xbb && buf[2] == (byte)0xbf) {
  167. return "UTF8"; //NOI18N
  168. }
  169. break;
  170. }
  171. }
  172. return null;
  173. }
  174. /**
  175. * Look for encoding='' anyway stop at <tt>?></tt>
  176. * @return found encoding or null if none declared
  177. */
  178. public static String detectDeclaredEncoding(byte[] data, String baseEncoding) throws IOException {
  179. StringBuffer buf = new StringBuffer();
  180. Reader r;
  181. char delimiter = '"';
  182. r = new InputStreamReader(new ByteArrayInputStream(data), baseEncoding);
  183. try {
  184. for (int c = r.read(); c != -1; c = r.read()) {
  185. buf.append((char)c);
  186. }
  187. } catch (IOException ex) {
  188. // EOF of data out of boundary
  189. // dont care try to guess from given data
  190. }
  191. String s = buf.toString();
  192. int iend = s.indexOf("?>");
  193. iend = iend == -1 ? s.length() : iend;
  194. int iestart = s.indexOf("encoding");
  195. if (iestart == -1 || iestart > iend) return null;
  196. char[] chars = s.toCharArray();
  197. int i = iestart;
  198. for (; i<iend; i++) {
  199. if (chars[i] == '=') break;
  200. }
  201. for (; i<iend; i++) {
  202. if (chars[i] == '\'' || chars[i] == '"') {
  203. delimiter = chars[i];
  204. break;
  205. }
  206. }
  207. i++;
  208. int ivalstart = i;
  209. for (; i<iend; i++) {
  210. if (chars[i] == delimiter) {
  211. return new String(chars, ivalstart, i - ivalstart);
  212. }
  213. }
  214. return null;
  215. }
  216. /**
  217. * Parse MIME content type for attributes.
  218. */
  219. public static String parseMIMECharSet(String mime) {
  220. final String CHARSET = "charset";
  221. if (mime != null) {
  222. int i;
  223. mime = mime.toLowerCase ();
  224. i = mime.indexOf (';');
  225. if (i != -1) {
  226. String attributes;
  227. attributes = mime.substring (i + 1);
  228. mime = mime.substring (0, i);
  229. // use "charset=..." if it's available // NOI18N
  230. i = attributes.indexOf (CHARSET); // NOI18N
  231. if (i != -1) {
  232. attributes = attributes.substring (i + CHARSET.length());
  233. // strip out subsequent attributes
  234. if ((i = attributes.indexOf (';')) != -1)
  235. attributes = attributes.substring (0, i);
  236. // find start of value
  237. if ((i = attributes.indexOf ('=')) != -1) {
  238. attributes = attributes.substring (i + 1);
  239. // strip out rfc822 comments
  240. if ((i = attributes.indexOf ('(')) != -1)
  241. attributes = attributes.substring (0, i);
  242. // double quotes are optional
  243. if ((i = attributes.indexOf ('"')) != -1) {
  244. attributes = attributes.substring (i + 1);
  245. attributes = attributes.substring (0,
  246. attributes.indexOf ('"'));
  247. }
  248. return attributes.trim();
  249. // XXX "\;", "\)" etc were mishandled above // NOI18N
  250. }
  251. }
  252. }
  253. }
  254. return null;
  255. }
  256. /** Document itself is encoded as Unicode, but in
  257. * the document prolog is an encoding attribute.
  258. * @return java encoding names ("UTF8", "ASCII", etc.) or null if no guess
  259. */
  260. public static String detectEncoding(Document doc) throws IOException {
  261. if (doc == null) return null;
  262. try {
  263. String text = doc.getText(0,
  264. doc.getLength() > EXPECTED_PROLOG_LENGTH ?
  265. EXPECTED_PROLOG_LENGTH : doc.getLength()
  266. );
  267. InputStream in = new ByteArrayInputStream(text.getBytes());
  268. return detectEncoding(in);
  269. } catch (BadLocationException ex) {
  270. throw new RuntimeException(ex.toString());
  271. }
  272. }
  273. /**
  274. * IANA to Java encoding mappings
  275. */
  276. final static Map<String, String> encodingIANA2JavaMap = new TreeMap<String, String>();
  277. final static Map<String, String> encodingIANADescriptionMap = new TreeMap<String, String>();
  278. final static Map<String, String> encodingIANAAliasesMap = new TreeMap<String, String>();
  279. final static Map<String, String> encodingJava2IANAMap = new TreeMap<String, String>();
  280. /**
  281. * Static initialization
  282. */
  283. static {
  284. encodingIANA2JavaMap.put("BIG5", "Big5"); // NOI18N
  285. encodingIANADescriptionMap.put("BIG5", NbBundle.getMessage(EncodingHelper.class, "NAME_BIG5")); // NOI18N
  286. encodingIANAAliasesMap.put("BIG5", "BIG5"); // NOI18N
  287. encodingIANA2JavaMap.put("IBM037", "CP037"); // NOI18N
  288. encodingIANADescriptionMap.put("IBM037", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM037")); // NOI18N
  289. encodingIANAAliasesMap.put("IBM037", "IBM037"); // NOI18N
  290. encodingIANAAliasesMap.put("EBCDIC-CP-US", "IBM037"); // NOI18N
  291. encodingIANAAliasesMap.put("EBCDIC-CP-CA", "IBM037"); // NOI18N
  292. encodingIANAAliasesMap.put("EBCDIC-CP-NL", "IBM037"); // NOI18N
  293. encodingIANAAliasesMap.put("EBCDIC-CP-WT", "IBM037"); // NOI18N
  294. encodingIANA2JavaMap.put("IBM277", "CP277"); // NOI18N
  295. encodingIANADescriptionMap.put("IBM277", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM277")); // NOI18N
  296. encodingIANAAliasesMap.put("IBM277", "IBM277"); // NOI18N
  297. encodingIANAAliasesMap.put("EBCDIC-CP-DK", "IBM277"); // NOI18N
  298. encodingIANAAliasesMap.put("EBCDIC-CP-NO", "IBM277"); // NOI18N
  299. encodingIANA2JavaMap.put("IBM278", "CP278"); // NOI18N
  300. encodingIANADescriptionMap.put("IBM278", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM277")); // NOI18N
  301. encodingIANAAliasesMap.put("IBM278", "IBM278"); // NOI18N
  302. encodingIANAAliasesMap.put("EBCDIC-CP-FI", "IBM278"); // NOI18N
  303. encodingIANAAliasesMap.put("EBCDIC-CP-SE", "IBM278"); // NOI18N
  304. encodingIANA2JavaMap.put("IBM280", "CP280"); // NOI18N
  305. encodingIANADescriptionMap.put("IBM280", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM280")); // NOI18N
  306. encodingIANAAliasesMap.put("IBM280", "IBM280"); // NOI18N
  307. encodingIANAAliasesMap.put("EBCDIC-CP-IT", "IBM280"); // NOI18N
  308. encodingIANA2JavaMap.put("IBM284", "CP284"); // NOI18N
  309. encodingIANADescriptionMap.put("IBM284", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM284")); // NOI18N
  310. encodingIANAAliasesMap.put("IBM284", "IBM284"); // NOI18N
  311. encodingIANAAliasesMap.put("EBCDIC-CP-ES", "IBM284"); // NOI18N
  312. encodingIANA2JavaMap.put("IBM285", "CP285"); // NOI18N
  313. encodingIANADescriptionMap.put("IBM285", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM285")); // NOI18N
  314. encodingIANAAliasesMap.put("IBM285", "IBM285"); // NOI18N
  315. encodingIANAAliasesMap.put("EBCDIC-CP-GB", "IBM285"); // NOI18N
  316. encodingIANA2JavaMap.put("IBM297", "CP297"); // NOI18N
  317. encodingIANADescriptionMap.put("IBM297", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM297")); // NOI18N
  318. encodingIANAAliasesMap.put("IBM297", "IBM297"); // NOI18N
  319. encodingIANAAliasesMap.put("EBCDIC-CP-FR", "IBM297"); // NOI18N
  320. encodingIANA2JavaMap.put("IBM424", "CP424"); // NOI18N
  321. encodingIANADescriptionMap.put("IBM424", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM424")); // NOI18N
  322. encodingIANAAliasesMap.put("IBM424", "IBM424"); // NOI18N
  323. encodingIANAAliasesMap.put("EBCDIC-CP-HE", "IBM424"); // NOI18N
  324. encodingIANA2JavaMap.put("IBM500", "CP500"); // NOI18N
  325. encodingIANADescriptionMap.put("IBM500", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM500")); // NOI18N
  326. encodingIANAAliasesMap.put("IBM500", "IBM500"); // NOI18N
  327. encodingIANAAliasesMap.put("EBCDIC-CP-CH", "IBM500"); // NOI18N
  328. encodingIANAAliasesMap.put("EBCDIC-CP-BE", "IBM500"); // NOI18N
  329. encodingIANA2JavaMap.put("IBM870", "CP870"); // NOI18N
  330. encodingIANADescriptionMap.put("IBM870", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM870")); // NOI18N
  331. encodingIANAAliasesMap.put("IBM870", "IBM870"); // NOI18N
  332. encodingIANAAliasesMap.put("EBCDIC-CP-ROECE", "IBM870"); // NOI18N
  333. encodingIANAAliasesMap.put("EBCDIC-CP-YU", "IBM870"); // NOI18N
  334. encodingIANA2JavaMap.put("IBM871", "CP871"); // NOI18N
  335. encodingIANADescriptionMap.put("IBM871", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM871")); // NOI18N
  336. encodingIANAAliasesMap.put("IBM871", "IBM871"); // NOI18N
  337. encodingIANAAliasesMap.put("EBCDIC-CP-IS", "IBM871"); // NOI18N
  338. encodingIANA2JavaMap.put("IBM918", "CP918"); // NOI18N
  339. encodingIANADescriptionMap.put("IBM918", NbBundle.getMessage(EncodingHelper.class, "NAME_IBM918")); // NOI18N
  340. encodingIANAAliasesMap.put("IBM918", "IBM918"); // NOI18N
  341. encodingIANAAliasesMap.put("EBCDIC-CP-AR2", "IBM918"); // NOI18N
  342. encodingIANA2JavaMap.put("EUC-JP", "EUCJIS"); // NOI18N
  343. encodingIANADescriptionMap.put("EUC-JP", NbBundle.getMessage(EncodingHelper.class, "NAME_EUC-JP")); // NOI18N
  344. encodingIANAAliasesMap.put("EUC-JP", "EUC-JP"); // NOI18N
  345. encodingIANA2JavaMap.put("EUC-KR", "KSC5601"); // NOI18N
  346. encodingIANADescriptionMap.put("EUC-KR", NbBundle.getMessage(EncodingHelper.class, "NAME_EUC-KR")); // NOI18N
  347. encodingIANAAliasesMap.put("EUC-KR", "EUC-KR"); // NOI18N
  348. encodingIANA2JavaMap.put("GB2312", "GB2312"); // NOI18N
  349. encodingIANADescriptionMap.put("GB2312", NbBundle.getMessage(EncodingHelper.class, "NAME_GB2312")); // NOI18N
  350. encodingIANAAliasesMap.put("GB2312", "GB2312"); // NOI18N
  351. encodingIANA2JavaMap.put("ISO-2022-JP", "JIS"); // NOI18N
  352. encodingIANADescriptionMap.put("ISO-2022-JP", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-2022-JP")); // NOI18N
  353. encodingIANAAliasesMap.put("ISO-2022-JP", "ISO-2022-JP"); // NOI18N
  354. encodingIANA2JavaMap.put("ISO-2022-KR", "ISO2022KR"); // NOI18N
  355. encodingIANADescriptionMap.put("ISO-2022-KR", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-2022-KR")); // NOI18N
  356. encodingIANAAliasesMap.put("ISO-2022-KR", "ISO-2022-KR"); // NOI18N
  357. encodingIANA2JavaMap.put("ISO-8859-1", "8859_1"); // NOI18N
  358. encodingIANADescriptionMap.put("ISO-8859-1", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-8859-1")); // NOI18N
  359. encodingIANAAliasesMap.put("ISO-8859-1", "ISO-8859-1"); // NOI18N
  360. encodingIANAAliasesMap.put("LATIN1", "ISO-8859-1"); // NOI18N
  361. encodingIANAAliasesMap.put("L1", "ISO-8859-1"); // NOI18N
  362. encodingIANAAliasesMap.put("IBM819", "ISO-8859-1"); // NOI18N
  363. encodingIANAAliasesMap.put("CP819", "ISO-8859-1"); // NOI18N
  364. encodingIANA2JavaMap.put("ISO-8859-2", "8859_2"); // NOI18N
  365. encodingIANADescriptionMap.put("ISO-8859-2", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-8859-2")); // NOI18N
  366. encodingIANAAliasesMap.put("ISO-8859-2", "ISO-8859-2"); // NOI18N
  367. encodingIANAAliasesMap.put("LATIN2", "ISO-8859-2"); // NOI18N
  368. encodingIANAAliasesMap.put("L2", "ISO-8859-2"); // NOI18N
  369. encodingIANA2JavaMap.put("ISO-8859-3", "8859_3"); // NOI18N
  370. encodingIANADescriptionMap.put("ISO-8859-3", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-8859-3")); // NOI18N
  371. encodingIANAAliasesMap.put("ISO-8859-3", "ISO-8859-3"); // NOI18N
  372. encodingIANAAliasesMap.put("LATIN3", "ISO-8859-3"); // NOI18N
  373. encodingIANAAliasesMap.put("L3", "ISO-8859-3"); // NOI18N
  374. encodingIANA2JavaMap.put("ISO-8859-4", "8859_4"); // NOI18N
  375. encodingIANADescriptionMap.put("ISO-8859-4", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-8859-4")); // NOI18N
  376. encodingIANAAliasesMap.put("ISO-8859-4", "ISO-8859-4"); // NOI18N
  377. encodingIANAAliasesMap.put("LATIN4", "ISO-8859-4"); // NOI18N
  378. encodingIANAAliasesMap.put("L4", "ISO-8859-4"); // NOI18N
  379. encodingIANA2JavaMap.put("ISO-8859-5", "8859_5"); // NOI18N
  380. encodingIANADescriptionMap.put("ISO-8859-5", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-8859-5")); // NOI18N
  381. encodingIANAAliasesMap.put("ISO-8859-5", "ISO-8859-5"); // NOI18N
  382. encodingIANAAliasesMap.put("CYRILLIC", "ISO-8859-5"); // NOI18N
  383. encodingIANA2JavaMap.put("ISO-8859-6", "8859_6"); // NOI18N
  384. encodingIANADescriptionMap.put("ISO-8859-6", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-8859-6")); // NOI18N
  385. encodingIANAAliasesMap.put("ISO-8859-6", "ISO-8859-6"); // NOI18N
  386. encodingIANA2JavaMap.put("ISO-8859-7", "8859_7"); // NOI18N
  387. encodingIANADescriptionMap.put("ISO-8859-7", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-8859-7")); // NOI18N
  388. encodingIANAAliasesMap.put("ISO-8859-7", "ISO-8859-7"); // NOI18N
  389. encodingIANAAliasesMap.put("GREEK", "ISO-8859-7"); // NOI18N
  390. encodingIANAAliasesMap.put("GREEK8", "ISO-8859-7"); // NOI18N
  391. encodingIANA2JavaMap.put("ISO-8859-8", "8859_8"); // NOI18N
  392. encodingIANADescriptionMap.put("ISO-8859-8", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-8859-8")); // NOI18N
  393. encodingIANAAliasesMap.put("ISO-8859-8", "ISO-8859-8"); // NOI18N
  394. encodingIANAAliasesMap.put("HEBREW", "ISO-8859-8"); // NOI18N
  395. encodingIANA2JavaMap.put("ISO-8859-9", "8859_9"); // NOI18N
  396. encodingIANADescriptionMap.put("ISO-8859-9", NbBundle.getMessage(EncodingHelper.class, "NAME_ISO-8859-9")); // NOI18N
  397. encodingIANAAliasesMap.put("ISO-8859-9", "ISO-8859-9"); // NOI18N
  398. encodingIANAAliasesMap.put("LATIN5", "ISO-8859-9"); // NOI18N
  399. encodingIANAAliasesMap.put("L5", "ISO-8859-9"); // NOI18N
  400. encodingIANA2JavaMap.put("KOI8-R", "KOI8_R"); // NOI18N
  401. encodingIANADescriptionMap.put("KOI8-R", NbBundle.getMessage(EncodingHelper.class, "NAME_KOI8-R")); // NOI18N
  402. encodingIANAAliasesMap.put("KOI8-R", "KOI8-R"); // NOI18N
  403. encodingIANADescriptionMap.put("US-ASCII", NbBundle.getMessage(EncodingHelper.class, "NAME_ASCII")); // NOI18N
  404. encodingIANAAliasesMap.put("ASCII", "US-ASCII"); // NOI18N
  405. encodingIANAAliasesMap.put("US-ASCII", "US-ASCII"); // NOI18N
  406. encodingIANAAliasesMap.put("ISO646-US", "US-ASCII"); // NOI18N
  407. encodingIANAAliasesMap.put("IBM367", "US-ASCII"); // NOI18N
  408. encodingIANAAliasesMap.put("CP367", "US-ASCII"); // NOI18N
  409. encodingIANA2JavaMap.put("UTF-8", "UTF8"); // NOI18N
  410. encodingIANADescriptionMap.put("UTF-8", NbBundle.getMessage(EncodingHelper.class, "NAME_UTF-8")); // NOI18N
  411. encodingIANAAliasesMap.put("UTF-8", "UTF-8"); // NOI18N
  412. encodingIANA2JavaMap.put("UTF-16", "Unicode"); // NOI18N
  413. encodingIANADescriptionMap.put("UTF-16", NbBundle.getMessage(EncodingHelper.class, "NAME_UTF-16")); // NOI18N
  414. encodingIANAAliasesMap.put("UTF-16", "UTF-16"); // NOI18N
  415. Iterator<String> iter = encodingIANA2JavaMap.keySet().iterator();
  416. String key;
  417. while (iter.hasNext()) {
  418. key = iter.next();
  419. encodingJava2IANAMap.put(encodingIANA2JavaMap.get(key), key);
  420. }
  421. encodingIANA2JavaMap.put("US-ASCII", "8859_1"); // NOI18N
  422. }
  423. }