1 package be
.nikiroo
.utils
.resources
;
3 import java
.io
.BufferedWriter
;
5 import java
.io
.FileInputStream
;
6 import java
.io
.FileOutputStream
;
7 import java
.io
.IOException
;
8 import java
.io
.InputStreamReader
;
9 import java
.io
.OutputStreamWriter
;
10 import java
.io
.Reader
;
11 import java
.io
.Writer
;
12 import java
.lang
.reflect
.Field
;
13 import java
.util
.ArrayList
;
14 import java
.util
.HashMap
;
15 import java
.util
.List
;
16 import java
.util
.Locale
;
18 import java
.util
.MissingResourceException
;
19 import java
.util
.PropertyResourceBundle
;
20 import java
.util
.ResourceBundle
;
22 import be
.nikiroo
.utils
.resources
.Meta
.Format
;
25 * This class encapsulate a {@link ResourceBundle} in UTF-8. It allows to
26 * retrieve values associated to an enumeration, and allows some additional
29 * It also sports a writable change map, and you can save back the
30 * {@link Bundle} to file with {@link Bundle#updateFile(String)}.
33 * the enum to use to get values out of this class
38 public class Bundle
<E
extends Enum
<E
>> {
40 protected Class
<E
> type
;
42 * The {@link Enum} associated to this {@link Bundle} (all the keys used in
43 * this {@link Bundle} will be of this type).
45 protected Enum
<?
> keyType
;
47 private TransBundle
<E
> descriptionBundle
;
50 private Map
<String
, String
> map
;
52 private Map
<String
, String
> changeMap
;
55 * Create a new {@link Bundles} of the given name.
58 * a runtime instance of the class of E
60 * the name of the {@link Bundles}
61 * @param descriptionBundle
62 * the description {@link TransBundle}, that is, a
63 * {@link TransBundle} dedicated to the description of the values
64 * of the given {@link Bundle} (can be NULL)
66 protected Bundle(Class
<E
> type
, Enum
<?
> name
,
67 TransBundle
<E
> descriptionBundle
) {
70 this.descriptionBundle
= descriptionBundle
;
72 this.map
= new HashMap
<String
, String
>();
73 this.changeMap
= new HashMap
<String
, String
>();
74 setBundle(name
, Locale
.getDefault(), false);
78 * Check if the setting is set into this {@link Bundle}.
81 * the id of the setting to check
82 * @param includeDefaultValue
83 * TRUE to only return false when the setting is not set AND
84 * there is no default value
86 * @return TRUE if the setting is set
88 public boolean isSet(E id
, boolean includeDefaultValue
) {
89 return isSet(id
.name(), includeDefaultValue
);
93 * Check if the setting is set into this {@link Bundle}.
96 * the id of the setting to check
97 * @param includeDefaultValue
98 * TRUE to only return false when the setting is not set AND
99 * there is no default value
101 * @return TRUE if the setting is set
103 protected boolean isSet(String name
, boolean includeDefaultValue
) {
104 if (getString(name
, null) == null) {
105 if (!includeDefaultValue
|| getString(name
, "") == null) {
114 * Return the value associated to the given id as a {@link String}.
117 * the id of the value to get
119 * @return the associated value, or NULL if not found (not present in the
122 public String
getString(E id
) {
123 return getString(id
, null);
127 * Return the value associated to the given id as a {@link String}.
129 * If no value is associated, take the default one if any.
132 * the id of the value to get
134 * the default value when it is not present in the config file
136 * @return the associated value, or NULL if not found (not present in the
139 public String
getString(E id
, String def
) {
140 return getString(id
, def
, -1);
144 * Return the value associated to the given id as a {@link String}.
146 * If no value is associated (or if it is empty!), take the default one if
150 * the id of the value to get
152 * the default value when it is not present in the config file
154 * the item number to get for an array of values, or -1 for
157 * @return the associated value, or NULL if not found (not present in the
160 public String
getString(E id
, String def
, int item
) {
161 String rep
= getString(id
.name(), null);
164 Meta meta
= type
.getDeclaredField(id
.name()).getAnnotation(
167 } catch (NoSuchFieldException e
) {
168 } catch (SecurityException e
) {
172 if (rep
== null || rep
.isEmpty()) {
177 List
<String
> values
= BundleHelper
.parseList(rep
, item
);
178 if (values
!= null && item
< values
.size()) {
179 return values
.get(item
);
189 * Set the value associated to the given id as a {@link String}.
192 * the id of the value to set
197 public void setString(E id
, String value
) {
198 setString(id
.name(), value
);
202 * Set the value associated to the given id as a {@link String}.
205 * the id of the value to set
209 * the item number to get for an array of values, or -1 for
213 public void setString(E id
, String value
, int item
) {
215 setString(id
.name(), value
);
217 List
<String
> values
= getList(id
);
218 setString(id
.name(), BundleHelper
.fromList(values
, value
, item
));
223 * Return the value associated to the given id as a {@link String} suffixed
224 * with the runtime value "_suffix" (that is, "_" and suffix).
226 * Will only accept suffixes that form an existing id.
228 * If no value is associated, take the default one if any.
231 * the id of the value to get
235 * @return the associated value, or NULL if not found (not present in the
238 public String
getStringX(E id
, String suffix
) {
239 return getStringX(id
, suffix
, null, -1);
243 * Return the value associated to the given id as a {@link String} suffixed
244 * with the runtime value "_suffix" (that is, "_" and suffix).
246 * Will only accept suffixes that form an existing id.
248 * If no value is associated, take the default one if any.
251 * the id of the value to get
255 * the default value when it is not present in the config file
257 * @return the associated value, or NULL if not found (not present in the
260 public String
getStringX(E id
, String suffix
, String def
) {
261 return getStringX(id
, suffix
, def
, -1);
265 * Return the value associated to the given id as a {@link String} suffixed
266 * with the runtime value "_suffix" (that is, "_" and suffix).
268 * Will only accept suffixes that form an existing id.
270 * If no value is associated, take the default one if any.
273 * the id of the value to get
277 * the default value when it is not present in the config file
279 * the item number to get for an array of values, or -1 for
282 * @return the associated value, or NULL if not found (not present in the
285 public String
getStringX(E id
, String suffix
, String def
, int item
) {
286 String key
= id
.name()
287 + (suffix
== null ?
"" : "_" + suffix
.toUpperCase());
290 id
= Enum
.valueOf(type
, key
);
291 return getString(id
, def
, item
);
292 } catch (IllegalArgumentException e
) {
299 * Set the value associated to the given id as a {@link String} suffixed
300 * with the runtime value "_suffix" (that is, "_" and suffix).
302 * Will only accept suffixes that form an existing id.
305 * the id of the value to set
311 public void setStringX(E id
, String suffix
, String value
) {
312 setStringX(id
, suffix
, value
, -1);
316 * Set the value associated to the given id as a {@link String} suffixed
317 * with the runtime value "_suffix" (that is, "_" and suffix).
319 * Will only accept suffixes that form an existing id.
322 * the id of the value to set
328 * the item number to get for an array of values, or -1 for
331 public void setStringX(E id
, String suffix
, String value
, int item
) {
332 String key
= id
.name()
333 + (suffix
== null ?
"" : "_" + suffix
.toUpperCase());
336 id
= Enum
.valueOf(type
, key
);
337 setString(id
, value
, item
);
338 } catch (IllegalArgumentException e
) {
343 * Return the value associated to the given id as a {@link Boolean}.
345 * If no value is associated, take the default one if any.
348 * the id of the value to get
350 * @return the associated value
352 public Boolean
getBoolean(E id
) {
353 return BundleHelper
.parseBoolean(getString(id
), -1);
357 * Return the value associated to the given id as a {@link Boolean}.
359 * If no value is associated, take the default one if any.
362 * the id of the value to get
364 * the default value when it is not present in the config file or
365 * if it is not a boolean value
367 * @return the associated value
369 public boolean getBoolean(E id
, boolean def
) {
370 Boolean value
= getBoolean(id
);
379 * Return the value associated to the given id as a {@link Boolean}.
381 * If no value is associated, take the default one if any.
384 * the id of the value to get
386 * the default value when it is not present in the config file or
387 * if it is not a boolean value
389 * the item number to get for an array of values, or -1 for
392 * @return the associated value
394 public Boolean
getBoolean(E id
, boolean def
, int item
) {
395 String value
= getString(id
);
397 return BundleHelper
.parseBoolean(value
, item
);
404 * Set the value associated to the given id as a {@link Boolean}.
407 * the id of the value to set
412 public void setBoolean(E id
, boolean value
) {
413 setBoolean(id
, value
, -1);
417 * Set the value associated to the given id as a {@link Boolean}.
420 * the id of the value to set
424 * the item number to get for an array of values, or -1 for
428 public void setBoolean(E id
, boolean value
, int item
) {
429 setString(id
, BundleHelper
.fromBoolean(value
), item
);
433 * Return the value associated to the given id as an {@link Integer}.
435 * If no value is associated, take the default one if any.
438 * the id of the value to get
440 * @return the associated value
442 public Integer
getInteger(E id
) {
443 String value
= getString(id
);
445 return BundleHelper
.parseInteger(value
, -1);
452 * Return the value associated to the given id as an int.
454 * If no value is associated, take the default one if any.
457 * the id of the value to get
459 * the default value when it is not present in the config file or
460 * if it is not a int value
462 * @return the associated value
464 public int getInteger(E id
, int def
) {
465 Integer value
= getInteger(id
);
474 * Return the value associated to the given id as an int.
476 * If no value is associated, take the default one if any.
479 * the id of the value to get
481 * the default value when it is not present in the config file or
482 * if it is not a int value
484 * the item number to get for an array of values, or -1 for
487 * @return the associated value
489 public Integer
getInteger(E id
, int def
, int item
) {
490 String value
= getString(id
);
492 return BundleHelper
.parseInteger(value
, item
);
499 * Set the value associated to the given id as a {@link Integer}.
502 * the id of the value to set
507 public void setInteger(E id
, int value
) {
508 setInteger(id
, value
, -1);
512 * Set the value associated to the given id as a {@link Integer}.
515 * the id of the value to set
519 * the item number to get for an array of values, or -1 for
523 public void setInteger(E id
, int value
, int item
) {
524 setString(id
, BundleHelper
.fromInteger(value
), item
);
528 * Return the value associated to the given id as a {@link Character}.
530 * If no value is associated, take the default one if any.
533 * the id of the value to get
535 * @return the associated value
537 public Character
getCharacter(E id
) {
538 return BundleHelper
.parseCharacter(getString(id
), -1);
542 * Return the value associated to the given id as a {@link Character}.
544 * If no value is associated, take the default one if any.
547 * the id of the value to get
549 * the default value when it is not present in the config file or
550 * if it is not a char value
552 * @return the associated value
554 public char getCharacter(E id
, char def
) {
555 Character value
= getCharacter(id
);
564 * Return the value associated to the given id as a {@link Character}.
566 * If no value is associated, take the default one if any.
569 * the id of the value to get
571 * the default value when it is not present in the config file or
572 * if it is not a char value
574 * the item number to get for an array of values, or -1 for
577 * @return the associated value
579 public Character
getCharacter(E id
, char def
, int item
) {
580 String value
= getString(id
);
582 return BundleHelper
.parseCharacter(value
, item
);
589 * Set the value associated to the given id as a {@link Character}.
592 * the id of the value to set
597 public void setCharacter(E id
, char value
) {
598 setCharacter(id
, value
, -1);
602 * Set the value associated to the given id as a {@link Character}.
605 * the id of the value to set
609 * the item number to get for an array of values, or -1 for
613 public void setCharacter(E id
, char value
, int item
) {
614 setString(id
, BundleHelper
.fromCharacter(value
), item
);
618 * Return the value associated to the given id as a colour if it is found
621 * The returned value is an ARGB value.
623 * If no value is associated, take the default one if any.
626 * the id of the value to get
628 * @return the associated value
630 public Integer
getColor(E id
) {
631 return BundleHelper
.parseColor(getString(id
), -1);
635 * Return the value associated to the given id as a colour if it is found
638 * The returned value is an ARGB value.
640 * If no value is associated, take the default one if any.
643 * the id of the value to get
645 * the default value when it is not present in the config file or
646 * if it is not a char value
648 * @return the associated value
650 public int getColor(E id
, int def
) {
651 Integer value
= getColor(id
);
660 * Return the value associated to the given id as a colour if it is found
663 * The returned value is an ARGB value.
665 * If no value is associated, take the default one if any.
668 * the id of the value to get
670 * the default value when it is not present in the config file or
671 * if it is not a char value
673 * the item number to get for an array of values, or -1 for
676 * @return the associated value
678 public Integer
getColor(E id
, int def
, int item
) {
679 String value
= getString(id
);
681 return BundleHelper
.parseColor(value
, item
);
688 * Set the value associated to the given id as a colour.
690 * The value is a BGRA value.
693 * the id of the value to set
697 public void setColor(E id
, Integer color
) {
698 setColor(id
, color
, -1);
702 * Set the value associated to the given id as a Color.
705 * the id of the value to set
709 * the item number to get for an array of values, or -1 for
713 public void setColor(E id
, int value
, int item
) {
714 setString(id
, BundleHelper
.fromColor(value
), item
);
718 * Return the value associated to the given id as a list of values if it is
719 * found and can be parsed.
721 * If no value is associated, take the default one if any.
724 * the id of the value to get
726 * @return the associated list, empty if the value is empty, NULL if it is
727 * not found or cannot be parsed as a list
729 public List
<String
> getList(E id
) {
730 return BundleHelper
.parseList(getString(id
), -1);
734 * Return the value associated to the given id as a list of values if it is
735 * found and can be parsed.
737 * If no value is associated, take the default one if any.
740 * the id of the value to get
742 * the default value when it is not present in the config file or
743 * if it is not a char value
745 * @return the associated list, empty if the value is empty, NULL if it is
746 * not found or cannot be parsed as a list
748 public List
<String
> getList(E id
, List
<String
> def
) {
749 List
<String
> value
= getList(id
);
758 * Return the value associated to the given id as a list of values if it is
759 * found and can be parsed.
761 * If no value is associated, take the default one if any.
764 * the id of the value to get
766 * the default value when it is not present in the config file or
767 * if it is not a char value
769 * the item number to get for an array of values, or -1 for
772 * @return the associated list, empty if the value is empty, NULL if it is
773 * not found or cannot be parsed as a list
775 public List
<String
> getList(E id
, List
<String
> def
, int item
) {
776 String value
= getString(id
);
778 return BundleHelper
.parseList(value
, item
);
785 * Set the value associated to the given id as a list of values.
788 * the id of the value to set
790 * the new list of values
792 public void setList(E id
, List
<String
> list
) {
793 setList(id
, list
, -1);
797 * Set the value associated to the given id as a {@link List}.
800 * the id of the value to set
804 * the item number to get for an array of values, or -1 for
808 public void setList(E id
, List
<String
> value
, int item
) {
809 setString(id
, BundleHelper
.fromList(value
), item
);
813 * Create/update the .properties file.
815 * Will use the most likely candidate as base if the file does not already
816 * exists and this resource is translatable (for instance, "en_US" will use
817 * "en" as a base if the resource is a translation file).
819 * Will update the files in {@link Bundles#getDirectory()}; it <b>MUST</b>
822 * @throws IOException
823 * in case of IO errors
825 public void updateFile() throws IOException
{
826 updateFile(Bundles
.getDirectory());
830 * Create/update the .properties file.
832 * Will use the most likely candidate as base if the file does not already
833 * exists and this resource is translatable (for instance, "en_US" will use
834 * "en" as a base if the resource is a translation file).
837 * the path where the .properties files are, <b>MUST NOT</b> be
840 * @throws IOException
841 * in case of IO errors
843 public void updateFile(String path
) throws IOException
{
844 File file
= getUpdateFile(path
);
846 BufferedWriter writer
= new BufferedWriter(new OutputStreamWriter(
847 new FileOutputStream(file
), "UTF-8"));
853 for (Field field
: type
.getDeclaredFields()) {
854 Meta meta
= field
.getAnnotation(Meta
.class);
856 E id
= Enum
.valueOf(type
, field
.getName());
857 String info
= getMetaInfo(meta
);
864 writeValue(writer
, id
);
872 * Delete the .properties file.
874 * Will use the most likely candidate as base if the file does not already
875 * exists and this resource is translatable (for instance, "en_US" will use
876 * "en" as a base if the resource is a translation file).
878 * Will delete the files in {@link Bundles#getDirectory()}; it <b>MUST</b>
881 * @return TRUE if the file was deleted
883 public boolean deleteFile() {
884 return deleteFile(Bundles
.getDirectory());
888 * Delete the .properties file.
890 * Will use the most likely candidate as base if the file does not already
891 * exists and this resource is translatable (for instance, "en_US" will use
892 * "en" as a base if the resource is a translation file).
895 * the path where the .properties files are, <b>MUST NOT</b> be
898 * @return TRUE if the file was deleted
900 public boolean deleteFile(String path
) {
901 File file
= getUpdateFile(path
);
902 return file
.delete();
906 * The description {@link TransBundle}, that is, a {@link TransBundle}
907 * dedicated to the description of the values of the given {@link Bundle}
910 * @return the description {@link TransBundle}
912 public TransBundle
<E
> getDescriptionBundle() {
913 return descriptionBundle
;
917 * Reload the {@link Bundle} data files.
919 * @param resetToDefault
920 * reset to the default configuration (do not look into the
921 * possible user configuration files, only take the original
924 public void reload(boolean resetToDefault
) {
925 setBundle(keyType
, Locale
.getDefault(), resetToDefault
);
929 * Check if the internal map contains the given key.
932 * the key to check for
934 * @return true if it does
936 protected boolean containsKey(String key
) {
937 return changeMap
.containsKey(key
) || map
.containsKey(key
);
941 * Get the value for the given key if it exists in the internal map, or
942 * <tt>def</tt> if not.
945 * the key to check for
947 * the default value when it is not present in the internal map
949 * @return the value, or <tt>def</tt> if not found
951 protected String
getString(String key
, String def
) {
952 if (changeMap
.containsKey(key
)) {
953 return changeMap
.get(key
);
956 if (map
.containsKey(key
)) {
964 * Set the value for this key, in the change map (it is kept in memory, not
970 * the associated value
972 protected void setString(String key
, String value
) {
973 changeMap
.put(key
, value
== null ?
null : value
.trim());
977 * Return formated, display-able information from the {@link Meta} field
978 * given. Each line will always starts with a "#" character.
981 * the {@link Meta} field
983 * @return the information to display or NULL if none
985 protected String
getMetaInfo(Meta meta
) {
986 String desc
= meta
.description();
987 boolean group
= meta
.group();
988 Meta
.Format format
= meta
.format();
989 String
[] list
= meta
.list();
990 boolean nullable
= meta
.nullable();
991 String def
= meta
.def();
992 boolean array
= meta
.array();
994 // Default, empty values -> NULL
995 if (desc
.length() + list
.length
+ def
.length() == 0 && !group
996 && nullable
&& format
== Format
.STRING
) {
1000 StringBuilder builder
= new StringBuilder();
1001 for (String line
: desc
.split("\n")) {
1002 builder
.append("# ").append(line
).append("\n");
1006 builder
.append("# This item is used as a group, its content is not expected to be used.");
1008 builder
.append("# (FORMAT: ").append(format
)
1009 .append(nullable ?
"" : ", required");
1010 builder
.append(") ");
1012 if (list
.length
> 0) {
1013 builder
.append("\n# ALLOWED VALUES: ");
1014 boolean first
= true;
1015 for (String value
: list
) {
1017 builder
.append(", ");
1019 builder
.append(BundleHelper
.escape(value
));
1025 builder
.append("\n# (This item accepts a list of ^escaped comma-separated values)");
1029 return builder
.toString();
1033 * The display name used in the <tt>.properties file</tt>.
1037 protected String
getBundleDisplayName() {
1038 return keyType
.toString();
1042 * Write the header found in the configuration <tt>.properties</tt> file of
1043 * this {@link Bundles}.
1046 * the {@link Writer} to write the header in
1048 * @throws IOException
1049 * in case of IO error
1051 protected void writeHeader(Writer writer
) throws IOException
{
1052 writer
.write("# " + getBundleDisplayName() + "\n");
1053 writer
.write("#\n");
1057 * Write the given data to the config file, i.e., "MY_ID = my_curent_value"
1058 * followed by a new line.
1060 * Will prepend a # sign if the is is not set (see
1061 * {@link Bundle#isSet(Enum, boolean)}).
1064 * the {@link Writer} to write into
1068 * @throws IOException
1069 * in case of IO error
1071 protected void writeValue(Writer writer
, E id
) throws IOException
{
1072 boolean set
= isSet(id
, false);
1073 writeValue(writer
, id
.name(), getString(id
), set
);
1077 * Write the given data to the config file, i.e., "MY_ID = my_curent_value"
1078 * followed by a new line.
1080 * Will prepend a # sign if the is is not set.
1083 * the {@link Writer} to write into
1089 * the value is set in this {@link Bundle}
1091 * @throws IOException
1092 * in case of IO error
1094 protected void writeValue(Writer writer
, String id
, String value
,
1095 boolean set
) throws IOException
{
1102 writer
.write(" = ");
1104 if (value
== null) {
1108 String
[] lines
= value
.replaceAll("\t", "\\\\\\t").split("\n");
1109 for (int i
= 0; i
< lines
.length
; i
++) {
1110 writer
.write(lines
[i
]);
1111 if (i
< lines
.length
- 1) {
1112 writer
.write("\\n\\");
1119 * Return the source file for this {@link Bundles} from the given path.
1122 * the path where the .properties files are
1124 * @return the source {@link File}
1126 protected File
getUpdateFile(String path
) {
1127 return new File(path
, keyType
.name() + ".properties");
1131 * Change the currently used bundle, and reset all changes.
1134 * the name of the bundle to load
1136 * the {@link Locale} to use
1137 * @param resetToDefault
1138 * reset to the default configuration (do not look into the
1139 * possible user configuration files, only take the original
1142 protected void setBundle(Enum
<?
> name
, Locale locale
, boolean resetToDefault
) {
1144 String dir
= Bundles
.getDirectory();
1145 String bname
= type
.getPackage().getName() + "." + name
.name();
1147 boolean found
= false;
1148 if (!resetToDefault
&& dir
!= null) {
1149 // Look into Bundles.getDirectory() for .properties files
1151 File file
= getPropertyFile(dir
, name
.name(), locale
);
1153 Reader reader
= new InputStreamReader(new FileInputStream(
1155 resetMap(new PropertyResourceBundle(reader
));
1158 } catch (IOException e
) {
1159 e
.printStackTrace();
1164 // Look into the package itself for resources
1166 resetMap(ResourceBundle
1167 .getBundle(bname
, locale
, type
.getClassLoader(),
1168 new FixedResourceBundleControl()));
1170 } catch (MissingResourceException e
) {
1171 } catch (Exception e
) {
1172 e
.printStackTrace();
1177 // We have no bundle for this Bundle
1178 System
.err
.println("No bundle found for: " + bname
);
1184 * Reset the backing map to the content of the given bundle, or with NULL
1185 * values if bundle is NULL.
1188 * the bundle to copy
1190 protected void resetMap(ResourceBundle bundle
) {
1192 for (Field field
: type
.getDeclaredFields()) {
1194 Meta meta
= field
.getAnnotation(Meta
.class);
1196 E id
= Enum
.valueOf(type
, field
.getName());
1199 if (bundle
!= null) {
1200 value
= bundle
.getString(id
.name());
1205 this.map
.put(id
.name(), value
== null ?
null : value
.trim());
1207 } catch (MissingResourceException e
) {
1213 * Take a snapshot of the changes in memory in this {@link Bundle} made by
1214 * the "set" methods ( {@link Bundle#setString(Enum, String)}...) at the
1217 * @return a snapshot to use with {@link Bundle#restoreSnapshot(Object)}
1219 public Object
takeSnapshot() {
1220 return new HashMap
<String
, String
>(changeMap
);
1224 * Restore a snapshot taken with {@link Bundle}, or reset the current
1225 * changes if the snapshot is NULL.
1228 * the snapshot or NULL
1230 @SuppressWarnings("unchecked")
1231 public void restoreSnapshot(Object snap
) {
1235 if (snap
instanceof Map
) {
1236 changeMap
= (Map
<String
, String
>) snap
;
1238 throw new RuntimeException(
1239 "Restoring changes in a Bundle must be done on a changes snapshot, "
1240 + "or NULL to discard current changes");
1246 * Return the resource file that is closer to the {@link Locale}.
1249 * the directory to look into
1251 * the file base name (without <tt>.properties</tt>)
1253 * the {@link Locale}
1255 * @return the closest match or NULL if none
1257 private File
getPropertyFile(String dir
, String name
, Locale locale
) {
1258 List
<String
> locales
= new ArrayList
<String
>();
1259 if (locale
!= null) {
1260 String country
= locale
.getCountry() == null ?
"" : locale
1262 String language
= locale
.getLanguage() == null ?
"" : locale
1264 if (!language
.isEmpty() && !country
.isEmpty()) {
1265 locales
.add("_" + language
+ "-" + country
);
1267 if (!language
.isEmpty()) {
1268 locales
.add("_" + language
);
1275 for (String loc
: locales
) {
1276 file
= new File(dir
, name
+ loc
+ ".properties");
1277 if (file
.exists()) {