1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package ca.uhn.hl7v2.llp;
28
29 import java.nio.charset.Charset;
30
31 import ca.uhn.hl7v2.parser.EncodingNotSupportedException;
32
33
34
35
36
37
38 enum HL7Charsets {
39 ASCII ("ASCII", "US-ASCII"),
40 ISO_8859_1 ("8859/1", "ISO-8859-1"),
41 ISO_8859_2 ("8859/2", "ISO-8859-2"),
42 ISO_8859_3 ("8859/3", "ISO-8859-3"),
43 ISO_8859_4 ("8859/4", "ISO-8859-4"),
44 ISO_8859_5 ("8859/5", "ISO-8859-5"),
45 ISO_8859_6 ("8859/6", "ISO-8859-6"),
46 ISO_8859_7 ("8859/7", "ISO-8859-7"),
47 ISO_8859_8 ("8859/8", "ISO-8859-8"),
48 ISO_8859_9 ("8859/9", "ISO-8859-9"),
49 ISO_8859_15 ("8859/15", "ISO-8859-15"),
50 ISO_IR_6 ("ISO IR6", "US-ASCII"),
51 ISO_IR_14 ("ISO IR14", "JIS_X0201"),
52 ISO_IR_87 ("ISO IR87", "x-JIS0208"),
53 ISO_IR_159 ("ISO IR159", "JIS_X0212-1990"),
54 GB_18030 ("GB 18030-2000", "GB18030"),
55 KS_X_1001 ("KS X 1001", "EUC-KR"),
56 CNS_11643 ("CNS 11643-1992", "x-EUC-TW"),
57 BIG_5 ("BIG-5", "Big5"),
58 UNICODE ("UNICODE", "UTF-8"),
59 UTF_8 ("UNICODE UTF-8", "UTF-8"),
60 UTF_16 ("UNICODE UTF-16", "UTF-16"),
61 UTF_32 ("UNICODE UTF-32", "UTF-32");
62
63
64 private final String hl7EncodingName;
65 private final Charset charset;
66
67 HL7Charsets(String hl7EncodingName, String charset) {
68 this.hl7EncodingName = hl7EncodingName;
69 this.charset = Charset.forName(charset);
70 }
71
72
73
74
75
76
77
78 public static Charset getCharsetForHL7Encoding(String hl7EncodingName) throws EncodingNotSupportedException {
79 if (hl7EncodingName == null || hl7EncodingName.length() == 0)
80 return HL7Charsets.ASCII.charset;
81 for (HL7Charsets encoding : HL7Charsets.values()) {
82 if (hl7EncodingName.equals(encoding.hl7EncodingName))
83 return encoding.charset;
84 }
85
86 throw new EncodingNotSupportedException(hl7EncodingName);
87 }
88
89 public static void main(String[] params) {
90 for (HL7Charsets entry : HL7Charsets.values()) {
91 Charset cs = entry.charset;
92 System.out.print(cs.displayName());
93 for (String alias : cs.aliases()) {
94 System.out.print(" " + alias);
95 }
96 System.out.println();
97 }
98 }
99 }