FileDocCategorySizeDatePackage
DOMMessageFormatter.javaAPI DocJava SE 6 API5410Tue Jun 10 00:22:36 BST 2008com.sun.org.apache.xerces.internal.dom

DOMMessageFormatter

public class DOMMessageFormatter extends Object
Used to format DOM error messages, using the system locale.
xerces.internal
author
Sandy Gao, IBM
version
$Id: DOMMessageFormatter.java,v 1.2.6.1 2005/08/30 13:23:29 sunithareddy Exp $

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.StringformatMessage(java.lang.String domain, java.lang.String key, java.lang.Object[] arguments)
Formats a message with the specified arguments using the given locale information.

param
domain domain from which error string is to come.
param
key The message key.
param
arguments The message replacement text arguments. The order of the arguments must match that of the placeholders in the actual message.
return
the formatted message.
throws
MissingResourceException Thrown if the message with the specified key cannot be found.

        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.ResourceBundlegetResourceBundle(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 voidinit()
Initialize Message Formatter.

        if (locale != null) {
            domResourceBundle = PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.DOMMessages", locale);
            serResourceBundle = PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLSerializerMessages", locale);
            xmlResourceBundle = PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLMessages", locale);
        }else{
            domResourceBundle = PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.DOMMessages");
            serResourceBundle = PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLSerializerMessages");
            xmlResourceBundle = PropertyResourceBundle.getBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLMessages");
        }
    
public static voidsetLocale(java.util.Locale dlocale)
setLocale to be used by the formatter.

param
locale

        locale = dlocale;