KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > resources > Resources


1 /*
2  * Copyright 1999-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
17 package org.apache.taglibs.standard.resources;
18
19 import java.text.MessageFormat JavaDoc;
20 import java.util.MissingResourceException JavaDoc;
21 import java.util.ResourceBundle JavaDoc;
22
23 /**
24  * <p>Provides locale-neutral access to string resources. Only the
25  * documentation and code are in English. :-)
26  *
27  * <p>The major goal, aside from globalization, is convenience.
28  * Access to resources with no parameters is made in the form:</p>
29  * <pre>
30  * Resources.getMessage(MESSAGE_NAME);
31  * </pre>
32  *
33  * <p>Access to resources with one parameter works like</p>
34  * <pre>
35  * Resources.getMessage(MESSAGE_NAME, arg1);
36  * </pre>
37  *
38  * <p>... and so on.</p>
39  *
40  * @author Shawn Bayern
41  */

42 public class Resources {
43
44     //*********************************************************************
45
// Static data
46

47     /** The location of our resources. */
48     private static final String JavaDoc RESOURCE_LOCATION
49     = "org.apache.taglibs.standard.resources.Resources";
50
51     /** Our class-wide ResourceBundle. */
52     private static ResourceBundle JavaDoc rb =
53     ResourceBundle.getBundle(RESOURCE_LOCATION);
54
55
56     //*********************************************************************
57
// Public static methods
58

59     /** Retrieves a message with no arguments. */
60     public static String JavaDoc getMessage(String JavaDoc name)
61         throws MissingResourceException JavaDoc {
62     return rb.getString(name);
63     }
64
65     /** Retrieves a message with arbitrarily many arguments. */
66     public static String JavaDoc getMessage(String JavaDoc name, Object JavaDoc[] a)
67         throws MissingResourceException JavaDoc {
68     String JavaDoc res = rb.getString(name);
69     return MessageFormat.format(res, a);
70     }
71
72     /** Retrieves a message with one argument. */
73     public static String JavaDoc getMessage(String JavaDoc name, Object JavaDoc a1)
74         throws MissingResourceException JavaDoc {
75     return getMessage(name, new Object JavaDoc[] { a1 });
76     }
77
78     /** Retrieves a message with two arguments. */
79     public static String JavaDoc getMessage(String JavaDoc name, Object JavaDoc a1, Object JavaDoc a2)
80         throws MissingResourceException JavaDoc {
81     return getMessage(name, new Object JavaDoc[] { a1, a2 });
82     }
83
84     /** Retrieves a message with three arguments. */
85     public static String JavaDoc getMessage(String JavaDoc name,
86                     Object JavaDoc a1,
87                     Object JavaDoc a2,
88                     Object JavaDoc a3)
89         throws MissingResourceException JavaDoc {
90     return getMessage(name, new Object JavaDoc[] { a1, a2, a3 });
91     }
92
93     /** Retrieves a message with four arguments. */
94     public static String JavaDoc getMessage(String JavaDoc name,
95                     Object JavaDoc a1,
96                     Object JavaDoc a2,
97                     Object JavaDoc a3,
98                     Object JavaDoc a4)
99         throws MissingResourceException JavaDoc {
100     return getMessage(name, new Object JavaDoc[] { a1, a2, a3, a4 });
101     }
102
103     /** Retrieves a message with five arguments. */
104     public static String JavaDoc getMessage(String JavaDoc name,
105                     Object JavaDoc a1,
106                     Object JavaDoc a2,
107                     Object JavaDoc a3,
108                     Object JavaDoc a4,
109                     Object JavaDoc a5)
110         throws MissingResourceException JavaDoc {
111     return getMessage(name, new Object JavaDoc[] { a1, a2, a3, a4, a5 });
112     }
113
114     /** Retrieves a message with six arguments. */
115     public static String JavaDoc getMessage(String JavaDoc name,
116                     Object JavaDoc a1,
117                     Object JavaDoc a2,
118                     Object JavaDoc a3,
119                     Object JavaDoc a4,
120                     Object JavaDoc a5,
121                     Object JavaDoc a6)
122         throws MissingResourceException JavaDoc {
123     return getMessage(name, new Object JavaDoc[] { a1, a2, a3, a4, a5, a6 });
124     }
125
126 }
127
Popular Tags