[Fix] I18nMessage.handle missing property and empty value in I18nMessage

This commit is contained in:
Robert von Burg 2017-11-21 18:03:57 +01:00
parent 332724439d
commit 278f59c11a
1 changed files with 13 additions and 4 deletions

View File

@ -2,14 +2,19 @@ package li.strolch.utils;
import static li.strolch.utils.helper.StringHelper.EMPTY;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import li.strolch.utils.dbc.DBC;
import li.strolch.utils.helper.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class I18nMessage {
private static final Logger logger = LoggerFactory.getLogger(I18nMessage.class);
private ResourceBundle bundle;
private String key;
private Properties values;
@ -32,14 +37,18 @@ public class I18nMessage {
public I18nMessage value(String key, String value) {
DBC.INTERIM.assertNotEmpty("key must be set!", key);
DBC.INTERIM.assertNotEmpty("value must be set!", value);
this.values.setProperty(key, value);
this.values.setProperty(key, value == null ? "-" : value);
return this;
}
public String formatMessage() {
String string = this.bundle.getString(this.key);
return StringHelper.replacePropertiesIn(this.values, EMPTY, string);
try {
String string = this.bundle.getString(this.key);
return StringHelper.replacePropertiesIn(this.values, EMPTY, string);
} catch (MissingResourceException e) {
logger.error("Key " + this.key + " is missing in bundle " + this.bundle.getBaseBundleName());
return this.key;
}
}
@Override