Factor out ECI-related code for reuse with Data Matrix later.
[zxing.git] / core / src / com / google / zxing / common / CharacterSetECI.java
1 /*
2  * Copyright 2008 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing.common;
18
19 import java.util.Hashtable;
20
21 /**
22  * Encapsulates a Character Set ECI, according to "Extended Channel Interpretations" 5.3.1.1
23  * of ISO 18004.
24  *
25  * @author srowen@google.com (Sean Owen)
26  */
27 public final class CharacterSetECI extends ECI {
28
29   private static final Hashtable VALUE_TO_ECI;
30   static {
31     VALUE_TO_ECI = new Hashtable(29);
32     // TODO figure out if these values are even right!
33     addCharacterSet(0, "Cp437");
34     addCharacterSet(1, "ISO8859_1");
35     addCharacterSet(2, "Cp437");
36     addCharacterSet(3, "ISO8859_1");
37     addCharacterSet(4, "ISO8859_2");
38     addCharacterSet(5, "ISO8859_3");
39     addCharacterSet(6, "ISO8859_4");
40     addCharacterSet(7, "ISO8859_5");
41     addCharacterSet(8, "ISO8859_6");
42     addCharacterSet(9, "ISO8859_7");
43     addCharacterSet(10, "ISO8859_8");
44     addCharacterSet(11, "ISO8859_9");
45     addCharacterSet(12, "ISO8859_10");
46     addCharacterSet(13, "ISO8859_11");
47     addCharacterSet(15, "ISO8859_13");
48     addCharacterSet(16, "ISO8859_14");
49     addCharacterSet(17, "ISO8859_15");
50     addCharacterSet(18, "ISO8859_16");
51     addCharacterSet(20, "SJIS");
52   }
53
54   private final String encodingName;
55
56   private CharacterSetECI(int value, String encodingName) {
57     super(value);
58     this.encodingName = encodingName;
59   }
60
61   public String getEncodingName() {
62     return encodingName;
63   }
64
65   private static void addCharacterSet(int value, String encodingName) {
66     VALUE_TO_ECI.put(new Integer(value), new CharacterSetECI(value, encodingName));
67   }
68
69   public static CharacterSetECI getCharacterSetECIByValue(int value) {
70     CharacterSetECI eci = (CharacterSetECI) VALUE_TO_ECI.get(new Integer(value));
71     if (eci == null) {
72       throw new IllegalArgumentException("Unsupported value: " + value);
73     }
74     return eci;
75   }
76
77 }