package de.lessvoid.xml.tools;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

/**
 * A BundleInfo that will use an already existing ResourceBundle. 
 * @author void
 */
public class BundleInfoResourceBundle implements BundleInfo {
  private final ResourceBundle defaultResourceBundle;
  private Map<Locale, ResourceBundle> resourceBundles = new HashMap<Locale, ResourceBundle>();

  public BundleInfoResourceBundle(final ResourceBundle resourceBundle) {
    this.defaultResourceBundle = resourceBundle;
    resourceBundles.put(resourceBundle.getLocale(), resourceBundle);
  }

  public void add(final ResourceBundle resourceBundle) {
    resourceBundles.put(resourceBundle.getLocale(), resourceBundle);
  }

  @Override
  public String getString(final String resourceKey, final Locale locale) {
    ResourceBundle res;
    if (locale == null) {
      res = defaultResourceBundle;
    } else {
      res = resourceBundles.get(locale);
    }
    return res.getString(resourceKey);
  }
}

@@ -988,16 +988,86 @@
 ocale);%0A
+      if (res == null) %7B%0A        res = defaultResourceBundle;%0A      %7D%0A
     %7D%0A  

return defaultResourceBundle in case no exact match could be found