1 57 package com.sun.org.apache.xerces.internal.util; 58 59 import java.util.Locale ; 60 import java.util.MissingResourceException ; 61 import java.util.ResourceBundle ; 62 import java.util.PropertyResourceBundle ; 63 64 71 public class SAXMessageFormatter { 72 73 88 public static String formatMessage(Locale locale, 89 String key, Object [] arguments) 90 throws MissingResourceException { 91 92 ResourceBundle resourceBundle = null; 93 if (locale != null) { 94 resourceBundle = 95 PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.SAXMessages", locale); 96 } 97 else { 98 resourceBundle = 99 PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.SAXMessages"); 100 } 101 102 String msg; 104 try { 105 msg = resourceBundle.getString(key); 106 if (arguments != null) { 107 try { 108 msg = java.text.MessageFormat.format(msg, arguments); 109 } 110 catch (Exception e) { 111 msg = resourceBundle.getString("FormatFailed"); 112 msg += " " + resourceBundle.getString(key); 113 } 114 } 115 } 116 117 catch (MissingResourceException e) { 119 msg = resourceBundle.getString("BadMessageKey"); 120 throw new MissingResourceException (key, msg, key); 121 } 122 123 if (msg == null) { 125 msg = key; 126 if (arguments.length > 0) { 127 StringBuffer str = new StringBuffer (msg); 128 str.append('?'); 129 for (int i = 0; i < arguments.length; i++) { 130 if (i > 0) { 131 str.append('&'); 132 } 133 str.append(String.valueOf(arguments[i])); 134 } 135 } 136 } 137 return msg; 138 } 139 } 140 | Popular Tags |