1 16 17 package org.apache.xerces.jaxp.validation; 18 19 import java.util.Locale ; 20 import java.util.MissingResourceException ; 21 import java.util.ResourceBundle ; 22 import java.util.PropertyResourceBundle ; 23 24 30 final class JAXPValidationMessageFormatter { 31 32 47 public static String formatMessage(Locale locale, 48 String key, Object [] arguments) 49 throws MissingResourceException { 50 51 ResourceBundle resourceBundle = null; 52 if (locale != null) { 53 resourceBundle = 54 PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.JAXPValidationMessages", locale); 55 } 56 else { 57 resourceBundle = 58 PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.JAXPValidationMessages"); 59 } 60 61 String msg; 63 try { 64 msg = resourceBundle.getString(key); 65 if (arguments != null) { 66 try { 67 msg = java.text.MessageFormat.format(msg, arguments); 68 } 69 catch (Exception e) { 70 msg = resourceBundle.getString("FormatFailed"); 71 msg += " " + resourceBundle.getString(key); 72 } 73 } 74 } 75 76 catch (MissingResourceException e) { 78 msg = resourceBundle.getString("BadMessageKey"); 79 throw new MissingResourceException (key, msg, key); 80 } 81 82 if (msg == null) { 84 msg = key; 85 if (arguments.length > 0) { 86 StringBuffer str = new StringBuffer (msg); 87 str.append('?'); 88 for (int i = 0; i < arguments.length; i++) { 89 if (i > 0) { 90 str.append('&'); 91 } 92 str.append(String.valueOf(arguments[i])); 93 } 94 } 95 } 96 return msg; 97 } 98 } 99 | Popular Tags |