1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.http;
24
25 import java.io.Serializable;
26 import java.util.ArrayList;
27 import java.util.Enumeration;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 import de.bea.domingo.i18n.ResourceManager;
33 import de.bea.domingo.i18n.Resources;
34
35 /***
36 * Enumeration of all possible locales in Lotus Notes.
37 *
38 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
39 */
40 public final class DominoLocale implements Serializable {
41
42 /*** serial version ID for serialization. */
43 private static final long serialVersionUID = 7747855846132804053L;
44
45 /*** value of field <tt>rg_date_component_order</tt>. */
46 public static final String WEEKDAY_DAY_MONTH_YEAR = "1";
47
48 /*** value of field <tt>rg_date_component_order</tt>. */
49 public static final String WEEKDAY_MONTH_DAY_YEAR = "0";
50
51 /*** value of field <tt>rg_date_component_order</tt>. */
52 public static final String YEAR_MONTH_DAY_WEEKDAY = "2";
53
54 /*** Map from locale strings to Domino locales. */
55 private static final Map LOCALES_MAP;
56
57 /*** Maps time zone strings to Lotus Notes format. */
58 private static final Resources RESOURCES = ResourceManager.getClassResources(DominoLocale.class).withFailOnError(true);
59
60 private static final List LOCALES;
61
62 private final String fLocaleString;
63
64 private final String fDateComponentOrder;
65
66 private final String fDateSeparator;
67
68 private final String fTimeSeparator;
69
70 private final String fClock24Hour;
71
72 private final String fAmString;
73
74 private final String fPmString;
75
76 private final String fAmPmSuffix;
77
78 private final String fDecimalSeparator;
79
80 private final String fNumberLeadingZero;
81
82 private final String fCurrencySymbol;
83
84 private final String fCurrencySuffix;
85
86 private final String fCurrencySpace;
87
88 private final String fThousandSeparator;
89
90 private final String fYearFormat;
91
92 static {
93 LOCALES = new ArrayList();
94 LOCALES_MAP = new HashMap();
95 Enumeration keys = RESOURCES.getBundle().getKeys();
96 while (keys.hasMoreElements()) {
97 String locale = (String) keys.nextElement();
98 String dominoLocaleString = RESOURCES.getString(locale);
99 addLocale(new DominoLocale(locale, dominoLocaleString));
100 }
101 }
102
103 /***
104 * Adds a given locale to the map of all locales.
105 *
106 * @param locale the locale to add
107 */
108 private static void addLocale(final DominoLocale locale) {
109 LOCALES_MAP.put(locale.getLocale(), locale);
110 LOCALES.add(locale);
111 }
112
113 /***
114 * Constructor.
115 * <dl> <dt>Format of parameter <tt>dominoLocaleString</tt></dt><dd>
116 * <tt>dateComponentOrder '|' dateSeparator '|' timeSeparator '|'
117 * clock24Hour '|' amString '|' pmString '|' amPmSuffix '|'
118 * decimalSeparator '|' numberLeadingZero '|' currencySymbol '|'
119 * currencySuffix '|' currencySpace '|' thousandSeparator '|'
120 * yearFormat</tt></p></dd>
121 * <dt>dateComponentOrder</dt><dd>order of date components</dd>
122 * <dt>dateSeparator</dt><dd>the date separator</dd>
123 * <dt>timeSeparator</dt><dd>the time separator</dd>
124 * <dt>clock24Hour</dt><dd>whether 24-hour clock is used</dd>
125 * <dt>amString</dt><dd>the AM string</dd>
126 * <dt>pmString</dt><dd>the PM string</dd>
127 * <dt>amPmSuffix</dt><dd>whether the AM/M string is a suffix to the time or a
128 * prefix</dd>
129 * <dt>decimalSeparator</dt><dd>the decimal separator</dd>
130 * <dt>numberLeadingZero</dt><dd>whether fractional numbers have a leading number</dd>
131 * <dt>currencySymbol</dt><dd>the currency symbol</dd>
132 * <dt>currencySuffix</dt><dd>whether the currency symbol is a suffix to the amount
133 * or a prefix</dd>
134 * <dt>currencySpace</dt><dd>whether a space is inserted between the amount an
135 * the currency symbol</dd>
136 * <dt>thousandSeparator</dt><dd>the thousands separator</dd>
137 * <dt>yearFormat</dt><dd>year format, always <tt>"1"</tt></dd>
138 * </dl>
139 *
140 * @param locale the locale string
141 * @param dominoLocaleString pipe-seperated list of values
142 */
143 private DominoLocale(final String locale, final String dominoLocaleString) {
144 String[] values = dominoLocaleString.split("//|");
145 int index = 0;
146 fLocaleString = locale;
147 fDateComponentOrder = values[index++];
148 fDateSeparator = values[index++];
149 fTimeSeparator = values[index++];
150 fClock24Hour = values[index++];
151 fAmString = values[index++];
152 fPmString = values[index++];
153 fAmPmSuffix = values[index++];
154 fDecimalSeparator = values[index++];
155 fNumberLeadingZero = values[index++];
156 fCurrencySymbol = values[index++];
157 fCurrencySuffix = values[index++];
158 fCurrencySpace = values[index++];
159 fThousandSeparator = values[index++];
160 fYearFormat = values[index++];
161 }
162
163 /***
164 * Returns a list of all Domino locales.
165 *
166 * @return list of locales
167 */
168 public static List getLocales() {
169 return LOCALES;
170 }
171
172 /***
173 * Returns the Domino locales for a given locale string.
174 *
175 * @param localeString e.g. <tt>"en-US"</tt> for USA or <tt>de-DE</tt>
176 * for Germany
177 * @return Domino locales
178 */
179 public static DominoLocale get(final String localeString) {
180 return (DominoLocale) LOCALES_MAP.get(localeString);
181 }
182
183 /***
184 * @return Returns the amPmPosition.
185 */
186 public String getAmPmSuffix() {
187 return fAmPmSuffix;
188 }
189
190 /***
191 * @return Returns the amString.
192 */
193 public String getAmString() {
194 return fAmString;
195 }
196
197 /***
198 * @return Returns the clock24Hour.
199 */
200 public String getClock24Hour() {
201 return fClock24Hour;
202 }
203
204 /***
205 * @return Returns the currencyPosition.
206 */
207 public String getCurrencySuffix() {
208 return fCurrencySuffix;
209 }
210
211 /***
212 * @return Returns the currencySpace.
213 */
214 public String getCurrencySpace() {
215 return fCurrencySpace;
216 }
217
218 /***
219 * @return Returns the currencyString.
220 */
221 public String getCurrencySymbol() {
222 return fCurrencySymbol;
223 }
224
225 /***
226 * @return Returns the dateComponentOrder.
227 */
228 public String getDateComponentOrder() {
229 return fDateComponentOrder;
230 }
231
232 /***
233 * @return Returns the dateString.
234 */
235 public String getDateSeparator() {
236 return fDateSeparator;
237 }
238
239 /***
240 * @return Returns the decimalString.
241 */
242 public String getDecimalSeparator() {
243 return fDecimalSeparator;
244 }
245
246 /***
247 * @return Returns the locale.
248 */
249 public String getLocale() {
250 return fLocaleString;
251 }
252
253 /***
254 * @return Returns the numberLeadingZero.
255 */
256 public String getNumberLeadingZero() {
257 return fNumberLeadingZero;
258 }
259
260 /***
261 * @return Returns the pmString.
262 */
263 public String getPmString() {
264 return fPmString;
265 }
266
267 /***
268 * @return Returns the thousandString.
269 */
270 public String getThousandSeparator() {
271 return fThousandSeparator;
272 }
273
274 /***
275 * @return Returns the timeString.
276 */
277 public String getTimeSeparator() {
278 return fTimeSeparator;
279 }
280
281 /***
282 * @return Returns the yearFormat.
283 */
284 public String getYearFormat() {
285 return fYearFormat;
286 }
287
288
289 /***
290 * @see java.lang.Object#toString()
291 *
292 * @return a string representation of the object.
293 */
294 public String toString() {
295 StringBuffer buffer = new StringBuffer();
296 buffer.append(fLocaleString + ":");
297 buffer.append(fDateComponentOrder + ":");
298 buffer.append(fDateSeparator + ":");
299 buffer.append(fTimeSeparator + ":");
300 buffer.append(fClock24Hour + ":");
301 buffer.append(fAmString + ":");
302 buffer.append(fPmString + ":");
303 buffer.append(fAmPmSuffix + ":");
304 buffer.append(fDecimalSeparator + ":");
305 buffer.append(fNumberLeadingZero + ":");
306 buffer.append(fCurrencySymbol + ":");
307 buffer.append(fCurrencySuffix + ":");
308 buffer.append(fCurrencySpace + ":");
309 buffer.append(fThousandSeparator + ":");
310 buffer.append(fYearFormat + ":");
311 return buffer.toString();
312 }
313 }