[Fix] I18nMessage.handle missing property and empty value in I18nMessage
This commit is contained in:
parent
332724439d
commit
278f59c11a
|
@ -2,14 +2,19 @@ package li.strolch.utils;
|
||||||
|
|
||||||
import static li.strolch.utils.helper.StringHelper.EMPTY;
|
import static li.strolch.utils.helper.StringHelper.EMPTY;
|
||||||
|
|
||||||
|
import java.util.MissingResourceException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
import li.strolch.utils.dbc.DBC;
|
import li.strolch.utils.dbc.DBC;
|
||||||
import li.strolch.utils.helper.StringHelper;
|
import li.strolch.utils.helper.StringHelper;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class I18nMessage {
|
public class I18nMessage {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(I18nMessage.class);
|
||||||
|
|
||||||
private ResourceBundle bundle;
|
private ResourceBundle bundle;
|
||||||
private String key;
|
private String key;
|
||||||
private Properties values;
|
private Properties values;
|
||||||
|
@ -32,14 +37,18 @@ public class I18nMessage {
|
||||||
|
|
||||||
public I18nMessage value(String key, String value) {
|
public I18nMessage value(String key, String value) {
|
||||||
DBC.INTERIM.assertNotEmpty("key must be set!", key);
|
DBC.INTERIM.assertNotEmpty("key must be set!", key);
|
||||||
DBC.INTERIM.assertNotEmpty("value must be set!", value);
|
this.values.setProperty(key, value == null ? "-" : value);
|
||||||
this.values.setProperty(key, value);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String formatMessage() {
|
public String formatMessage() {
|
||||||
|
try {
|
||||||
String string = this.bundle.getString(this.key);
|
String string = this.bundle.getString(this.key);
|
||||||
return StringHelper.replacePropertiesIn(this.values, EMPTY, string);
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue