src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XSMessageFormatter.java
author joehw
Wed, 04 Oct 2017 10:54:18 -0700
changeset 47312 d4f959806fe9
parent 47216 71c04702a3d5
child 48409 5ab69533994b
permissions -rw-r--r--
8187593: Cleanup: removing SecuritySupport files Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
     3
 * @LastModified: Sep 2017
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
44797
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
8b3b3b911b8a 8162572: Update License Header for all JAXP sources
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xerces.internal.impl.xs;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    24
import com.sun.org.apache.xerces.internal.util.MessageFormatter;
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;
47312
d4f959806fe9 8187593: Cleanup: removing SecuritySupport files
joehw
parents: 47216
diff changeset
    28
import jdk.xml.internal.SecuritySupport;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * SchemaMessageProvider implements an XMLMessageProvider that
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * provides localizable error messages for the W3C XML Schema Language
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * @xerces.internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * @author Elena Litani, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
public class XSMessageFormatter implements MessageFormatter {
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
     * The domain of messages concerning the XML Schema: Structures specification.
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
    public static final String SCHEMA_DOMAIN = "http://www.w3.org/TR/xml-schema-1";
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    // private objects to cache the locale and resource bundle
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    private Locale fLocale = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
    private ResourceBundle fResourceBundle = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
     * Formats a message with the specified arguments using the given
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
     * locale information.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
     * @param locale    The locale of the message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
     * @param key       The message key.
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
     * @param arguments The message replacement text arguments. The order
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
     *                  of the arguments must match that of the placeholders
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
     *                  in the actual message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
     * @return Returns the formatted message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
     * @throws MissingResourceException Thrown if the message with the
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
     *                                  specified key cannot be found.
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     public String formatMessage(Locale locale, String key, Object[] arguments)
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
        throws MissingResourceException {
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
        if (fResourceBundle == null || locale != fLocale) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
            if (locale != null) {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    70
                fResourceBundle = SecuritySupport.getResourceBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages", locale);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
                // memorize the most-recent locale
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
                fLocale = locale;
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
            if (fResourceBundle == null)
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    75
                fResourceBundle = SecuritySupport.getResourceBundle("com.sun.org.apache.xerces.internal.impl.msg.XMLSchemaMessages");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
        String msg = fResourceBundle.getString(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        if (arguments != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
                msg = java.text.MessageFormat.format(msg, arguments);
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
            } catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
                msg = fResourceBundle.getString("FormatFailed");
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
                msg += " " + fResourceBundle.getString(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        if (msg == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
            msg = fResourceBundle.getString("BadMessageKey");
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
            throw new MissingResourceException(msg, "com.sun.org.apache.xerces.internal.impl.msg.SchemaMessages", key);
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
        return msg;
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
}