1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.language;
24  
25  import com.liferay.portal.kernel.bean.BeanLocatorUtil;
26  
27  import java.util.Locale;
28  
29  import javax.portlet.ActionRequest;
30  import javax.portlet.RenderRequest;
31  
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.http.HttpServletResponse;
34  import javax.servlet.jsp.PageContext;
35  
36  /**
37   * <a href="LanguageUtil.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class LanguageUtil {
43  
44      public static String format(
45          Locale locale, String pattern, Object argument) {
46  
47          return getLanguage().format(locale, pattern, argument);
48      }
49  
50      public static String format(
51          Locale locale, String pattern, Object[] arguments) {
52  
53          return getLanguage().format(locale, pattern, arguments);
54      }
55  
56      public static String format(
57          long companyId, Locale locale, String pattern, Object argument) {
58  
59          return getLanguage().format(companyId, locale, pattern, argument);
60      }
61  
62      public static String format(
63          long companyId, Locale locale, String pattern, Object[] arguments) {
64  
65          return getLanguage().format(companyId, locale, pattern, arguments);
66      }
67  
68      public static String format(
69          PageContext pageContext, String pattern, Object argument) {
70  
71          return getLanguage().format(pageContext, pattern, argument);
72      }
73  
74      public static String format(
75          PageContext pageContext, String pattern, Object argument,
76          boolean translateArguments) {
77  
78          return getLanguage().format(
79              pageContext, pattern, argument, translateArguments);
80      }
81  
82      public static String format(
83          PageContext pageContext, String pattern, Object[] arguments) {
84  
85          return getLanguage().format(pageContext, pattern, arguments);
86      }
87  
88      public static String format(
89          PageContext pageContext, String pattern, Object[] arguments,
90          boolean translateArguments) {
91  
92          return getLanguage().format(
93              pageContext, pattern, arguments, translateArguments);
94      }
95  
96      public static String format(
97          PageContext pageContext, String pattern, LanguageWrapper argument) {
98  
99          return getLanguage().format(pageContext, pattern, argument);
100     }
101 
102     public static String format(
103         PageContext pageContext, String pattern, LanguageWrapper argument,
104         boolean translateArguments) {
105 
106         return getLanguage().format(
107             pageContext, pattern, argument, translateArguments);
108     }
109 
110     public static String format(
111         PageContext pageContext, String pattern, LanguageWrapper[] arguments) {
112 
113         return getLanguage().format(pageContext, pattern, arguments);
114     }
115 
116     public static String format(
117         PageContext pageContext, String pattern, LanguageWrapper[] arguments,
118         boolean translateArguments) {
119 
120         return getLanguage().format(
121             pageContext, pattern, arguments, translateArguments);
122     }
123 
124     public static String get(Locale locale, String key) {
125         return getLanguage().get(locale, key);
126     }
127 
128     public static String get(long companyId, Locale locale, String key) {
129         return getLanguage().get(companyId, locale, key);
130     }
131 
132     public static String get(
133         long companyId, Locale locale, String key, String defaultValue) {
134 
135         return getLanguage().get(companyId, locale, key, defaultValue);
136     }
137 
138     public static String get(PageContext pageContext, String key) {
139         return getLanguage().get(pageContext, key);
140     }
141 
142     public static String get(
143         PageContext pageContext, String key, String defaultValue) {
144 
145         return getLanguage().get(pageContext, key, defaultValue);
146     }
147 
148     public static Locale[] getAvailableLocales() {
149         return getLanguage().getAvailableLocales();
150     }
151 
152     public static String getCharset(Locale locale) {
153         return getLanguage().getCharset(locale);
154     }
155 
156     public static Language getLanguage() {
157         return _getUtil()._language;
158     }
159 
160     public static String getLanguageId(ActionRequest req) {
161         return getLanguage().getLanguageId(req);
162     }
163 
164     public static String getLanguageId(RenderRequest req) {
165         return getLanguage().getLanguageId(req);
166     }
167 
168     public static String getLanguageId(HttpServletRequest req) {
169         return getLanguage().getLanguageId(req);
170     }
171 
172     public static String getLanguageId(Locale locale) {
173         return getLanguage().getLanguageId(locale);
174     }
175 
176     public static Locale getLocale(String languageCode) {
177         return getLanguage().getLocale(languageCode);
178     }
179 
180     public static String getTimeDescription(
181         PageContext pageContext, Long milliseconds) {
182 
183         return getLanguage().getTimeDescription(pageContext, milliseconds);
184     }
185 
186     public static String getTimeDescription(
187         PageContext pageContext, long milliseconds) {
188 
189         return getLanguage().getTimeDescription(pageContext, milliseconds);
190     }
191 
192     public static void updateCookie(HttpServletResponse res, Locale locale) {
193         getLanguage().updateCookie(res, locale);
194     }
195 
196     public void setLanguage(Language language) {
197         _language = language;
198     }
199 
200     private static LanguageUtil _getUtil() {
201         if (_util == null) {
202             _util = (LanguageUtil)BeanLocatorUtil.locate(_UTIL);
203         }
204 
205         return _util;
206     }
207 
208     private static final String _UTIL = LanguageUtil.class.getName();
209 
210     private static LanguageUtil _util;
211 
212     private Language _language;
213 
214 }