Ejemplo n.º 1
0
        public static string get(string key, params object[] args)
        {
            string template = null;

            try
            {
                template = RESOURCE_BUNDLE.getString(key);
            }
            catch (MissingResourceException)
            {
                StringBuilder b = new StringBuilder();
                try
                {
                    b.Append(RESOURCE_BUNDLE.getString("message.unknown"));
                    b.Append(": ");
                }
                catch (MissingResourceException)
                {
                }
                b.Append(key);
                if (args != null && args.Length > 0)
                {
                    b.Append("(");
                    b.Append(args[0]);
                    for (int i = 1; i < args.Length; i++)
                    {
                        b.Append(", ");
                        b.Append(args[i]);
                    }
                    b.Append(")");
                }
                return(b.ToString());
            }
            return(MessageFormat.format(template, args));
        }
Ejemplo n.º 2
0
        /*
         * Formats a {@code LogRecord} object into a localized string
         * representation. This is a convenience method for subclasses of {@code
         * Formatter}.
         * <p>
         * The message string is firstly localized using the {@code ResourceBundle}
         * object associated with the supplied {@code LogRecord}.
         * <p>
         * Notice : if message contains "{0", then java.text.MessageFormat is used.
         * Otherwise no formatting is performed.
         *
         * @param r
         *            the log record to be formatted.
         * @return the string resulted from the formatting.
         */
        public String formatMessage(LogRecord r)
        {
            String         pattern = r.getMessage();
            ResourceBundle rb      = null;

            // try to localize the message string first
            if (null != (rb = r.getResourceBundle()))
            {
                try {
                    pattern = rb.getString(pattern);
                } catch (Exception e) {
                    pattern = r.getMessage();
                }
            }
            if (null != pattern)
            {
                Object[] paramsJ = r.getParameters();

                /*
                 * if the message contains "{0", use java.text.MessageFormat to
                 * format the string
                 */
                if (pattern.indexOf("{0") >= 0 && null != paramsJ && //$NON-NLS-1$
                    paramsJ.Length > 0)
                {
                    try {
                        pattern = java.text.MessageFormat.format(pattern, paramsJ);
                    } catch (java.lang.IllegalArgumentException e) {
                        pattern = r.getMessage();
                    }
                }
            }
            return(pattern);
        }
Ejemplo n.º 3
0
 /**
  * @param key
  * @return
  */
 public static string getString(string key)
 {
     // TODO Auto-generated method stub
     try {
         return(RESOURCE_BUNDLE.getString(key));
     } catch (MissingResourceException e) {
         return('!' + key + '!');
     }
 }
Ejemplo n.º 4
0
 public static String GetString(CultureInfo culture, String name, Object[] args)
 {
     try
     {
         String str = _resource.getString(name);
         if (args != null && (int)args.Length > 0)
         {
             return(String.Format(str, args));
         }
         else
         {
             return(str);
         }
     }
     catch (MissingResourceException)
     {
         return(null);
     }
 }
Ejemplo n.º 5
0
        /**
         * Gets the localized name of this level. The default locale is used. If no
         * resource bundle is associated with this level then the original level
         * name is returned.
         *
         * @return the localized name of this level.
         */
        public String getLocalizedName()
        {
            if (rb == null)
            {
                return(name);
            }

            try {
                return(rb.getString(name));
            } catch (MissingResourceException) {
                return(name);
            }
        }
Ejemplo n.º 6
0
        /*
         * Helper method to do the actual work of fetching resources; allows
         * getResString(S,S) to be deprecated without affecting getResString(S);
         */
        private static String getResStringDefault(String key, String defaultValue, Locale forcedLocale)
        {
            if (key == null)
            {
                return(null);
            }
            // Resource keys cannot contain spaces, and are forced to lower case
            String resKey = key.Replace(' ', '_'); // $NON-NLS-1$ // $NON-NLS-2$

            resKey = resKey.ToLower();
            String resString = null;

            try {
                ResourceBundle bundle = resources;
                if (forcedLocale != null)
                {
                    bundle = ResourceBundle.getBundle("org.apache.jmeter.resources.messages", forcedLocale); // $NON-NLS-1$
                }
                if (bundle.containsKey(resKey))
                {
                    resString = bundle.getString(resKey);
                }
                else
                {
                    //log.warn("ERROR! Resource string not found: [" + resKey + "]");
                    resString = defaultValue;
                }
                if (ignoreResorces)   // Special mode for debugging resource handling
                {
                    return("[" + key + "]");
                }
            }
            catch (MissingResourceException mre)
            {
                if (ignoreResorces)   // Special mode for debugging resource handling
                {
                    return("[?" + key + "?]");
                }
                //log.warn("ERROR! Resource string not found: [" + resKey + "]", mre);
                resString = defaultValue;
            }
            return(resString);
        }