Java Code Examples for java.util.ListResourceBundle#getString()

The following examples show how to use java.util.ListResourceBundle#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLMessages.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement
 * arguments, localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey  The message key to use.
 * @param args      The arguments to be used as replacement text
 *                  in the message created.
 *
 * @return The formatted message string.
 */
public static final String createMsg(ListResourceBundle fResourceBundle,
      String msgKey, Object args[])  //throws Exception
{

  String fmsg = null;
  boolean throwex = false;
  String msg = null;

  if (msgKey != null)
    msg = fResourceBundle.getString(msgKey);

  if (msg == null)
  {
    msg = fResourceBundle.getString(BAD_CODE);
    throwex = true;
  }

  if (args != null)
  {
    try
    {

      // Do this to keep format from crying.
      // This is better than making a bunch of conditional
      // code all over the place.
      int n = args.length;

      for (int i = 0; i < n; i++)
      {
        if (null == args[i])
          args[i] = "";
      }

      fmsg = java.text.MessageFormat.format(msg, args);
    }
    catch (Exception e)
    {
      fmsg = fResourceBundle.getString(FORMAT_FAILED);
      fmsg += " " + msg;
    }
  }
  else
    fmsg = msg;

  if (throwex)
  {
    throw new RuntimeException(fmsg);
  }

  return fmsg;
}
 
Example 2
Source File: XPATHMessages.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement arguments,
 * localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey The message key to use.
 * @param args The arguments to be used as replacement text in the message
 * created.
 *
 * @return The formatted message string.
 */
public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
        String msgKey, Object args[]) //throws Exception
{

    String fmsg = null;
    boolean throwex = false;
    String msg = null;

    if (msgKey != null) {
        msg = fResourceBundle.getString(msgKey);
    }

    if (msg == null) {
        msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
        throwex = true;
    }

    if (args != null) {
        try {

            // Do this to keep format from crying.
            // This is better than making a bunch of conditional
            // code all over the place.
            int n = args.length;

            for (int i = 0; i < n; i++) {
                if (null == args[i]) {
                    args[i] = "";
                }
            }

            fmsg = java.text.MessageFormat.format(msg, args);
        } catch (Exception e) {
            fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
            fmsg += " " + msg;
        }
    } else {
        fmsg = msg;
    }

    if (throwex) {
        throw new RuntimeException(fmsg);
    }

    return fmsg;
}
 
Example 3
Source File: XMLMessages.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement
 * arguments, localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey  The message key to use.
 * @param args      The arguments to be used as replacement text
 *                  in the message created.
 *
 * @return The formatted message string.
 */
public static final String createMsg(ListResourceBundle fResourceBundle,
      String msgKey, Object args[])  //throws Exception
{

  String fmsg = null;
  boolean throwex = false;
  String msg = null;

  if (msgKey != null)
    msg = fResourceBundle.getString(msgKey);

  if (msg == null)
  {
    msg = fResourceBundle.getString(BAD_CODE);
    throwex = true;
  }

  if (args != null)
  {
    try
    {

      // Do this to keep format from crying.
      // This is better than making a bunch of conditional
      // code all over the place.
      int n = args.length;

      for (int i = 0; i < n; i++)
      {
        if (null == args[i])
          args[i] = "";
      }

      fmsg = java.text.MessageFormat.format(msg, args);
    }
    catch (Exception e)
    {
      fmsg = fResourceBundle.getString(FORMAT_FAILED);
      fmsg += " " + msg;
    }
  }
  else
    fmsg = msg;

  if (throwex)
  {
    throw new RuntimeException(fmsg);
  }

  return fmsg;
}
 
Example 4
Source File: XPATHMessages.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement arguments,
 * localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey The message key to use.
 * @param args The arguments to be used as replacement text in the message
 * created.
 *
 * @return The formatted message string.
 */
public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
        String msgKey, Object args[]) //throws Exception
{

    String fmsg = null;
    boolean throwex = false;
    String msg = null;

    if (msgKey != null) {
        msg = fResourceBundle.getString(msgKey);
    }

    if (msg == null) {
        msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
        throwex = true;
    }

    if (args != null) {
        try {

            // Do this to keep format from crying.
            // This is better than making a bunch of conditional
            // code all over the place.
            int n = args.length;

            for (int i = 0; i < n; i++) {
                if (null == args[i]) {
                    args[i] = "";
                }
            }

            fmsg = java.text.MessageFormat.format(msg, args);
        } catch (Exception e) {
            fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
            fmsg += " " + msg;
        }
    } else {
        fmsg = msg;
    }

    if (throwex) {
        throw new RuntimeException(fmsg);
    }

    return fmsg;
}
 
Example 5
Source File: XMLMessages.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement
 * arguments, localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey  The message key to use.
 * @param args      The arguments to be used as replacement text
 *                  in the message created.
 *
 * @return The formatted message string.
 */
public static final String createMsg(ListResourceBundle fResourceBundle,
      String msgKey, Object args[])  //throws Exception
{

  String fmsg = null;
  boolean throwex = false;
  String msg = null;

  if (msgKey != null)
    msg = fResourceBundle.getString(msgKey);

  if (msg == null)
  {
    msg = fResourceBundle.getString(BAD_CODE);
    throwex = true;
  }

  if (args != null)
  {
    try
    {

      // Do this to keep format from crying.
      // This is better than making a bunch of conditional
      // code all over the place.
      int n = args.length;

      for (int i = 0; i < n; i++)
      {
        if (null == args[i])
          args[i] = "";
      }

      fmsg = java.text.MessageFormat.format(msg, args);
    }
    catch (Exception e)
    {
      fmsg = fResourceBundle.getString(FORMAT_FAILED);
      fmsg += " " + msg;
    }
  }
  else
    fmsg = msg;

  if (throwex)
  {
    throw new RuntimeException(fmsg);
  }

  return fmsg;
}
 
Example 6
Source File: XPATHMessages.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement arguments,
 * localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey The message key to use.
 * @param args The arguments to be used as replacement text in the message
 * created.
 *
 * @return The formatted message string.
 */
public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
        String msgKey, Object args[]) //throws Exception
{

    String fmsg = null;
    boolean throwex = false;
    String msg = null;

    if (msgKey != null) {
        msg = fResourceBundle.getString(msgKey);
    }

    if (msg == null) {
        msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
        throwex = true;
    }

    if (args != null) {
        try {

            // Do this to keep format from crying.
            // This is better than making a bunch of conditional
            // code all over the place.
            int n = args.length;

            for (int i = 0; i < n; i++) {
                if (null == args[i]) {
                    args[i] = "";
                }
            }

            fmsg = java.text.MessageFormat.format(msg, args);
        } catch (Exception e) {
            fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
            fmsg += " " + msg;
        }
    } else {
        fmsg = msg;
    }

    if (throwex) {
        throw new RuntimeException(fmsg);
    }

    return fmsg;
}
 
Example 7
Source File: XMLMessages.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
  * Creates a message from the specified key and replacement
  * arguments, localized to the given locale.
  *
  * @param fResourceBundle The resource bundle to use.
  * @param msgKey  The message key to use.
  * @param args      The arguments to be used as replacement text
  *                  in the message created.
  *
  * @return The formatted message string.
  */
 public static final String createMsg(ListResourceBundle fResourceBundle,
String msgKey, Object args[])  //throws Exception
 {

   String fmsg = null;
   boolean throwex = false;
   String msg = null;

   if (msgKey != null)
     msg = fResourceBundle.getString(msgKey);

   if (msg == null)
   {
     msg = fResourceBundle.getString(BAD_CODE);
     throwex = true;
   }

   if (args != null)
   {
     try
     {

       // Do this to keep format from crying.
       // This is better than making a bunch of conditional
       // code all over the place.
       int n = args.length;

       for (int i = 0; i < n; i++)
       {
         if (null == args[i])
           args[i] = "";
       }

       fmsg = java.text.MessageFormat.format(msg, args);
     }
     catch (Exception e)
     {
       fmsg = fResourceBundle.getString(FORMAT_FAILED);
       fmsg += " " + msg;
     }
   }
   else
     fmsg = msg;

   if (throwex)
   {
     throw new RuntimeException(fmsg);
   }

   return fmsg;
 }
 
Example 8
Source File: XPATHMessages.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement arguments,
 * localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey The message key to use.
 * @param args The arguments to be used as replacement text in the message
 * created.
 *
 * @return The formatted message string.
 */
public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
        String msgKey, Object args[]) //throws Exception
{

    String fmsg = null;
    boolean throwex = false;
    String msg = null;

    if (msgKey != null) {
        msg = fResourceBundle.getString(msgKey);
    }

    if (msg == null) {
        msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
        throwex = true;
    }

    if (args != null) {
        try {

            // Do this to keep format from crying.
            // This is better than making a bunch of conditional
            // code all over the place.
            int n = args.length;

            for (int i = 0; i < n; i++) {
                if (null == args[i]) {
                    args[i] = "";
                }
            }

            fmsg = java.text.MessageFormat.format(msg, args);
        } catch (Exception e) {
            fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
            fmsg += " " + msg;
        }
    } else {
        fmsg = msg;
    }

    if (throwex) {
        throw new RuntimeException(fmsg);
    }

    return fmsg;
}
 
Example 9
Source File: XMLMessages.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement
 * arguments, localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey  The message key to use.
 * @param args      The arguments to be used as replacement text
 *                  in the message created.
 *
 * @return The formatted message string.
 */
public static final String createMsg(ListResourceBundle fResourceBundle,
      String msgKey, Object args[])  //throws Exception
{

  String fmsg = null;
  boolean throwex = false;
  String msg = null;

  if (msgKey != null)
    msg = fResourceBundle.getString(msgKey);

  if (msg == null)
  {
    msg = fResourceBundle.getString(BAD_CODE);
    throwex = true;
  }

  if (args != null)
  {
    try
    {

      // Do this to keep format from crying.
      // This is better than making a bunch of conditional
      // code all over the place.
      int n = args.length;

      for (int i = 0; i < n; i++)
      {
        if (null == args[i])
          args[i] = "";
      }

      fmsg = java.text.MessageFormat.format(msg, args);
    }
    catch (Exception e)
    {
      fmsg = fResourceBundle.getString(FORMAT_FAILED);
      fmsg += " " + msg;
    }
  }
  else
    fmsg = msg;

  if (throwex)
  {
    throw new RuntimeException(fmsg);
  }

  return fmsg;
}
 
Example 10
Source File: XPATHMessages.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement arguments,
 * localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey The message key to use.
 * @param args The arguments to be used as replacement text in the message
 * created.
 *
 * @return The formatted message string.
 */
public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
        String msgKey, Object args[]) //throws Exception
{

    String fmsg = null;
    boolean throwex = false;
    String msg = null;

    if (msgKey != null) {
        msg = fResourceBundle.getString(msgKey);
    }

    if (msg == null) {
        msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
        throwex = true;
    }

    if (args != null) {
        try {

            // Do this to keep format from crying.
            // This is better than making a bunch of conditional
            // code all over the place.
            int n = args.length;

            for (int i = 0; i < n; i++) {
                if (null == args[i]) {
                    args[i] = "";
                }
            }

            fmsg = java.text.MessageFormat.format(msg, args);
        } catch (Exception e) {
            fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
            fmsg += " " + msg;
        }
    } else {
        fmsg = msg;
    }

    if (throwex) {
        throw new RuntimeException(fmsg);
    }

    return fmsg;
}
 
Example 11
Source File: XMLMessages.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement
 * arguments, localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey  The message key to use.
 * @param args      The arguments to be used as replacement text
 *                  in the message created.
 *
 * @return The formatted message string.
 */
public static final String createMsg(ListResourceBundle fResourceBundle,
      String msgKey, Object args[])  //throws Exception
{

  String fmsg = null;
  boolean throwex = false;
  String msg = null;

  if (msgKey != null)
    msg = fResourceBundle.getString(msgKey);

  if (msg == null)
  {
    msg = fResourceBundle.getString(BAD_CODE);
    throwex = true;
  }

  if (args != null)
  {
    try
    {

      // Do this to keep format from crying.
      // This is better than making a bunch of conditional
      // code all over the place.
      int n = args.length;

      for (int i = 0; i < n; i++)
      {
        if (null == args[i])
          args[i] = "";
      }

      fmsg = java.text.MessageFormat.format(msg, args);
    }
    catch (Exception e)
    {
      fmsg = fResourceBundle.getString(FORMAT_FAILED);
      fmsg += " " + msg;
    }
  }
  else
    fmsg = msg;

  if (throwex)
  {
    throw new RuntimeException(fmsg);
  }

  return fmsg;
}
 
Example 12
Source File: XPATHMessages.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement arguments,
 * localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey The message key to use.
 * @param args The arguments to be used as replacement text in the message
 * created.
 *
 * @return The formatted message string.
 */
public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
        String msgKey, Object args[]) //throws Exception
{

    String fmsg = null;
    boolean throwex = false;
    String msg = null;

    if (msgKey != null) {
        msg = fResourceBundle.getString(msgKey);
    }

    if (msg == null) {
        msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
        throwex = true;
    }

    if (args != null) {
        try {

            // Do this to keep format from crying.
            // This is better than making a bunch of conditional
            // code all over the place.
            int n = args.length;

            for (int i = 0; i < n; i++) {
                if (null == args[i]) {
                    args[i] = "";
                }
            }

            fmsg = java.text.MessageFormat.format(msg, args);
        } catch (Exception e) {
            fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
            fmsg += " " + msg;
        }
    } else {
        fmsg = msg;
    }

    if (throwex) {
        throw new RuntimeException(fmsg);
    }

    return fmsg;
}
 
Example 13
Source File: XMLMessages.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement
 * arguments, localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey  The message key to use.
 * @param args      The arguments to be used as replacement text
 *                  in the message created.
 *
 * @return The formatted message string.
 */
public static final String createMsg(ListResourceBundle fResourceBundle,
      String msgKey, Object args[])  //throws Exception
{

  String fmsg = null;
  boolean throwex = false;
  String msg = null;

  if (msgKey != null)
    msg = fResourceBundle.getString(msgKey);

  if (msg == null)
  {
    msg = fResourceBundle.getString(BAD_CODE);
    throwex = true;
  }

  if (args != null)
  {
    try
    {

      // Do this to keep format from crying.
      // This is better than making a bunch of conditional
      // code all over the place.
      int n = args.length;

      for (int i = 0; i < n; i++)
      {
        if (null == args[i])
          args[i] = "";
      }

      fmsg = java.text.MessageFormat.format(msg, args);
    }
    catch (Exception e)
    {
      fmsg = fResourceBundle.getString(FORMAT_FAILED);
      fmsg += " " + msg;
    }
  }
  else
    fmsg = msg;

  if (throwex)
  {
    throw new RuntimeException(fmsg);
  }

  return fmsg;
}
 
Example 14
Source File: XPATHMessages.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement
 * arguments, localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey  The message key to use.
 * @param args      The arguments to be used as replacement text
 *                  in the message created.
 *
 * @return The formatted message string.
 */
public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
                                          String msgKey, Object args[])  //throws Exception
{

  String fmsg = null;
  boolean throwex = false;
  String msg = null;

  if (msgKey != null)
    msg = fResourceBundle.getString(msgKey); 

  if (msg == null)
  {
    msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
    throwex = true;
  }

  if (args != null)
  {
    try
    {

      // Do this to keep format from crying.
      // This is better than making a bunch of conditional
      // code all over the place.
      int n = args.length;

      for (int i = 0; i < n; i++)
      {
        if (null == args[i])
          args[i] = "";
      }

      fmsg = java.text.MessageFormat.format(msg, args);
    }
    catch (Exception e)
    {
      fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
      fmsg += " " + msg;
    }
  }
  else
    fmsg = msg;

  if (throwex)
  {
    throw new RuntimeException(fmsg);
  }

  return fmsg;
}
 
Example 15
Source File: XMLMessages.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement
 * arguments, localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey  The message key to use.
 * @param args      The arguments to be used as replacement text
 *                  in the message created.
 *
 * @return The formatted message string.
 */
public static final String createMsg(ListResourceBundle fResourceBundle,
      String msgKey, Object args[])  //throws Exception
{

  String fmsg = null;
  boolean throwex = false;
  String msg = null;

  if (msgKey != null)
    msg = fResourceBundle.getString(msgKey);

  if (msg == null)
  {
    msg = fResourceBundle.getString(BAD_CODE);
    throwex = true;
  }

  if (args != null)
  {
    try
    {

      // Do this to keep format from crying.
      // This is better than making a bunch of conditional
      // code all over the place.
      int n = args.length;

      for (int i = 0; i < n; i++)
      {
        if (null == args[i])
          args[i] = "";
      }

      fmsg = java.text.MessageFormat.format(msg, args);
    }
    catch (Exception e)
    {
      fmsg = fResourceBundle.getString(FORMAT_FAILED);
      fmsg += " " + msg;
    }
  }
  else
    fmsg = msg;

  if (throwex)
  {
    throw new RuntimeException(fmsg);
  }

  return fmsg;
}
 
Example 16
Source File: XPATHMessages.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement arguments,
 * localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey The message key to use.
 * @param args The arguments to be used as replacement text in the message
 * created.
 *
 * @return The formatted message string.
 */
public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
        String msgKey, Object args[]) //throws Exception
{

    String fmsg = null;
    boolean throwex = false;
    String msg = null;

    if (msgKey != null) {
        msg = fResourceBundle.getString(msgKey);
    }

    if (msg == null) {
        msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
        throwex = true;
    }

    if (args != null) {
        try {

            // Do this to keep format from crying.
            // This is better than making a bunch of conditional
            // code all over the place.
            int n = args.length;

            for (int i = 0; i < n; i++) {
                if (null == args[i]) {
                    args[i] = "";
                }
            }

            fmsg = java.text.MessageFormat.format(msg, args);
        } catch (Exception e) {
            fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
            fmsg += " " + msg;
        }
    } else {
        fmsg = msg;
    }

    if (throwex) {
        throw new RuntimeException(fmsg);
    }

    return fmsg;
}
 
Example 17
Source File: XMLMessages.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement
 * arguments, localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey  The message key to use.
 * @param args      The arguments to be used as replacement text
 *                  in the message created.
 *
 * @return The formatted message string.
 */
public static final String createMsg(ListResourceBundle fResourceBundle,
      String msgKey, Object args[])  //throws Exception
{

  String fmsg = null;
  boolean throwex = false;
  String msg = null;

  if (msgKey != null)
    msg = fResourceBundle.getString(msgKey);

  if (msg == null)
  {
    msg = fResourceBundle.getString(BAD_CODE);
    throwex = true;
  }

  if (args != null)
  {
    try
    {

      // Do this to keep format from crying.
      // This is better than making a bunch of conditional
      // code all over the place.
      int n = args.length;

      for (int i = 0; i < n; i++)
      {
        if (null == args[i])
          args[i] = "";
      }

      fmsg = java.text.MessageFormat.format(msg, args);
    }
    catch (Exception e)
    {
      fmsg = fResourceBundle.getString(FORMAT_FAILED);
      fmsg += " " + msg;
    }
  }
  else
    fmsg = msg;

  if (throwex)
  {
    throw new RuntimeException(fmsg);
  }

  return fmsg;
}
 
Example 18
Source File: XPATHMessages.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement arguments,
 * localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey The message key to use.
 * @param args The arguments to be used as replacement text in the message
 * created.
 *
 * @return The formatted message string.
 */
public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
        String msgKey, Object args[]) //throws Exception
{

    String fmsg = null;
    boolean throwex = false;
    String msg = null;

    if (msgKey != null) {
        msg = fResourceBundle.getString(msgKey);
    }

    if (msg == null) {
        msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
        throwex = true;
    }

    if (args != null) {
        try {

            // Do this to keep format from crying.
            // This is better than making a bunch of conditional
            // code all over the place.
            int n = args.length;

            for (int i = 0; i < n; i++) {
                if (null == args[i]) {
                    args[i] = "";
                }
            }

            fmsg = java.text.MessageFormat.format(msg, args);
        } catch (Exception e) {
            fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
            fmsg += " " + msg;
        }
    } else {
        fmsg = msg;
    }

    if (throwex) {
        throw new RuntimeException(fmsg);
    }

    return fmsg;
}
 
Example 19
Source File: XMLMessages.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement
 * arguments, localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey  The message key to use.
 * @param args      The arguments to be used as replacement text
 *                  in the message created.
 *
 * @return The formatted message string.
 */
public static final String createMsg(ListResourceBundle fResourceBundle,
      String msgKey, Object args[])  //throws Exception
{

  String fmsg = null;
  boolean throwex = false;
  String msg = null;

  if (msgKey != null)
    msg = fResourceBundle.getString(msgKey);

  if (msg == null)
  {
    msg = fResourceBundle.getString(BAD_CODE);
    throwex = true;
  }

  if (args != null)
  {
    try
    {

      // Do this to keep format from crying.
      // This is better than making a bunch of conditional
      // code all over the place.
      int n = args.length;

      for (int i = 0; i < n; i++)
      {
        if (null == args[i])
          args[i] = "";
      }

      fmsg = java.text.MessageFormat.format(msg, args);
    }
    catch (Exception e)
    {
      fmsg = fResourceBundle.getString(FORMAT_FAILED);
      fmsg += " " + msg;
    }
  }
  else
    fmsg = msg;

  if (throwex)
  {
    throw new RuntimeException(fmsg);
  }

  return fmsg;
}
 
Example 20
Source File: XPATHMessages.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a message from the specified key and replacement arguments,
 * localized to the given locale.
 *
 * @param fResourceBundle The resource bundle to use.
 * @param msgKey The message key to use.
 * @param args The arguments to be used as replacement text in the message
 * created.
 *
 * @return The formatted message string.
 */
public static final String createXPATHMsg(ListResourceBundle fResourceBundle,
        String msgKey, Object args[]) //throws Exception
{

    String fmsg = null;
    boolean throwex = false;
    String msg = null;

    if (msgKey != null) {
        msg = fResourceBundle.getString(msgKey);
    }

    if (msg == null) {
        msg = fResourceBundle.getString(XPATHErrorResources.BAD_CODE);
        throwex = true;
    }

    if (args != null) {
        try {

            // Do this to keep format from crying.
            // This is better than making a bunch of conditional
            // code all over the place.
            int n = args.length;

            for (int i = 0; i < n; i++) {
                if (null == args[i]) {
                    args[i] = "";
                }
            }

            fmsg = java.text.MessageFormat.format(msg, args);
        } catch (Exception e) {
            fmsg = fResourceBundle.getString(XPATHErrorResources.FORMAT_FAILED);
            fmsg += " " + msg;
        }
    } else {
        fmsg = msg;
    }

    if (throwex) {
        throw new RuntimeException(fmsg);
    }

    return fmsg;
}