1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.feedparser.tools; |
18 | |
|
19 | |
import java.util.HashMap; |
20 | |
import java.util.Locale; |
21 | |
import java.util.StringTokenizer; |
22 | |
|
23 | 0 | public class RFC3066LocaleParser { |
24 | |
|
25 | 0 | static HashMap locales = new HashMap(); |
26 | |
|
27 | |
public static Locale parse( String input ) { |
28 | |
|
29 | 0 | StringTokenizer tok = new StringTokenizer( input, "-" ); |
30 | |
|
31 | 0 | while ( tok.hasMoreElements() ) { |
32 | 0 | String current = (String)tok.nextElement(); |
33 | |
|
34 | 0 | current = current.toLowerCase(); |
35 | |
|
36 | 0 | if ( current.length() == 2 ) { |
37 | 0 | return getLocale( current ); |
38 | |
} |
39 | |
|
40 | 0 | } |
41 | |
|
42 | 0 | return null; |
43 | |
|
44 | |
} |
45 | |
|
46 | |
public static Locale getLocale( String language ) { |
47 | 0 | return (Locale)locales.get( language ); |
48 | |
} |
49 | |
|
50 | |
private static void initLocale( String name ) { |
51 | 0 | locales.put( name, new Locale( name ) ); |
52 | 0 | } |
53 | |
|
54 | |
static { |
55 | |
|
56 | |
|
57 | |
|
58 | 0 | initLocale( "aa" ); |
59 | 0 | initLocale( "ab" ); |
60 | 0 | initLocale( "af" ); |
61 | 0 | initLocale( "am" ); |
62 | 0 | initLocale( "ar" ); |
63 | 0 | initLocale( "as" ); |
64 | 0 | initLocale( "ay" ); |
65 | 0 | initLocale( "az" ); |
66 | 0 | initLocale( "ba" ); |
67 | 0 | initLocale( "be" ); |
68 | 0 | initLocale( "bg" ); |
69 | 0 | initLocale( "bh" ); |
70 | 0 | initLocale( "bi" ); |
71 | 0 | initLocale( "bn" ); |
72 | 0 | initLocale( "bo" ); |
73 | 0 | initLocale( "br" ); |
74 | 0 | initLocale( "ca" ); |
75 | 0 | initLocale( "co" ); |
76 | 0 | initLocale( "cs" ); |
77 | 0 | initLocale( "cy" ); |
78 | 0 | initLocale( "da" ); |
79 | 0 | initLocale( "de" ); |
80 | 0 | initLocale( "dz" ); |
81 | 0 | initLocale( "el" ); |
82 | 0 | initLocale( "en" ); |
83 | 0 | initLocale( "eo" ); |
84 | 0 | initLocale( "es" ); |
85 | 0 | initLocale( "et" ); |
86 | 0 | initLocale( "eu" ); |
87 | 0 | initLocale( "fa" ); |
88 | 0 | initLocale( "fi" ); |
89 | 0 | initLocale( "fj" ); |
90 | 0 | initLocale( "fo" ); |
91 | 0 | initLocale( "fr" ); |
92 | 0 | initLocale( "fy" ); |
93 | 0 | initLocale( "ga" ); |
94 | 0 | initLocale( "gd" ); |
95 | 0 | initLocale( "gl" ); |
96 | 0 | initLocale( "gn" ); |
97 | 0 | initLocale( "gu" ); |
98 | 0 | initLocale( "ha" ); |
99 | 0 | initLocale( "hi" ); |
100 | 0 | initLocale( "hr" ); |
101 | 0 | initLocale( "hu" ); |
102 | 0 | initLocale( "hy" ); |
103 | 0 | initLocale( "ia" ); |
104 | 0 | initLocale( "ie" ); |
105 | 0 | initLocale( "ik" ); |
106 | 0 | initLocale( "in" ); |
107 | 0 | initLocale( "is" ); |
108 | 0 | initLocale( "it" ); |
109 | 0 | initLocale( "iw" ); |
110 | 0 | initLocale( "ja" ); |
111 | 0 | initLocale( "ji" ); |
112 | 0 | initLocale( "jw" ); |
113 | 0 | initLocale( "ka" ); |
114 | 0 | initLocale( "kk" ); |
115 | 0 | initLocale( "kl" ); |
116 | 0 | initLocale( "km" ); |
117 | 0 | initLocale( "kn" ); |
118 | 0 | initLocale( "ko" ); |
119 | 0 | initLocale( "ks" ); |
120 | 0 | initLocale( "ku" ); |
121 | 0 | initLocale( "ky" ); |
122 | 0 | initLocale( "la" ); |
123 | 0 | initLocale( "ln" ); |
124 | 0 | initLocale( "lo" ); |
125 | 0 | initLocale( "lt" ); |
126 | 0 | initLocale( "lv" ); |
127 | 0 | initLocale( "mg" ); |
128 | 0 | initLocale( "mi" ); |
129 | 0 | initLocale( "mk" ); |
130 | 0 | initLocale( "ml" ); |
131 | 0 | initLocale( "mn" ); |
132 | 0 | initLocale( "mo" ); |
133 | 0 | initLocale( "mr" ); |
134 | 0 | initLocale( "ms" ); |
135 | 0 | initLocale( "mt" ); |
136 | 0 | initLocale( "my" ); |
137 | 0 | initLocale( "na" ); |
138 | 0 | initLocale( "ne" ); |
139 | 0 | initLocale( "nl" ); |
140 | 0 | initLocale( "no" ); |
141 | 0 | initLocale( "oc" ); |
142 | 0 | initLocale( "om" ); |
143 | 0 | initLocale( "or" ); |
144 | 0 | initLocale( "pa" ); |
145 | 0 | initLocale( "pl" ); |
146 | 0 | initLocale( "ps" ); |
147 | 0 | initLocale( "pt" ); |
148 | 0 | initLocale( "qu" ); |
149 | 0 | initLocale( "rm" ); |
150 | 0 | initLocale( "rn" ); |
151 | 0 | initLocale( "ro" ); |
152 | 0 | initLocale( "ru" ); |
153 | 0 | initLocale( "rw" ); |
154 | 0 | initLocale( "sa" ); |
155 | 0 | initLocale( "sd" ); |
156 | 0 | initLocale( "sg" ); |
157 | 0 | initLocale( "sh" ); |
158 | 0 | initLocale( "si" ); |
159 | 0 | initLocale( "sk" ); |
160 | 0 | initLocale( "sl" ); |
161 | 0 | initLocale( "sm" ); |
162 | 0 | initLocale( "sn" ); |
163 | 0 | initLocale( "so" ); |
164 | 0 | initLocale( "sq" ); |
165 | 0 | initLocale( "sr" ); |
166 | 0 | initLocale( "ss" ); |
167 | 0 | initLocale( "st" ); |
168 | 0 | initLocale( "su" ); |
169 | 0 | initLocale( "sv" ); |
170 | 0 | initLocale( "sw" ); |
171 | 0 | initLocale( "ta" ); |
172 | 0 | initLocale( "te" ); |
173 | 0 | initLocale( "tg" ); |
174 | 0 | initLocale( "th" ); |
175 | 0 | initLocale( "ti" ); |
176 | 0 | initLocale( "tk" ); |
177 | 0 | initLocale( "tl" ); |
178 | 0 | initLocale( "tn" ); |
179 | 0 | initLocale( "to" ); |
180 | 0 | initLocale( "tr" ); |
181 | 0 | initLocale( "ts" ); |
182 | 0 | initLocale( "tt" ); |
183 | 0 | initLocale( "tw" ); |
184 | 0 | initLocale( "uk" ); |
185 | 0 | initLocale( "ur" ); |
186 | 0 | initLocale( "uz" ); |
187 | 0 | initLocale( "vi" ); |
188 | 0 | initLocale( "vo" ); |
189 | 0 | initLocale( "wo" ); |
190 | 0 | initLocale( "xh" ); |
191 | 0 | initLocale( "yo" ); |
192 | 0 | initLocale( "zh" ); |
193 | 0 | initLocale( "zu" ); |
194 | |
|
195 | 0 | } |
196 | |
|
197 | |
} |