PageRenderTime 25ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/xml.core/src/org/netbeans/modules/xml/api/EncodingUtil.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 583 lines | 370 code | 83 blank | 130 comment | 73 complexity | e4319a7f3536654491e51c3e8b0e1693 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.api;
  45. import java.io.*;
  46. import java.nio.charset.Charset;
  47. import java.util.Iterator;
  48. import java.util.Map;
  49. import java.util.TreeMap;
  50. import java.util.logging.Level;
  51. import java.util.logging.Logger;
  52. import javax.swing.text.*;
  53. import org.netbeans.api.project.FileOwnerQuery;
  54. import org.netbeans.api.project.Project;
  55. import org.netbeans.modules.xml.core.lib.UnicodeReader;
  56. import org.netbeans.spi.queries.FileEncodingQueryImplementation;
  57. import org.openide.filesystems.FileObject;
  58. import org.openide.util.NbBundle;
  59. /**
  60. * XML uses inband encoding detection - this class obtains it.
  61. *
  62. * @author Petr Jiricka
  63. * @version 1.0
  64. */
  65. public class EncodingUtil {
  66. // heuristic constant guessing max prolog length
  67. private static final int EXPECTED_PROLOG_LENGTH = 1000;
  68. private static final Logger logger = Logger.getLogger(EncodingUtil.class.getName());
  69. /**
  70. * Returns a specialized reader that allows to skip BOM marks.
  71. * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058.
  72. * See http://www.netbeans.org/issues/show_bug.cgi?id=83321.
  73. * @param in
  74. * @param encoding
  75. * @return a specialized reader that allows to skip BOM marks.
  76. */
  77. public static Reader getUnicodeReader(InputStream in, String encoding) {
  78. return new UnicodeReader(in, encoding);
  79. }
  80. /**
  81. * Detect input stream encoding.
  82. * The stream stays intact.
  83. * @return java encoding names ("UTF8", "ASCII", etc.) or null
  84. * if the stream is not markable or enoding cannot be detected.
  85. */
  86. public static String detectEncoding(InputStream in) throws IOException {
  87. return doDetectEncoding(in);
  88. }
  89. /** Document itself is encoded as Unicode, but in
  90. * the document prolog is an encoding attribute.
  91. * @return java encoding names ("UTF8", "ASCII", etc.) or null if no guess
  92. */
  93. public static String detectEncoding(Document doc) throws IOException {
  94. return doDetectEncoding(doc);
  95. }
  96. /**
  97. * Checks the validity of an encoding string.
  98. */
  99. public static boolean isValidEncoding(String encoding) {
  100. boolean valid = true;
  101. try {
  102. Charset.forName(encoding);
  103. } catch (Exception ex) {
  104. valid = false;
  105. }
  106. return valid;
  107. }
  108. /**
  109. * Returns the project's encoding for the specified file.
  110. * Returns UTF-8 encoding, if none found.
  111. */
  112. public static String getProjectEncoding(FileObject file) {
  113. Project project = FileOwnerQuery.getOwner(file);
  114. if(project == null) {
  115. logger.log(Level.INFO, NbBundle.getMessage(EncodingUtil.class, "Null_Project")); //NOI18N
  116. return "UTF-8"; //NOI18N
  117. }
  118. FileEncodingQueryImplementation feq = project.getLookup().
  119. lookup(FileEncodingQueryImplementation.class);
  120. if(feq == null) {
  121. logger.log(Level.INFO, NbBundle.getMessage(EncodingUtil.class, "Null_FEQ")); //NOI18N
  122. return "UTF-8"; //NOI18N
  123. }
  124. if(feq.getEncoding(file) == null){
  125. logger.log(Level.INFO, NbBundle.getMessage(EncodingUtil.class, "Null_Encoding")); //NOI18N
  126. return "UTF-8";
  127. }
  128. return feq.getEncoding(file).name();
  129. }
  130. /**
  131. * Returns the Java encoding name for the specified IANA encoding name.
  132. *
  133. * @param ianaEncoding
  134. * @return
  135. */
  136. public static String getIANA2JavaMapping(String ianaEncoding) {
  137. String java = (String) encodingIANA2JavaMap.get (ianaEncoding.toUpperCase ());
  138. return java == null ? ianaEncoding : java;
  139. }
  140. /**
  141. * Returns the IANA encoding name for the specified Java encoding name.
  142. *
  143. * @param ianaEncoding
  144. * @return
  145. */
  146. public static String getJava2IANAMapping(String javaEncoding) {
  147. String iana = (String) encodingJava2IANAMap.get (javaEncoding);
  148. return iana == null ? javaEncoding : iana;
  149. }
  150. /** Detect input stream encoding.
  151. * The stream stays intact.
  152. * @return java encoding names ("UTF8", "ASCII", etc.) or null
  153. * if the stream is not markable or enoding cannot be detected.
  154. */
  155. private static String doDetectEncoding(InputStream in) throws IOException {
  156. if (! in.markSupported()) {
  157. logger.log(Level.WARNING, "EncodingHelper got unmarkable stream: " + in.getClass()); // NOI18N
  158. return null;
  159. }
  160. try {
  161. in.mark(EXPECTED_PROLOG_LENGTH);
  162. byte[] bytes = new byte[EXPECTED_PROLOG_LENGTH];
  163. int size = 0;
  164. try {
  165. size = in.read(bytes);
  166. } catch (EOFException ex) {
  167. }
  168. String enc = autoDetectEncoding(bytes, size);
  169. if (enc == null) return null;
  170. enc = detectDeclaredEncoding(bytes, enc, size);
  171. if (enc == null) return null;
  172. return getIANA2JavaMapping(enc);
  173. } finally {
  174. in.reset();
  175. }
  176. }
  177. /**
  178. * @return Java encoding family identifier or <tt>null</tt> for unrecognized
  179. */
  180. static String autoDetectEncoding(byte[] buf) throws IOException {
  181. return autoDetectEncoding(buf, buf.length);
  182. }
  183. private static String autoDetectEncoding(byte[] buf, int len) throws IOException {
  184. if (len >= 4) {
  185. switch (buf[0]) {
  186. case 0:
  187. // byte order mark of (1234-big endian) or (2143) USC-4
  188. // or '<' encoded as UCS-4 (1234, 2143, 3412) or UTF-16BE
  189. if (buf[1] == (byte)0x3c && buf[2] == (byte)0x00 && buf[3] == (byte)0x3f) {
  190. return "UnicodeBigUnmarked";
  191. }
  192. // else it's probably UCS-4
  193. break;
  194. case 0x3c:
  195. switch (buf[1]) {
  196. // First character is '<'; could be XML without
  197. // an XML directive such as "<hello>", "<!-- ...", // NOI18N
  198. // and so on.
  199. // 3c 00 3f 00 UTF-16 little endian
  200. case 0x00:
  201. if (buf [2] == (byte)0x3f && buf [3] == (byte)0x00) {
  202. return "UnicodeLittleUnmarked";
  203. }
  204. break;
  205. // 3c 3f 78 6d == ASCII and supersets '<?xm'
  206. case '?':
  207. if (buf [2] == 'x' && buf [3] == 'm') {
  208. return "UTF8"; // NOI18N
  209. }
  210. break;
  211. }
  212. break;
  213. // 4c 6f a7 94 ... some EBCDIC code page
  214. case 0x4c:
  215. if (buf[1] == (byte)0x6f && buf[2] == (byte)0xa7 && buf[3] == (byte)0x94) {
  216. return "Cp037"; // NOI18N
  217. }
  218. break;
  219. // UTF-16 big-endian marked
  220. case (byte)0xfe:
  221. if (buf[1] == (byte)0xff && (buf[2] != 0 || buf[3] != 0)) {
  222. return "UnicodeBig"; // NOI18N
  223. }
  224. break;
  225. // UTF-16 little-endian marked
  226. case (byte)0xff:
  227. if (buf[1] == (byte)0xfe && (buf[2] != 0 || buf[3] != 0)) {
  228. return "UnicodeLittle"; // NOI18N
  229. }
  230. break;
  231. // UTF-8 byte order mark
  232. case (byte)0xef:
  233. if (buf[1] == (byte)0xbb && buf[2] == (byte)0xbf) {
  234. return "UTF8"; //NOI18N
  235. }
  236. break;
  237. }
  238. }
  239. return null;
  240. }
  241. /**
  242. * Look for encoding='' anyway stop at <tt>?></tt>
  243. * @return found encoding or null if none declared
  244. */
  245. static String detectDeclaredEncoding(byte[] data, String baseEncoding) throws IOException {
  246. return detectDeclaredEncoding(data, baseEncoding, data.length);
  247. }
  248. private static String detectDeclaredEncoding(byte[] data, String baseEncoding, int size) throws IOException {
  249. char delimiter = '"';
  250. String s = new String(data, 0, size, baseEncoding);
  251. int iend = s.indexOf("?>");
  252. iend = iend == -1 ? s.length() : iend;
  253. int iestart = s.indexOf("encoding");
  254. if (iestart == -1 || iestart > iend) return null;
  255. char[] chars = s.toCharArray();
  256. int i = iestart;
  257. for (; i<iend; i++) {
  258. if (chars[i] == '=') break;
  259. }
  260. for (; i<iend; i++) {
  261. if (chars[i] == '\'' || chars[i] == '"') {
  262. delimiter = chars[i];
  263. break;
  264. }
  265. }
  266. i++;
  267. int ivalstart = i;
  268. for (; i<iend; i++) {
  269. if (chars[i] == delimiter) {
  270. return new String(chars, ivalstart, i - ivalstart);
  271. }
  272. }
  273. return null;
  274. }
  275. /**
  276. * Parse MIME content type for attributes.
  277. */
  278. private static String parseMIMECharSet(String mime) {
  279. final String CHARSET = "charset";
  280. if (mime != null) {
  281. int i;
  282. mime = mime.toLowerCase ();
  283. i = mime.indexOf (';');
  284. if (i != -1) {
  285. String attributes;
  286. attributes = mime.substring (i + 1);
  287. mime = mime.substring (0, i);
  288. // use "charset=..." if it's available // NOI18N
  289. i = attributes.indexOf (CHARSET); // NOI18N
  290. if (i != -1) {
  291. attributes = attributes.substring (i + CHARSET.length());
  292. // strip out subsequent attributes
  293. if ((i = attributes.indexOf (';')) != -1)
  294. attributes = attributes.substring (0, i);
  295. // find start of value
  296. if ((i = attributes.indexOf ('=')) != -1) {
  297. attributes = attributes.substring (i + 1);
  298. // strip out rfc822 comments
  299. if ((i = attributes.indexOf ('(')) != -1)
  300. attributes = attributes.substring (0, i);
  301. // double quotes are optional
  302. if ((i = attributes.indexOf ('"')) != -1) {
  303. attributes = attributes.substring (i + 1);
  304. attributes = attributes.substring (0,
  305. attributes.indexOf ('"'));
  306. }
  307. return attributes.trim();
  308. // XXX "\;", "\)" etc were mishandled above // NOI18N
  309. }
  310. }
  311. }
  312. }
  313. return null;
  314. }
  315. /** Document itself is encoded as Unicode, but in
  316. * the document prolog is an encoding attribute.
  317. * @return java encoding names ("UTF8", "ASCII", etc.) or null if no guess
  318. */
  319. private static String doDetectEncoding(final Document doc) throws IOException {
  320. if (doc == null) return null;
  321. final String[] text = new String[1];
  322. final BadLocationException[] exc = new BadLocationException[1];
  323. doc.render(new Runnable() {
  324. public void run() {
  325. try {
  326. text[0] = doc.getText(0,
  327. doc.getLength() > EXPECTED_PROLOG_LENGTH ?
  328. EXPECTED_PROLOG_LENGTH : doc.getLength()
  329. );
  330. } catch (BadLocationException e) {
  331. exc[0] = e;
  332. }
  333. }
  334. });
  335. if (exc[0] != null) {
  336. IOException e = new IOException("Cannot read contents");
  337. e.initCause(exc[0]);
  338. throw e;
  339. }
  340. InputStream in = new ByteArrayInputStream(text[0].getBytes());
  341. return detectEncoding(in);
  342. }
  343. /**
  344. * IANA to Java encoding mappings
  345. */
  346. final static Map<String, String> encodingIANA2JavaMap = new TreeMap<String, String>();
  347. final static Map<String, String> encodingIANADescriptionMap = new TreeMap<String, String>();
  348. final static Map<String, String> encodingIANAAliasesMap = new TreeMap<String, String>();
  349. final static Map<String, String> encodingJava2IANAMap = new TreeMap<String, String>();
  350. /**
  351. * Static initialization
  352. */
  353. static {
  354. encodingIANA2JavaMap.put("BIG5", "Big5"); // NOI18N
  355. encodingIANADescriptionMap.put("BIG5", NbBundle.getMessage(EncodingUtil.class, "NAME_BIG5")); // NOI18N
  356. encodingIANAAliasesMap.put("BIG5", "BIG5"); // NOI18N
  357. encodingIANA2JavaMap.put("IBM037", "CP037"); // NOI18N
  358. encodingIANADescriptionMap.put("IBM037", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM037")); // NOI18N
  359. encodingIANAAliasesMap.put("IBM037", "IBM037"); // NOI18N
  360. encodingIANAAliasesMap.put("EBCDIC-CP-US", "IBM037"); // NOI18N
  361. encodingIANAAliasesMap.put("EBCDIC-CP-CA", "IBM037"); // NOI18N
  362. encodingIANAAliasesMap.put("EBCDIC-CP-NL", "IBM037"); // NOI18N
  363. encodingIANAAliasesMap.put("EBCDIC-CP-WT", "IBM037"); // NOI18N
  364. encodingIANA2JavaMap.put("IBM277", "CP277"); // NOI18N
  365. encodingIANADescriptionMap.put("IBM277", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM277")); // NOI18N
  366. encodingIANAAliasesMap.put("IBM277", "IBM277"); // NOI18N
  367. encodingIANAAliasesMap.put("EBCDIC-CP-DK", "IBM277"); // NOI18N
  368. encodingIANAAliasesMap.put("EBCDIC-CP-NO", "IBM277"); // NOI18N
  369. encodingIANA2JavaMap.put("IBM278", "CP278"); // NOI18N
  370. encodingIANADescriptionMap.put("IBM278", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM277")); // NOI18N
  371. encodingIANAAliasesMap.put("IBM278", "IBM278"); // NOI18N
  372. encodingIANAAliasesMap.put("EBCDIC-CP-FI", "IBM278"); // NOI18N
  373. encodingIANAAliasesMap.put("EBCDIC-CP-SE", "IBM278"); // NOI18N
  374. encodingIANA2JavaMap.put("IBM280", "CP280"); // NOI18N
  375. encodingIANADescriptionMap.put("IBM280", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM280")); // NOI18N
  376. encodingIANAAliasesMap.put("IBM280", "IBM280"); // NOI18N
  377. encodingIANAAliasesMap.put("EBCDIC-CP-IT", "IBM280"); // NOI18N
  378. encodingIANA2JavaMap.put("IBM284", "CP284"); // NOI18N
  379. encodingIANADescriptionMap.put("IBM284", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM284")); // NOI18N
  380. encodingIANAAliasesMap.put("IBM284", "IBM284"); // NOI18N
  381. encodingIANAAliasesMap.put("EBCDIC-CP-ES", "IBM284"); // NOI18N
  382. encodingIANA2JavaMap.put("IBM285", "CP285"); // NOI18N
  383. encodingIANADescriptionMap.put("IBM285", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM285")); // NOI18N
  384. encodingIANAAliasesMap.put("IBM285", "IBM285"); // NOI18N
  385. encodingIANAAliasesMap.put("EBCDIC-CP-GB", "IBM285"); // NOI18N
  386. encodingIANA2JavaMap.put("IBM297", "CP297"); // NOI18N
  387. encodingIANADescriptionMap.put("IBM297", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM297")); // NOI18N
  388. encodingIANAAliasesMap.put("IBM297", "IBM297"); // NOI18N
  389. encodingIANAAliasesMap.put("EBCDIC-CP-FR", "IBM297"); // NOI18N
  390. encodingIANA2JavaMap.put("IBM424", "CP424"); // NOI18N
  391. encodingIANADescriptionMap.put("IBM424", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM424")); // NOI18N
  392. encodingIANAAliasesMap.put("IBM424", "IBM424"); // NOI18N
  393. encodingIANAAliasesMap.put("EBCDIC-CP-HE", "IBM424"); // NOI18N
  394. encodingIANA2JavaMap.put("IBM500", "CP500"); // NOI18N
  395. encodingIANADescriptionMap.put("IBM500", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM500")); // NOI18N
  396. encodingIANAAliasesMap.put("IBM500", "IBM500"); // NOI18N
  397. encodingIANAAliasesMap.put("EBCDIC-CP-CH", "IBM500"); // NOI18N
  398. encodingIANAAliasesMap.put("EBCDIC-CP-BE", "IBM500"); // NOI18N
  399. encodingIANA2JavaMap.put("IBM870", "CP870"); // NOI18N
  400. encodingIANADescriptionMap.put("IBM870", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM870")); // NOI18N
  401. encodingIANAAliasesMap.put("IBM870", "IBM870"); // NOI18N
  402. encodingIANAAliasesMap.put("EBCDIC-CP-ROECE", "IBM870"); // NOI18N
  403. encodingIANAAliasesMap.put("EBCDIC-CP-YU", "IBM870"); // NOI18N
  404. encodingIANA2JavaMap.put("IBM871", "CP871"); // NOI18N
  405. encodingIANADescriptionMap.put("IBM871", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM871")); // NOI18N
  406. encodingIANAAliasesMap.put("IBM871", "IBM871"); // NOI18N
  407. encodingIANAAliasesMap.put("EBCDIC-CP-IS", "IBM871"); // NOI18N
  408. encodingIANA2JavaMap.put("IBM918", "CP918"); // NOI18N
  409. encodingIANADescriptionMap.put("IBM918", NbBundle.getMessage(EncodingUtil.class, "NAME_IBM918")); // NOI18N
  410. encodingIANAAliasesMap.put("IBM918", "IBM918"); // NOI18N
  411. encodingIANAAliasesMap.put("EBCDIC-CP-AR2", "IBM918"); // NOI18N
  412. encodingIANA2JavaMap.put("EUC-JP", "EUCJIS"); // NOI18N
  413. encodingIANADescriptionMap.put("EUC-JP", NbBundle.getMessage(EncodingUtil.class, "NAME_EUC-JP")); // NOI18N
  414. encodingIANAAliasesMap.put("EUC-JP", "EUC-JP"); // NOI18N
  415. encodingIANA2JavaMap.put("EUC-KR", "KSC5601"); // NOI18N
  416. encodingIANADescriptionMap.put("EUC-KR", NbBundle.getMessage(EncodingUtil.class, "NAME_EUC-KR")); // NOI18N
  417. encodingIANAAliasesMap.put("EUC-KR", "EUC-KR"); // NOI18N
  418. encodingIANA2JavaMap.put("GB2312", "GB2312"); // NOI18N
  419. encodingIANADescriptionMap.put("GB2312", NbBundle.getMessage(EncodingUtil.class, "NAME_GB2312")); // NOI18N
  420. encodingIANAAliasesMap.put("GB2312", "GB2312"); // NOI18N
  421. encodingIANA2JavaMap.put("ISO-2022-JP", "JIS"); // NOI18N
  422. encodingIANADescriptionMap.put("ISO-2022-JP", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-2022-JP")); // NOI18N
  423. encodingIANAAliasesMap.put("ISO-2022-JP", "ISO-2022-JP"); // NOI18N
  424. encodingIANA2JavaMap.put("ISO-2022-KR", "ISO2022KR"); // NOI18N
  425. encodingIANADescriptionMap.put("ISO-2022-KR", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-2022-KR")); // NOI18N
  426. encodingIANAAliasesMap.put("ISO-2022-KR", "ISO-2022-KR"); // NOI18N
  427. encodingIANA2JavaMap.put("ISO-8859-1", "8859_1"); // NOI18N
  428. encodingIANADescriptionMap.put("ISO-8859-1", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-8859-1")); // NOI18N
  429. encodingIANAAliasesMap.put("ISO-8859-1", "ISO-8859-1"); // NOI18N
  430. encodingIANAAliasesMap.put("LATIN1", "ISO-8859-1"); // NOI18N
  431. encodingIANAAliasesMap.put("L1", "ISO-8859-1"); // NOI18N
  432. encodingIANAAliasesMap.put("IBM819", "ISO-8859-1"); // NOI18N
  433. encodingIANAAliasesMap.put("CP819", "ISO-8859-1"); // NOI18N
  434. encodingIANA2JavaMap.put("ISO-8859-2", "8859_2"); // NOI18N
  435. encodingIANADescriptionMap.put("ISO-8859-2", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-8859-2")); // NOI18N
  436. encodingIANAAliasesMap.put("ISO-8859-2", "ISO-8859-2"); // NOI18N
  437. encodingIANAAliasesMap.put("LATIN2", "ISO-8859-2"); // NOI18N
  438. encodingIANAAliasesMap.put("L2", "ISO-8859-2"); // NOI18N
  439. encodingIANA2JavaMap.put("ISO-8859-3", "8859_3"); // NOI18N
  440. encodingIANADescriptionMap.put("ISO-8859-3", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-8859-3")); // NOI18N
  441. encodingIANAAliasesMap.put("ISO-8859-3", "ISO-8859-3"); // NOI18N
  442. encodingIANAAliasesMap.put("LATIN3", "ISO-8859-3"); // NOI18N
  443. encodingIANAAliasesMap.put("L3", "ISO-8859-3"); // NOI18N
  444. encodingIANA2JavaMap.put("ISO-8859-4", "8859_4"); // NOI18N
  445. encodingIANADescriptionMap.put("ISO-8859-4", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-8859-4")); // NOI18N
  446. encodingIANAAliasesMap.put("ISO-8859-4", "ISO-8859-4"); // NOI18N
  447. encodingIANAAliasesMap.put("LATIN4", "ISO-8859-4"); // NOI18N
  448. encodingIANAAliasesMap.put("L4", "ISO-8859-4"); // NOI18N
  449. encodingIANA2JavaMap.put("ISO-8859-5", "8859_5"); // NOI18N
  450. encodingIANADescriptionMap.put("ISO-8859-5", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-8859-5")); // NOI18N
  451. encodingIANAAliasesMap.put("ISO-8859-5", "ISO-8859-5"); // NOI18N
  452. encodingIANAAliasesMap.put("CYRILLIC", "ISO-8859-5"); // NOI18N
  453. encodingIANA2JavaMap.put("ISO-8859-6", "8859_6"); // NOI18N
  454. encodingIANADescriptionMap.put("ISO-8859-6", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-8859-6")); // NOI18N
  455. encodingIANAAliasesMap.put("ISO-8859-6", "ISO-8859-6"); // NOI18N
  456. encodingIANA2JavaMap.put("ISO-8859-7", "8859_7"); // NOI18N
  457. encodingIANADescriptionMap.put("ISO-8859-7", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-8859-7")); // NOI18N
  458. encodingIANAAliasesMap.put("ISO-8859-7", "ISO-8859-7"); // NOI18N
  459. encodingIANAAliasesMap.put("GREEK", "ISO-8859-7"); // NOI18N
  460. encodingIANAAliasesMap.put("GREEK8", "ISO-8859-7"); // NOI18N
  461. encodingIANA2JavaMap.put("ISO-8859-8", "8859_8"); // NOI18N
  462. encodingIANADescriptionMap.put("ISO-8859-8", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-8859-8")); // NOI18N
  463. encodingIANAAliasesMap.put("ISO-8859-8", "ISO-8859-8"); // NOI18N
  464. encodingIANAAliasesMap.put("HEBREW", "ISO-8859-8"); // NOI18N
  465. encodingIANA2JavaMap.put("ISO-8859-9", "8859_9"); // NOI18N
  466. encodingIANADescriptionMap.put("ISO-8859-9", NbBundle.getMessage(EncodingUtil.class, "NAME_ISO-8859-9")); // NOI18N
  467. encodingIANAAliasesMap.put("ISO-8859-9", "ISO-8859-9"); // NOI18N
  468. encodingIANAAliasesMap.put("LATIN5", "ISO-8859-9"); // NOI18N
  469. encodingIANAAliasesMap.put("L5", "ISO-8859-9"); // NOI18N
  470. encodingIANA2JavaMap.put("KOI8-R", "KOI8_R"); // NOI18N
  471. encodingIANADescriptionMap.put("KOI8-R", NbBundle.getMessage(EncodingUtil.class, "NAME_KOI8-R")); // NOI18N
  472. encodingIANAAliasesMap.put("KOI8-R", "KOI8-R"); // NOI18N
  473. encodingIANADescriptionMap.put("US-ASCII", NbBundle.getMessage(EncodingUtil.class, "NAME_ASCII")); // NOI18N
  474. encodingIANAAliasesMap.put("ASCII", "US-ASCII"); // NOI18N
  475. encodingIANAAliasesMap.put("US-ASCII", "US-ASCII"); // NOI18N
  476. encodingIANAAliasesMap.put("ISO646-US", "US-ASCII"); // NOI18N
  477. encodingIANAAliasesMap.put("IBM367", "US-ASCII"); // NOI18N
  478. encodingIANAAliasesMap.put("CP367", "US-ASCII"); // NOI18N
  479. encodingIANA2JavaMap.put("UTF-8", "UTF8"); // NOI18N
  480. encodingIANADescriptionMap.put("UTF-8", NbBundle.getMessage(EncodingUtil.class, "NAME_UTF-8")); // NOI18N
  481. encodingIANAAliasesMap.put("UTF-8", "UTF-8"); // NOI18N
  482. encodingIANA2JavaMap.put("UTF-16", "Unicode"); // NOI18N
  483. encodingIANADescriptionMap.put("UTF-16", NbBundle.getMessage(EncodingUtil.class, "NAME_UTF-16")); // NOI18N
  484. encodingIANAAliasesMap.put("UTF-16", "UTF-16"); // NOI18N
  485. Iterator<String> iter = encodingIANA2JavaMap.keySet().iterator();
  486. String key;
  487. while (iter.hasNext()) {
  488. key = iter.next();
  489. encodingJava2IANAMap.put(encodingIANA2JavaMap.get(key), key);
  490. }
  491. encodingIANA2JavaMap.put("US-ASCII", "8859_1"); // NOI18N
  492. }
  493. }