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 $
4
* $Date: 2004/03/14 06:23:49 $
2
* $Id: I18nFactorySet.java 265658 2005-09-01 05:54:57Z niallp $
6
* Copyright 1999-2004 The Apache Software Foundation.
4
* Copyright 1999-2005 The Apache Software Foundation.
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" };
93
* Maximum length of one branch of the resource search path tree.
94
* Used in getBundle().
96
private static final int MAX_BUNDLES_SEARCHED = 2;
99
91
* Default filenames extension.
336
328
// Build possible postfixes
337
List possiblePostfixes = calculatePostixes("", (Locale) key);
329
List possiblePostfixes = calculateSuffixes((Locale) key);
339
331
// Search last postix corresponding to a config file to load.
340
332
// First check if something is loaded for this postfix.
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
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();
407
if (languageLength + countryLength + variantLength == 0) {
408
//The locale is "", "", "".
412
final StringBuffer temp = new StringBuffer(baseName);
414
temp.append(language);
416
if (languageLength > 0)
417
result.add(temp.toString());
419
if (countryLength + variantLength == 0)
423
temp.append(country);
425
if (countryLength > 0)
426
result.add(temp.toString());
428
if (variantLength == 0) {
432
temp.append(variant);
433
result.add(temp.toString());
387
private List calculateSuffixes(Locale locale) {
389
List suffixes = new ArrayList(3);
390
String language = locale.getLanguage();
391
String country = locale.getCountry();
392
String variant = locale.getVariant();
394
StringBuffer suffix = new StringBuffer();
396
suffix.append(language);
397
if (language.length() > 0) {
398
suffixes.add(suffix.toString());
402
suffix.append(country);
403
if (country.length() > 0) {
404
suffixes.add(suffix.toString());
408
suffix.append(variant);
409
if (variant.length() > 0) {
410
suffixes.add(suffix.toString());
501
480
} catch (Exception e) {
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
487
input = getClass().getResourceAsStream(filename);
505
490
// If still nothing found, this mean no config file is associated
506
491
if (input == null) {