Rev | Line | |
---|
[857] | 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 | return properties.getString(key);
|
---|
| 28 | } catch (Exception e) {
|
---|
| 29 | System.err.println(key+" / "+e.toString());
|
---|
| 30 | }
|
---|
| 31 | return null;
|
---|
| 32 | }
|
---|
| 33 | public static String[] getTypeProperties(String partialKey){
|
---|
| 34 | Enumeration<String> keySet = properties.getKeys();
|
---|
| 35 | String key;
|
---|
| 36 | int i = 0;
|
---|
| 37 | ArrayList<String> result = new ArrayList<String>();
|
---|
| 38 |
|
---|
| 39 | while(keySet.hasMoreElements()){
|
---|
| 40 | key = keySet.nextElement();
|
---|
| 41 | if (key.startsWith(partialKey)){
|
---|
| 42 | result.add(getProperty(key));
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 | result.trimToSize();
|
---|
| 46 | return result.toArray(new String[0]);
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.