1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.office.excel.records.syntax;
22
23 import org.millscript.office.excel.RecordSyntax;
24 import org.millscript.office.excel.RecordTokenizer;
25 import org.millscript.office.excel.alerts.BIFFAlert;
26 import org.millscript.office.excel.records.CodePage;
27 import org.millscript.office.excel.versions.BIFF2;
28 import org.millscript.office.excel.versions.BIFF3;
29 import org.millscript.office.excel.versions.BIFF4S;
30 import org.millscript.office.excel.versions.BIFF4W;
31 import org.millscript.office.excel.versions.BIFF5;
32 import org.millscript.office.excel.versions.BIFF7;
33 import org.millscript.office.excel.versions.BIFF8;
34 import org.millscript.office.excel.versions.BIFF8X;
35
36 import java.nio.charset.Charset;
37 import java.nio.charset.IllegalCharsetNameException;
38 import java.nio.charset.UnsupportedCharsetException;
39
40 /**
41 *
42 */
43 public class CodePageRecordSyntax extends RecordSyntax implements BIFF2, BIFF3, BIFF4S, BIFF4W, BIFF5, BIFF7, BIFF8, BIFF8X {
44
45 public String getCharsetName( final int code ) {
46 switch ( code ) {
47 case 0x016F:
48 return "US-ASCII";
49 case 0x01B5:
50 return "IBM437";
51 case 0x02D0:
52 return "CP-720";
53 case 0x02E1:
54 return "x-IBM737";
55 case 0x0307:
56 return "IBM775";
57 case 0x0352:
58 return "IBM850";
59 case 0x0354:
60 return "IBM852";
61 case 0x0357:
62 return "IBM855";
63 case 0x0359:
64 return "IBM857";
65 case 0x035A:
66 return "IBM00858";
67 case 0x035C:
68 return "IBM860";
69 case 0x035D:
70 return "IBM861";
71 case 0x035E:
72 return "IBM862";
73 case 0x035F:
74 return "IBM863";
75 case 0x0360:
76 return "IBM864";
77 case 0x0361:
78 return "IBM865";
79 case 0x0362:
80 return "IBM866";
81 case 0x0365:
82 return "IBM869";
83 case 0x036A:
84 return "x-IBM874";
85 case 0x03A4:
86 return "windows-31j";
87 case 0x03A8:
88 return "x-mswin-936";
89 case 0x03B5:
90 return "x-IBM949";
91 case 0x03B6:
92 return "x-IBM950";
93 case 0x04B0:
94 return "UTF-16LE";
95 case 0x04E2:
96 return "windows-1250";
97 case 0x04E3:
98 return "windows-1251";
99 case 0x04E4:
100 return "windows-1252";
101 case 0x04E5:
102 return "windows-1253";
103 case 0x04E6:
104 return "windows-1254";
105 case 0x04E7:
106 return "windows-1255";
107 case 0x04E8:
108 return "windows-1256";
109 case 0x04E9:
110 return "windows-1257";
111 case 0x04EA:
112 return "windows-1258";
113 case 0x0551:
114 return "x-Johab";
115 case 0x2710:
116 return "x-MacRoman";
117 case 0x8000:
118 return "x-MacRoman";
119 case 0x8001:
120 return "windows-1252";
121 default:
122 throw new BIFFAlert(
123 "Unknown charset code for CODEPAGE record"
124 ).culprit( "charset code", code ).mishap();
125 }
126 }
127
128 /**
129 * @see org.millscript.office.excel.RecordSyntax#newRecord(RecordTokenizer)
130 */
131 @Override
132 public CodePage newRecord( final RecordTokenizer tokenizer ) {
133 final String name = this.getCharsetName( tokenizer.read2ByteInt() );
134 try {
135
136
137 tokenizer.setCodepage( Charset.forName( name ) );
138 return new CodePage( tokenizer.getCodepage() );
139 } catch ( IllegalCharsetNameException ex ) {
140
141 } catch ( UnsupportedCharsetException ex ) {
142
143 }
144 throw new BIFFAlert(
145 "Unsupported charset in CODEPAGE record"
146 ).culprit( "charset", name ).mishap();
147 }
148
149 }