import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
* @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 <tt>def</tt> if not found (not present
+ * in the resource file)
*/
public String getString(E id, String def) {
return getString(id, def, -1);
* 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, <tt>def</tt> 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);
rep = getMetaDef(id.name());
}
- if (rep == null || rep.isEmpty()) {
+ if (rep.isEmpty()) {
return def;
}
* 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, <tt>def</tt> 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()
}
/**
- * 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")
boolean found = false;
if (!resetToDefault && dir != null) {
- // Look into Bundles.getDirectory() for .properties files
try {
+ // Look into Bundles.getDirectory() for .properties files
File file = getPropertyFile(dir, name.name(), locale);
if (file != null) {
- Reader reader = new InputStreamReader(new FileInputStream(
- file), "UTF-8");
- resetMap(new PropertyResourceBundle(reader));
+ InputStream in = new FileInputStream(file);
+ try {
+ Reader reader = new InputStreamReader(in, "UTF-8");
+ try {
+ resetMap(new PropertyResourceBundle(reader));
+ } finally {
+ reader.close();
+ }
+ } finally {
+ in.close();
+ }
found = true;
}
} catch (IOException e) {
*/
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) {
}
}
}