~ubuntu-branches/ubuntu/lucid/libstruts1.2-java/lucid

« back to all changes in this revision

Viewing changes to src/share/org/apache/struts/tiles/xmlDefinition/I18nFactorySet.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2006-04-24 12:14:23 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060424121423-naev53qigqgks0sa
Tags: 1.2.9-1
New upstream  release Fixes  three security  problems: CVE-2006-1546,
CVE-2006-1547,  CVE-2006-1548  (closes:  #360551),  thanks  to  Moritz
Muehlenhoff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/tiles/xmlDefinition/I18nFactorySet.java,v 1.13 2004/03/14 06:23:49 sraeburn Exp $
3
 
 * $Revision: 1.13 $
4
 
 * $Date: 2004/03/14 06:23:49 $
 
2
 * $Id: I18nFactorySet.java 265658 2005-09-01 05:54:57Z niallp $ 
5
3
 *
6
 
 * Copyright 1999-2004 The Apache Software Foundation.
 
4
 * Copyright 1999-2005 The Apache Software Foundation.
7
5
 * 
8
6
 * Licensed under the Apache License, Version 2.0 (the "License");
9
7
 * you may not use this file except in compliance with the License.
89
87
            "/WEB-INF/componentDefinitions.xml",
90
88
            "/WEB-INF/instanceDefinitions.xml" };
91
89
 
92
 
    /**
93
 
     * Maximum length of one branch of the resource search path tree.
94
 
     * Used in getBundle().
95
 
     */
96
 
    private static final int MAX_BUNDLES_SEARCHED = 2;
97
 
 
98
90
    /** 
99
91
     * Default filenames extension. 
100
92
     */
334
326
        }
335
327
 
336
328
        // Build possible postfixes
337
 
        List possiblePostfixes = calculatePostixes("", (Locale) key);
 
329
        List possiblePostfixes = calculateSuffixes((Locale) key);
338
330
 
339
331
        // Search last postix corresponding to a config file to load.
340
332
        // First check if something is loaded for this postfix.
389
381
    }
390
382
 
391
383
    /**
392
 
     * Calculate the postixes along the search path from the base bundle to the
393
 
     * bundle specified by baseName and locale.
394
 
     * Method copied from java.util.ResourceBundle
395
 
     * @param baseName the base bundle name
 
384
     * Calculate the suffixes based on the locale.
396
385
     * @param locale the locale
397
386
     */
398
 
    private static List calculatePostixes(String baseName, Locale locale) {
399
 
        final List result = new ArrayList(MAX_BUNDLES_SEARCHED);
400
 
        final String language = locale.getLanguage();
401
 
        final int languageLength = language.length();
402
 
        final String country = locale.getCountry();
403
 
        final int countryLength = country.length();
404
 
        final String variant = locale.getVariant();
405
 
        final int variantLength = variant.length();
406
 
 
407
 
        if (languageLength + countryLength + variantLength == 0) {
408
 
            //The locale is "", "", "".
409
 
            return result;
410
 
        }
411
 
 
412
 
        final StringBuffer temp = new StringBuffer(baseName);
413
 
        temp.append('_');
414
 
        temp.append(language);
415
 
 
416
 
        if (languageLength > 0)
417
 
            result.add(temp.toString());
418
 
 
419
 
        if (countryLength + variantLength == 0)
420
 
            return result;
421
 
 
422
 
        temp.append('_');
423
 
        temp.append(country);
424
 
 
425
 
        if (countryLength > 0)
426
 
            result.add(temp.toString());
427
 
 
428
 
        if (variantLength == 0) {
429
 
            return result;
430
 
        } else {
431
 
            temp.append('_');
432
 
            temp.append(variant);
433
 
            result.add(temp.toString());
434
 
            return result;
435
 
        }
 
387
    private List calculateSuffixes(Locale locale) {
 
388
 
 
389
        List suffixes = new ArrayList(3);
 
390
        String language = locale.getLanguage();
 
391
        String country  = locale.getCountry();
 
392
        String variant  = locale.getVariant();
 
393
 
 
394
        StringBuffer suffix = new StringBuffer();
 
395
        suffix.append('_');
 
396
        suffix.append(language);
 
397
        if (language.length() > 0) {
 
398
            suffixes.add(suffix.toString());
 
399
        }
 
400
 
 
401
        suffix.append('_');
 
402
        suffix.append(country);
 
403
        if (country.length() > 0) {
 
404
            suffixes.add(suffix.toString());
 
405
        }
 
406
 
 
407
        suffix.append('_');
 
408
        suffix.append(variant);
 
409
        if (variant.length() > 0) {
 
410
            suffixes.add(suffix.toString());
 
411
        }
 
412
 
 
413
        return suffixes;
 
414
 
436
415
    }
437
416
 
438
417
    /**
501
480
                } catch (Exception e) {
502
481
                }
503
482
            }
 
483
            
 
484
            // If the config isn't in the servlet context, try the class loader
 
485
            // which allows the config files to be stored in a jar
 
486
            if (input == null) {
 
487
                input = getClass().getResourceAsStream(filename);
 
488
            }
504
489
 
505
490
            // If still nothing found, this mean no config file is associated
506
491
            if (input == null) {