|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| package nu.xom; |
|
23 |
| |
|
24 |
| import java.io.UnsupportedEncodingException; |
|
25 |
| import java.io.Writer; |
|
26 |
| import java.util.Locale; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| class TextWriterFactory { |
|
33 |
| |
|
34 |
19228
| public static TextWriter getTextWriter(
|
|
35 |
| Writer out, String encoding) { |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
19228
| String encodingUpperCase = encoding.toUpperCase(Locale.ENGLISH);
|
|
40 |
19228
| if (encodingUpperCase.startsWith("UTF")
|
|
41 |
| || encodingUpperCase.startsWith("UNICODE") |
|
42 |
| ) { |
|
43 |
19160
| return new UnicodeWriter(out, encoding);
|
|
44 |
| } |
|
45 |
68
| else if (encodingUpperCase.startsWith("ISO-10646-UCS")
|
|
46 |
| || encodingUpperCase.startsWith("UCS") |
|
47 |
| || encodingUpperCase.equals("GB18030")) { |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
2
| return new UCSWriter(out, encoding);
|
|
53 |
| } |
|
54 |
66
| else if (encodingUpperCase.equals("ISO-8859-1")) {
|
|
55 |
33
| return new Latin1Writer(out, encoding);
|
|
56 |
| } |
|
57 |
33
| else if (encodingUpperCase.equals("ISO-8859-2")) {
|
|
58 |
1
| return new Latin2Writer(out, encodingUpperCase);
|
|
59 |
| } |
|
60 |
32
| else if (encodingUpperCase.equals("ISO-8859-3")) {
|
|
61 |
1
| return new Latin3Writer(out, encodingUpperCase);
|
|
62 |
| } |
|
63 |
31
| else if (encodingUpperCase.equals("ISO-8859-4")) {
|
|
64 |
1
| return new Latin4Writer(out, encodingUpperCase);
|
|
65 |
| } |
|
66 |
30
| else if (encodingUpperCase.equals("ISO-8859-5")) {
|
|
67 |
4
| return new ISOCyrillicWriter(out, encodingUpperCase);
|
|
68 |
| } |
|
69 |
26
| else if (encodingUpperCase.equals("ISO-8859-6")) {
|
|
70 |
1
| return new ISOArabicWriter(out, encodingUpperCase);
|
|
71 |
| } |
|
72 |
25
| else if (encodingUpperCase.equals("ISO-8859-7")) {
|
|
73 |
1
| return new ISOGreekWriter(out, encodingUpperCase);
|
|
74 |
| } |
|
75 |
24
| else if (encodingUpperCase.equals("ISO-8859-8")) {
|
|
76 |
1
| return new ISOHebrewWriter(out, encodingUpperCase);
|
|
77 |
| } |
|
78 |
23
| else if (encodingUpperCase.equals("ISO-8859-9")
|
|
79 |
| || encodingUpperCase.equals("EBCDIC-CP-TR") |
|
80 |
| || encodingUpperCase.equals("CP1037")) { |
|
81 |
1
| return new Latin5Writer(out, encodingUpperCase);
|
|
82 |
| } |
|
83 |
22
| else if (encoding.equals("ISO-8859-10")) {
|
|
84 |
0
| return new Latin6Writer(out, encoding);
|
|
85 |
| } |
|
86 |
22
| else if (encodingUpperCase.equals("ISO-8859-11")
|
|
87 |
| || encodingUpperCase.equals("TIS-620") |
|
88 |
| || encodingUpperCase.equals("TIS620")) { |
|
89 |
1
| return new ISOThaiWriter(out, encodingUpperCase);
|
|
90 |
| } |
|
91 |
| |
|
92 |
| |
|
93 |
21
| else if (encodingUpperCase.equals("ISO-8859-13")) {
|
|
94 |
1
| return new Latin7Writer(out, encodingUpperCase);
|
|
95 |
| } |
|
96 |
20
| else if (encoding.equals("ISO-8859-14")) {
|
|
97 |
0
| return new Latin8Writer(out, encoding);
|
|
98 |
| } |
|
99 |
20
| else if (encodingUpperCase.equals("ISO-8859-15")) {
|
|
100 |
1
| return new Latin9Writer(out, encodingUpperCase);
|
|
101 |
| } |
|
102 |
19
| else if (encoding.equals("ISO-8859-16")) {
|
|
103 |
0
| return new Latin10Writer(out, encoding);
|
|
104 |
| } |
|
105 |
19
| else if (encodingUpperCase.endsWith("ASCII")) {
|
|
106 |
11
| return new ASCIIWriter(out, encodingUpperCase);
|
|
107 |
| } |
|
108 |
8
| else if (encodingUpperCase.equals("IBM037")
|
|
109 |
| || encodingUpperCase.equals("CP037") |
|
110 |
| || encodingUpperCase.equals("EBCDIC-CP-US") |
|
111 |
| || encodingUpperCase.equals("EBCDIC-CP-CA") |
|
112 |
| || encodingUpperCase.equals("EBCDIC-CP-WA") |
|
113 |
| || encodingUpperCase.equals("EBCDIC-CP-NL") |
|
114 |
| || encodingUpperCase.equals("CSIBM037")) { |
|
115 |
| |
|
116 |
| |
|
117 |
1
| return new Latin1Writer(out, encodingUpperCase);
|
|
118 |
| } |
|
119 |
| else { |
|
120 |
7
| try {
|
|
121 |
7
| return new GenericWriter(out, encoding);
|
|
122 |
| } |
|
123 |
| catch (UnsupportedEncodingException ex) { |
|
124 |
0
| return new ASCIIWriter(out, encoding);
|
|
125 |
| } |
|
126 |
| } |
|
127 |
| |
|
128 |
| } |
|
129 |
| |
|
130 |
| } |