comparison src/org/tn5250j/encoding/CharMappings.java @ 5:cbdff98c45ea tn5250

adding tn5250 files
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 12:38:09 -0700
parents
children 77ac18bc1b2f
comparison
equal deleted inserted replaced
4:1f5d9b76a183 5:cbdff98c45ea
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 for (String cp : BuiltInCodePageFactory.getInstance().getAvailableCodePages()) {
48 cpset.add(cp);
49 }
50 for (String cp : ToolboxCodePageFactory.getInstance().getAvailableCodePages()) {
51 cpset.add(cp);
52 }
53 String[] cparray = cpset.toArray(new String[cpset.size()]);
54 Arrays.sort(cparray);
55 return cparray;
56 }
57
58 public static ICodePage getCodePage(String encoding) {
59 if (map.containsKey(encoding)) {
60 return map.get(encoding);
61 }
62
63 ICodePage cp = BuiltInCodePageFactory.getInstance().getCodePage(encoding);
64 if (cp != null) {
65 map.put(encoding, cp);
66 return cp;
67 }
68
69 cp = ToolboxCodePageFactory.getInstance().getCodePage(encoding);
70 if (cp != null) {
71 map.put(encoding, cp);
72 return cp;
73 }
74
75 cp = JavaCodePageFactory.getCodePage(encoding);
76 if (cp != null) {
77 map.put(encoding, cp);
78 return cp;
79 }
80
81 // unsupported codepage ==> return default
82 return BuiltInCodePageFactory.getInstance().getCodePage(DFT_ENC);
83 }
84
85 }