1 18 19 20 package org.objectweb.speedo.generation.start; 21 22 import java.util.ResourceBundle ; 23 import java.util.Locale ; 24 import java.util.Hashtable ; 25 import java.text.MessageFormat ; 26 27 28 class I18NHelper 29 { 30 private static Hashtable bundles = new Hashtable (); 31 private static Locale locale = Locale.getDefault(); 32 33 36 public I18NHelper() 37 {} 38 39 42 public static ResourceBundle loadBundle(String bundleName) 43 { 44 ResourceBundle messages = (ResourceBundle )bundles.get(bundleName); 45 46 if (messages == null) { 48 messages = ResourceBundle.getBundle(bundleName, locale); 49 bundles.put(bundleName, messages); 50 } 51 return messages; 52 } 53 54 55 58 final public static String getMessage(ResourceBundle messages, String messageKey) 59 { 60 return messages.getString(messageKey); 61 } 62 63 66 final public static String getMessage(ResourceBundle messages, String messageKey, Object msgArgs[]) 67 { 68 for (int i=0; i<msgArgs.length; i++) { 69 if (msgArgs[i] == null) msgArgs[i] = ""; } 71 MessageFormat formatter = new MessageFormat (messages.getString(messageKey)); 72 return formatter.format(msgArgs); 73 } 74 77 final public static String getMessage(ResourceBundle messages, String messageKey, String arg) 78 { 79 Object []args = {arg}; 80 return getMessage(messages, messageKey, args); 81 } 82 85 final public static String getMessage(ResourceBundle messages, String messageKey, String arg1, 86 String arg2) 87 { 88 Object []args = {arg1, arg2}; 89 return getMessage(messages, messageKey, args); 90 } 91 94 final public static String getMessage(ResourceBundle messages, String messageKey, String arg1, 95 String arg2, String arg3) 96 { 97 Object []args = {arg1, arg2, arg3}; 98 return getMessage(messages, messageKey, args); 99 } 100 104 final public static String getMessage(ResourceBundle messages, String messageKey, Object arg) 105 { 106 Object []args = {arg}; 107 return getMessage(messages, messageKey, args); 108 } 109 112 final public static String getMessage(ResourceBundle messages, String messageKey, int arg) 113 { 114 Object []args = {new Integer (arg)}; 115 return getMessage(messages, messageKey, args); 116 } 117 120 final public static String getMessage(ResourceBundle messages, String messageKey, boolean arg) 121 { 122 Object []args = {String.valueOf(arg)}; 123 return getMessage(messages, messageKey, args); 124 } 125 } 126 127 128 131 public class Support 132 extends Assertion 133 { 134 static public Timer timer = new Timer(); 136 137 140 static private ResourceBundle MESSAGES; 141 142 143 146 static 147 { 148 try 149 { 150 MESSAGES = I18NHelper.loadBundle("org.objectweb.speedo.generation.start.Bundle"); 151 } 152 catch (java.util.MissingResourceException ex) 153 { 154 ex.printStackTrace (); 155 } 156 } 157 158 161 static protected final String getI18N(String key) 162 { 163 return I18NHelper.getMessage(MESSAGES, key); 164 } 165 166 169 static protected final String getI18N(String key, 170 String arg) 171 { 172 return I18NHelper.getMessage(MESSAGES, key, arg); 173 } 174 175 178 static protected final String getI18N(String key, 179 String arg1, 180 String arg2) 181 { 182 return I18NHelper.getMessage(MESSAGES, key, arg1, arg2); 183 } 184 185 188 static protected final String getI18N(String key, 189 String arg1, 190 String arg2, 191 String arg3) 192 { 193 return I18NHelper.getMessage(MESSAGES, key, arg1, arg2, arg3); 194 } 195 196 199 static protected final String getI18N(String key, 200 int arg1, 201 String arg2) 202 { 203 return I18NHelper.getMessage(MESSAGES, key, 204 new Object []{new Integer (arg1), arg2}); 205 } 206 207 210 static protected final String getI18N(String key, 211 Object [] args) 212 { 213 return I18NHelper.getMessage(MESSAGES, key, args); 214 } 215 } 216 | Popular Tags |