1 16 17 package org.apache.xerces.util; 18 19 import java.util.Locale ; 20 import java.util.MissingResourceException ; 21 import java.util.PropertyResourceBundle ; 22 import java.util.ResourceBundle ; 23 24 30 public class DatatypeMessageFormatter { 31 32 private static final String BASE_NAME = "org.apache.xerces.impl.msg.DatatypeMessages"; 33 34 49 public static String formatMessage(Locale locale, 50 String key, Object [] arguments) 51 throws MissingResourceException { 52 53 ResourceBundle resourceBundle = null; 54 if (locale != null) { 55 resourceBundle = 56 PropertyResourceBundle.getBundle(BASE_NAME, locale); 57 } 58 else { 59 resourceBundle = 60 PropertyResourceBundle.getBundle(BASE_NAME); 61 } 62 63 String msg; 65 try { 66 msg = resourceBundle.getString(key); 67 if (arguments != null) { 68 try { 69 msg = java.text.MessageFormat.format(msg, arguments); 70 } 71 catch (Exception e) { 72 msg = resourceBundle.getString("FormatFailed"); 73 msg += " " + resourceBundle.getString(key); 74 } 75 } 76 } 77 78 catch (MissingResourceException e) { 80 msg = resourceBundle.getString("BadMessageKey"); 81 throw new MissingResourceException (key, msg, key); 82 } 83 84 if (msg == null) { 86 msg = key; 87 if (arguments.length > 0) { 88 StringBuffer str = new StringBuffer (msg); 89 str.append('?'); 90 for (int i = 0; i < arguments.length; i++) { 91 if (i > 0) { 92 str.append('&'); 93 } 94 str.append(String.valueOf(arguments[i])); 95 } 96 } 97 } 98 return msg; 99 } 100 } 101 | Popular Tags |