01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.util;
20:
21: import java.text.MessageFormat;
22: import java.util.ResourceBundle;
23:
24: /**
25: * Convenience class for dealing with resource bundles.
26: */
27: public class Bundle {
28:
29: private static final String BUNDLE_NAME = "org.apache.beehive.netui.util.netui";
30:
31: /** No need, it's all static */
32: private Bundle() {
33: }
34:
35: /**
36: * Returns the resource bundle named Bundle[].properties in the
37: * package of the specified class.
38: */
39: private static ResourceBundle getBundle() {
40: return ResourceBundle.getBundle(BUNDLE_NAME);
41: }
42:
43: /**
44: * Returns the string specified by aKey from the errors.properties bundle.
45: */
46: public static String getString(String aKey) {
47: try {
48: return getBundle().getString(aKey);
49: } catch (Exception e) {
50: return getString("System_StringNotFound",
51: new Object[] { aKey });
52: }
53: }
54:
55: /**
56: * Returns the string specified by aKey from the errors.properties bundle.
57: *
58: * @param aKey The key for the message pattern in the bundle.
59: * @param arg The arg to use in the message format.
60: */
61: public static String getString(String aKey, Object arg) {
62: return getString(aKey, new Object[] { arg });
63: }
64:
65: /**
66: * Returns the string specified by aKey from the errors.properties bundle.
67: *
68: * @param aKey The key for the message pattern in the bundle.
69: * @param args The args to use in the message format.
70: */
71: public static String getString(String aKey, Object[] args) {
72: String pattern = getBundle().getString(aKey);
73: MessageFormat format = new MessageFormat(pattern);
74:
75: return format.format(args).toString();
76: }
77:
78: /**
79: *
80: */
81: public static String getErrorString(String aKey, Object[] args) {
82: String pattern = getBundle().getString(aKey);
83: MessageFormat format = new MessageFormat(pattern);
84:
85: return format.format(args);
86: }
87:
88: public static String getErrorString(String aKey) {
89: return getBundle().getString(aKey);
90: }
91:
92: }
|