01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.uilib.util;
16:
17: import java.text.MessageFormat;
18: import org.araneaframework.Environment;
19: import org.araneaframework.framework.LocalizationContext;
20:
21: public class MessageUtil {
22: public static String localize(String messageCode, Environment env) {
23: LocalizationContext locCtx = (LocalizationContext) env
24: .getEntry(LocalizationContext.class);
25: return locCtx.getResourceBundle().getString(messageCode);
26: }
27:
28: public static String format(String message, Object parameter) {
29: return format(message, new Object[] { parameter });
30: }
31:
32: public static String format(String message, Object parameter1,
33: Object parameter2) {
34: return format(message, new Object[] { parameter1, parameter2 });
35: }
36:
37: public static String format(String message, Object[] parameters) {
38: return MessageFormat.format(message, parameters);
39: }
40:
41: public static String localizeAndFormat(String message,
42: Object parameter, Environment env) {
43: return localizeAndFormat(message, new Object[] { parameter },
44: env);
45: }
46:
47: public static String localizeAndFormat(String message,
48: Object parameter1, Object parameter2, Environment env) {
49: return localizeAndFormat(message, new Object[] { parameter1,
50: parameter2 }, env);
51: }
52:
53: public static String localizeAndFormat(String message,
54: Object[] parameters, Environment env) {
55: return format(localize(message, env), parameters);
56: }
57: }
|