1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. 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.apache.commons.el;
18
19 import java.text.MessageFormat;
20
21 /**
22 * <p>Utility class for generating parameterized messages.</p>
23 *
24 * @version $Id: MessageUtil.java 480405 2006-11-29 04:49:34Z bayard $
25 */
26
27 public class MessageUtil
28 {
29
30 /**
31 * <p>Returns a formatted message based on the provided template and
32 * a single parameter.</p>
33 * @param pTemplate the base message
34 * @param pArg0 parameter
35 * @return Returns a formatted message based on the provided template and
36 * a single parameter.
37 */
38 public static String getMessageWithArgs(String pTemplate, Object pArg0) {
39 return MessageFormat.format(pTemplate, new Object[]{ "" + pArg0 });
40 }
41
42 /**
43 * <p>Returns a formatted message based on the provided template and
44 * provided parameter.</p>
45 * @param pTemplate the base message
46 * @param pArg0 parameter 1
47 * @param pArg1 parameter 2
48 * @return Returns a formatted message based on the provided template and
49 * provided parameter
50 */
51 public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1) {
52 return MessageFormat.format(pTemplate, new Object[]{"" + pArg0, "" + pArg1 });
53 }
54
55 /**
56 * <p>Returns a formatted message based on the provided template and
57 * provided parameter.</p>
58 * @param pTemplate the base message
59 * @param pArg0 parameter 1
60 * @param pArg1 parameter 2
61 * @param pArg2 parameter 3
62 * @return Returns a formatted message based on the provided template and
63 * provided parameter
64 */
65 public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1, Object pArg2) {
66 return MessageFormat.format(pTemplate, new Object[]{
67 "" + pArg0,
68 "" + pArg1,
69 "" + pArg2
70 });
71 }
72
73 /**
74 * <p>Returns a formatted message based on the provided template and
75 * provided parameter.</p>
76 * @param pTemplate the base message
77 * @param pArg0 parameter 1
78 * @param pArg1 parameter 2
79 * @param pArg2 parameter 3
80 * @param pArg3 parameter 4
81 * @return Returns a formatted message based on the provided template and
82 * provided parameter
83 */
84 public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1, Object pArg2, Object pArg3) {
85 return MessageFormat.format(
86 pTemplate, new Object[]{
87 "" + pArg0,
88 "" + pArg1,
89 "" + pArg2,
90 "" + pArg3
91 });
92 }
93
94 /**
95 * <p>Returns a formatted message based on the provided template and
96 * provided parameter.</p>
97 * @param pTemplate the base message
98 * @param pArg0 parameter 1
99 * @param pArg1 parameter 2
100 * @param pArg2 parameter 3
101 * @param pArg3 parameter 4
102 * @param pArg4 parameter 5
103 * @return Returns a formatted message based on the provided template and
104 * provided parameter
105 */
106 public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1, Object pArg2, Object pArg3, Object pArg4) {
107 return MessageFormat.format(
108 pTemplate, new Object[]{
109 "" + pArg0,
110 "" + pArg1,
111 "" + pArg2,
112 "" + pArg3,
113 "" + pArg4
114 });
115 }
116
117 /**
118 * <p>Returns a formatted message based on the provided template and
119 * provided parameter.</p>
120 * @param pTemplate the base message
121 * @param pArg0 parameter 1
122 * @param pArg1 parameter 2
123 * @param pArg2 parameter 3
124 * @param pArg3 parameter 4
125 * @param pArg4 parameter 5
126 * @param pArg5 parameter 6
127 * @return Returns a formatted message based on the provided template and
128 * provided parameter
129 */
130 public static String getMessageWithArgs(
131 String pTemplate, Object pArg0, Object pArg1, Object pArg2, Object pArg3,
132 Object pArg4, Object pArg5) {
133 return MessageFormat.format(
134 pTemplate, new Object[]{
135 "" + pArg0,
136 "" + pArg1,
137 "" + pArg2,
138 "" + pArg3,
139 "" + pArg4,
140 "" + pArg5
141 });
142 }
143 }