Spring Framework MessageSource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework MessageSource class.

This code example shows how to use the following methods:getMessage
	} 
 
	@Override 
	public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
		if (this.parentMessageSource != null) {
			return this.parentMessageSource.getMessage(code, args, locale);
		} 
		else { 
			throw new NoSuchMessageException(code, locale);
		} 
	} 
 
	@Override 
	public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
		if (this.parentMessageSource != null) {
			return this.parentMessageSource.getMessage(resolvable, locale);
		} 
		else { 
			if (resolvable.getDefaultMessage() != null) {
				return renderDefaultMessage(resolvable.getDefaultMessage(), resolvable.getArguments(), locale);
6
CodeRank
This code example shows how to use the following methods:getMessage
			HttpServletResponse response, Object handler, Exception ex) throws Exception { 
 
		int statusCode = responseStatus.value().value(); 
		String reason = responseStatus.reason(); 
		if (this.messageSource != null) { 
			reason = this.messageSource.getMessage(reason, null, reason, LocaleContextHolder.getLocale()); 
		} 
		if (!StringUtils.hasLength(reason)) { 
			response.sendError(statusCode); 
		} 
		else { 
			response.sendError(statusCode, reason); 
		} 
		return new ModelAndView(); 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getMessage
	 * Returns {@code null} if the message could not be resolved. 
	 */ 
	@Override 
	protected Object handleGetObject(String key) { 
		try { 
			return this.messageSource.getMessage(key, null, this.locale); 
		} 
		catch (NoSuchMessageException ex) { 
			return null; 
		} 
	} 
 
	/** 
	 * This implementation checks whether the target MessageSource can resolve 
	 * a message for the given key, translating {@code NoSuchMessageException} 
	 * accordingly. In contrast to ResourceBundle's default implementation in 
	 * JDK 1.6, this does not rely on the capability to enumerate message keys. 
	 */ 
	@Override 
	public boolean containsKey(String key) { 
6
CodeRank
This code example shows how to use the following methods:getMessage
	 * @param args arguments for the message, or {@code null} if none 
	 * @return the message 
	 * @throws org.springframework.context.NoSuchMessageException if not found 
	 */ 
	public String getMessage(String code, Object[] args) throws NoSuchMessageException {
		return this.messageSource.getMessage(code, args, getDefaultLocale());
	} 
 
	/** 
	 * Retrieve the message for the given code and the given Locale. 
	 * @param code code of the message 
	 * @param args arguments for the message, or {@code null} if none 
	 * @param locale Locale in which to do lookup 
	 * @return the message 
	 * @throws org.springframework.context.NoSuchMessageException if not found 
	 */ 
	public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
		return this.messageSource.getMessage(code, args, locale);
	} 
 
5
CodeRank
This code example shows how to use the following methods:getMessage
    protected void initBinder(HttpServletRequest request, 
                              ServletRequestDataBinder binder) { 
        binder.registerCustomEditor(Integer.class, null, 
                                    new CustomNumberEditor(Integer.class, null, true)); 
        binder.registerCustomEditor(Long.class, null, 
                                    new CustomNumberEditor(Long.class, null, true)); 
        binder.registerCustomEditor(byte[].class, 
                                    new ByteArrayMultipartFileEditor()); 
        SimpleDateFormat dateFormat =  
            new SimpleDateFormat(getText("date.format", request.getLocale())); 
        dateFormat.setLenient(false); 
        binder.registerCustomEditor(Date.class, null,  
                                    new CustomDateEditor(dateFormat, true)); 
    } 
 
    /** 
     * Convenience message to send messages to users, includes app URL as footer. 
     * @param user the user to send a message to. 
     * @param msg the message to send. 
     * @param url the URL of the application. 
4
CodeRank
This code example shows how to use the following methods:getMessage
 
	public String getMessage(Object object, Object[] args, Locale locale) throws NoSuchObjectMessageException {
		String message = getFullyResolvedMessage(object, args, locale, false);
		if (message == null && object != null) {
			throw new NoSuchObjectMessageException(object, locale);
		} 
		return message;
	} 
 
	/** 
	 * Returns a fully resolved message, includes resolving any message parameters. 
	 * @param object the object to resolve. Can be <tt>null</tt> 
	 * @param args the message arguments 
	 * @param locale the locale 
	 * @param allowResolveToString if the {@link #resolveToString(Object)} can be used to create the result 
	 * @return a fully resolved message 
	 */ 
	private String getFullyResolvedMessage(Object object, Object[] args, Locale locale, boolean allowResolveToString) {
		if (object == null) {
			return null; 
4
CodeRank
This code example shows how to use the following methods:getMessage
    protected void initBinder(HttpServletRequest request, 
                              ServletRequestDataBinder binder) { 
        binder.registerCustomEditor(Integer.class, null, 
                                    new CustomNumberEditor(Integer.class, null, true)); 
        binder.registerCustomEditor(Long.class, null, 
                                    new CustomNumberEditor(Long.class, null, true)); 
        binder.registerCustomEditor(byte[].class, 
                                    new ByteArrayMultipartFileEditor()); 
        SimpleDateFormat dateFormat =  
            new SimpleDateFormat(getText("date.format", request.getLocale())); 
        dateFormat.setLenient(false); 
        binder.registerCustomEditor(Date.class, null,  
                                    new CustomDateEditor(dateFormat, true)); 
    } 
 
    /** 
     * Convenience message to send messages to users, includes app URL as footer. 
     * @param user the user to send a message to. 
     * @param msg the message to send. 
     * @param url the URL of the application. 
4
CodeRank
See Code Examples for Spring Framework MessageSource Methods: