public static LocalizationContext getLocalizationContext()

in jelly-tags/fmt/src/main/java/org/apache/commons/jelly/tags/fmt/BundleTag.java [152:217]


    public static LocalizationContext getLocalizationContext(JellyContext jellyContext,
    String basename) {
        LocalizationContext locCtxt = null;
        ResourceBundle bundle = null;

        if ((basename == null) || basename.isEmpty()) {
            return new LocalizationContext();
        }

        // Try preferred locales
        Locale pref = null; {
            Object tmp = jellyContext.getVariable(Config.FMT_LOCALE);
            if (tmp != null && tmp instanceof Locale) {
                pref = (Locale) tmp;
            }
        }
        if (pref != null) {
            // Preferred locale is application-based
            bundle = findMatch(basename, pref, jellyContext.getClassLoader());
            if (bundle != null) {
                locCtxt = new LocalizationContext(bundle, pref);
            }
        }

        if (locCtxt == null) {
            // No match found with preferred locales, try using fallback locale
            {
                Object tmp = jellyContext.getVariable(Config.FMT_FALLBACK_LOCALE);
                if (tmp != null && tmp instanceof Locale) {
                    pref = (Locale) tmp;
                }
            }
            if (pref != null) {
                bundle = findMatch(basename, pref, jellyContext.getClassLoader());
                if (bundle != null) {
                    locCtxt = new LocalizationContext(bundle, pref);
                }
            }
        }

        if (locCtxt == null) {
            // try using the root resource bundle with the given basename
            try {
                bundle = ResourceBundle.getBundle(basename, EMPTY_LOCALE,
                jellyContext.getClassLoader());
                if (bundle != null) {
                    locCtxt = new LocalizationContext(bundle, null);
                }
            } catch (MissingResourceException mre) {
                // do nothing
            }
        }

        if (locCtxt != null) {
            // set response locale
            if (locCtxt.getLocale() != null) {
                // TODO
                // SetLocaleSupport.setResponseLocale(jc, locCtxt.getLocale());
            }
        } else {
            // create empty localization context
            locCtxt = new LocalizationContext();
        }

        return locCtxt;
    }