X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fresources%2FBundle.java;h=84efceafabfacac5d1edf887dc49f3542bd76725;hp=c757e2b1d705dc005b52ac425f7a9a89a14deabd;hb=6fdf8ca30c75521d7d5830ae86f2f25b0725c047;hpb=26a1f3fe044c616802367e8a0f2cd4f099413ceb diff --git a/src/be/nikiroo/utils/resources/Bundle.java b/src/be/nikiroo/utils/resources/Bundle.java index c757e2b..84efcea 100644 --- a/src/be/nikiroo/utils/resources/Bundle.java +++ b/src/be/nikiroo/utils/resources/Bundle.java @@ -133,8 +133,8 @@ public class Bundle> { * @param def * the default value when it is not present in the config file * - * @return the associated value, or NULL if not found (not present in the - * resource file) + * @return the associated value, or def if not found (not present + * in the resource file) */ public String getString(E id, String def) { return getString(id, def, -1); @@ -154,8 +154,9 @@ public class Bundle> { * the item number to get for an array of values, or -1 for * non-arrays * - * @return the associated value, or NULL if not found (not present in the - * resource file) + * @return the associated value, def if not found (not present in + * the resource file) or NULL if the item is specified (not -1) and + * does not exist */ public String getString(E id, String def, int item) { String rep = getString(id.name(), null); @@ -163,7 +164,7 @@ public class Bundle> { rep = getMetaDef(id.name()); } - if (rep == null || rep.isEmpty()) { + if (rep.isEmpty()) { return def; } @@ -273,8 +274,9 @@ public class Bundle> { * the item number to get for an array of values, or -1 for * non-arrays * - * @return the associated value, or NULL if not found (not present in the - * resource file) + * @return the associated value, def if not found (not present in + * the resource file), NULL if the item is specified (not -1) but + * does not exist and NULL if bad key */ public String getStringX(E id, String suffix, String def, int item) { String key = id.name() @@ -932,7 +934,7 @@ public class Bundle> { } /** - * The default {@link MetaInfo.def} value for the given enumeration name. + * The default {@link Meta#def()} value for the given enumeration name. * * @param id * the enumeration name (the "id") @@ -1209,22 +1211,18 @@ public class Bundle> { */ protected void resetMap(ResourceBundle bundle) { this.map.clear(); - for (Field field : type.getDeclaredFields()) { - try { - Meta meta = field.getAnnotation(Meta.class); - if (meta != null) { - E id = Enum.valueOf(type, field.getName()); - - String value; - if (bundle != null) { - value = bundle.getString(id.name()); - } else { - value = null; + if (bundle != null) { + for (Field field : type.getDeclaredFields()) { + try { + Meta meta = field.getAnnotation(Meta.class); + if (meta != null) { + E id = Enum.valueOf(type, field.getName()); + String value = bundle.getString(id.name()); + this.map.put(id.name(), + value == null ? null : value.trim()); } - - this.map.put(id.name(), value == null ? null : value.trim()); + } catch (MissingResourceException e) { } - } catch (MissingResourceException e) { } } }