/**
  * Retrieves all supported locales. This will return null when all found locales should be
  * included.
  *
  * @param env the environment
  * @return Returns the supported locales.
  */
 public LocaleSetting[] getSupportedLocales(Environment env) {
   BooleanEvaluator evaluator = env.getBooleanEvaluator();
   ArrayList locales = new ArrayList(this.supportedLocales.size());
   for (int i = 0; i < this.supportedLocales.size(); i++) {
     LocaleSetting setting = (LocaleSetting) this.supportedLocales.get(i);
     if (setting.isActive(evaluator)) {
       locales.add(setting);
     }
   }
   return (LocaleSetting[]) locales.toArray(new LocaleSetting[locales.size()]);
 }
 /**
  * Adds a specific setting for a locale, this can be used for allowing different locale dependent
  * encodings, for example.
  *
  * @param setting the setting
  */
 private void add(LocaleSetting setting) {
   LocaleSetting existingSetting =
       (LocaleSetting) this.localesByName.get(setting.getLocale().toString());
   if (existingSetting != null
       && (setting.getCondition() == null || (existingSetting.getCondition() == null))) {
     throw new BuildException(
         "The locale "
             + setting.getLocale()
             + " has been defined several times, at least one time without a condition. Check your <localization> and <localesetting> elements.");
   }
   this.supportedLocales.add(setting);
 }
 /**
  * Retrieves all supported locale as a comma separated string, e.g. "de,en,fr"
  *
  * @param env the environment
  * @return all supported locale as a comma separated string
  */
 public String getSupportedLocalesAsString(Environment env) {
   StringBuffer buffer = new StringBuffer();
   if (this.defaultLocale == null) {
     this.defaultLocale = getDefaultLocale();
   }
   buffer.append(this.defaultLocale.toString());
   LocaleSetting[] settings = getSupportedLocales(env);
   for (int i = 0; i < settings.length; i++) {
     LocaleSetting setting = settings[i];
     if (!setting.getLocale().equals(this.defaultLocale.getLocale())) {
       buffer.append(",").append(setting.toString());
     }
   }
   return buffer.toString();
 }
 /**
  * Retrieves the default locale. This call makes only sense when dynamic locales are used.
  *
  * @return the default locale
  */
 public LocaleSetting getDefaultLocale() {
   if (this.defaultLocale != null) {
     return this.defaultLocale;
   } else if (this.supportedLocales.size() == 1) {
     return (LocaleSetting) this.supportedLocales.get(0);
   } else if (this.supportedLocales.size() == 0) {
     throw new BuildException("No locales are defined - check your <localization> setting.");
   } else {
     Locale locale = Locale.getDefault();
     for (int i = 0; i < this.supportedLocales.size(); i++) {
       LocaleSetting supportedLocale = (LocaleSetting) this.supportedLocales.get(i);
       if (locale.equals(supportedLocale.getLocale())) {
         return supportedLocale;
       }
     }
     return (LocaleSetting) this.supportedLocales.get(0);
   }
 }
 /**
  * Adds a specific setting for a locale, this can be used for allowing different locale dependent
  * encodings, for example.
  *
  * @param setting the setting
  */
 public void addConfiguredLocaleSetting(LocaleSetting setting) {
   Locale[] locales = setting.getLocales();
   if (locales == null) {
     throw new BuildException(
         "Invalid <localesetting> definition - each <localesetting> requires the \"locale\" attribute.");
   }
   if (locales.length == 1) {
     add(setting);
   } else {
     for (int i = 0; i < locales.length; i++) {
       Locale locale = locales[i];
       add(new LocaleSetting(locale, setting));
     }
   }
 }