01: /*
02: * Copyright 2006, 2007 Odysseus Software GmbH
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: */
16: package de.odysseus.el.misc;
17:
18: import java.text.MessageFormat;
19: import java.util.MissingResourceException;
20: import java.util.ResourceBundle;
21:
22: public final class LocalMessages {
23: private static final String BUNDLE_NAME = "de.odysseus.el.misc.LocalStrings";
24: private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
25: .getBundle(BUNDLE_NAME);
26:
27: public static String get(String key, Object... args) {
28: String template = null;
29: try {
30: template = RESOURCE_BUNDLE.getString(key);
31: } catch (MissingResourceException e) {
32: StringBuilder b = new StringBuilder();
33: try {
34: b.append(RESOURCE_BUNDLE.getString("message.unknown"));
35: b.append(": ");
36: } catch (MissingResourceException e2) {
37: }
38: b.append(key);
39: if (args != null && args.length > 0) {
40: b.append("(");
41: b.append(args[0]);
42: for (int i = 1; i < args.length; i++) {
43: b.append(", ");
44: b.append(args[i]);
45: }
46: b.append(")");
47: }
48: return b.toString();
49: }
50: return MessageFormat.format(template, args);
51: }
52: }
|