View Javadoc

1   /*
2    * Copyright 1999-2004 The Apache Software Foundation.
3    * Modifications, Copyright 2005 Stephen Colebourne
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */ 
17  package org.joda.time.contrib.jsptag;
18  
19  import java.text.MessageFormat;
20  import java.util.MissingResourceException;
21  import java.util.ResourceBundle;
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 RESOURCE_LOCATION = "org.joda.time.contrib.jsptag.Resources";
49  
50      /** Our class-wide ResourceBundle. */
51      private static ResourceBundle rb = ResourceBundle.getBundle(RESOURCE_LOCATION);
52  
53  
54      //*********************************************************************
55      // Public static methods
56  
57      /** Retrieves a message with no arguments. */
58      public static String getMessage(String name)
59        throws MissingResourceException {
60          return rb.getString(name);
61      }
62  
63      /** Retrieves a message with arbitrarily many arguments. */
64      public static String getMessage(String name, Object[] a)
65        throws MissingResourceException {
66          String res = rb.getString(name);
67          return MessageFormat.format(res, a);
68      }
69  
70      /** Retrieves a message with one argument. */
71      public static String getMessage(String name, Object a1)
72        throws MissingResourceException {
73          return getMessage(name, new Object[] { a1 });
74      }
75  
76      /** Retrieves a message with two arguments. */
77      public static String getMessage(String name, Object a1, Object a2)
78        throws MissingResourceException {
79          return getMessage(name, new Object[] { a1, a2 });
80      }
81  
82      /** Retrieves a message with three arguments. */
83      public static String getMessage(String name,
84              Object a1,
85              Object a2,
86              Object a3)
87        throws MissingResourceException {
88          return getMessage(name, new Object[] { a1, a2, a3 });
89      }
90  
91      /** Retrieves a message with four arguments. */
92      public static String getMessage(String name,
93               Object a1,
94              Object a2,
95              Object a3,
96              Object a4)
97        throws MissingResourceException {
98          return getMessage(name, new Object[] { a1, a2, a3, a4 });
99      }
100 
101     /** Retrieves a message with five arguments. */
102     public static String getMessage(String name,
103             Object a1,
104             Object a2,
105             Object a3,
106             Object a4,
107             Object a5)
108       throws MissingResourceException {
109         return getMessage(name, new Object[] { a1, a2, a3, a4, a5 });
110     }
111 
112     /** Retrieves a message with six arguments. */
113     public static String getMessage(String name,
114             Object a1,
115             Object a2,
116             Object a3,
117             Object a4,
118             Object a5,
119             Object a6)
120       throws MissingResourceException {
121         return getMessage(name, new Object[] { a1, a2, a3, a4, a5, a6 });
122     }
123 
124 }