View | Details | Raw Unified | Return to bug 18525
Collapse All | Expand All

(-)BundleTag.java (-12 / +17 lines)
Lines 193-210 Link Here
193
                "i18n:bundle tag, a baseName attribute must be specified.");
193
                "i18n:bundle tag, a baseName attribute must be specified.");
194
        }
194
        }
195
195
196
        // Add a local variable to keep _locale unchanged.
197
        Locale locale = _locale;
198
196
        // if locale not provided, but an attribute was, search for it
199
        // if locale not provided, but an attribute was, search for it
197
        if (_locale == null && _localeAttribute != null) {
200
        if (locale == null && _localeAttribute != null) {
198
            _locale = (Locale)pageContext.findAttribute(_localeAttribute);
201
            locale = (Locale)pageContext.findAttribute(_localeAttribute);
199
        }
202
        }
200
203
201
        // if we now have a locale, grab the resource bundle
204
        // if we now have a locale, grab the resource bundle
202
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
205
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
203
        if (_locale != null) {
206
        if (locale != null) {
204
            _bundle = ResourceBundle.getBundle(_baseName,_locale,cl);
207
            _bundle = ResourceBundle.getBundle(_baseName,locale,cl);
205
            if (_debug) {
208
            if (_debug) {
206
                ServletContext sc = pageContext.getServletContext();
209
                ServletContext sc = pageContext.getServletContext();
207
                sc.log("i18n:bundle tag debug: found locale " + _locale);
210
                sc.log("i18n:bundle tag debug: found locale " + locale);
208
            }
211
            }
209
        }
212
        }
210
        
213
        
Lines 213-228 Link Here
213
        else {
216
        else {
214
            Enumeration localeEnumerator = pageContext.getRequest().getLocales();
217
            Enumeration localeEnumerator = pageContext.getRequest().getLocales();
215
            while (localeEnumerator.hasMoreElements()) {
218
            while (localeEnumerator.hasMoreElements()) {
216
                _locale = (Locale)localeEnumerator.nextElement();
219
                locale = (Locale)localeEnumerator.nextElement();
217
220
218
                if (_debug) {
221
                if (_debug) {
219
                    ServletContext sc = pageContext.getServletContext();
222
                    ServletContext sc = pageContext.getServletContext();
220
                    sc.log("i18n:bundle tag debug: enumerating locale = " + _locale);    
223
                    sc.log("i18n:bundle tag debug: enumerating locale = " + locale);    
221
                }
224
                }
222
                    
225
                    
223
                // get a bundle and see whether it has a good locale
226
                // get a bundle and see whether it has a good locale
224
                ResourceBundle test = 
227
                ResourceBundle test = 
225
                    ResourceBundle.getBundle(_baseName,_locale,cl);
228
                    ResourceBundle.getBundle(_baseName,locale,cl);
226
                String language = test.getLocale().getLanguage();
229
                String language = test.getLocale().getLanguage();
227
                String country = test.getLocale().getCountry();
230
                String country = test.getLocale().getCountry();
228
231
Lines 230-242 Link Here
230
                // return a bundle with a locale for the same language, or will
233
                // return a bundle with a locale for the same language, or will
231
                // return the default locale, so we need to compare the locale
234
                // return the default locale, so we need to compare the locale
232
                // of the bundle we got back with the one we asked for
235
                // of the bundle we got back with the one we asked for
233
                if (test.getLocale().equals(_locale)) {
236
                if (test.getLocale().equals(locale)) {
234
                    // exactly what we were looking for - stop here and use this
237
                    // exactly what we were looking for - stop here and use this
235
                    _bundle = test;
238
                    _bundle = test;
236
                    break;                
239
                    break;                
237
                } else if (_locale.getLanguage().equals(language)) {
240
                } else if (locale.getLanguage().equals(language)) {
238
                    // the language matches; see if the country matches as well
241
                    // the language matches; see if the country matches as well
239
                    if (_locale.getCountry().equals(country)) {
242
                    if (locale.getCountry().equals(country)) {
240
                        // keep looking but this is a good option. it only gets
243
                        // keep looking but this is a good option. it only gets
241
                        // better if the variant matches too!  (note: we will only
244
                        // better if the variant matches too!  (note: we will only
242
                        // get to this statement if a variant has been provided)
245
                        // get to this statement if a variant has been provided)
Lines 253-259 Link Here
253
                    }
256
                    }
254
                } else if (_debug) {
257
                } else if (_debug) {
255
                    ServletContext sc = pageContext.getServletContext();
258
                    ServletContext sc = pageContext.getServletContext();
256
                    sc.log("i18n:bundle tag requested locale not available: " + _locale);
259
                    sc.log("i18n:bundle tag requested locale not available: " + locale);
257
                }
260
                }
258
            }
261
            }
259
262
Lines 285-290 Link Here
285
     */
288
     */
286
    public int doStartTag() throws JspException
289
    public int doStartTag() throws JspException
287
    {
290
    {
291
    	// initialize internal member variables
292
    	_bundle = null;
288
        findBundle();
293
        findBundle();
289
294
290
        if (_debug) {
295
        if (_debug) {

Return to bug 18525