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