View Javadoc
1   /**
2    * Copyright 2011-2013 The Kuali Foundation Licensed under the Educational
3    * Community License, Version 2.0 (the "License"); you may not use this file
4    * except in compliance with the License. You may obtain a copy of the License
5    * at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12   * License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package org.kuali.mobility.util;
16  
17  import java.text.MessageFormat;
18  import java.util.Locale;
19  
20  import org.kuali.mobility.l10n.entity.LocalisedString;
21  import org.kuali.mobility.l10n.service.LocalisationService;
22  import org.springframework.beans.factory.annotation.Autowired;
23  import org.springframework.beans.factory.annotation.Qualifier;
24  import org.springframework.context.support.AbstractMessageSource;
25  
26  /**
27   * A message source used by KME.
28   * This message source can be configured to read string from the database
29   * @author Kuali Mobility Team (mobility.collab@kuali.org)
30   * @since 
31   */
32  public class KMEMessageSource extends AbstractMessageSource{
33  
34  	/**
35  	 * A reference to the <code>LocalisationService</code>
36  	 */
37  	@Autowired
38  	@Qualifier("localisationService")
39  	private LocalisationService localisationService;
40  	
41  	/**
42  	 * Initialised this message source
43  	 */
44  	public void initialise(){
45  	}
46  	
47  	
48  	/* (non-Javadoc)
49  	 * @see org.springframework.context.support.AbstractMessageSource#resolveCode(java.lang.String, java.util.Locale)
50  	 */
51  	@Override
52  	protected MessageFormat resolveCode(String code, Locale locale) {
53  		LocalisedString ls = localisationService.getLocalisedString(code, locale.getLanguage());
54  		if (ls != null){
55  			return createMessageFormat(ls.getContent(), locale);
56  		}
57  		return null;
58  	}
59  
60  }