001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. 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.apache.commons.el;
018
019 import java.text.MessageFormat;
020
021 /**
022 * <p>Utility class for generating parameterized messages.</p>
023 *
024 * @version $Id: MessageUtil.java 480405 2006-11-29 04:49:34Z bayard $
025 */
026
027 public class MessageUtil
028 {
029
030 /**
031 * <p>Returns a formatted message based on the provided template and
032 * a single parameter.</p>
033 * @param pTemplate the base message
034 * @param pArg0 parameter
035 * @return Returns a formatted message based on the provided template and
036 * a single parameter.
037 */
038 public static String getMessageWithArgs(String pTemplate, Object pArg0) {
039 return MessageFormat.format(pTemplate, new Object[]{ "" + pArg0 });
040 }
041
042 /**
043 * <p>Returns a formatted message based on the provided template and
044 * provided parameter.</p>
045 * @param pTemplate the base message
046 * @param pArg0 parameter 1
047 * @param pArg1 parameter 2
048 * @return Returns a formatted message based on the provided template and
049 * provided parameter
050 */
051 public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1) {
052 return MessageFormat.format(pTemplate, new Object[]{"" + pArg0, "" + pArg1 });
053 }
054
055 /**
056 * <p>Returns a formatted message based on the provided template and
057 * provided parameter.</p>
058 * @param pTemplate the base message
059 * @param pArg0 parameter 1
060 * @param pArg1 parameter 2
061 * @param pArg2 parameter 3
062 * @return Returns a formatted message based on the provided template and
063 * provided parameter
064 */
065 public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1, Object pArg2) {
066 return MessageFormat.format(pTemplate, new Object[]{
067 "" + pArg0,
068 "" + pArg1,
069 "" + pArg2
070 });
071 }
072
073 /**
074 * <p>Returns a formatted message based on the provided template and
075 * provided parameter.</p>
076 * @param pTemplate the base message
077 * @param pArg0 parameter 1
078 * @param pArg1 parameter 2
079 * @param pArg2 parameter 3
080 * @param pArg3 parameter 4
081 * @return Returns a formatted message based on the provided template and
082 * provided parameter
083 */
084 public static String getMessageWithArgs(String pTemplate, Object pArg0, Object pArg1, Object pArg2, Object pArg3) {
085 return MessageFormat.format(
086 pTemplate, new Object[]{
087 "" + pArg0,
088 "" + pArg1,
089 "" + pArg2,
090 "" + pArg3
091 });
092 }
093
094 /**
095 * <p>Returns a formatted message based on the provided template and
096 * provided parameter.</p>
097 * @param pTemplate the base message
098 * @param pArg0 parameter 1
099 * @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 }