View Javadoc
1 /* 2 * The Apache Software License, Version 1.1 3 * 4 * Copyright (c) 1999 The Apache Software Foundation. All rights 5 * reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * 19 * 3. The end-user documentation included with the redistribution, if 20 * any, must include the following acknowlegement: 21 * "This product includes software developed by the 22 * Apache Software Foundation (http://www.apache.org/)." 23 * Alternately, this acknowlegement may appear in the software itself, 24 * if and wherever such third-party acknowlegements normally appear. 25 * 26 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software 27 * Foundation" must not be used to endorse or promote products derived 28 * from this software without prior written permission. For written 29 * permission, please contact apache@apache.org. 30 * 31 * 5. Products derived from this software may not be called "Apache" 32 * nor may "Apache" appear in their names without prior written 33 * permission of the Apache Group. 34 * 35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 46 * SUCH DAMAGE. 47 * ==================================================================== 48 * 49 * This software consists of voluntary contributions made by many 50 * individuals on behalf of the Apache Software Foundation. For more 51 * information on the Apache Software Foundation, please see 52 * <http://www.apache.org/>;. 53 * 54 */ 55 56 package org.apache.commons.jelly.tags; 57 58 import java.util.*; 59 import java.text.*; 60 61 /*** 62 * <p>Provides locale-neutral access to string resources. Only the 63 * documentation and code are in English. :-) 64 * 65 * <p>The major goal, aside from globalization, is convenience. 66 * Access to resources with no parameters is made in the form:</p> 67 * <pre> 68 * Resources.getMessage(MESSAGE_NAME); 69 * </pre> 70 * 71 * <p>Access to resources with one parameter works like</p> 72 * <pre> 73 * Resources.getMessage(MESSAGE_NAME, arg1); 74 * </pre> 75 * 76 * <p>... and so on.</p> 77 * 78 * @author Shawn Bayern 79 */ 80 public class Resources { 81 82 //********************************************************************** 83 // Static data 84 85 /** The location of our resources. */ 86 private static final String RESOURCE_LOCATION 87 = "org.apache.commons.jelly.tags.Resources"; 88 89 /*** Our class-wide ResourceBundle. */ 90 private static ResourceBundle rb = 91 ResourceBundle.getBundle(RESOURCE_LOCATION); 92 93 94 //********************************************************************** 95 // Public static methods 96 97 /** Retrieves a message with no arguments. */ 98 public static String getMessage(String name) 99 throws MissingResourceException { 100 return rb.getString(name); 101 } 102 103 /*** Retrieves a message with arbitrarily many arguments. */ 104 public static String getMessage(String name, Object[] a) 105 throws MissingResourceException { 106 String res = rb.getString(name); 107 return MessageFormat.format(res, a); 108 } 109 110 /*** Retrieves a message with one argument. */ 111 public static String getMessage(String name, Object a1) 112 throws MissingResourceException { 113 return getMessage(name, new Object[] { a1 }); 114 } 115 116 /*** Retrieves a message with two arguments. */ 117 public static String getMessage(String name, Object a1, Object a2) 118 throws MissingResourceException { 119 return getMessage(name, new Object[] { a1, a2 }); 120 } 121 122 /*** Retrieves a message with three arguments. */ 123 public static String getMessage(String name, 124 Object a1, 125 Object a2, 126 Object a3) 127 throws MissingResourceException { 128 return getMessage(name, new Object[] { a1, a2, a3 }); 129 } 130 131 /*** Retrieves a message with four arguments. */ 132 public static String getMessage(String name, 133 Object a1, 134 Object a2, 135 Object a3, 136 Object a4) 137 throws MissingResourceException { 138 return getMessage(name, new Object[] { a1, a2, a3, a4 }); 139 } 140 141 /*** Retrieves a message with five arguments. */ 142 public static String getMessage(String name, 143 Object a1, 144 Object a2, 145 Object a3, 146 Object a4, 147 Object a5) 148 throws MissingResourceException { 149 return getMessage(name, new Object[] { a1, a2, a3, a4, a5 }); 150 } 151 152 /*** Retrieves a message with six arguments. */ 153 public static String getMessage(String name, 154 Object a1, 155 Object a2, 156 Object a3, 157 Object a4, 158 Object a5, 159 Object a6) 160 throws MissingResourceException { 161 return getMessage(name, new Object[] { a1, a2, a3, a4, a5, a6 }); 162 } 163 164 }

This page was automatically generated by Maven