Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * 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();
 }
Exemplo n.º 3
0
 /**
  * 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);
   }
 }