1 57 58 package com.sun.org.apache.xerces.internal.impl.msg; 59 60 import java.util.Locale ; 61 import java.util.MissingResourceException ; 62 import java.util.ResourceBundle ; 63 import java.util.PropertyResourceBundle ; 64 65 import com.sun.org.apache.xerces.internal.util.MessageFormatter; 66 67 75 public class XMLMessageFormatter implements MessageFormatter { 76 79 public static final String XML_DOMAIN = "http://www.w3.org/TR/1998/REC-xml-19980210"; 80 public static final String XMLNS_DOMAIN = "http://www.w3.org/TR/1999/REC-xml-names-19990114"; 81 82 private Locale fLocale = null; 84 private ResourceBundle fResourceBundle = null; 85 86 90 105 public String formatMessage(Locale locale, String key, Object [] arguments) 106 throws MissingResourceException { 107 108 if (fResourceBundle == null || locale != fLocale) { 109 if (locale != null) { 110 fResourceBundle = PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLMessages", locale); 111 fLocale = locale; 113 } 114 if (fResourceBundle == null) 115 fResourceBundle = PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLMessages"); 116 } 117 118 String msg; 120 try { 121 msg = fResourceBundle.getString(key); 122 if (arguments != null) { 123 try { 124 msg = java.text.MessageFormat.format(msg, arguments); 125 } 126 catch (Exception e) { 127 msg = fResourceBundle.getString("FormatFailed"); 128 msg += " " + fResourceBundle.getString(key); 129 } 130 } 131 } 132 133 catch (MissingResourceException e) { 135 msg = fResourceBundle.getString("BadMessageKey"); 136 throw new MissingResourceException (key, msg, key); 137 } 138 139 if (msg == null) { 141 msg = key; 142 if (arguments.length > 0) { 143 StringBuffer str = new StringBuffer (msg); 144 str.append('?'); 145 for (int i = 0; i < arguments.length; i++) { 146 if (i > 0) { 147 str.append('&'); 148 } 149 str.append(String.valueOf(arguments[i])); 150 } 151 } 152 } 153 154 return msg; 155 } 156 157 } 158 | Popular Tags |