KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > messages > util > LocaleHelper


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12 */

13 package org.pentaho.messages.util;
14
15 import java.util.Locale JavaDoc;
16
17 public class LocaleHelper {
18
19     private static final ThreadLocal JavaDoc threadLocales = new ThreadLocal JavaDoc();
20
21     private static Locale JavaDoc defaultLocale;
22
23     private static String JavaDoc ENCODING = "UTF-8"; //$NON-NLS-1$
24

25     private static String JavaDoc TEXT_DIRECTION = "LTR"; //$NON-NLS-1$
26

27     public static void setDefaultLocale(Locale JavaDoc newLocale) {
28         defaultLocale = newLocale;
29     }
30
31     public static Locale JavaDoc getDefaultLocale() {
32         return defaultLocale;
33     }
34
35     public static void setLocale(Locale JavaDoc newLocale) {
36         threadLocales.set(newLocale);
37     }
38
39     public static Locale JavaDoc getLocale() {
40         Locale JavaDoc rtn = (Locale JavaDoc) threadLocales.get();
41         if (rtn != null) {
42             return rtn;
43         }
44         defaultLocale = Locale.getDefault();
45         setLocale(defaultLocale);
46         return defaultLocale;
47     }
48
49     public static void setSystemEncoding(String JavaDoc encoding) {
50         ENCODING = encoding;
51     }
52
53     public static void setTextDirection(String JavaDoc textDirection) {
54         // TODO make this ThreadLocal
55
TEXT_DIRECTION = textDirection;
56     }
57
58     public static String JavaDoc getSystemEncoding() {
59         return ENCODING;
60     }
61
62     public static String JavaDoc getTextDirection() {
63         // TODO make this ThreadLocal
64
return TEXT_DIRECTION;
65     }
66
67 }
68
Popular Tags