X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fresources%2FBundle.java;h=c757e2b1d705dc005b52ac425f7a9a89a14deabd;hb=75efdb7e651001aa1141c3080a80dd92544cc08f;hp=21021e065f05a938f4521bfb5fd399b40847a77d;hpb=24604392c3aa6d9298aacd10fde7bb2df1322a10;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/resources/Bundle.java b/src/be/nikiroo/utils/resources/Bundle.java index 21021e0..c757e2b 100644 --- a/src/be/nikiroo/utils/resources/Bundle.java +++ b/src/be/nikiroo/utils/resources/Bundle.java @@ -92,11 +92,11 @@ public class Bundle> { /** * Check if the setting is set into this {@link Bundle}. * - * @param id + * @param name * the id of the setting to check * @param includeDefaultValue - * TRUE to only return false when the setting is not set AND - * there is no default value + * TRUE to only return false when the setting is explicitly set + * to NULL (and not just "no set") in the change maps * * @return TRUE if the setting is set */ @@ -160,13 +160,7 @@ public class Bundle> { public String getString(E id, String def, int item) { String rep = getString(id.name(), null); if (rep == null) { - try { - Meta meta = type.getDeclaredField(id.name()).getAnnotation( - Meta.class); - rep = meta.def(); - } catch (NoSuchFieldException e) { - } catch (SecurityException e) { - } + rep = getMetaDef(id.name()); } if (rep == null || rep.isEmpty()) { @@ -215,11 +209,7 @@ public class Bundle> { setString(id.name(), value); } else { List values = getList(id); - for (int i = values.size(); i < item; i++) { - values.add(null); - } - values.set(item, value); - setString(id.name(), BundleHelper.fromList(values)); + setString(id.name(), BundleHelper.fromList(values, value, item)); } } @@ -277,9 +267,6 @@ public class Bundle> { * the id of the value to get * @param suffix * the runtime suffix - * @param item - * the item number to get for an array of values, or -1 for - * non-arrays * @param def * the default value when it is not present in the config file * @param item @@ -577,6 +564,9 @@ public class Bundle> { * @param def * the default value when it is not present in the config file or * if it is not a char value + * @param item + * the item number to get for an array of values, or -1 for + * non-arrays * * @return the associated value */ @@ -645,6 +635,9 @@ public class Bundle> { * * @param id * the id of the value to get + * @param def + * the default value when it is not present in the config file or + * if it is not a char value * * @return the associated value */ @@ -667,6 +660,12 @@ public class Bundle> { * * @param id * the id of the value to get + * @param def + * the default value when it is not present in the config file or + * if it is not a char value + * @param item + * the item number to get for an array of values, or -1 for + * non-arrays * * @return the associated value */ @@ -733,6 +732,9 @@ public class Bundle> { * * @param id * the id of the value to get + * @param def + * the default value when it is not present in the config file or + * if it is not a char value * * @return the associated list, empty if the value is empty, NULL if it is * not found or cannot be parsed as a list @@ -754,6 +756,12 @@ public class Bundle> { * * @param id * the id of the value to get + * @param def + * the default value when it is not present in the config file or + * if it is not a char value + * @param item + * the item number to get for an array of values, or -1 for + * non-arrays * * @return the associated list, empty if the value is empty, NULL if it is * not found or cannot be parsed as a list @@ -923,9 +931,35 @@ public class Bundle> { return changeMap.containsKey(key) || map.containsKey(key); } + /** + * The default {@link MetaInfo.def} value for the given enumeration name. + * + * @param id + * the enumeration name (the "id") + * + * @return the def value in the {@link MetaInfo} or "" if none (never NULL) + */ + protected String getMetaDef(String id) { + String rep = ""; + try { + Meta meta = type.getDeclaredField(id).getAnnotation(Meta.class); + rep = meta.def(); + } catch (NoSuchFieldException e) { + } catch (SecurityException e) { + } + + if (rep == null) { + rep = ""; + } + + return rep; + } + /** * Get the value for the given key if it exists in the internal map, or * def if not. + *

+ * DO NOT get the default meta value (MetaInfo.def()). * * @param key * the key to check for @@ -1167,7 +1201,7 @@ public class Bundle> { } /** - * Reset the backing map to the content of the given bundle, or with default + * Reset the backing map to the content of the given bundle, or with NULL * values if bundle is NULL. * * @param bundle @@ -1185,7 +1219,7 @@ public class Bundle> { if (bundle != null) { value = bundle.getString(id.name()); } else { - value = meta.def(); + value = null; } this.map.put(id.name(), value == null ? null : value.trim());