001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Portions Copyright Apache Software Foundation.
007: *
008: * The contents of this file are subject to the terms of either the GNU
009: * General Public License Version 2 only ("GPL") or the Common Development
010: * and Distribution License("CDDL") (collectively, the "License"). You
011: * may not use this file except in compliance with the License. You can obtain
012: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
013: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
014: * language governing permissions and limitations under the License.
015: *
016: * When distributing the software, include this License Header Notice in each
017: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
018: * Sun designates this particular file as subject to the "Classpath" exception
019: * as provided by Sun in the GPL Version 2 section of the License file that
020: * accompanied this code. If applicable, add the following below the License
021: * Header, with the fields enclosed by brackets [] replaced by your own
022: * identifying information: "Portions Copyrighted [year]
023: * [name of copyright owner]"
024: *
025: * Contributor(s):
026: *
027: * If you wish your version of this file to be governed by only the CDDL or
028: * only the GPL Version 2, indicate your decision by adding "[Contributor]
029: * elects to include this software in this distribution under the [CDDL or GPL
030: * Version 2] license." If you don't indicate a single choice of license, a
031: * recipient has the option to distribute your version of this file under
032: * either the CDDL, the GPL Version 2 or to extend the choice of license to
033: * its licensees as provided above. However, if you add GPL Version 2 code
034: * and therefore, elected the GPL Version 2 license, then the option applies
035: * only if the new code is made subject to such option by the copyright
036: * holder.
037: */
038:
039: package org.apache.taglibs.standard.resources;
040:
041: import java.text.MessageFormat;
042: import java.util.MissingResourceException;
043: import java.util.ResourceBundle;
044:
045: /**
046: * <p>Provides locale-neutral access to string resources. Only the
047: * documentation and code are in English. :-)
048: *
049: * <p>The major goal, aside from globalization, is convenience.
050: * Access to resources with no parameters is made in the form:</p>
051: * <pre>
052: * Resources.getMessage(MESSAGE_NAME);
053: * </pre>
054: *
055: * <p>Access to resources with one parameter works like</p>
056: * <pre>
057: * Resources.getMessage(MESSAGE_NAME, arg1);
058: * </pre>
059: *
060: * <p>... and so on.</p>
061: *
062: * @author Shawn Bayern
063: */
064: public class Resources {
065:
066: //*********************************************************************
067: // Static data
068:
069: /** The location of our resources. */
070: private static final String RESOURCE_LOCATION = "org.apache.taglibs.standard.resources.Resources";
071:
072: /** Our class-wide ResourceBundle. */
073: private static ResourceBundle rb = ResourceBundle
074: .getBundle(RESOURCE_LOCATION);
075:
076: //*********************************************************************
077: // Public static methods
078:
079: /** Retrieves a message with no arguments. */
080: public static String getMessage(String name)
081: throws MissingResourceException {
082: return rb.getString(name);
083: }
084:
085: /** Retrieves a message with arbitrarily many arguments. */
086: public static String getMessage(String name, Object[] a)
087: throws MissingResourceException {
088: String res = rb.getString(name);
089: return MessageFormat.format(res, a);
090: }
091:
092: /** Retrieves a message with one argument. */
093: public static String getMessage(String name, Object a1)
094: throws MissingResourceException {
095: return getMessage(name, new Object[] { a1 });
096: }
097:
098: /** Retrieves a message with two arguments. */
099: public static String getMessage(String name, Object a1, Object a2)
100: throws MissingResourceException {
101: return getMessage(name, new Object[] { a1, a2 });
102: }
103:
104: /** Retrieves a message with three arguments. */
105: public static String getMessage(String name, Object a1, Object a2,
106: Object a3) throws MissingResourceException {
107: return getMessage(name, new Object[] { a1, a2, a3 });
108: }
109:
110: /** Retrieves a message with four arguments. */
111: public static String getMessage(String name, Object a1, Object a2,
112: Object a3, Object a4) throws MissingResourceException {
113: return getMessage(name, new Object[] { a1, a2, a3, a4 });
114: }
115:
116: /** Retrieves a message with five arguments. */
117: public static String getMessage(String name, Object a1, Object a2,
118: Object a3, Object a4, Object a5)
119: throws MissingResourceException {
120: return getMessage(name, new Object[] { a1, a2, a3, a4, a5 });
121: }
122:
123: /** Retrieves a message with six arguments. */
124: public static String getMessage(String name, Object a1, Object a2,
125: Object a3, Object a4, Object a5, Object a6)
126: throws MissingResourceException {
127: return getMessage(name, new Object[] { a1, a2, a3, a4, a5, a6 });
128: }
129:
130: }
|