comparison app/src/main/java/org/tn5250j/encoding/CharMappings.java @ 438:d29cce60f393

migrate from Eclipse to Android Studio
author Carl Byington <carl@five-ten-sg.com>
date Thu, 03 Dec 2015 11:23:55 -0800
parents src/org/tn5250j/encoding/CharMappings.java@77ac18bc1b2f
children
comparison
equal deleted inserted replaced
437:208b31032318 438:d29cce60f393
1 /**
2 * Title: CharMappings.java
3 * Copyright: Copyright (c) 2001,2002,2003
4 * Company:
5 * @author Kenneth J. Pouncey
6 * rewritten by LDC, WVL, Luc
7 * @version 0.4
8 *
9 * Description:
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this software; see the file COPYING. If not, write to
23 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
24 * Boston, MA 02111-1307 USA
25 *
26 */
27 package org.tn5250j.encoding;
28
29 import java.util.Arrays;
30 import java.util.HashMap;
31 import java.util.HashSet;
32 import java.util.Set;
33
34 /**
35 * Character Mappings for EBCDIC to ASCII and ASCII to EBCDIC translations
36 */
37 public class CharMappings {
38
39 public static final String DFT_ENC = "37";
40 public static final int NATIVE_CP = 0;
41 public static final int TOOLBOX_CP = 1;
42
43 private static final HashMap<String, ICodePage> map = new HashMap<String, ICodePage>();
44
45 public static String[] getAvailableCodePages() {
46 Set<String> cpset = new HashSet<String>(); // no double entries
47
48 for (String cp : BuiltInCodePageFactory.getInstance().getAvailableCodePages()) {
49 cpset.add(cp);
50 }
51
52 for (String cp : ToolboxCodePageFactory.getInstance().getAvailableCodePages()) {
53 cpset.add(cp);
54 }
55
56 String[] cparray = cpset.toArray(new String[cpset.size()]);
57 Arrays.sort(cparray);
58 return cparray;
59 }
60
61 public static ICodePage getCodePage(String encoding) {
62 if (map.containsKey(encoding)) {
63 return map.get(encoding);
64 }
65
66 ICodePage cp = BuiltInCodePageFactory.getInstance().getCodePage(encoding);
67
68 if (cp != null) {
69 map.put(encoding, cp);
70 return cp;
71 }
72
73 cp = ToolboxCodePageFactory.getInstance().getCodePage(encoding);
74
75 if (cp != null) {
76 map.put(encoding, cp);
77 return cp;
78 }
79
80 cp = JavaCodePageFactory.getCodePage(encoding);
81
82 if (cp != null) {
83 map.put(encoding, cp);
84 return cp;
85 }
86
87 // unsupported codepage ==> return default
88 return BuiltInCodePageFactory.getInstance().getCodePage(DFT_ENC);
89 }
90
91 }