1 16 17 package org.apache.xerces.impl.xs; 18 19 import java.util.Locale ; 20 import java.util.MissingResourceException ; 21 import java.util.ResourceBundle ; 22 import java.util.PropertyResourceBundle ; 23 import org.apache.xerces.util.MessageFormatter; 24 25 26 35 public class XSMessageFormatter implements MessageFormatter { 36 39 public static final String SCHEMA_DOMAIN = "http://www.w3.org/TR/xml-schema-1"; 40 41 42 private Locale fLocale = null; 44 private ResourceBundle fResourceBundle = null; 45 46 61 public String formatMessage(Locale locale, String key, Object [] arguments) 62 throws MissingResourceException { 63 64 if (fResourceBundle == null || locale != fLocale) { 65 if (locale != null) { 66 fResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLSchemaMessages", locale); 67 fLocale = locale; 69 } 70 if (fResourceBundle == null) 71 fResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLSchemaMessages"); 72 } 73 74 String msg = fResourceBundle.getString(key); 75 if (arguments != null) { 76 try { 77 msg = java.text.MessageFormat.format(msg, arguments); 78 } catch (Exception e) { 79 msg = fResourceBundle.getString("FormatFailed"); 80 msg += " " + fResourceBundle.getString(key); 81 } 82 } 83 84 if (msg == null) { 85 msg = fResourceBundle.getString("BadMessageKey"); 86 throw new MissingResourceException (msg, "org.apache.xerces.impl.msg.SchemaMessages", key); 87 } 88 89 return msg; 90 } 91 } 92 | Popular Tags |