001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.kernel.language;
022:
023: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
024:
025: import java.util.Locale;
026:
027: import javax.portlet.ActionRequest;
028: import javax.portlet.RenderRequest;
029:
030: import javax.servlet.http.HttpServletRequest;
031: import javax.servlet.http.HttpServletResponse;
032: import javax.servlet.jsp.PageContext;
033:
034: /**
035: * <a href="LanguageUtil.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class LanguageUtil {
041:
042: public static String format(Locale locale, String pattern,
043: Object argument) {
044:
045: return getLanguage().format(locale, pattern, argument);
046: }
047:
048: public static String format(Locale locale, String pattern,
049: Object[] arguments) {
050:
051: return getLanguage().format(locale, pattern, arguments);
052: }
053:
054: public static String format(long companyId, Locale locale,
055: String pattern, Object argument) {
056:
057: return getLanguage().format(companyId, locale, pattern,
058: argument);
059: }
060:
061: public static String format(long companyId, Locale locale,
062: String pattern, Object[] arguments) {
063:
064: return getLanguage().format(companyId, locale, pattern,
065: arguments);
066: }
067:
068: public static String format(PageContext pageContext,
069: String pattern, Object argument) {
070:
071: return getLanguage().format(pageContext, pattern, argument);
072: }
073:
074: public static String format(PageContext pageContext,
075: String pattern, Object argument, boolean translateArguments) {
076:
077: return getLanguage().format(pageContext, pattern, argument,
078: translateArguments);
079: }
080:
081: public static String format(PageContext pageContext,
082: String pattern, Object[] arguments) {
083:
084: return getLanguage().format(pageContext, pattern, arguments);
085: }
086:
087: public static String format(PageContext pageContext,
088: String pattern, Object[] arguments,
089: boolean translateArguments) {
090:
091: return getLanguage().format(pageContext, pattern, arguments,
092: translateArguments);
093: }
094:
095: public static String format(PageContext pageContext,
096: String pattern, LanguageWrapper argument) {
097:
098: return getLanguage().format(pageContext, pattern, argument);
099: }
100:
101: public static String format(PageContext pageContext,
102: String pattern, LanguageWrapper argument,
103: boolean translateArguments) {
104:
105: return getLanguage().format(pageContext, pattern, argument,
106: translateArguments);
107: }
108:
109: public static String format(PageContext pageContext,
110: String pattern, LanguageWrapper[] arguments) {
111:
112: return getLanguage().format(pageContext, pattern, arguments);
113: }
114:
115: public static String format(PageContext pageContext,
116: String pattern, LanguageWrapper[] arguments,
117: boolean translateArguments) {
118:
119: return getLanguage().format(pageContext, pattern, arguments,
120: translateArguments);
121: }
122:
123: public static String get(Locale locale, String key) {
124: return getLanguage().get(locale, key);
125: }
126:
127: public static String get(long companyId, Locale locale, String key) {
128: return getLanguage().get(companyId, locale, key);
129: }
130:
131: public static String get(long companyId, Locale locale, String key,
132: String defaultValue) {
133:
134: return getLanguage().get(companyId, locale, key, defaultValue);
135: }
136:
137: public static String get(PageContext pageContext, String key) {
138: return getLanguage().get(pageContext, key);
139: }
140:
141: public static String get(PageContext pageContext, String key,
142: String defaultValue) {
143:
144: return getLanguage().get(pageContext, key, defaultValue);
145: }
146:
147: public static Locale[] getAvailableLocales() {
148: return getLanguage().getAvailableLocales();
149: }
150:
151: public static String getCharset(Locale locale) {
152: return getLanguage().getCharset(locale);
153: }
154:
155: public static Language getLanguage() {
156: return _getUtil()._language;
157: }
158:
159: public static String getLanguageId(ActionRequest req) {
160: return getLanguage().getLanguageId(req);
161: }
162:
163: public static String getLanguageId(RenderRequest req) {
164: return getLanguage().getLanguageId(req);
165: }
166:
167: public static String getLanguageId(HttpServletRequest req) {
168: return getLanguage().getLanguageId(req);
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(PageContext pageContext,
180: Long milliseconds) {
181:
182: return getLanguage().getTimeDescription(pageContext,
183: milliseconds);
184: }
185:
186: public static String getTimeDescription(PageContext pageContext,
187: long milliseconds) {
188:
189: return getLanguage().getTimeDescription(pageContext,
190: milliseconds);
191: }
192:
193: public static void updateCookie(HttpServletResponse res,
194: Locale locale) {
195: getLanguage().updateCookie(res, locale);
196: }
197:
198: public void setLanguage(Language language) {
199: _language = language;
200: }
201:
202: private static LanguageUtil _getUtil() {
203: if (_util == null) {
204: _util = (LanguageUtil) BeanLocatorUtil.locate(_UTIL);
205: }
206:
207: return _util;
208: }
209:
210: private static final String _UTIL = LanguageUtil.class.getName();
211:
212: private static LanguageUtil _util;
213:
214: private Language _language;
215:
216: }
|