KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > util > Bundle


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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  * $Header:$
17  */

18 package org.apache.beehive.netui.util;
19
20 import java.text.MessageFormat JavaDoc;
21 import java.util.ResourceBundle JavaDoc;
22
23 /**
24  * Convenience class for dealing with resource bundles.
25  */

26 public class Bundle
27 {
28
29     private static final String JavaDoc BUNDLE_NAME = "org.apache.beehive.netui.util.netui";
30
31     /** No need, it's all static */
32     private Bundle(){}
33
34     /**
35      * Returns the resource bundle named Bundle[].properties in the
36      * package of the specified class.
37      */

38     private static ResourceBundle JavaDoc getBundle()
39     {
40         return ResourceBundle.getBundle(BUNDLE_NAME);
41     }
42
43
44     /**
45      * Returns the string specified by aKey from the errors.properties bundle.
46      */

47     public static String JavaDoc getString(String JavaDoc aKey)
48     {
49         try
50         {
51             return getBundle().getString(aKey);
52         }
53         catch(Exception JavaDoc e)
54         {
55             return getString("System_StringNotFound",new Object JavaDoc[]{aKey});
56         }
57     }
58
59     /**
60      * Returns the string specified by aKey from the errors.properties bundle.
61      *
62      * @param aKey The key for the message pattern in the bundle.
63      * @param arg The arg to use in the message format.
64      */

65     public static String JavaDoc getString(String JavaDoc aKey, Object JavaDoc arg)
66     {
67         return getString(aKey,new Object JavaDoc[]{arg});
68     }
69
70     /**
71      * Returns the string specified by aKey from the errors.properties bundle.
72      *
73      * @param aKey The key for the message pattern in the bundle.
74      * @param args The args to use in the message format.
75      */

76     public static String JavaDoc getString(String JavaDoc aKey, Object JavaDoc[] args)
77     {
78         String JavaDoc pattern = getBundle().getString(aKey);
79         MessageFormat JavaDoc format = new MessageFormat JavaDoc(pattern);
80         
81         return format.format(args).toString();
82     }
83     
84     /**
85      *
86      */

87     public static String JavaDoc getErrorString(String JavaDoc aKey, Object JavaDoc[] args)
88     {
89         String JavaDoc pattern = getBundle().getString(aKey);
90         MessageFormat JavaDoc format = new MessageFormat JavaDoc(pattern);
91         
92         return format.format(args);
93     }
94
95     public static String JavaDoc getErrorString(String JavaDoc aKey)
96     {
97         return getBundle().getString(aKey);
98     }
99
100 }
101
Popular Tags