io.spotnext.spring.web.message.NestedReloadingMessageSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spot-spring-web-support Show documentation
Show all versions of spot-spring-web-support Show documentation
The spOt microservice framework.
package io.spotnext.spring.web.message;
import java.util.Locale;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
/**
* NestedReloadingMessageSource class.
*
* @author mojo2012
* @version 1.0
* @since 1.0
*/
public class NestedReloadingMessageSource extends ReloadableResourceBundleMessageSource {
protected boolean ignoreMissingMessageCode = false;
@Override
protected String getMessageInternal(final String code, final Object[] args, final Locale locale) {
String message = null;
try {
message = super.getMessageInternal(code, args, locale);
} catch (final NoSuchMessageException e) {
// catch exceptions from the parent message source and ignore it
}
if (ignoreMissingMessageCode && StringUtils.isBlank(message)) {
message = String.format("#%s", code);
}
return message;
}
// @Override
// public final String getMessage(final MessageSourceResolvable resolvable,
// final Locale locale) {
// String message = null;
//
// for (final String code : resolvable.getCodes()) {
// message = getMessageInternal(code, resolvable.getArguments(), locale);
// }
//
// return message
// }
/**
* If no message is found and this is set to true, then the key will be
* returned as message. Otherwise a {@link org.springframework.context.NoSuchMessageException} is
* thrown.
*
* @param ignoreMissingMessageCode a boolean.
*/
public void setIgnoreMissingMessageCode(final boolean ignoreMissingMessageCode) {
this.ignoreMissingMessageCode = ignoreMissingMessageCode;
}
}