/** * <p> * Format a message, merging it with its parameters, before returning. * </p> * <p> * This is meant to be overridden by subclasses if necessary. The default mechanism will simply * use a standard {@link java.text.MessageFormat} instance. * </p> * * @param locale the locale * @param message the resolved message * @param messageParameters the message parameters (might be null) * @return the formatted message */ protected String formatMessage( final Locale locale, final String message, final Object[] messageParameters) { return StandardMessageResolutionUtils.formatMessage(locale, message, messageParameters); }
static String formatMessage(final Locale locale, final String message, final Object[] messageParameters) { if (message == null) { return null; } if (!isFormatCandidate(message)) { // trying to avoid creating MessageFormat if not needed return message; } final MessageFormat messageFormat = new MessageFormat(message, locale); return messageFormat.format((messageParameters != null? messageParameters : EMPTY_MESSAGE_PARAMETERS)); }
/** * <p> * Resolve messages for a specific origin and locale. * </p> * <p> * This is meant to be overridden by subclasses if necessary, so that the way in which messages * are obtained for a specific origin can be modified without changing the rest of the * message resolution mechanisms. * </p> * <p> * The standard mechanism will look for files in the classpath (only classpath), * at the same package and with the same name as the origin class, with {@code .properties} * extension. * </p> * * @param origin the origin * @param locale the locale * @return a Map containing all the possible messages for the specified origin and locale. Can return null. */ protected Map<String,String> resolveMessagesForOrigin(final Class<?> origin, final Locale locale) { return StandardMessageResolutionUtils.resolveMessagesForOrigin(origin, locale); }
final List<String> messageResourceNames = computeMessageResourceNamesFromBase(resourceBaseName, locale); final Properties messageProperties = readMessagesResource(messageResourceReader); if (messageProperties != null && !messageProperties.isEmpty()) {
/** * <p> * Resolve messages for a specific template and locale. * </p> * <p> * This is meant to be overridden by subclasses if necessary, so that the way in which messages * are obtained for a specific template can be modified without changing the rest of the * message resolution mechanisms. * </p> * <p> * The standard mechanism will look for {@code .properties} files at the same location as * the template (using the same resource resolution mechanism), and with the same name base. * </p> * * @param template the template * @param templateResource the template resource * @param locale the locale * @return a Map containing all the possible messages for the specified template and locale. Can return null. */ protected Map<String,String> resolveMessagesForTemplate( final String template, final ITemplateResource templateResource, final Locale locale) { return StandardMessageResolutionUtils.resolveMessagesForTemplate(templateResource, locale); }
static Map<String,String> resolveMessagesForOrigin(final Class<?> origin, final Locale locale) { final Map<String,String> combinedMessages = new HashMap<String, String>(20); Class<?> currentClass = origin; combinedMessages.putAll(resolveMessagesForSpecificClass(currentClass, locale)); while (!currentClass.getSuperclass().equals(Object.class)) { currentClass = currentClass.getSuperclass(); final Map<String,String> messagesForCurrentClass = resolveMessagesForSpecificClass(currentClass, locale); for (final String messageKey : messagesForCurrentClass.keySet()) { if (!combinedMessages.containsKey(messageKey)) { combinedMessages.put(messageKey, messagesForCurrentClass.get(messageKey)); } } } return Collections.unmodifiableMap(combinedMessages); }
final List<String> messageResourceNames = computeMessageResourceNamesFromBase(resourceBaseName, locale); if (messageResourceReader != null) { final Properties messageProperties = readMessagesResource(messageResourceReader); if (messageProperties != null && !messageProperties.isEmpty()) {