コード例 #1
0
 /** Initialize the MessageSource. Use parent's if none defined in this context. */
 protected void initMessageSource() {
   ConfigurableListableBeanFactory beanFactory = getBeanFactory();
   if (beanFactory.containsLocalBean(MESSAGE_SOURCE_BEAN_NAME)) {
     this.messageSource = beanFactory.getBean(MESSAGE_SOURCE_BEAN_NAME, MessageSource.class);
     // Make MessageSource aware of parent MessageSource.
     if (this.parent != null && this.messageSource instanceof HierarchicalMessageSource) {
       HierarchicalMessageSource hms = (HierarchicalMessageSource) this.messageSource;
       if (hms.getParentMessageSource() == null) {
         // Only set parent context as parent MessageSource if no parent MessageSource
         // registered already.
         hms.setParentMessageSource(getInternalParentMessageSource());
       }
     }
     if (logger.isDebugEnabled()) {
       logger.debug("Using MessageSource [" + this.messageSource + "]");
     }
   } else {
     // Use empty MessageSource to be able to accept getMessage calls.
     DelegatingMessageSource dms = new DelegatingMessageSource();
     dms.setParentMessageSource(getInternalParentMessageSource());
     this.messageSource = dms;
     beanFactory.registerSingleton(MESSAGE_SOURCE_BEAN_NAME, this.messageSource);
     if (logger.isDebugEnabled()) {
       logger.debug(
           "Unable to locate MessageSource with name '"
               + MESSAGE_SOURCE_BEAN_NAME
               + "': using default ["
               + this.messageSource
               + "]");
     }
   }
 }
コード例 #2
0
  private String getInvitationTextForGameType(final String gameType) {
    if (gameType != null) {
      final String cleanedGameType = gameType.split("_IN_GAME")[0];
      try {
        final String invitationText =
            resourceBundleMessageSource.getMessage(
                "invite." + cleanedGameType + ".text", null, null);

        if (StringUtils.isNotBlank(invitationText)) {
          return invitationText;
        }
      } catch (NoSuchMessageException e) {
        LOG.warn("couldn't find message text for invite.{}.text", cleanedGameType, e);
      }
    }

    return resourceBundleMessageSource.getMessage("invite.default.text", null, null);
  }