1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils.locale;
18
19 import org.apache.commons.collections.FastHashMap;
20
21 import java.util.Locale;
22
23 /**
24 * <p>Utility methods for converting locale-sensitive String scalar values to objects of the
25 * specified Class, String arrays to arrays of the specified Class and
26 * object to locale-sensitive String scalar value.</p>
27 *
28 * <p>The implementations for these method are provided by {@link LocaleConvertUtilsBean}.
29 * These static utility method use the default instance. More sophisticated can be provided
30 * by using a <code>LocaleConvertUtilsBean</code> instance.</p>
31 *
32 * @author Yauheny Mikulski
33 */
34 public class LocaleConvertUtils {
35
36
37
38 /**
39 * <p>Gets the <code>Locale</code> which will be used when
40 * no <code>Locale</code> is passed to a method.</p>
41 *
42 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
43 *
44 * @see LocaleConvertUtilsBean#getDefaultLocale()
45 */
46 public static Locale getDefaultLocale() {
47
48 return LocaleConvertUtilsBean.getInstance().getDefaultLocale();
49 }
50
51 /**
52 * <p>Sets the <code>Locale</code> which will be used when
53 * no <code>Locale</code> is passed to a method.</p>
54 *
55 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
56 *
57 * @see LocaleConvertUtilsBean#setDefaultLocale(Locale)
58 */
59 public static void setDefaultLocale(Locale locale) {
60
61 LocaleConvertUtilsBean.getInstance().setDefaultLocale(locale);
62 }
63
64 /**
65 * <p>Gets applyLocalized.</p>
66 *
67 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
68 *
69 * @see LocaleConvertUtilsBean#getApplyLocalized()
70 */
71 public static boolean getApplyLocalized() {
72 return LocaleConvertUtilsBean.getInstance().getApplyLocalized();
73 }
74
75 /**
76 * <p>Sets applyLocalized.</p>
77 *
78 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
79 *
80 * @see LocaleConvertUtilsBean#setApplyLocalized(boolean)
81 */
82 public static void setApplyLocalized(boolean newApplyLocalized) {
83 LocaleConvertUtilsBean.getInstance().setApplyLocalized(newApplyLocalized);
84 }
85
86
87
88 /**
89 * <p>Convert the specified locale-sensitive value into a String.</p>
90 *
91 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
92 *
93 * @see LocaleConvertUtilsBean#convert(Object)
94 */
95 public static String convert(Object value) {
96 return LocaleConvertUtilsBean.getInstance().convert(value);
97 }
98
99 /**
100 * <p>Convert the specified locale-sensitive value into a String
101 * using the convertion pattern.</p>
102 *
103 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
104 *
105 * @see LocaleConvertUtilsBean#convert(Object, String)
106 */
107 public static String convert(Object value, String pattern) {
108 return LocaleConvertUtilsBean.getInstance().convert(value, pattern);
109 }
110
111 /**
112 * <p>Convert the specified locale-sensitive value into a String
113 * using the paticular convertion pattern.</p>
114 *
115 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
116 *
117 * @see LocaleConvertUtilsBean#convert(Object, Locale, String)
118 */
119 public static String convert(Object value, Locale locale, String pattern) {
120
121 return LocaleConvertUtilsBean.getInstance().convert(value, locale, pattern);
122 }
123
124 /**
125 * <p>Convert the specified value to an object of the specified class (if
126 * possible). Otherwise, return a String representation of the value.</p>
127 *
128 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
129 *
130 * @see LocaleConvertUtilsBean#convert(String, Class)
131 */
132 public static Object convert(String value, Class clazz) {
133
134 return LocaleConvertUtilsBean.getInstance().convert(value, clazz);
135 }
136
137 /**
138 * <p>Convert the specified value to an object of the specified class (if
139 * possible) using the convertion pattern. Otherwise, return a String
140 * representation of the value.</p>
141 *
142 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
143 *
144 * @see LocaleConvertUtilsBean#convert(String, Class, String)
145 */
146 public static Object convert(String value, Class clazz, String pattern) {
147
148 return LocaleConvertUtilsBean.getInstance().convert(value, clazz, pattern);
149 }
150
151 /**
152 * <p>Convert the specified value to an object of the specified class (if
153 * possible) using the convertion pattern. Otherwise, return a String
154 * representation of the value.</p>
155 *
156 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
157 *
158 * @see LocaleConvertUtilsBean#convert(String, Class, Locale, String)
159 */
160 public static Object convert(String value, Class clazz, Locale locale, String pattern) {
161
162 return LocaleConvertUtilsBean.getInstance().convert(value, clazz, locale, pattern);
163 }
164
165 /**
166 * <p>Convert an array of specified values to an array of objects of the
167 * specified class (if possible) using the convertion pattern.</p>
168 *
169 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
170 *
171 * @see LocaleConvertUtilsBean#convert(String[], Class, String)
172 */
173 public static Object convert(String values[], Class clazz, String pattern) {
174
175 return LocaleConvertUtilsBean.getInstance().convert(values, clazz, pattern);
176 }
177
178 /**
179 * <p>Convert an array of specified values to an array of objects of the
180 * specified class (if possible).</p>
181 *
182 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
183 *
184 * @see LocaleConvertUtilsBean#convert(String[], Class)
185 */
186 public static Object convert(String values[], Class clazz) {
187
188 return LocaleConvertUtilsBean.getInstance().convert(values, clazz);
189 }
190
191 /**
192 * <p>Convert an array of specified values to an array of objects of the
193 * specified class (if possible) using the convertion pattern.</p>
194 *
195 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
196 *
197 * @see LocaleConvertUtilsBean#convert(String[], Class, Locale, String)
198 */
199 public static Object convert(String values[], Class clazz, Locale locale, String pattern) {
200
201 return LocaleConvertUtilsBean.getInstance().convert(values, clazz, locale, pattern);
202 }
203
204 /**
205 * <p>Register a custom {@link LocaleConverter} for the specified destination
206 * <code>Class</code>, replacing any previously registered converter.</p>
207 *
208 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
209 *
210 * @see LocaleConvertUtilsBean#register(LocaleConverter, Class, Locale)
211 */
212 public static void register(LocaleConverter converter, Class clazz, Locale locale) {
213
214 LocaleConvertUtilsBean.getInstance().register(converter, clazz, locale);
215 }
216
217 /**
218 * <p>Remove any registered {@link LocaleConverter}.</p>
219 *
220 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
221 *
222 * @see LocaleConvertUtilsBean#deregister()
223 */
224 public static void deregister() {
225
226 LocaleConvertUtilsBean.getInstance().deregister();
227 }
228
229
230 /**
231 * <p>Remove any registered {@link LocaleConverter} for the specified locale.</p>
232 *
233 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
234 *
235 * @see LocaleConvertUtilsBean#deregister(Locale)
236 */
237 public static void deregister(Locale locale) {
238
239 LocaleConvertUtilsBean.getInstance().deregister(locale);
240 }
241
242
243 /**
244 * <p>Remove any registered {@link LocaleConverter} for the specified locale and Class.</p>
245 *
246 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
247 *
248 * @see LocaleConvertUtilsBean#deregister(Class, Locale)
249 */
250 public static void deregister(Class clazz, Locale locale) {
251
252 LocaleConvertUtilsBean.getInstance().deregister(clazz, locale);
253 }
254
255 /**
256 * <p>Look up and return any registered {@link LocaleConverter} for the specified
257 * destination class and locale; if there is no registered Converter, return
258 * <code>null</code>.</p>
259 *
260 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
261 *
262 * @see LocaleConvertUtilsBean#lookup(Class, Locale)
263 */
264 public static LocaleConverter lookup(Class clazz, Locale locale) {
265
266 return LocaleConvertUtilsBean.getInstance().lookup(clazz, locale);
267 }
268
269 /**
270 * <p>Look up and return any registered FastHashMap instance for the specified locale.</p>
271 *
272 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
273 *
274 * @see LocaleConvertUtilsBean#lookup(Locale)
275 */
276 protected static FastHashMap lookup(Locale locale) {
277 return LocaleConvertUtilsBean.getInstance().lookup(locale);
278 }
279
280 /**
281 * <p>Create all {@link LocaleConverter} types for specified locale.</p>
282 *
283 * <p>For more details see <code>LocaleConvertUtilsBean</code></p>
284 *
285 * @see LocaleConvertUtilsBean#create(Locale)
286 */
287 protected static FastHashMap create(Locale locale) {
288
289 return LocaleConvertUtilsBean.getInstance().create(locale);
290 }
291 }