jaxp/src/com/sun/org/apache/xerces/internal/xinclude/XIncludeMessageFormatter.java
author joehw
Mon, 18 Feb 2013 11:33:35 -0800
changeset 16953 a44e04deb948
parent 12457 c348e06f0e82
child 25264 040625ce9b72
permissions -rw-r--r--
6657673: Issues with JAXP Reviewed-by: alanb, lancea, ahgross, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 2003-2005 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xerces.internal.xinclude;
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    23
import com.sun.org.apache.xerces.internal.util.MessageFormatter;
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    24
import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import java.util.Locale;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import java.util.MissingResourceException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import java.util.ResourceBundle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
// TODO: fix error messages in XIncludeMessages.properties
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * XIncludeMessageFormatter provides error messages for the XInclude 1.0 Candidate Recommendation
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * @author Peter McCracken, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    35
 * @version $Id: XIncludeMessageFormatter.java,v 1.7 2010-11-01 04:40:18 joehw Exp $
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
public class XIncludeMessageFormatter implements MessageFormatter {
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
    public static final String XINCLUDE_DOMAIN = "http://www.w3.org/TR/xinclude";
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
     // private objects to cache the locale and resource bundle
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
    private Locale fLocale = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
    private ResourceBundle fResourceBundle = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
     * Formats a message with the specified arguments using the given
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
     * locale information.
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
     * @param locale    The locale of the message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
     * @param key       The message key.
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
     * @param arguments The message replacement text arguments. The order
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
     *                  of the arguments must match that of the placeholders
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
     *                  in the actual message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
     * @return Returns the formatted message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
     * @throws MissingResourceException Thrown if the message with the
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
     *                                  specified key cannot be found.
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
     public String formatMessage(Locale locale, String key, Object[] arguments)
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
        throws MissingResourceException {
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
        if (fResourceBundle == null || locale != fLocale) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
            if (locale != null) {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    65
                fResourceBundle = SecuritySupport.getResourceBundle("com.sun.org.apache.xerces.internal.impl.msg.XIncludeMessages", locale);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
                // memorize the most-recent locale
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
                fLocale = locale;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
            if (fResourceBundle == null)
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    70
                fResourceBundle = SecuritySupport.getResourceBundle("com.sun.org.apache.xerces.internal.impl.msg.XIncludeMessages");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
        String msg = fResourceBundle.getString(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
        if (arguments != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
                msg = java.text.MessageFormat.format(msg, arguments);
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
            } catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
                msg = fResourceBundle.getString("FormatFailed");
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
                msg += " " + fResourceBundle.getString(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
        if (msg == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
            msg = fResourceBundle.getString("BadMessageKey");
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
            throw new MissingResourceException(msg, "com.sun.org.apache.xerces.internal.impl.msg.XIncludeMessages", key);
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        return msg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
}