1 24 package org.riotfamily.common.io; 25 26 import java.io.Reader ; 27 import java.util.Locale ; 28 29 import org.springframework.context.MessageSource; 30 31 public class MessageFilterReader extends AbstractTokenFilterReader { 32 33 private MessageSource messageSource; 34 35 private String prefix; 36 37 private Locale locale; 38 39 public MessageFilterReader(Reader in, MessageSource messageSource, 40 Locale locale) { 41 42 this (in, messageSource, locale, null); 43 } 44 45 public MessageFilterReader(Reader in, MessageSource messageSource, 46 Locale locale, String prefix) { 47 48 super(in); 49 this.messageSource = messageSource; 50 this.locale = locale; 51 this.prefix = prefix; 52 } 53 54 public void setPrefix(String prefix) { 55 this.prefix = prefix; 56 } 57 58 protected String getReplacement(String key) { 59 if (prefix != null) { 60 key = prefix + key; 61 } 62 return messageSource.getMessage(key, null, key, locale); 63 } 64 } 65 | Popular Tags |