2 * Copyright 2008 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing.common;
19 import java.util.Hashtable;
22 * Encapsulates a Character Set ECI, according to "Extended Channel Interpretations" 5.3.1.1
27 public final class CharacterSetECI extends ECI {
29 private static Hashtable VALUE_TO_ECI;
30 private static Hashtable NAME_TO_ECI;
32 private static void initialize() {
33 VALUE_TO_ECI = new Hashtable(29);
34 NAME_TO_ECI = new Hashtable(29);
35 // TODO figure out if these values are even right!
36 addCharacterSet(0, "Cp437");
37 addCharacterSet(1, new String[] {"ISO8859_1", "ISO-8859-1"});
38 addCharacterSet(2, "Cp437");
39 addCharacterSet(3, new String[] {"ISO8859_1", "ISO-8859-1"});
40 addCharacterSet(4, "ISO8859_2");
41 addCharacterSet(5, "ISO8859_3");
42 addCharacterSet(6, "ISO8859_4");
43 addCharacterSet(7, "ISO8859_5");
44 addCharacterSet(8, "ISO8859_6");
45 addCharacterSet(9, "ISO8859_7");
46 addCharacterSet(10, "ISO8859_8");
47 addCharacterSet(11, "ISO8859_9");
48 addCharacterSet(12, "ISO8859_10");
49 addCharacterSet(13, "ISO8859_11");
50 addCharacterSet(15, "ISO8859_13");
51 addCharacterSet(16, "ISO8859_14");
52 addCharacterSet(17, "ISO8859_15");
53 addCharacterSet(18, "ISO8859_16");
54 addCharacterSet(20, new String[] {"SJIS", "Shift_JIS"});
57 private final String encodingName;
59 private CharacterSetECI(int value, String encodingName) {
61 this.encodingName = encodingName;
64 public String getEncodingName() {
68 private static void addCharacterSet(int value, String encodingName) {
69 CharacterSetECI eci = new CharacterSetECI(value, encodingName);
70 VALUE_TO_ECI.put(new Integer(value), eci); // can't use valueOf
71 NAME_TO_ECI.put(encodingName, eci);
74 private static void addCharacterSet(int value, String[] encodingNames) {
75 CharacterSetECI eci = new CharacterSetECI(value, encodingNames[0]);
76 VALUE_TO_ECI.put(new Integer(value), eci); // can't use valueOf
77 for (int i = 0; i < encodingNames.length; i++) {
78 NAME_TO_ECI.put(encodingNames[i], eci);
83 * @param value character set ECI value
84 * @return {@link CharacterSetECI} representing ECI of given value, or null if it is legal but
86 * @throws IllegalArgumentException if ECI value is invalid
88 public static CharacterSetECI getCharacterSetECIByValue(int value) {
89 if (VALUE_TO_ECI == null) {
92 if (value < 0 || value >= 900) {
93 throw new IllegalArgumentException("Bad ECI value: " + value);
95 return (CharacterSetECI) VALUE_TO_ECI.get(new Integer(value));
99 * @param name character set ECI encoding name
100 * @return {@link CharacterSetECI} representing ECI for character encoding, or null if it is legal
103 public static CharacterSetECI getCharacterSetECIByName(String name) {
104 if (NAME_TO_ECI == null) {
107 return (CharacterSetECI) NAME_TO_ECI.get(name);