1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.ebay.carad.os.vitalsigns.util;
22
23 import java.text.MessageFormat;
24
25 /***
26 * Provides basic <code>MessageFormat</code> utility methods.
27 *
28 * @author Jeremy Kraybill
29 * @version $Id$
30 */
31 public abstract class MessageFormatUtil {
32
33 /***
34 * Escape single-quotes for MessageFormat. Single quotes get special treatment
35 * by MessageFormat, but we almost never want that behavior.
36 *
37 * @param inStr the string to escape
38 * @return an escaped string
39 */
40 private static String escapeSingleQuotes(String inStr) {
41 return inStr.replaceAll("'", "''");
42 }
43
44 /***
45 * Reformats the passed-in message format-ready string with the passed-in parameters.
46 * Single quotes in the passed-in string are escaped and therefore ignored by MessageFormat.
47 *
48 * @param inStr the string to format
49 * @param params the parameters to substitute
50 * @return a formatted string
51 */
52 public static String format(String inStr, Object[] params) {
53 return MessageFormat.format(escapeSingleQuotes(inStr), params);
54 }
55
56 }