KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > key > passwd > console > Resources


1 /*
2  * Copyright 2006 Schlichtherle IT Services
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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
17 package de.schlichtherle.key.passwd.console;
18
19 import java.text.MessageFormat JavaDoc;
20 import java.util.ResourceBundle JavaDoc;
21
22 /**
23  * Convenience class to look up the bundle in a {@link ResourceBundle}.
24  * Provided for comfort.
25  *
26  * @author Christian Schlichtherle
27  */

28 class Resources {
29
30     /** The resource bundle used. */
31     public final ResourceBundle JavaDoc bundle;
32
33     public Resources(String JavaDoc baseName) {
34         bundle = ResourceBundle.getBundle(baseName);
35     }
36
37     /**
38      * Looks up a string resource identified by <code>key</code> in
39      * <code>bundle</code>.
40      */

41     public final String JavaDoc getString(String JavaDoc key) {
42         return bundle.getString(key);
43     }
44
45     /**
46      * Looks up a string resource identified by <code>key</code> in
47      * <code>bundle</code> and formats it as a message using
48      * <code>MessageFormat.format</code> with the given <code>arguments</code>.
49      */

50     public final String JavaDoc getString(String JavaDoc key, Object JavaDoc[] arguments) {
51         return MessageFormat.format(getString(key), arguments);
52     }
53     
54     /**
55      * Looks up a string resource identified by <code>key</code> in
56      * <code>bundle</code> and formats it as a message using
57      * <code>MessageFormat.format</code> with the given singular <code>argument</code>.
58      */

59     public final String JavaDoc getString(String JavaDoc key, Object JavaDoc argument) {
60         return MessageFormat.format(getString(key), new Object JavaDoc[] { argument });
61     }
62     
63     /**
64      * Looks up a string resource identified by <code>key</code> in
65      * <code>bundle</code> and formats it as a message using
66      * <code>MessageFormat.format</code> with the given singular <code>argument</code>.
67      */

68     public final String JavaDoc getString(String JavaDoc key, int argument) {
69         return MessageFormat.format(getString(key), new Object JavaDoc[] { new Integer JavaDoc(argument) });
70     }
71 }
72
Popular Tags