1 16 17 package org.apache.xerces.impl.msg; 18 19 import java.util.Locale ; 20 import java.util.MissingResourceException ; 21 import java.util.ResourceBundle ; 22 import java.util.PropertyResourceBundle ; 23 24 import org.apache.xerces.util.MessageFormatter; 25 26 36 public class XMLMessageFormatter implements MessageFormatter { 37 40 public static final String XML_DOMAIN = "http://www.w3.org/TR/1998/REC-xml-19980210"; 41 public static final String XMLNS_DOMAIN = "http://www.w3.org/TR/1999/REC-xml-names-19990114"; 42 43 private Locale fLocale = null; 45 private ResourceBundle fResourceBundle = null; 46 47 51 66 public String formatMessage(Locale locale, String key, Object [] arguments) 67 throws MissingResourceException { 68 69 if (fResourceBundle == null || locale != fLocale) { 70 if (locale != null) { 71 fResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLMessages", locale); 72 fLocale = locale; 74 } 75 if (fResourceBundle == null) 76 fResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLMessages"); 77 } 78 79 String msg; 81 try { 82 msg = fResourceBundle.getString(key); 83 if (arguments != null) { 84 try { 85 msg = java.text.MessageFormat.format(msg, arguments); 86 } 87 catch (Exception e) { 88 msg = fResourceBundle.getString("FormatFailed"); 89 msg += " " + fResourceBundle.getString(key); 90 } 91 } 92 } 93 94 catch (MissingResourceException e) { 96 msg = fResourceBundle.getString("BadMessageKey"); 97 throw new MissingResourceException (key, msg, key); 98 } 99 100 if (msg == null) { 102 msg = key; 103 if (arguments.length > 0) { 104 StringBuffer str = new StringBuffer (msg); 105 str.append('?'); 106 for (int i = 0; i < arguments.length; i++) { 107 if (i > 0) { 108 str.append('&'); 109 } 110 str.append(String.valueOf(arguments[i])); 111 } 112 } 113 } 114 115 return msg; 116 } 117 118 } 119 | Popular Tags |