DOMMessageFormatterpublic class DOMMessageFormatter extends Object Used to format DOM error messages, using the system locale. |
Fields Summary |
---|
public static final String | DOM_DOMAIN | public static final String | XML_DOMAIN | public static final String | SERIALIZER_DOMAIN | private static ResourceBundle | domResourceBundle | private static ResourceBundle | xmlResourceBundle | private static ResourceBundle | serResourceBundle | private static Locale | locale |
Constructors Summary |
---|
DOMMessageFormatter()
locale = Locale.getDefault();
|
Methods Summary |
---|
public static java.lang.String | formatMessage(java.lang.String domain, java.lang.String key, java.lang.Object[] arguments)Formats a message with the specified arguments using the given
locale information.
ResourceBundle resourceBundle = getResourceBundle(domain);
if(resourceBundle == null){
init();
resourceBundle = getResourceBundle(domain);
if(resourceBundle == null)
throw new MissingResourceException("Unknown domain" + domain, null, key);
}
// format message
String msg;
try {
msg = key + ": " + resourceBundle.getString(key);
if (arguments != null) {
try {
msg = java.text.MessageFormat.format(msg, arguments);
}
catch (Exception e) {
msg = resourceBundle.getString("FormatFailed");
msg += " " + resourceBundle.getString(key);
}
}
} // error
catch (MissingResourceException e) {
msg = resourceBundle.getString("BadMessageKey");
throw new MissingResourceException(key, msg, key);
}
// no message
if (msg == null) {
msg = key;
if (arguments.length > 0) {
StringBuffer str = new StringBuffer(msg);
str.append('?");
for (int i = 0; i < arguments.length; i++) {
if (i > 0) {
str.append('&");
}
str.append(String.valueOf(arguments[i]));
}
}
}
return msg;
| static java.util.ResourceBundle | getResourceBundle(java.lang.String domain)
if(domain == DOM_DOMAIN || domain.equals(DOM_DOMAIN))
return domResourceBundle;
else if( domain == XML_DOMAIN || domain.equals(XML_DOMAIN))
return xmlResourceBundle;
else if(domain == SERIALIZER_DOMAIN || domain.equals(SERIALIZER_DOMAIN))
return serResourceBundle;
return null;
| public static void | init()Initialize Message Formatter.
if (locale != null) {
domResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.DOMMessages", locale);
serResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLSerializerMessages", locale);
xmlResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLMessages", locale);
}else{
domResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.DOMMessages");
serResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLSerializerMessages");
xmlResourceBundle = PropertyResourceBundle.getBundle("org.apache.xerces.impl.msg.XMLMessages");
}
| public static void | setLocale(java.util.Locale dlocale)Set Locale to be used by the formatter.
locale = dlocale;
|
|