public String getMessage(String code, Object args[], String defaultMessage, Locale locale) {
   try {
     return messageSource.getMessage(code, args, defaultMessage, locale);
   } catch (Exception e) {
     LOG.error(
         "This message key doesn't exist: " + code + ", for this locale: " + locale.toString());
     if (BooleanUtils.negate(locale.toString().equalsIgnoreCase(Constants.DEFAULT_LOCALE_CODE))) {
       return getMessage(code, args, defaultMessage, new Locale(Constants.DEFAULT_LOCALE_CODE));
     }
   }
   return null;
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.hoteia.qalingo.core.i18n.message.CoreMessageSource#getMessage(java
  * .lang.String, java.lang.Object[], java.util.Locale)
  */
 public String getMessage(final String code, final Object args[], final Locale locale)
     throws NoSuchMessageException {
   try {
     return messageSource.getMessage(code, args, locale);
   } catch (Exception e) {
     logger.info(
         "This message key doesn't exist: " + code + ", for this locale: " + locale.toString());
     if (BooleanUtils.negate(locale.toString().equalsIgnoreCase(Constants.DEFAULT_LOCALE_CODE))) {
       return getMessage(code, args, new Locale(Constants.DEFAULT_LOCALE_CODE));
     }
   }
   return null;
 }
 public String getMessage(MessageSourceResolvable resolvable, Locale locale)
     throws NoSuchMessageException {
   try {
     return messageSource.getMessage(resolvable, locale);
   } catch (Exception e) {
     LOG.error(
         "This message key doesn't exist: "
             + resolvable.getCodes()
             + ", for this locale: "
             + locale.toString());
     if (BooleanUtils.negate(locale.toString().equalsIgnoreCase(Constants.DEFAULT_LOCALE_CODE))) {
       return getMessage(resolvable, new Locale(Constants.DEFAULT_LOCALE_CODE));
     }
   }
   return null;
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.hoteia.qalingo.core.i18n.message.CoreMessageSource#getMessage(java
  * .lang.String, java.lang.Object[], java.lang.String, java.util.Locale)
  */
 public String getMessage(
     final String code, final Object args[], final String defaultMessage, final Locale locale) {
   try {
     return messageSource.getMessage(code, args, defaultMessage, locale);
   } catch (Exception e) {
     if (code != null && code.contains("javax")) {
       logger.info(
           "This message key doesn't exist: " + code + ", for this locale: " + locale.toString());
     } else {
       logger.info(
           "This message key doesn't exist: " + code + ", for this locale: " + locale.toString());
     }
     if (BooleanUtils.negate(locale.toString().equalsIgnoreCase(Constants.DEFAULT_LOCALE_CODE))) {
       return getMessage(code, args, defaultMessage, new Locale(Constants.DEFAULT_LOCALE_CODE));
     }
   }
   return null;
 }
  private CatalogCategoryMasterAttribute getCatalogCategoryAttribute(
      Set<CatalogCategoryMasterAttribute> catalogCategoryAttributes,
      String attributeCode,
      Long marketAreaId,
      String localizationCode) {
    CatalogCategoryMasterAttribute catalogCategoryAttributeToReturn = null;
    List<CatalogCategoryMasterAttribute> catalogCategoryAttributesFilter =
        new ArrayList<CatalogCategoryMasterAttribute>();
    if (catalogCategoryAttributes != null) {
      // GET ALL CategoryAttributes FOR THIS ATTRIBUTE
      for (Iterator<CatalogCategoryMasterAttribute> iterator = catalogCategoryAttributes.iterator();
          iterator.hasNext(); ) {
        CatalogCategoryMasterAttribute catalogCategoryAttribute =
            (CatalogCategoryMasterAttribute) iterator.next();
        AttributeDefinition attributeDefinition = catalogCategoryAttribute.getAttributeDefinition();
        if (attributeDefinition != null
            && attributeDefinition.getCode().equalsIgnoreCase(attributeCode)) {
          catalogCategoryAttributesFilter.add(catalogCategoryAttribute);
        }
      }
      // REMOVE ALL CategoryAttributes NOT ON THIS MARKET AREA
      if (marketAreaId != null) {
        for (Iterator<CatalogCategoryMasterAttribute> iterator =
                catalogCategoryAttributesFilter.iterator();
            iterator.hasNext(); ) {
          CatalogCategoryMasterAttribute catalogCategoryAttribute =
              (CatalogCategoryMasterAttribute) iterator.next();
          AttributeDefinition attributeDefinition =
              catalogCategoryAttribute.getAttributeDefinition();
          if (BooleanUtils.negate(attributeDefinition.isGlobal())) {
            if (catalogCategoryAttribute.getMarketAreaId() != null
                && BooleanUtils.negate(
                    catalogCategoryAttribute.getMarketAreaId().equals(marketAreaId))) {
              iterator.remove();
            }
          }
        }
      }
      // FINALLY RETAIN ONLY CategoryAttributes FOR THIS LOCALIZATION CODE
      if (StringUtils.isNotEmpty(localizationCode)) {
        for (Iterator<CatalogCategoryMasterAttribute> iterator =
                catalogCategoryAttributesFilter.iterator();
            iterator.hasNext(); ) {
          CatalogCategoryMasterAttribute catalogCategoryAttribute =
              (CatalogCategoryMasterAttribute) iterator.next();
          AttributeDefinition attributeDefinition =
              catalogCategoryAttribute.getAttributeDefinition();
          if (BooleanUtils.negate(attributeDefinition.isGlobal())) {
            String attributeLocalizationCode = catalogCategoryAttribute.getLocalizationCode();
            if (StringUtils.isNotEmpty(attributeLocalizationCode)
                && BooleanUtils.negate(attributeLocalizationCode.equals(localizationCode))) {
              iterator.remove();
            }
          }
        }
        if (catalogCategoryAttributesFilter.size() == 0) {
          // TODO : warning ?

          // NOT ANY CategoryAttributes FOR THIS LOCALIZATION CODE - GET A FALLBACK
          for (Iterator<CatalogCategoryMasterAttribute> iterator =
                  catalogCategoryMarketAreaAttributes.iterator();
              iterator.hasNext(); ) {
            CatalogCategoryMasterAttribute catalogCategoryAttribute =
                (CatalogCategoryMasterAttribute) iterator.next();

            // TODO : get a default locale code from setting database ?

            if (Constants.DEFAULT_LOCALE_CODE.equals(
                catalogCategoryAttribute.getLocalizationCode())) {
              catalogCategoryAttributeToReturn = catalogCategoryAttribute;
            }
          }
        }
      }
    }

    if (catalogCategoryAttributesFilter.size() == 1) {
      catalogCategoryAttributeToReturn = catalogCategoryAttributesFilter.get(0);
    } else {
      // TODO : throw error ?
    }

    return catalogCategoryAttributeToReturn;
  }