2
* Copyright 2001-2004 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package org.apache.axis.i18n;
19
import java.text.MessageFormat;
20
import java.util.Locale;
21
import java.util.MissingResourceException;
22
import java.util.ResourceBundle;
25
* Accept parameters for ProjectResourceBundle,
26
* but defer object instantiation (and therefore
27
* resource bundle loading) until required.
29
* @author Richard A. Sitze (rsitze@us.ibm.com)
30
* @author Karl Moss (kmoss@macromedia.com)
31
* @author Glen Daniels (gdaniels@apache.org)
33
public class MessageBundle {
34
private boolean loaded = false;
36
private ProjectResourceBundle _resourceBundle = null;
38
private final String projectName;
39
private final String packageName;
40
private final String resourceName;
41
private final Locale locale;
42
private final ClassLoader classLoader;
43
private final ResourceBundle parent;
46
public final ProjectResourceBundle getResourceBundle() {
48
_resourceBundle = ProjectResourceBundle.getBundle(projectName,
56
return _resourceBundle;
60
* Construct a new ExtendMessages
62
public MessageBundle(String projectName,
66
ClassLoader classLoader,
67
ResourceBundle parent)
68
throws MissingResourceException
70
this.projectName = projectName;
71
this.packageName = packageName;
72
this.resourceName = resourceName;
74
this.classLoader = classLoader;
79
* Gets a string message from the resource bundle for the given key
80
* @param key The resource key
83
public String getMessage(String key) throws MissingResourceException
85
return getMessage(key, (String[]) null);
89
* <p>Gets a string message from the resource bundle for the given key. The
90
* message may contain variables that will be substituted with the given
91
* arguments. Variables have the format:</p>
93
* This message has two variables: {0} and {1}
95
* @param key The resource key
96
* @param arg0 The argument to place in variable {0}
99
public String getMessage(String key, String arg0) throws MissingResourceException
101
return getMessage(key, new String[] { arg0 });
105
* <p>Gets a string message from the resource bundle for the given key. The
106
* message may contain variables that will be substituted with the given
107
* arguments. Variables have the format:</p>
109
* This message has two variables: {0} and {1}
111
* @param key The resource key
112
* @param arg0 The argument to place in variable {0}
113
* @param arg1 The argument to place in variable {1}
114
* @return The message
116
public String getMessage(String key, String arg0, String arg1) throws MissingResourceException
118
return getMessage(key, new String[] { arg0, arg1 });
122
* <p>Gets a string message from the resource bundle for the given key. The
123
* message may contain variables that will be substituted with the given
124
* arguments. Variables have the format:</p>
126
* This message has two variables: {0} and {1}
128
* @param key The resource key
129
* @param arg0 The argument to place in variable {0}
130
* @param arg1 The argument to place in variable {1}
131
* @param arg2 The argument to place in variable {2}
132
* @return The message
134
public String getMessage(String key, String arg0, String arg1, String arg2) throws MissingResourceException
136
return getMessage(key, new String[] { arg0, arg1, arg2 });
140
* <p>Gets a string message from the resource bundle for the given key. The
141
* message may contain variables that will be substituted with the given
142
* arguments. Variables have the format:</p>
144
* This message has two variables: {0} and {1}
146
* @param key The resource key
147
* @param arg0 The argument to place in variable {0}
148
* @param arg1 The argument to place in variable {1}
149
* @param arg2 The argument to place in variable {2}
150
* @param arg3 The argument to place in variable {3}
151
* @return The message
153
public String getMessage(String key, String arg0, String arg1, String arg2, String arg3) throws MissingResourceException
155
return getMessage(key, new String[] { arg0, arg1, arg2, arg3 });
159
* <p>Gets a string message from the resource bundle for the given key. The
160
* message may contain variables that will be substituted with the given
161
* arguments. Variables have the format:</p>
163
* This message has two variables: {0} and {1}
165
* @param key The resource key
166
* @param arg0 The argument to place in variable {0}
167
* @param arg1 The argument to place in variable {1}
168
* @param arg2 The argument to place in variable {2}
169
* @param arg3 The argument to place in variable {3}
170
* @param arg4 The argument to place in variable {4}
171
* @return The message
173
public String getMessage(String key, String arg0, String arg1, String arg2, String arg3, String arg4) throws MissingResourceException
175
return getMessage(key, new String[] { arg0, arg1, arg2, arg3, arg4 });
179
* <p>Gets a string message from the resource bundle for the given key. The
180
* message may contain variables that will be substituted with the given
181
* arguments. Variables have the format:</p>
183
* This message has two variables: {0} and {1}
185
* @param key The resource key
186
* @param array An array of objects to place in corresponding variables
187
* @return The message
189
public String getMessage(String key, String[] array) throws MissingResourceException
192
if (getResourceBundle() != null) {
193
msg = getResourceBundle().getString(key);
197
throw new MissingResourceException("Cannot find resource key \"" + key +
199
getResourceBundle().getResourceName(),
200
getResourceBundle().getResourceName(), key);
203
return MessageFormat.format(msg, array);