source: vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/PropertyBundle.java@ 865

Last change on this file since 865 was 865, checked in by tobias, on Apr 20, 2010 at 5:21:42 PM

comments added
all methods of the wsdl file implemented

File size: 1.9 KB
Line 
1package de.dass_it.vanhelsing.gui;
2
3import java.util.ArrayList;
4import java.util.Enumeration;
5import java.util.Locale;
6import java.util.ResourceBundle;
7import javax.faces.context.FacesContext;
8/**
9 * Class containing the methods used to access the messages property bundle
10 * @author tgoecke
11 *
12 */
13public class PropertyBundle{
14
15 private static ResourceBundle properties;
16 private static final String path = "de.dass_it.vanhelsing.gui.messages";
17 /**
18 * reads the messages property file
19 */
20 private static void initialize(){
21 Locale l = FacesContext.getCurrentInstance().getViewRoot().getLocale();
22
23 if (l == null){
24 l = Locale.ENGLISH;
25 }
26 properties = ResourceBundle.getBundle(path, l);
27 }
28 /**
29 * method returns a single value of a given key
30 * @param key key of
31 * @return value of the property identified by key. If an exception is thrown, null will be returned
32 */
33 public static String getProperty(String key){
34 try{
35 if (properties == null){
36 initialize();
37 }
38 key = key.toLowerCase();
39 return properties.getString(key);
40 } catch (Exception e) {
41 System.err.println(key+" / "+e.toString());
42 }
43 return null;
44 }
45 /**
46 * method to retrieve properties with a partial key. a partial key is the first n characters of a key
47 *
48 * @param partialKey first n characters of a property key
49 * @return an array of values whose keys started with partialKey. an empty array is returned if no matchings have been found
50 */
51 public static String[] getTypeProperties(String partialKey){
52 Enumeration<String> keySet = properties.getKeys();
53 String key;
54 int i = 0;
55 ArrayList<String> result = new ArrayList<String>();
56
57 while(keySet.hasMoreElements()){
58 key = keySet.nextElement();
59 if (key.startsWith(partialKey)){
60 result.add(getProperty(key));
61 }
62 }
63 result.trimToSize();
64 if (result.size()>0) return (String[]) result.toArray();
65 return result.toArray(new String[0]);
66 }
67}
68
Note: See TracBrowser for help on using the repository browser.