Line | |
---|
1 | package de.dass_it.vanhelsing.gui;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Enumeration;
|
---|
5 | import java.util.Locale;
|
---|
6 | import java.util.ResourceBundle;
|
---|
7 | import javax.faces.context.FacesContext;
|
---|
8 |
|
---|
9 | public class PropertyBundle{
|
---|
10 |
|
---|
11 | private static ResourceBundle properties;
|
---|
12 | private static final String path = "de.dass_it.vanhelsing.gui.messages";
|
---|
13 |
|
---|
14 | private static void initialize(){
|
---|
15 | Locale l = FacesContext.getCurrentInstance().getViewRoot().getLocale();
|
---|
16 |
|
---|
17 | if (l == null){
|
---|
18 | l = Locale.ENGLISH;
|
---|
19 | }
|
---|
20 | properties = ResourceBundle.getBundle(path, l);
|
---|
21 | }
|
---|
22 | public static String getProperty(String key){
|
---|
23 | try{
|
---|
24 | if (properties == null){
|
---|
25 | initialize();
|
---|
26 | }
|
---|
27 | key = key.toLowerCase();
|
---|
28 | return properties.getString(key);
|
---|
29 | } catch (Exception e) {
|
---|
30 | System.err.println(key+" / "+e.toString());
|
---|
31 | }
|
---|
32 | return null;
|
---|
33 | }
|
---|
34 | public static String[] getTypeProperties(String partialKey){
|
---|
35 | Enumeration<String> keySet = properties.getKeys();
|
---|
36 | String key;
|
---|
37 | int i = 0;
|
---|
38 | ArrayList<String> result = new ArrayList<String>();
|
---|
39 |
|
---|
40 | while(keySet.hasMoreElements()){
|
---|
41 | key = keySet.nextElement();
|
---|
42 | if (key.startsWith(partialKey)){
|
---|
43 | result.add(getProperty(key));
|
---|
44 | }
|
---|
45 | }
|
---|
46 | result.trimToSize();
|
---|
47 | return result.toArray(new String[0]);
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.