jaxp/src/com/sun/org/apache/xpath/internal/res/XPATHMessages.java
author joehw
Mon, 18 Feb 2013 11:33:35 -0800
changeset 16953 a44e04deb948
parent 12457 c348e06f0e82
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 1999-2004 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
 * $Id: XPATHMessages.java,v 1.2.4.1 2005/09/01 14:57:34 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xpath.internal.res;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    25
import com.sun.org.apache.bcel.internal.util.SecuritySupport;
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    26
import com.sun.org.apache.xml.internal.res.XMLMessages;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import java.util.ListResourceBundle;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 * A utility class for issuing XPath error messages.
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    31
 *
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * @xsl.usage internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 */
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    34
public class XPATHMessages extends XMLMessages {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    36
    /**
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    37
     * The language specific resource object for XPath messages.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    38
     */
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    39
    private static ListResourceBundle XPATHBundle = null;
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    40
    /**
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    41
     * The class name of the XPath error message string table.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    42
     */
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    43
    private static final String XPATH_ERROR_RESOURCES =
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    44
            "com.sun.org.apache.xpath.internal.res.XPATHErrorResources";
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    46
    /**
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    47
     * Creates a message from the specified key and replacement arguments,
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    48
     * localized to the given locale.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    49
     *
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    50
     * @param msgKey The key for the message text.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    51
     * @param args The arguments to be used as replacement text in the message
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    52
     * created.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    53
     *
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    54
     * @return The formatted message string.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    55
     */
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    56
    public static final String createXPATHMessage(String msgKey, Object args[]) //throws Exception
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
    {
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    58
        if (XPATHBundle == null) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    59
            XPATHBundle = SecuritySupport.getResourceBundle(XPATH_ERROR_RESOURCES);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    60
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    62
        if (XPATHBundle != null) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    63
            return createXPATHMsg(XPATHBundle, msgKey, args);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    64
        } else {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    65
            return "Could not load any resource bundles.";
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    66
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    69
    /**
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    70
     * Creates a message from the specified key and replacement arguments,
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    71
     * localized to the given locale.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    72
     *
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    73
     * @param msgKey The key for the message text.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    74
     * @param args The arguments to be used as replacement text in the message
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    75
     * created.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    76
     *
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    77
     * @return The formatted warning string.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    78
     */
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    79
    public static final String createXPATHWarning(String msgKey, Object args[]) //throws Exception
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    80
    {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    81
        if (XPATHBundle == null) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    82
            XPATHBundle = SecuritySupport.getResourceBundle(XPATH_ERROR_RESOURCES);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    83
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    85
        if (XPATHBundle != null) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    86
            return createXPATHMsg(XPATHBundle, msgKey, args);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    87
        } else {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    88
            return "Could not load any resource bundles.";
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    89
        }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    92
    /**
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    93
     * Creates a message from the specified key and replacement arguments,
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    94
     * localized to the given locale.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    95
     *
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    96
     * @param fResourceBundle The resource bundle to use.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    97
     * @param msgKey The message key to use.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    98
     * @param args The arguments to be used as replacement text in the message
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
    99
     * created.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   100
     *
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   101
     * @return The formatted message string.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   102
     */
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   103
    public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   104
            String msgKey, Object args[]) //throws Exception
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   107
        String fmsg = null;
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   108
        boolean throwex = false;
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   109
        String msg = null;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   111
        if (msgKey != null) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   112
            msg = fResourceBundle.getString(msgKey);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   113
        }
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   114
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   115
        if (msg == null) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   116
            msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   117
            throwex = true;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
16953
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   120
        if (args != null) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   121
            try {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   122
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   123
                // Do this to keep format from crying.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   124
                // This is better than making a bunch of conditional
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   125
                // code all over the place.
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   126
                int n = args.length;
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   127
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   128
                for (int i = 0; i < n; i++) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   129
                    if (null == args[i]) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   130
                        args[i] = "";
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   131
                    }
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   132
                }
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   133
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   134
                fmsg = java.text.MessageFormat.format(msg, args);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   135
            } catch (Exception e) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   136
                fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   137
                fmsg += " " + msg;
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   138
            }
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   139
        } else {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   140
            fmsg = msg;
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   141
        }
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   142
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   143
        if (throwex) {
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   144
            throw new RuntimeException(fmsg);
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   145
        }
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   146
a44e04deb948 6657673: Issues with JAXP
joehw
parents: 12457
diff changeset
   147
        return fmsg;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
}