/** * 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; }
/* * 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); }