/** * Create an ExtendedMessageFormat for the specified pattern and locale and check the * formated output matches the expected result for the parameters. * @param pattern string * @param registryUnused map (currently unused) * @param args Object[] * @param locale Locale */ private void checkBuiltInFormat(final String pattern, final Map<String, ?> registryUnused, final Object[] args, final Locale locale) { final StringBuilder buffer = new StringBuilder(); buffer.append("Pattern=["); buffer.append(pattern); buffer.append("], locale=["); buffer.append(locale); buffer.append("]"); final MessageFormat mf = createMessageFormat(pattern, locale); ExtendedMessageFormat emf = null; if (locale == null) { emf = new ExtendedMessageFormat(pattern); } else { emf = new ExtendedMessageFormat(pattern, locale); } assertEquals("format " + buffer.toString(), mf.format(args), emf.format(args)); assertEquals("toPattern " + buffer.toString(), mf.toPattern(), emf.toPattern()); }
final String expectedPattern = extendedPattern + builtins.toPattern(); DateFormat df = null; NumberFormat nf = null;
String suffix = key.substring(index + ARGUMENT_COUNT_PREFIX.length()); argumentCount = Integer.parseInt(suffix); resources.put(key, message.toPattern()); } catch (NumberFormatException exception) { warning(file, key, "Bad number in resource key", exception);
/** * Create an ExtendedMessageFormat for the specified pattern and locale and check the * formated output matches the expected result for the parameters. * @param pattern string * @param registryUnused map (currently unused) * @param args Object[] * @param locale Locale */ private void checkBuiltInFormat(final String pattern, final Map<String, ?> registryUnused, final Object[] args, final Locale locale) { final StringBuilder buffer = new StringBuilder(); buffer.append("Pattern=["); buffer.append(pattern); buffer.append("], locale=["); buffer.append(locale); buffer.append("]"); final MessageFormat mf = createMessageFormat(pattern, locale); // System.out.println(buffer + ", result=[" + mf.format(args) +"]"); ExtendedMessageFormat emf = null; if (locale == null) { emf = new ExtendedMessageFormat(pattern); } else { emf = new ExtendedMessageFormat(pattern, locale); } assertEquals(mf.format(args), emf.format(args), "format " + buffer.toString()); assertEquals(mf.toPattern(), emf.toPattern(), "toPattern " + buffer.toString()); }
final String expectedPattern = extendedPattern + builtins.toPattern(); DateFormat df = null; NumberFormat nf = null;
/** * Returns a pattern representing the current state of the message format. * The string is constructed from internal information and therefore * does not necessarily equal the previously applied pattern. * * @return a pattern representing the current state of the message format * @stable ICU 3.0 */ public String toPattern() { String pattern = savedPattern == null ? messageFormat.toPattern() : savedPattern; return pattern; }
/** * Returns a pattern representing the current state of the message format. * The string is constructed from internal information and therefore * does not necessarily equal the previously applied pattern. * * @return a pattern representing the current state of the message format * @stable ICU 3.0 */ public String toPattern() { String pattern = savedPattern == null ? messageFormat.toPattern() : savedPattern; return pattern; }
@Override public String toString() { return getClass().getSimpleName() + "{" + messageFormat.toPattern() + "}"; } }
@Override public String toString() { return getClass().getSimpleName() + "{" + messageFormat.toPattern() + "}"; } }
@Override @GwtIncompatible("java.text.MessageFormat.toPattern()") public String toString() { return key + ": " + format.toPattern(); } }
@Override @GwtIncompatible("java.text.MessageFormat.toPattern()") public String toString() { return key + ": " + format.toPattern(); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("["); // NOI18N sb.append("background="); // NOI18N sb.append(background); sb.append(", foreground="); // NOI18N sb.append(foreground); sb.append(", format="); // NOI18N sb.append(format != null ? format.toPattern() : null); sb.append(", tooltip="); // NOI18N sb.append(tooltip); sb.append("]"); // NOI18N return sb.toString(); } @Override
/** * @see org.displaytag.decorator.DisplaytagColumnDecorator#decorate(Object, PageContext, MediaTypeEnum) */ public Object decorate(Object columnValue, PageContext pageContext, MediaTypeEnum media) { try { return this.format.format(new Object[]{columnValue}); } catch (IllegalArgumentException e) { log.error(Messages.getString("MessageFormatColumnDecorator.invalidArgument", new Object[]{ //$NON-NLS-1$ this.format.toPattern(), columnValue != null ? columnValue.getClass().getName() : "null"})); //$NON-NLS-1$ return columnValue; } } }
/** * @see org.displaytag.decorator.DisplaytagColumnDecorator#decorate(Object, PageContext, MediaTypeEnum) */ @Override public Object decorate(Object columnValue, PageContext pageContext, MediaTypeEnum media) { try { return this.format.format(new Object[]{columnValue}); } catch (IllegalArgumentException e) { log.error(Messages.getString("MessageFormatColumnDecorator.invalidArgument", new Object[]{ //$NON-NLS-1$ this.format.toPattern(), columnValue != null ? columnValue.getClass().getName() : "null"})); //$NON-NLS-1$ return columnValue; } }
public class GracefulMessageSource extends org.springframework.context.support.ReloadableResourceBundleMessageSource { final static private Locale defaultLocale = Locale.ENGLISH; @Override protected MessageFormat resolveCode(final String code, final Locale locale) { MessageFormat result = superResolveCode(code, locale); if (result.toPattern().isEmpty() && !locale.equals(this.defaultLocale)) { result = superResolveCode(code, this.defaultLocale); } return result; } @Override protected String resolveCodeWithoutArguments(final String code, final Locale locale) { String result = superResolveCodeWithoutArguments(code, locale); if (result.isEmpty() && !locale.equals(this.defaultLocale)) { result = superResolveCodeWithoutArguments(code, this.defaultLocale); } return result; } protected MessageFormat superResolveCode(final String code, final Locale locale) { return super.resolveCode(code, locale); } protected String superResolveCodeWithoutArguments(final String code, final Locale locale) { return super.resolveCodeWithoutArguments(code, locale); } }
iterator.remove(); log.warn("Removed value mapping as it didn't have one format: {} -> {}", entry.getKey(), entry.getValue().toPattern());
private void wrapNestedFormatters(java.text.MessageFormat mfmt) { // Update nested formatters created by Java MessageFormat // with ICU versions, so FieldPosition / AttributedText will // use ICU formatter's definition, such as com.ibm.icu.text.NumberFormat.INTEGER_FIELD // Replacing nested formatter may change the pattern string // originally used. For example, "{0,integer} files" is replaced // with "{0} files". We preserve the original pattern. savedPattern = mfmt.toPattern(); Format[] subfmts = mfmt.getFormats(); for (int i = 0; i < subfmts.length; i++) { if (subfmts[i] instanceof java.text.DateFormat) { subfmts[i] = new DateFormat((java.text.DateFormat)subfmts[i]); } else if (subfmts[i] instanceof java.text.NumberFormat) { subfmts[i] = new NumberFormat((java.text.NumberFormat)subfmts[i]); } } mfmt.setFormats(subfmts); }
private void wrapNestedFormatters(java.text.MessageFormat mfmt) { // Update nested formatters created by Java MessageFormat // with ICU versions, so FieldPosition / AttributedText will // use ICU formatter's definition, such as com.ibm.icu.text.NumberFormat.INTEGER_FIELD // Replacing nested formatter may change the pattern string // originally used. For example, "{0,integer} files" is replaced // with "{0} files". We preserve the original pattern. savedPattern = mfmt.toPattern(); Format[] subfmts = mfmt.getFormats(); for (int i = 0; i < subfmts.length; i++) { if (subfmts[i] instanceof java.text.DateFormat) { subfmts[i] = new DateFormat((java.text.DateFormat)subfmts[i]); } else if (subfmts[i] instanceof java.text.NumberFormat) { subfmts[i] = new NumberFormat((java.text.NumberFormat)subfmts[i]); } } mfmt.setFormats(subfmts); }