@Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((template == null) ? 0 : template.hashCode());
   result = prime * result + ((textDefault == null) ? 0 : textDefault.hashCode());
   result = prime * result + ((textKey == null) ? 0 : textKey.hashCode());
   result = prime * result + ((detailKey == null) ? 0 : detailKey.hashCode());
   return result;
 }
  public Message build() {
    String text;
    try {
      text = bundles.get(clientLocale, textKey.getBundle()).getString(textKey.getKey());
    } catch (Exception e) {
      log.warn("Could not load bundle: " + textKey);
      text = textDefault;
    }

    if ((text == null) || "".equals(text)) {
      text = textKey.toString();
    }

    template.text(text);
    return template.build();
  }
 @Override
 public boolean equals(final Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null) {
     return false;
   }
   if (getClass() != obj.getClass()) {
     return false;
   }
   BundleTemplateMessageImpl other = (BundleTemplateMessageImpl) obj;
   if (template == null) {
     if (other.template != null) {
       return false;
     }
   } else if (!template.equals(other.template)) {
     return false;
   }
   if (textDefault == null) {
     if (other.textDefault != null) {
       return false;
     }
   } else if (!textDefault.equals(other.textDefault)) {
     return false;
   }
   if (textKey == null) {
     if (other.textKey != null) {
       return false;
     }
   } else if (!textKey.equals(other.textKey)) {
     return false;
   }
   return true;
 }
Exemplo n.º 4
0
  // This method is synchronized so that the cache is properly
  // handled.
  public static synchronized ResourceBundle getBundle(
      String baseName, Locale locale, ClassLoader classLoader) {
    Locale defaultLocale = Locale.getDefault();
    // This will throw NullPointerException if any arguments are null.
    lookupKey.set(defaultLocale, baseName, locale, classLoader);
    Object obj = bundleCache.get(lookupKey);
    if (obj instanceof ResourceBundle) return (ResourceBundle) obj;

    if (obj == nullEntry)
      throw new MissingResourceException(
          "Bundle "
              + baseName
              + " not found for locale "
              + locale
              + " by classloader "
              + classLoader,
          baseName,
          "");
    // First, look for a bundle for the specified locale. We don't want
    // the base bundle this time.
    boolean wantBase = locale.equals(defaultLocale);
    ResourceBundle bundle = tryBundle(baseName, locale, classLoader, wantBase);
    // Try the default locale if neccessary.
    if (bundle == null && !wantBase) bundle = tryBundle(baseName, defaultLocale, classLoader, true);

    BundleKey key = new BundleKey(defaultLocale, baseName, locale, classLoader);
    if (bundle == null) {
      // Cache the fact that this lookup has previously failed.
      bundleCache.put(key, nullEntry);
      throw new MissingResourceException(
          "Bundle "
              + baseName
              + " not found for locale "
              + locale
              + " by classloader "
              + classLoader,
          baseName,
          "");
    }
    // Cache the result and return it.
    bundleCache.put(key, bundle);
    return bundle;
  }