1 16 package org.directwebremoting.util; 17 18 import java.text.MessageFormat ; 19 import java.util.MissingResourceException ; 20 import java.util.ResourceBundle ; 21 22 26 public class Messages 27 { 28 31 private Messages() 32 { 33 } 34 35 40 public static String getString(String key) 41 { 42 try 43 { 44 return RESOURCE_BUNDLE.getString(key); 45 } 46 catch (MissingResourceException ex) 47 { 48 log.error("Missing I18N string: " + key, ex); 49 return '!' + key + '!'; 50 } 51 } 52 53 59 public static String getString(String key, Object param) 60 { 61 return getString(key, new Object [] { param, }); 62 } 63 64 71 public static String getString(String key, Object param1, Object param2) 72 { 73 return getString(key, new Object [] { param1, param2, }); 74 } 75 76 84 public static String getString(String key, Object param1, Object param2, Object param3) 85 { 86 return getString(key, new Object [] { param1, param2, param3, }); 87 } 88 89 98 public static String getString(String key, Object param1, Object param2, Object param3, Object param4) 99 { 100 return getString(key, new Object [] { param1, param2, param3, param4, }); 101 } 102 103 109 public static String getString(String key, Object [] params) 110 { 111 try 112 { 113 String format = RESOURCE_BUNDLE.getString(key); 114 return MessageFormat.format(format, params); 115 } 116 catch (MissingResourceException ex) 117 { 118 StringBuffer buffer = new StringBuffer (); 120 buffer.append('['); 121 for (int i = 0; i < params.length; i++) 122 { 123 if (i != 0) 124 { 125 buffer.append(','); 126 } 127 buffer.append(params[i].toString()); 128 } 129 buffer.append(']'); 130 131 log.error("Missing I18N string: " + key + ". Params: " + buffer.toString()); 132 return '!' + key + '!' + buffer.toString() + '!'; 133 } 134 } 135 136 139 private static final Logger log = Logger.getLogger(Messages.class); 140 141 144 private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle("org.directwebremoting.messages"); 145 } 146 | Popular Tags |