001    /*
002     * Copyright 1999-2004 The Apache Software Foundation.
003     * Modifications, Copyright 2005 Stephen Colebourne
004     * 
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     * 
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     * 
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */ 
017    package org.joda.time.contrib.jsptag;
018    
019    import java.text.MessageFormat;
020    import java.util.MissingResourceException;
021    import java.util.ResourceBundle;
022    
023    /**
024     * <p>Provides locale-neutral access to string resources.  Only the
025     * documentation and code are in English. :-)
026     *
027     * <p>The major goal, aside from globalization, is convenience.
028     * Access to resources with no parameters is made in the form:</p>
029     * <pre>
030     *     Resources.getMessage(MESSAGE_NAME);
031     * </pre>
032     *
033     * <p>Access to resources with one parameter works like</p>
034     * <pre>
035     *     Resources.getMessage(MESSAGE_NAME, arg1);
036     * </pre>
037     *
038     * <p>... and so on.</p>
039     *
040     * @author Shawn Bayern
041     */
042    public class Resources {
043    
044        //*********************************************************************
045        // Static data
046    
047        /** The location of our resources. */
048        private static final String RESOURCE_LOCATION = "org.joda.time.contrib.jsptag.Resources";
049    
050        /** Our class-wide ResourceBundle. */
051        private static ResourceBundle rb = ResourceBundle.getBundle(RESOURCE_LOCATION);
052    
053    
054        //*********************************************************************
055        // Public static methods
056    
057        /** Retrieves a message with no arguments. */
058        public static String getMessage(String name)
059          throws MissingResourceException {
060            return rb.getString(name);
061        }
062    
063        /** Retrieves a message with arbitrarily many arguments. */
064        public static String getMessage(String name, Object[] a)
065          throws MissingResourceException {
066            String res = rb.getString(name);
067            return MessageFormat.format(res, a);
068        }
069    
070        /** Retrieves a message with one argument. */
071        public static String getMessage(String name, Object a1)
072          throws MissingResourceException {
073            return getMessage(name, new Object[] { a1 });
074        }
075    
076        /** Retrieves a message with two arguments. */
077        public static String getMessage(String name, Object a1, Object a2)
078          throws MissingResourceException {
079            return getMessage(name, new Object[] { a1, a2 });
080        }
081    
082        /** Retrieves a message with three arguments. */
083        public static String getMessage(String name,
084                Object a1,
085                Object a2,
086                Object a3)
087          throws MissingResourceException {
088            return getMessage(name, new Object[] { a1, a2, a3 });
089        }
090    
091        /** Retrieves a message with four arguments. */
092        public static String getMessage(String name,
093                 Object a1,
094                Object a2,
095                Object a3,
096                Object a4)
097          throws MissingResourceException {
098            return getMessage(name, new Object[] { a1, a2, a3, a4 });
099        }
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    }