| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 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 | 0 | public class Resources { |
| 42 | ||
| 43 | //********************************************************************* |
|
| 44 | // Static data |
|
| 45 | ||
| 46 | /** The location of our resources. */ |
|
| 47 | private static final String RESOURCE_LOCATION |
|
| 48 | = "org.apache.commons.jelly.tags.Resources"; |
|
| 49 | ||
| 50 | /** Our class-wide ResourceBundle. */ |
|
| 51 | 0 | 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 getMessage(String name) |
|
| 60 | throws MissingResourceException { |
|
| 61 | 0 | return rb.getString(name); |
| 62 | } |
|
| 63 | ||
| 64 | /** Retrieves a message with arbitrarily many arguments. */ |
|
| 65 | public static String getMessage(String name, Object[] a) |
|
| 66 | throws MissingResourceException { |
|
| 67 | 0 | String res = rb.getString(name); |
| 68 | 0 | return MessageFormat.format(res, a); |
| 69 | } |
|
| 70 | ||
| 71 | /** Retrieves a message with one argument. */ |
|
| 72 | public static String getMessage(String name, Object a1) |
|
| 73 | throws MissingResourceException { |
|
| 74 | 0 | return getMessage(name, new Object[] { a1 }); |
| 75 | } |
|
| 76 | ||
| 77 | /** Retrieves a message with two arguments. */ |
|
| 78 | public static String getMessage(String name, Object a1, Object a2) |
|
| 79 | throws MissingResourceException { |
|
| 80 | 0 | return getMessage(name, new Object[] { a1, a2 }); |
| 81 | } |
|
| 82 | ||
| 83 | /** Retrieves a message with three arguments. */ |
|
| 84 | public static String getMessage(String name, |
|
| 85 | Object a1, |
|
| 86 | Object a2, |
|
| 87 | Object a3) |
|
| 88 | throws MissingResourceException { |
|
| 89 | 0 | return getMessage(name, new Object[] { a1, a2, a3 }); |
| 90 | } |
|
| 91 | ||
| 92 | /** Retrieves a message with four arguments. */ |
|
| 93 | public static String getMessage(String name, |
|
| 94 | Object a1, |
|
| 95 | Object a2, |
|
| 96 | Object a3, |
|
| 97 | Object a4) |
|
| 98 | throws MissingResourceException { |
|
| 99 | 0 | return getMessage(name, new Object[] { a1, a2, a3, a4 }); |
| 100 | } |
|
| 101 | ||
| 102 | /** Retrieves a message with five arguments. */ |
|
| 103 | public static String getMessage(String name, |
|
| 104 | Object a1, |
|
| 105 | Object a2, |
|
| 106 | Object a3, |
|
| 107 | Object a4, |
|
| 108 | Object a5) |
|
| 109 | throws MissingResourceException { |
|
| 110 | 0 | return getMessage(name, new Object[] { a1, a2, a3, a4, a5 }); |
| 111 | } |
|
| 112 | ||
| 113 | /** Retrieves a message with six arguments. */ |
|
| 114 | public static String getMessage(String name, |
|
| 115 | Object a1, |
|
| 116 | Object a2, |
|
| 117 | Object a3, |
|
| 118 | Object a4, |
|
| 119 | Object a5, |
|
| 120 | Object a6) |
|
| 121 | throws MissingResourceException { |
|
| 122 | 0 | return getMessage(name, new Object[] { a1, a2, a3, a4, a5, a6 }); |
| 123 | } |
|
| 124 | ||
| 125 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |