/** * <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); }
/** * <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); }
/** * <p> * Constructor for {@code TemplateEngine} objects. * </p> * <p> * This is the only way to create a {@code TemplateEngine} instance (which * should be configured after creation). * </p> */ public TemplateEngine() { super(); setCacheManager(new StandardCacheManager()); setEngineContextFactory(new StandardEngineContextFactory()); setMessageResolver(new StandardMessageResolver()); setLinkBuilder(new StandardLinkBuilder()); setDecoupledTemplateLogicResolver(new StandardDecoupledTemplateLogicResolver()); setDialect(new StandardDialect()); }
messagesForLocaleForTemplate = resolveMessagesForTemplate(template, templateResource, locale); if (messagesForLocaleForTemplate == null) { messagesForLocaleForTemplate = Collections.emptyMap(); messagesForLocaleForTemplate = resolveMessagesForTemplate(template, templateResource, locale); if (messagesForLocaleForTemplate == null) { messagesForLocaleForTemplate = Collections.emptyMap(); return formatMessage(locale, message, messageParameters); messagesForLocaleForOrigin = resolveMessagesForOrigin(origin, locale); if (messagesForLocaleForOrigin == null) { messagesForLocaleForOrigin = Collections.emptyMap(); return formatMessage(locale, message, messageParameters); return formatMessage(locale, message, messageParameters);
public MessageResolution resolveMessage( final Arguments arguments, final String key, final Object[] messageParameters) { // This method can be overriden checkInitialized(); final String message = StandardMessageResolutionUtils.resolveMessageForTemplate( arguments, key, messageParameters, unsafeGetDefaultMessages()); if (message == null) { return null; } return new MessageResolution(message); }
public String createAbsentMessageRepresentation( final ITemplateContext context, final Class<?> origin, final String key, final Object[] messageParameters) { return this.standardMessageResolver.createAbsentMessageRepresentation(context, origin, key, messageParameters); }
public final String getMessage( final Class<?> origin, final String key, final Object[] messageParameters, final boolean useAbsentMessageRepresentation) { // origin CAN be null Validate.notNull(key, "Message key cannot be null"); // messageParameter CAN be null final Set<IMessageResolver> messageResolvers = this.configuration.getMessageResolvers(); // Try to resolve the message for (final IMessageResolver messageResolver : messageResolvers) { final String resolvedMessage = messageResolver.resolveMessage(this, origin, key, messageParameters); if (resolvedMessage != null) { return resolvedMessage; } } // Message unresolved: try to create an "absent message representation" (if specified to do so) if (useAbsentMessageRepresentation) { for (final IMessageResolver messageResolver : messageResolvers) { final String absentMessageRepresentation = messageResolver.createAbsentMessageRepresentation(this, origin, key, messageParameters); if (absentMessageRepresentation != null) { return absentMessageRepresentation; } } } return null; }
final List<String> messageResourceNames = computeMessageResourceNamesFromBase(resourceBaseName, locale); final Properties messageProperties = readMessagesResource(messageResourceReader); if (messageProperties != null && !messageProperties.isEmpty()) {
/** * <p> * Sets a new order for the message resolver. * </p> * * @param order the new order */ public void setOrder(final Integer order) { checkNotInitialized(); this.order = order; }
/** * <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 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)); }
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); }
public SpringMessageResolver() { super(); this.standardMessageResolver = new StandardMessageResolver(); }
public String createAbsentMessageRepresentation( final ITemplateContext context, final Class<?> origin, final String key, final Object[] messageParameters) { return this.standardMessageResolver.createAbsentMessageRepresentation(context, origin, key, messageParameters); }
final List<String> messageResourceNames = computeMessageResourceNamesFromBase(resourceBaseName, locale); if (messageResourceReader != null) { final Properties messageProperties = readMessagesResource(messageResourceReader); if (messageProperties != null && !messageProperties.isEmpty()) {
/** * <p> * Sets a name for this message resolver. * </p> * * @param name the new name */ public void setName(final String name) { checkNotInitialized(); this.name = name; }
public SpringMessageResolver() { super(); this.standardMessageResolver = new StandardMessageResolver(); }
public SpringMessageResolver() { super(); this.standardMessageResolver = new StandardMessageResolver(); }