1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  package org.kuali.mobility.util;
16  
17  import java.util.Collections;
18  import java.util.HashMap;
19  import java.util.List;
20  import java.util.Map;
21  
22  import javax.annotation.Resource;
23  import javax.servlet.http.HttpServletRequest;
24  
25  import org.springframework.context.annotation.DependsOn;
26  import org.springframework.stereotype.Component;
27  
28  
29  
30  
31  
32  
33  @Component(value="localisationUtil")
34  @DependsOn(value={"supportedLanguages"})
35  public class LocalisationUtil {
36  
37  	
38  
39  
40  	@Resource(name="supportedLanguages")
41  	private List<String> supportedLanguages;
42  	
43  	
44  
45  
46  
47  
48  
49  	public Map<String, String> getLocalisedString(String fieldName, HttpServletRequest request){
50  		Map<String, String> fieldMap = new HashMap<String, String>();
51  		
52  		String value;
53  		for(String language : this.supportedLanguages){
54  			value = request.getParameter(fieldName + "." + language);
55  			if(value != null){
56  				fieldMap.put(language, value);
57  			}
58  		}
59  		return fieldMap;
60  	}
61  	
62  	
63  
64  
65  
66  
67  
68  
69  
70  	public String getLocalisedStringCode(String fieldName, HttpServletRequest request){
71  		String code = request.getParameter(fieldName + ".code");
72  		return code == null ? generateNewCode() : code;
73  	}
74  	
75  	
76  
77  
78  
79  	public List<String> getSupportedLanguages(){
80  		return Collections.unmodifiableList(supportedLanguages);
81  	}
82  	
83  	
84  
85  
86  
87  
88  	public boolean isSupportedLanguage(String language){
89  		return supportedLanguages.contains(language);
90  	}
91  	
92  	
93  
94  
95  
96  	private String generateNewCode(){
97  		
98  		return System.currentTimeMillis() + "";
99  	}
100 }