Index: lutinutil/src/java/org/codelutin/i18n/bundle/I18nBundleScope.java diff -u lutinutil/src/java/org/codelutin/i18n/bundle/I18nBundleScope.java:1.4 lutinutil/src/java/org/codelutin/i18n/bundle/I18nBundleScope.java:1.5 --- lutinutil/src/java/org/codelutin/i18n/bundle/I18nBundleScope.java:1.4 Sun Mar 23 06:02:24 2008 +++ lutinutil/src/java/org/codelutin/i18n/bundle/I18nBundleScope.java Sun Mar 23 16:25:22 2008 @@ -19,34 +19,34 @@ import org.codelutin.i18n.I18nLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * Definition de la portée d'un bundle i18n. + * The enumaration defines the scope of a bundle entry. *

- * La portée est le niveau de spécialisation du bundle. + * There is three scope possible: + *

*

- * La portée le plus basse étant {@link #GENERAL}, qui correspond à un bunle sans - * indication de locale (par exemple lutin.properties). + * We define a order relation, from general to full scope : *

- * Vient ensuite la portée {@link #LANGUAGE} qui correspond à un bundle avec un - * spécialisation sur la langue (par exemple lutin-fr.properties). + * {@link #GENERAL} < {@link #LANGUAGE} < {@link #FULL} *

- * Enfin, la portée la plus haute {@link #FULL} qui correspond à un bunle avec - * une spécialisation sur la langue et le pays (par exemple - * lutin-fr_FR.properties). + * Scopes are inclusives, in a search of entries, eg the search of en_GB will include en scope... *

- * Les portées sont inclusives, i.e qu'une portée inclue les portées de niveaux - * inferieures. + * The {@link #patternAll} is the searching pattern of bundle of the scope. *

- * Note : on utilise la propriété {@link #ordinal} de l'énum pour définir l'ordre - * sur les portées. + * The method {@link #getMatcher(String)} obtain from the {@link #patternAll} the matcher for a bundle path. + *

+ * The method {@link #getLocale(Matcher)} obtain from the {@link #patternAll} matched in a bundle path, the + * corresponding locale. + *

+ * The class offer also a static method {@link #valueOf(java.util.Locale)} to obtain the scope of a locale. * * @author chemit */ @@ -62,7 +62,6 @@ /** language scope (no country information) */ LANGUAGE("(.*18n/.+)-(\\w\\w)\\.properties") { - public Locale getLocale(Matcher matcher) { Locale result = null; if (matcher.matches()) { @@ -83,14 +82,25 @@ } }; - /** pattern to use for a scope to detect bundle entry */ + /** pattern used to detect bundle entry */ private final Pattern patternAll; - /** cache of scope in reverse order */ - static I18nBundleScope[] reverseValues; - - private I18nBundleScope(String patternAll) { - this.patternAll = Pattern.compile(patternAll); + /** + * Obtain the scope of a given locale. + *

+ * The given locale can be null, which means {@link I18nBundleScope#GENERAL} scope. + * + * @param locale given locale to convert + * @return the scope of given locale + */ + public static I18nBundleScope valueOf(Locale locale) { + if (locale == null || locale.getLanguage() == null || locale.getLanguage().length() == 0) { + return GENERAL; + } + if (locale.getCountry() == null || locale.getCountry().length() == 0) { + return LANGUAGE; + } + return FULL; } /** @@ -104,6 +114,14 @@ } /** + * get the locale for a given matcher. + * + * @param matcher the scope matcher to use + * @return the locale + */ + public abstract Locale getLocale(Matcher matcher); + + /** * @param matcher the scope matcher to use * @return the prefix of the bundle */ @@ -115,38 +133,7 @@ return result; } - /** - * @param matcher the scope matcher to use - * @return the locale - */ - public abstract Locale getLocale(Matcher matcher); - - /** - * Obtain the scope of a locale. - *

- * The given locale can be null, which means {@link I18nBundleScope#GENERAL} scope - * - * @param locale locale used - * @return the scope of given locale - */ - public static I18nBundleScope valueOf(Locale locale) { - if (locale == null) { - return GENERAL; - } - if (locale.getCountry() == null) { - return LANGUAGE; - } - return FULL; - } - - /** @return the arrayof scope from more specialized scope to less specialized scope */ - public static synchronized I18nBundleScope[] reverseValues() { - if (reverseValues == null) { - List list = new ArrayList(Arrays.asList(values())); - Collections.sort(list); - Collections.reverse(list); - reverseValues = list.toArray(new I18nBundleScope[list.size()]); - } - return reverseValues; + private I18nBundleScope(String patternAll) { + this.patternAll = Pattern.compile(patternAll); } } \ No newline at end of file