Bug#3232 (Support res://[resourceBundleName]/[key] style of resources)

This commit is contained in:
Dmitry Abramov 2009-02-20 13:40:11 +00:00
parent 22a269dfa4
commit a7fc0a887a
2 changed files with 24 additions and 6 deletions

View File

@ -71,13 +71,33 @@ public abstract class ComponentLoader implements com.haulmont.cuba.gui.xml.layou
String caption = element.attributeValue("caption");
if (!StringUtils.isEmpty(caption)) {
if (caption.startsWith("res://") && resourceBundle != null) {
caption = resourceBundle.getString(caption.substring(6));
}
caption = loadResourceString(caption);
component.setCaption(caption);
}
}
protected String loadResourceString(String caption) {
if (caption.startsWith("res://")) {
String path = caption.substring(6);
final String[] strings = path.split("/");
if (strings.length == 1) {
if (resourceBundle != null) {
caption = resourceBundle.getString(strings[0]);
}
} else if (strings.length == 2) {
try {
final ResourceBundle bundle = ResourceBundle.getBundle(strings[0], getLocale());
bundle.getString(strings[1]);
} catch (Throwable e) {
// Do nothing
}
} else {
throw new UnsupportedOperationException();
}
}
return caption;
}
protected void loadAlign(Component component, Element element) {
final String align = element.attributeValue("align");
if (!StringUtils.isBlank(align)) {

View File

@ -28,9 +28,7 @@ public class LabelLoader extends ComponentLoader {
String caption = element.attributeValue("value");
if (!StringUtils.isEmpty(caption)) {
if (caption.startsWith("res://") && resourceBundle != null) {
caption = resourceBundle.getString(caption.substring(6));
}
caption = loadResourceString(caption);
component.setCaption(caption);
}