static Locale getFormattingLocale()

in jelly-tags/fmt/src/main/java/org/apache/commons/jelly/tags/fmt/SetLocaleTag.java [207:263]


    static Locale getFormattingLocale(JellyContext jc,
    Tag fromTag,
    boolean format,
    Locale[] avail) {

        LocalizationContext locCtxt = null;

        // Get formatting locale from enclosing <fmt:bundle>
        Tag parent = findAncestorWithClass(fromTag, BundleTag.class);
        if (parent != null) {
        /*
         * use locale from localization context established by parent
         * <fmt:bundle> action, unless that locale is null
         */
            locCtxt = ((BundleTag) parent).getLocalizationContext();
            if (locCtxt.getLocale() != null) {
                if (format) {
                    //setResponseLocale(jc, locCtxt.getLocale());
                }
                return locCtxt.getLocale();
            }
        }

        // Use locale from default I18N localization context, unless it is null
        if ((locCtxt = BundleTag.getLocalizationContext(jc)) != null) {
            if (locCtxt.getLocale() != null) {
                if (format) {
                    //setResponseLocale(jc, locCtxt.getLocale());
                }
                return locCtxt.getLocale();
            }
        }

    /*
     * Establish formatting locale by comparing the preferred locales
     * (in order of preference) against the available formatting
     * locales, and determining the best matching locale.
     */
        Locale match = null;
        Locale pref = getLocale(jc, Config.FMT_LOCALE);
        if (pref != null) {
            // Preferred locale is application-based
            match = findFormattingMatch(pref, avail);
        }
        if (match == null) {
            //Use fallback locale.
            pref = getLocale(jc, Config.FMT_FALLBACK_LOCALE);
            if (pref != null) {
                match = findFormattingMatch(pref, avail);
            }
        }
        if (format && (match != null)) {
            //setResponseLocale(jc, match);
        }

        return match;
    }