1 16 package org.apache.xerces.xpointer; 17 18 import java.util.Locale ; 19 import java.util.MissingResourceException ; 20 import java.util.ResourceBundle ; 21 import java.util.PropertyResourceBundle ; 22 import org.apache.xerces.util.MessageFormatter; 23 24 32 class XPointerMessageFormatter implements MessageFormatter { 33 34 public static final String XPOINTER_DOMAIN = "http://www.w3.org/TR/XPTR"; 35 36 private Locale fLocale = null; 38 39 private ResourceBundle fResourceBundle = null; 40 41 59 public String formatMessage(Locale locale, String key, Object [] arguments) 60 throws MissingResourceException { 61 62 if (fResourceBundle == null || locale != fLocale) { 63 if (locale != null) { 64 fResourceBundle = PropertyResourceBundle.getBundle( 65 "org.apache.xerces.impl.msg.XPointerMessages", locale); 66 fLocale = locale; 68 } 69 if (fResourceBundle == null) 70 fResourceBundle = PropertyResourceBundle 71 .getBundle("org.apache.xerces.impl.msg.XPointerMessages"); 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, 87 "org.apache.xerces.impl.msg.XPointerMessages", key); 88 } 89 90 return msg; 91 } 92 } | Popular Tags |