- Timestamp:
- Apr 16, 2010, 5:55:54 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/BeanUtil.java
r862 r864 1 1 package de.dass_it.vanhelsing.gui; 2 3 4 2 5 3 import javax.faces.application.FacesMessage; … … 9 7 import java.util.ResourceBundle; 10 8 import java.util.Locale; 11 12 9 import java.util.HashMap; 13 10 14 11 //import org.apache.log4j.Logger; 15 12 16 /* 13 /** 17 14 * Helper class to encapsulate common bean methods. 18 15 * Managed beans will extend this class either directly or … … 20 17 */ 21 18 public class BeanUtil { 22 //Logging 23 24 //protected final Logger logger = Logger.getLogger(this.getClass()); 25 26 //Messagebundles 27 public static String getProperty(String key){ 19 // Logging 20 21 // protected final Logger logger = Logger.getLogger(this.getClass()); 22 23 // Messagebundles 24 /** 25 * getter method for a property value 26 * @param key key of the queried property, e.g. director.client.name.type 27 * @return s value of the property 28 */ 29 public static String getProperty(String key) { 28 30 String s = PropertyBundle.getProperty(key); 29 31 return s; 30 32 } 31 32 public static String[] getProperties(String key){ 33 String[] suffix = {"ref", "type", "required", "def"}; 33 /** 34 * 35 * @param key key contains the key value of the set of properties for a given attribute<br/> 36 * except for the suffix which defines the content type of the property. 37 * @return bundle contains all four properties of an attribute 38 */ 39 public static String[] getProperties(String key) { 40 String[] suffix = { "ref", "type", "required", "def" }; 34 41 String[] bundle = new String[4]; 35 42 for (int i = 0; i < 4; i++) { 36 bundle[i] = BeanUtil.getProperty(key +"."+suffix[i]);43 bundle[i] = BeanUtil.getProperty(key + "." + suffix[i]); 37 44 } 38 45 return bundle; 39 46 } 40 public static boolean getRequired(String type, String key){ 47 /** 48 * 49 * @param type resource type of the attribute, like Client 50 * @param key attribute name of the resource, like Port 51 * @return true if the field is required or false 52 */ 53 public static boolean getRequired(String type, String key) { 41 54 String s = getFieldProperty(type, key, 2); 42 if (s.equals("true") )return true; 55 if (s.equals("true")) 56 return true; 43 57 return false; 44 58 } 45 public static String getDataType(String type, String key){ 59 /** 60 * returns the data type of a given attribute. 61 * @param type resource type of the attribute, like Client 62 * @param key attribute name of the resource, like Port 63 * @return data type of the attribute 64 */ 65 public static String getDataType(String type, String key) { 46 66 return getFieldProperty(type, key, 1); 47 67 } 48 //getRenderer returns rendererType based on properties 49 public static String getRenderer(String type, String key){ 68 69 // getRenderer returns rendererType based on properties 70 /** 71 * returns the renderer for a given attribute 72 * @param type resource type of the attribute, like Client 73 * @param key attribute name of the resource, like Port 74 * @return "inputText", "radioGroup" or "selectOneMenu" 75 * 76 */ 77 public static String getRenderer(String type, String key) { 50 78 return getFieldProperty(type, key, 0); 51 79 } 52 public static String getFieldProperty(String type, String key, int i){ 80 /** 81 * returns properties for a given attribute depending on the value of i. 82 * One should use the getter method for the property. 83 * @param type resource type of the attribute, like Client 84 * @param key attribute name of the resource, like Port 85 * @param i i maybe between 0 and 3. The return value of the method is selected by the value of i 86 * @return one of the four properties as a String of a given attribute. 87 */ 88 public static String getFieldProperty(String type, String key, int i) { 53 89 String daemon = "director"; 54 90 String res = "inputText"; 55 if (type.startsWith("SD")) {91 if (type.startsWith("SD")) { 56 92 daemon = "storagedaemon"; 57 93 } 58 if (type.startsWith("FD")) {94 if (type.startsWith("FD")) { 59 95 daemon = "filedaemon"; 60 96 } … … 62 98 key = key.toLowerCase(); 63 99 key = key.replaceAll(" ", ""); 64 String result[] = getProperties((daemon +"."+type+"."+key));100 String result[] = getProperties((daemon + "." + type + "." + key)); 65 101 if (i == 0) { 66 if (result[1].equals("boolean")) {67 return "radioGroup"; 102 if (result[1].equals("boolean")) { 103 return "radioGroup"; 68 104 } 69 if (!(result[0].equals("0"))) {105 if (!(result[0].equals("0"))) { 70 106 return "selectOneMenu"; 71 } 107 } 72 108 return res; 73 109 } 74 if (i == 2) return result[2]; 75 if (i == 1) return result[1]; 76 if (i == 3) return result[3]; 110 if (i == 2) 111 return result[2]; 112 if (i == 1) 113 return result[1]; 114 if (i == 3) 115 return result[3]; 77 116 return res; 78 117 } 79 80 //Statusmeldungen an den Client 81 public static void setInfoMessage(String client, String message){ 82 FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_INFO, message, message)); 83 } 84 public static void setErrorMessage(String client, String message){ 85 FacesContext.getCurrentInstance().addMessage(client, new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message)); 86 } 87 88 //Linkout to Bacula documentation 89 //ListItemsConfigView 90 //ListItemsTopologyView 91 //ListItemsJobSchedule 92 93 //GetParameterFromContext 94 public static String getRequestParameter(String name){ 95 return (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name); 118 119 // Statusmeldungen an den Client 120 /** 121 * sends an information type message to the message field at the bottom of the screen 122 * @param client could contain an identifier of a client. value can be set to null 123 * @param message the message to be displayed at the clients view 124 */ 125 public static void setInfoMessage(String client, String message) { 126 FacesContext.getCurrentInstance().addMessage(client, 127 new FacesMessage(FacesMessage.SEVERITY_INFO, message, message)); 96 128 } 97 98 public static String getAccessType(String type){ 99 if (type.equals("jobdefs")) return "job"; 129 /** 130 * sends an error type message to the message field at the bottom of the screen 131 * @param client could contain an identifier of a client. value can be set to null 132 * @param message the message to be displayed at the clients view 133 */ 134 public static void setErrorMessage(String client, String message) { 135 FacesContext.getCurrentInstance() 136 .addMessage( 137 client, 138 new FacesMessage(FacesMessage.SEVERITY_ERROR, message, 139 message)); 140 } 141 142 // Linkout to Bacula documentation 143 // ListItemsConfigView 144 // ListItemsTopologyView 145 // ListItemsJobSchedule 146 147 // GetParameterFromContext 148 /** 149 * returns values of a given parameter of the FacesContext 150 * @param name name of the parameter e.g. the id of a parameter in the view. 151 * @return value of a given parameter 152 */ 153 public static String getRequestParameter(String name) { 154 return (String) FacesContext.getCurrentInstance().getExternalContext() 155 .getRequestParameterMap().get(name); 156 } 157 /** 158 * translation method for resource or object names. 159 * @param type untranslated name 160 * @return translated name if there is a translation. Otherwise type will be returned. 161 */ 162 public static String getAccessType(String type) { 163 String result = new String(); 164 HashMap<String, String> map = new HashMap<String, String>(); 165 map.put("jobdefs", "job"); 166 map.put("SDStorage", "Storage"); 167 map.put("Storage", "SDStorage"); 168 map.put("SDDevice", "Device"); 169 map.put("Device", "SDDevice"); 170 map.put("SDDevice", "Device"); 171 result = map.get(type); 172 if (result != null) 173 return result; 100 174 return type; 101 175 } 102 176 103 177 }
Note:
See TracChangeset
for help on using the changeset viewer.