KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jelly > tags > Resources


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

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

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

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