List of usage examples for org.springframework.context MessageSource getMessage
@Nullable String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale);
From source file:egovframework.rte.fdl.cmmn.trace.LeaveaTrace.java
/** * trace // w w w .ja v a2 s . c om * @param clazz leaveaTrace ? ? * @param messageKey * @param messageParameters ? * @param locale / * @param log ? */ public void trace(Class<?> clazz, MessageSource messageSource, String messageKey, Object[] messageParameters, Locale locale, Log log) { String message = messageSource.getMessage(messageKey, messageParameters, null, locale); if (log != null) { log.info(" LeaveaTrace.trace() this.message =>" + message); } if (traceHandlerServices == null) return; for (TraceHandlerService traceHandlerService : traceHandlerServices) { if (traceHandlerService.hasReqExpMatcher()) { traceHandlerService.setReqExpMatcher(pm); } traceHandlerService.setPackageName(clazz.getCanonicalName()); traceHandlerService.trace(clazz, message); } }
From source file:egovframework.rte.fdl.cmmn.exception.EgovBizException.java
public EgovBizException(MessageSource messageSource, String messageKey, Object[] messageParameters, String defaultMessage, Locale locale, Exception wrappedException) { this.messageKey = messageKey; this.messageParameters = messageParameters; this.message = messageSource.getMessage(messageKey, messageParameters, defaultMessage, locale); this.wrappedException = wrappedException; }
From source file:egovframework.rte.fdl.cmmn.exception.FdlException.java
public FdlException(MessageSource messageSource, String messageKey, Object[] messageParameters, String defaultMessage, Locale locale, Throwable wrappedException) { super(wrappedException); this.messageKey = messageKey; this.messageParameters = messageParameters; this.message = messageSource.getMessage(messageKey, messageParameters, defaultMessage, locale); }
From source file:com.orange.mmp.i18n.helpers.DefaultInternationalizationManager.java
public String getMessage(String messageSourceName, String code, Object[] args, String defaultMessage, Locale locale) throws MMPI18NException { try {// w w w. j av a 2 s. c o m MessageSource messageSource = this.messageSourceMap.get(messageSourceName); if (messageSource != null) { return messageSource.getMessage(code, args, defaultMessage, locale); } else return this.defaultMessageSource.getMessage(code, args, defaultMessage, locale); } catch (NoSuchMessageException nsme) { throw new MMPI18NException(nsme); } }
From source file:com.trenako.values.LocalizedEnum.java
private String getMessage(String code, MessageSource messageSource, MessageFailback<T> failback) { if (messageSource == null) { if (failback != null) { return failback.failbackMessage(val); }// ww w . jav a2 s . c o m return key; } return messageSource.getMessage(code, null, key, null); }
From source file:gex.jaxrs.provider.support.SpringErrorsExtractor.java
public List<String> extractError(Errors errors, MessageSource messageSource) { notNull(errors, "The errors can not be null"); notNull(messageSource, "The messageSource can not be null"); return errors.getFieldErrors().stream().map(fieldError -> { return of(fieldError.getCodes()).map(code -> { log.debug("Searching code: '{}' with arguments '{}' and locale '{}'", code, fieldError.getArguments(), getLocale()); return messageSource.getMessage(code, fieldError.getArguments(), "", getLocale()); }).filter(StringUtils::hasText).findFirst().orElseGet(() -> { log.debug("Searching code: '{}' with arguments '{}', defaultMessage '{}' and locale '{}'", fieldError.getCode(), fieldError.getArguments(), fieldError.getDefaultMessage(), getLocale());/*from w ww.j av a 2 s .co m*/ return messageSource.getMessage(fieldError.getCode(), fieldError.getArguments(), fieldError.getDefaultMessage(), getLocale()); }); }).collect(toList()); }
From source file:egovframework.rte.fdl.cmmn.exception.BaseException.java
/** * BaseException ?? /*from w w w . j ava 2s . co m*/ * @param messageSource * @param messageKey * @param messageParameters ? * @param defaultMessage () * @param locale / * @param wrappedException ? Exception ?. */ public BaseException(MessageSource messageSource, String messageKey, Object[] messageParameters, String defaultMessage, Locale locale, Throwable wrappedException) { super(wrappedException); this.messageKey = messageKey; this.messageParameters = messageParameters; this.message = messageSource.getMessage(messageKey, messageParameters, defaultMessage, locale); }
From source file:org.vaadin.spring.i18n.Translator.java
private void translateFields(Locale locale, MessageSource messageSource) { for (Map.Entry<TranslatedProperty, Field> fieldEntry : translatedFields.entrySet()) { final Field field = fieldEntry.getValue(); final TranslatedProperty annotation = fieldEntry.getKey(); field.setAccessible(true);// www . j a va2 s. com Object fieldValue; try { fieldValue = field.get(target); } catch (IllegalAccessException e) { throw new RuntimeException("Could not access field " + field.getName()); } if (fieldValue != null) { setPropertyValue(fieldValue, annotation.property(), messageSource.getMessage(annotation.key(), null, annotation.defaultValue(), locale)); } } }
From source file:org.vaadin.spring.i18n.Translator.java
private void translatedMethods(Locale locale, MessageSource messageSource) { for (Map.Entry<TranslatedProperty, Method> methodEntry : translatedMethods.entrySet()) { final Method method = methodEntry.getValue(); final TranslatedProperty annotation = methodEntry.getKey(); method.setAccessible(true);//from w w w. j av a2 s . c om Object methodValue; try { methodValue = method.invoke(target); } catch (IllegalAccessException e) { throw new RuntimeException("Could not access method " + method.getName()); } catch (InvocationTargetException e) { throw new RuntimeException("Could not invoke method " + method.getName(), e); } if (methodValue != null) { setPropertyValue(methodValue, annotation.property(), messageSource.getMessage(annotation.key(), null, annotation.defaultValue(), locale)); } } }