1   /**
2    * Copyright (c) 2000-2008 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.PortalBeanLocatorUtil;
26  
27  import java.util.Locale;
28  
29  import javax.portlet.PortletRequest;
30  
31  import javax.servlet.http.HttpServletRequest;
32  import javax.servlet.http.HttpServletResponse;
33  import javax.servlet.jsp.PageContext;
34  
35  /**
36   * <a href="LanguageUtil.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class LanguageUtil {
42  
43      public static String format(
44          Locale locale, String pattern, Object argument) {
45  
46          return getLanguage().format(locale, pattern, argument);
47      }
48  
49      public static String format(
50          Locale locale, String pattern, Object[] arguments) {
51  
52          return getLanguage().format(locale, pattern, arguments);
53      }
54  
55      public static String format(
56          long companyId, Locale locale, String pattern, Object argument) {
57  
58          return getLanguage().format(companyId, locale, pattern, argument);
59      }
60  
61      public static String format(
62          long companyId, Locale locale, String pattern, Object[] arguments) {
63  
64          return getLanguage().format(companyId, locale, pattern, arguments);
65      }
66  
67      public static String format(
68          PageContext pageContext, String pattern, Object argument) {
69  
70          return getLanguage().format(pageContext, pattern, argument);
71      }
72  
73      public static String format(
74          PageContext pageContext, String pattern, Object argument,
75          boolean translateArguments) {
76  
77          return getLanguage().format(
78              pageContext, pattern, argument, translateArguments);
79      }
80  
81      public static String format(
82          PageContext pageContext, String pattern, Object[] arguments) {
83  
84          return getLanguage().format(pageContext, pattern, arguments);
85      }
86  
87      public static String format(
88          PageContext pageContext, String pattern, Object[] arguments,
89          boolean translateArguments) {
90  
91          return getLanguage().format(
92              pageContext, pattern, arguments, translateArguments);
93      }
94  
95      public static String format(
96          PageContext pageContext, String pattern, LanguageWrapper argument) {
97  
98          return getLanguage().format(pageContext, pattern, argument);
99      }
100 
101     public static String format(
102         PageContext pageContext, String pattern, LanguageWrapper argument,
103         boolean translateArguments) {
104 
105         return getLanguage().format(
106             pageContext, pattern, argument, translateArguments);
107     }
108 
109     public static String format(
110         PageContext pageContext, String pattern, LanguageWrapper[] arguments) {
111 
112         return getLanguage().format(pageContext, pattern, arguments);
113     }
114 
115     public static String format(
116         PageContext pageContext, String pattern, LanguageWrapper[] arguments,
117         boolean translateArguments) {
118 
119         return getLanguage().format(
120             pageContext, pattern, arguments, translateArguments);
121     }
122 
123     public static void init() {
124         getLanguage().init();
125     }
126 
127     public static String get(Locale locale, String key) {
128         return getLanguage().get(locale, key);
129     }
130 
131     public static String get(long companyId, Locale locale, String key) {
132         return getLanguage().get(companyId, locale, key);
133     }
134 
135     public static String get(
136         long companyId, Locale locale, String key, String defaultValue) {
137 
138         return getLanguage().get(companyId, locale, key, defaultValue);
139     }
140 
141     public static String get(PageContext pageContext, String key) {
142         return getLanguage().get(pageContext, key);
143     }
144 
145     public static String get(
146         PageContext pageContext, String key, String defaultValue) {
147 
148         return getLanguage().get(pageContext, key, defaultValue);
149     }
150 
151     public static Locale[] getAvailableLocales() {
152         return getLanguage().getAvailableLocales();
153     }
154 
155     public static String getCharset(Locale locale) {
156         return getLanguage().getCharset(locale);
157     }
158 
159     public static Language getLanguage() {
160         return _getUtil()._language;
161     }
162 
163     public static String getLanguageId(PortletRequest portletRequest) {
164         return getLanguage().getLanguageId(portletRequest);
165     }
166 
167     public static String getLanguageId(HttpServletRequest request) {
168         return getLanguage().getLanguageId(request);
169     }
170 
171     public static String getLanguageId(Locale locale) {
172         return getLanguage().getLanguageId(locale);
173     }
174 
175     public static Locale getLocale(String languageCode) {
176         return getLanguage().getLocale(languageCode);
177     }
178 
179     public static String getTimeDescription(
180         PageContext pageContext, Long milliseconds) {
181 
182         return getLanguage().getTimeDescription(pageContext, milliseconds);
183     }
184 
185     public static String getTimeDescription(
186         PageContext pageContext, long milliseconds) {
187 
188         return getLanguage().getTimeDescription(pageContext, milliseconds);
189     }
190 
191     public static void updateCookie(
192         HttpServletResponse response, Locale locale) {
193 
194         getLanguage().updateCookie(response, locale);
195     }
196 
197     public void setLanguage(Language language) {
198         _language = language;
199     }
200 
201     private static LanguageUtil _getUtil() {
202         if (_util == null) {
203             _util = (LanguageUtil)PortalBeanLocatorUtil.locate(_UTIL);
204         }
205 
206         return _util;
207     }
208 
209     private static final String _UTIL = LanguageUtil.class.getName();
210 
211     private static LanguageUtil _util;
212 
213     private Language _language;
214 
215 }