Example usage for org.springframework.context NoSuchMessageException NoSuchMessageException

List of usage examples for org.springframework.context NoSuchMessageException NoSuchMessageException

Introduction

In this page you can find the example usage for org.springframework.context NoSuchMessageException NoSuchMessageException.

Prototype

public NoSuchMessageException(String code, Locale locale) 

Source Link

Document

Create a new exception.

Usage

From source file:org.agatom.springatom.webmvc.controllers.SVLocaleController.java

@Override
public String getMessage(final String key, final Locale locale) throws Exception {
    try {//from   w  w w . java 2  s  .  co  m
        final String message = this.messageSource.getMessage(key, locale);
        if (message == null || message.trim().equalsIgnoreCase(key)) {
            throw new NoSuchMessageException(key, locale);
        }
        return message;
    } catch (NoSuchMessageException exp) {
        throw new CTNotFoundException(exp);
    }
}

From source file:ch.silviowangler.dox.AutomaticTranslatorAdvice.java

private String getTranslation(String messageKey, Locale locale) {
    try {/*from   www . ja  v a2s .co  m*/
        return messageSource.getMessage("translationadvice.no.translation.available",
                new Object[] { messageKey, locale }, locale);
    } catch (NoSuchMessageException e1) {
        if (Locale.GERMAN.equals(locale)) {
            throw new NoSuchMessageException(messageKey, locale);
        }
        return getTranslation(messageKey, Locale.GERMAN);
    }
}

From source file:org.springframework.context.support.AbstractMessageSource.java

public final String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
    String msg = getMessageInternal(code, args, locale);
    if (msg != null) {
        return msg;
    }/* w w  w  .j a  va2 s .c om*/
    String fallback = getDefaultMessage(code);
    if (fallback != null) {
        return fallback;
    }
    throw new NoSuchMessageException(code, locale);
}

From source file:org.springframework.context.support.AbstractMessageSource.java

public final String getMessage(MessageSourceResolvable resolvable, Locale locale)
        throws NoSuchMessageException {

    String[] codes = resolvable.getCodes();
    if (codes == null) {
        codes = new String[0];
    }//w ww . j av a 2s.  co  m
    for (int i = 0; i < codes.length; i++) {
        String msg = getMessageInternal(codes[i], resolvable.getArguments(), locale);
        if (msg != null) {
            return msg;
        }
    }
    if (resolvable.getDefaultMessage() != null) {
        return renderDefaultMessage(resolvable.getDefaultMessage(), resolvable.getArguments(), locale);
    }
    if (codes.length > 0) {
        String fallback = getDefaultMessage(codes[0]);
        if (fallback != null) {
            return fallback;
        }
    }
    throw new NoSuchMessageException(codes.length > 0 ? codes[codes.length - 1] : null, locale);
}